From 6e4b1901695d6fbcb0737b9a4929913b7f894206 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 21 Aug 2019 12:59:16 +1000 Subject: [PATCH] protocol: rename a few protocol messages to better reflect what they do 0xc3 is 'download the oldest file' 0xca is 'delete the oldest file' (usually the one we just received) from the tablet. 0xc1 is 'how many files are there' Signed-off-by: Peter Hutterer --- test/test_messages.py | 20 ++++++++++---------- tuhi/protocol.py | 26 +++++++++++++------------- tuhi/wacom.py | 20 ++++++++++---------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/test/test_messages.py b/test/test_messages.py index 184b963..57ff54b 100644 --- a/test/test_messages.py +++ b/test/test_messages.py @@ -316,7 +316,7 @@ class TestProtocolAny(unittest.TestCase): self.assertEqual(msg.count, count) self.assertEqual(msg.timestamp, int(ts)) - def test_get_data_available(self, cb=None, ndata=1234): + def test_available_files_count(self, cb=None, ndata=1234): def _cb(request, requires_reply=True, userdata=None, timeout=5): self.assertEqual(request.opcode, 0xc1) self.assertEqual(request.length, 1) @@ -327,10 +327,10 @@ class TestProtocolAny(unittest.TestCase): cb = cb or _cb p = Protocol(self.protocol_version, callback=cb) - msg = p.execute(Interactions.GET_DATA_AVAILABLE) + msg = p.execute(Interactions.AVAILABLE_FILES_COUNT) self.assertEqual(msg.count, ndata) - def test_start_reading(self, cb=None): + def test_download_oldest_file(self, cb=None): def _cb(request, requires_reply=True, userdata=None, timeout=5): self.assertEqual(request.opcode, 0xc3) self.assertEqual(request.length, 1) @@ -340,9 +340,9 @@ class TestProtocolAny(unittest.TestCase): cb = cb or _cb p = Protocol(self.protocol_version, callback=cb) - p.execute(Interactions.START_READING) + p.execute(Interactions.DOWNLOAD_OLDEST_FILE) - def test_ack_transaction(self, cb=None): + def test_delete_oldest_file(self, cb=None): def _cb(request, requires_reply=True, userdata=None, timeout=5): self.assertEqual(request.opcode, 0xca) self.assertEqual(request.length, 1) @@ -352,7 +352,7 @@ class TestProtocolAny(unittest.TestCase): cb = cb or _cb p = Protocol(self.protocol_version, callback=cb) - p.execute(Interactions.ACK_TRANSACTION) + p.execute(Interactions.DELETE_OLDEST_FILE) def test_register_complete(self, cb=None): def _cb(request, requires_reply=True, userdata=None, timeout=5): @@ -441,7 +441,7 @@ class TestProtocolSlate(TestProtocolSpark): super().test_get_strokes(cb or _cb, count=count, ts=ts) - def test_get_data_available(self, cb=None, ndata=1234): + def test_available_files_count(self, cb=None, ndata=1234): def _cb(request, requires_reply=True, userdata=None, timeout=5): self.assertEqual(request.opcode, 0xc1) self.assertEqual(request.length, 1) @@ -449,16 +449,16 @@ class TestProtocolSlate(TestProtocolSpark): data = list(ndata.to_bytes(2, byteorder='little')) return NordicData([0xc2, len(data)] + data) - super().test_get_data_available(cb or _cb, ndata=ndata) + super().test_available_files_count(cb or _cb, ndata=ndata) - def test_ack_transaction(self, cb=None): + def test_delete_oldest_file(self, cb=None): def _cb(request, requires_reply=True, userdata=None, timeout=5): self.assertEqual(request.opcode, 0xca) self.assertEqual(request.length, 1) self.assertEqual(request[0], 0x00) return SUCCESS - super().test_ack_transaction(cb or _cb) + super().test_delete_oldest_file(cb or _cb) def test_register_press_button(self, cb=None, uuid='abcdef123456'): def _cb(request, requires_reply=True, userdata=None, timeout=5): diff --git a/tuhi/protocol.py b/tuhi/protocol.py index 3ae60fb..3d3434e 100644 --- a/tuhi/protocol.py +++ b/tuhi/protocol.py @@ -116,9 +116,9 @@ class Interactions(enum.Enum): GET_HEIGHT = enum.auto() SET_MODE = enum.auto() GET_STROKES = enum.auto() - GET_DATA_AVAILABLE = enum.auto() - START_READING = enum.auto() - ACK_TRANSACTION = enum.auto() + AVAILABLE_FILES_COUNT = enum.auto() + DOWNLOAD_OLDEST_FILE = enum.auto() + DELETE_OLDEST_FILE = enum.auto() REGISTER_PRESS_BUTTON = enum.auto() REGISTER_WAIT_FOR_BUTTON = enum.auto() REGISTER_COMPLETE = enum.auto() @@ -1087,13 +1087,13 @@ class MsgGetStrokesIntuosPro(Msg): self.timestamp = seconds -class MsgGetDataAvailable(Msg): +class MsgAvailableFilesCount(Msg): ''' .. attribute:: count The number of drawings available ''' - interaction = Interactions.GET_DATA_AVAILABLE + interaction = Interactions.AVAILABLE_FILES_COUNT opcode = 0xc1 protocol = ProtocolVersion.ANY @@ -1104,13 +1104,13 @@ class MsgGetDataAvailable(Msg): self.count = int.from_bytes(reply[0:2], byteorder='big') -class MsgGetDataAvailableSlate(Msg): +class MsgAvailableFilesCountSlate(Msg): ''' .. attribute:: count The number of drawings available ''' - interaction = Interactions.GET_DATA_AVAILABLE + interaction = Interactions.AVAILABLE_FILES_COUNT opcode = 0xc1 protocol = ProtocolVersion.SLATE @@ -1121,8 +1121,8 @@ class MsgGetDataAvailableSlate(Msg): self.count = little_u16(reply[0:2]) -class MsgStartReading(Msg): - interaction = Interactions.START_READING +class MsgDownloadOldestFile(Msg): + interaction = Interactions.DOWNLOAD_OLDEST_FILE opcode = 0xc3 protocol = ProtocolVersion.ANY @@ -1134,15 +1134,15 @@ class MsgStartReading(Msg): raise UnexpectedDataError(reply) -class MsgAckTransaction(Msg): - interaction = Interactions.ACK_TRANSACTION +class MsgDeleteOldestFile(Msg): + interaction = Interactions.DELETE_OLDEST_FILE opcode = 0xca protocol = ProtocolVersion.ANY requires_reply = False -class MsgAckTransactionSlate(Msg): - interaction = Interactions.ACK_TRANSACTION +class MsgDeleteOldestFileSlate(Msg): + interaction = Interactions.DELETE_OLDEST_FILE opcode = 0xca protocol = ProtocolVersion.SLATE diff --git a/tuhi/wacom.py b/tuhi/wacom.py index 14e8594..8dada7b 100644 --- a/tuhi/wacom.py +++ b/tuhi/wacom.py @@ -639,18 +639,18 @@ class WacomProtocolBase(WacomProtocolLowLevelComm): def set_paper_mode(self): self.p.execute(Interactions.SET_MODE, Mode.PAPER).execute() - def is_data_available(self): - n = self.p.execute(Interactions.GET_DATA_AVAILABLE).count + def count_available_files(self): + n = self.p.execute(Interactions.AVAILABLE_FILES_COUNT).count logger.debug(f'Drawings available: {n}') - return n > 0 + return n def get_stroke_data(self): msg = self.p.execute(Interactions.GET_STROKES) # logger.debug(f'cc returned {data} ') return msg.count, msg.timestamp - def start_reading(self): - self.p.execute(Interactions.START_READING) + def start_downloading_oldest_file(self): + self.p.execute(Interactions.DOWNLOAD_OLDEST_FILE) def wait_nordic_unless_pen_data(self, opcode, timeout=None): data = None @@ -692,8 +692,8 @@ class WacomProtocolBase(WacomProtocolLowLevelComm): except WacomEEAGAINException: logger.warning('no data, please make sure the LED is blue and the button is pressed to switch it back to green') - def ack_transaction(self): - self.p.execute(Interactions.ACK_TRANSACTION) + def delete_oldest_file(self): + self.p.execute(Interactions.DELETE_OLDEST_FILE) def get_coordinate(self, bitmask, n, data, v, dv): # drop the first 2 bytes as they are not valuable here @@ -745,17 +745,17 @@ class WacomProtocolBase(WacomProtocolLowLevelComm): def read_offline_data(self): self.set_paper_mode() transaction_count = 0 - while self.is_data_available(): + while self.count_available_files(): count, timestamp = self.get_stroke_data() logger.info(f'receiving {count} bytes drawn on UTC {time.strftime("%y%m%d%H%M%S", time.gmtime(timestamp))}') - self.start_reading() + self.start_downloading_oldest_file() pen_data = self.wait_for_end_read() str_pen = binascii.hexlify(bytes(pen_data)) logger.info(f'received {str_pen}') drawing = self.parse_pen_data(pen_data, timestamp) if drawing: self.emit('drawing', drawing) - self.ack_transaction() + self.delete_oldest_file() transaction_count += 1 return transaction_count