diff --git a/tools_python/pr.py b/tools_python/pr.py index b4a9bf7..0f8e1f2 100644 --- a/tools_python/pr.py +++ b/tools_python/pr.py @@ -2,12 +2,11 @@ # 2018 furrtek - furrtek.org # See LICENSE -def terminate_frame(frame, repeats): - # Compute whole frame's CRC16 +def crc16(data): result = 0x8408 poly = 0x8408 - for by in frame: + for by in data: result ^= by for bi in range(0, 8): if (result & 1): @@ -16,8 +15,12 @@ def terminate_frame(frame, repeats): else: result >>= 1 - frame.append(result & 255) - frame.append((result // 256) & 255) + return result + +def terminate_frame(frame, repeats): + crc = crc16(frame) + frame.append(crc & 255) + frame.append((crc // 256) & 255) frame.append(repeats & 255) # This is used by the transmitter, it's not part of the transmitted data frame.append((repeats // 256) & 255) # This is used by the transmitter, it's not part of the transmitted data diff --git a/tools_python/setsegs.py b/tools_python/setsegs.py new file mode 100644 index 0000000..0720fb5 --- /dev/null +++ b/tools_python/setsegs.py @@ -0,0 +1,68 @@ +# Allows setting ESL segments +# 2019 furrtek - furrtek.org +# See LICENSE + +import pr +import tx +import sys + +def usage(): + print("Usage:") + print("setsegs.py port barcode bitmap\n") + print(" port: serial port name (0 for ESL Blaster)") + print(" barcode: 17-character barcode data, or 0") + print(" bitmap: hex 23-byte segment on/off bitmap") + exit() + +if len(sys.argv) != 4: + usage() +if len(sys.argv[3]) != 46: + print("Segment bitmap must be exactly 46 digits") + usage() + +port = sys.argv[1] + +# Search for connected ESL Blaster if required +if (port == "0"): + blaster_port = tx.search_esl_blaster() + if (blaster_port == "0"): + exit() + +# Get PLID from barcode string +PLID = pr.get_plid(sys.argv[2]) + +bitmap = bytearray.fromhex(sys.argv[3]) + +frames = [] + +# Update page command + data +payload = [0xBA, 0x00, 0x00, 0x00] +payload.extend(bitmap[1:]) +# Segment bitmap has its own CRC16 +segcrc = pr.crc16(bitmap) +payload.append(segcrc & 255) +payload.append((segcrc // 256) & 255) +# Page number, duration and some other unknown stuff +payload.extend([0x00, 0x00, 0x09, 0x00, 0x10, 0x00, 0x31]) + +frame = pr.make_raw_frame(0x84, PLID, payload[0]) +frame.extend(payload[1:]) +pr.terminate_frame(frame, 100) +frames.append(frame) + +print(frame) + +# DEBUG +#f = open("out.txt", "w") +#for fr in frames: +# for b in fr: +# f.write(format(b, '02X') + " ") +# f.write("\n") +#exit() + +# Send data to IR transmitter +if (port == "0"): + tx.transmit_esl_blaster(frames, blaster_port) +else: + tx.transmit_serial(frames, port) +print("Done.") diff --git a/tools_python/tx.py b/tools_python/tx.py index fb85a39..5ceeb98 100644 --- a/tools_python/tx.py +++ b/tools_python/tx.py @@ -21,7 +21,7 @@ def search_esl_blaster(): else: print("Timeout on " + comport) except serial.SerialException: - print("SerialException on " + comport) + #print("SerialException on " + comport) continue if (found == 0):