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 <peter.hutterer@who-t.net>
pull/181/head
Peter Hutterer 2019-08-21 12:59:16 +10:00
parent 8690e305cf
commit 6e4b190169
3 changed files with 33 additions and 33 deletions

View File

@ -316,7 +316,7 @@ class TestProtocolAny(unittest.TestCase):
self.assertEqual(msg.count, count) self.assertEqual(msg.count, count)
self.assertEqual(msg.timestamp, int(ts)) 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): def _cb(request, requires_reply=True, userdata=None, timeout=5):
self.assertEqual(request.opcode, 0xc1) self.assertEqual(request.opcode, 0xc1)
self.assertEqual(request.length, 1) self.assertEqual(request.length, 1)
@ -327,10 +327,10 @@ class TestProtocolAny(unittest.TestCase):
cb = cb or _cb cb = cb or _cb
p = Protocol(self.protocol_version, callback=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) 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): def _cb(request, requires_reply=True, userdata=None, timeout=5):
self.assertEqual(request.opcode, 0xc3) self.assertEqual(request.opcode, 0xc3)
self.assertEqual(request.length, 1) self.assertEqual(request.length, 1)
@ -340,9 +340,9 @@ class TestProtocolAny(unittest.TestCase):
cb = cb or _cb cb = cb or _cb
p = Protocol(self.protocol_version, callback=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): def _cb(request, requires_reply=True, userdata=None, timeout=5):
self.assertEqual(request.opcode, 0xca) self.assertEqual(request.opcode, 0xca)
self.assertEqual(request.length, 1) self.assertEqual(request.length, 1)
@ -352,7 +352,7 @@ class TestProtocolAny(unittest.TestCase):
cb = cb or _cb cb = cb or _cb
p = Protocol(self.protocol_version, callback=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 test_register_complete(self, cb=None):
def _cb(request, requires_reply=True, userdata=None, timeout=5): 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) 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): def _cb(request, requires_reply=True, userdata=None, timeout=5):
self.assertEqual(request.opcode, 0xc1) self.assertEqual(request.opcode, 0xc1)
self.assertEqual(request.length, 1) self.assertEqual(request.length, 1)
@ -449,16 +449,16 @@ class TestProtocolSlate(TestProtocolSpark):
data = list(ndata.to_bytes(2, byteorder='little')) data = list(ndata.to_bytes(2, byteorder='little'))
return NordicData([0xc2, len(data)] + data) 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): def _cb(request, requires_reply=True, userdata=None, timeout=5):
self.assertEqual(request.opcode, 0xca) self.assertEqual(request.opcode, 0xca)
self.assertEqual(request.length, 1) self.assertEqual(request.length, 1)
self.assertEqual(request[0], 0x00) self.assertEqual(request[0], 0x00)
return SUCCESS 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 test_register_press_button(self, cb=None, uuid='abcdef123456'):
def _cb(request, requires_reply=True, userdata=None, timeout=5): def _cb(request, requires_reply=True, userdata=None, timeout=5):

View File

@ -116,9 +116,9 @@ class Interactions(enum.Enum):
GET_HEIGHT = enum.auto() GET_HEIGHT = enum.auto()
SET_MODE = enum.auto() SET_MODE = enum.auto()
GET_STROKES = enum.auto() GET_STROKES = enum.auto()
GET_DATA_AVAILABLE = enum.auto() AVAILABLE_FILES_COUNT = enum.auto()
START_READING = enum.auto() DOWNLOAD_OLDEST_FILE = enum.auto()
ACK_TRANSACTION = enum.auto() DELETE_OLDEST_FILE = enum.auto()
REGISTER_PRESS_BUTTON = enum.auto() REGISTER_PRESS_BUTTON = enum.auto()
REGISTER_WAIT_FOR_BUTTON = enum.auto() REGISTER_WAIT_FOR_BUTTON = enum.auto()
REGISTER_COMPLETE = enum.auto() REGISTER_COMPLETE = enum.auto()
@ -1087,13 +1087,13 @@ class MsgGetStrokesIntuosPro(Msg):
self.timestamp = seconds self.timestamp = seconds
class MsgGetDataAvailable(Msg): class MsgAvailableFilesCount(Msg):
''' '''
.. attribute:: count .. attribute:: count
The number of drawings available The number of drawings available
''' '''
interaction = Interactions.GET_DATA_AVAILABLE interaction = Interactions.AVAILABLE_FILES_COUNT
opcode = 0xc1 opcode = 0xc1
protocol = ProtocolVersion.ANY protocol = ProtocolVersion.ANY
@ -1104,13 +1104,13 @@ class MsgGetDataAvailable(Msg):
self.count = int.from_bytes(reply[0:2], byteorder='big') self.count = int.from_bytes(reply[0:2], byteorder='big')
class MsgGetDataAvailableSlate(Msg): class MsgAvailableFilesCountSlate(Msg):
''' '''
.. attribute:: count .. attribute:: count
The number of drawings available The number of drawings available
''' '''
interaction = Interactions.GET_DATA_AVAILABLE interaction = Interactions.AVAILABLE_FILES_COUNT
opcode = 0xc1 opcode = 0xc1
protocol = ProtocolVersion.SLATE protocol = ProtocolVersion.SLATE
@ -1121,8 +1121,8 @@ class MsgGetDataAvailableSlate(Msg):
self.count = little_u16(reply[0:2]) self.count = little_u16(reply[0:2])
class MsgStartReading(Msg): class MsgDownloadOldestFile(Msg):
interaction = Interactions.START_READING interaction = Interactions.DOWNLOAD_OLDEST_FILE
opcode = 0xc3 opcode = 0xc3
protocol = ProtocolVersion.ANY protocol = ProtocolVersion.ANY
@ -1134,15 +1134,15 @@ class MsgStartReading(Msg):
raise UnexpectedDataError(reply) raise UnexpectedDataError(reply)
class MsgAckTransaction(Msg): class MsgDeleteOldestFile(Msg):
interaction = Interactions.ACK_TRANSACTION interaction = Interactions.DELETE_OLDEST_FILE
opcode = 0xca opcode = 0xca
protocol = ProtocolVersion.ANY protocol = ProtocolVersion.ANY
requires_reply = False requires_reply = False
class MsgAckTransactionSlate(Msg): class MsgDeleteOldestFileSlate(Msg):
interaction = Interactions.ACK_TRANSACTION interaction = Interactions.DELETE_OLDEST_FILE
opcode = 0xca opcode = 0xca
protocol = ProtocolVersion.SLATE protocol = ProtocolVersion.SLATE

View File

@ -639,18 +639,18 @@ class WacomProtocolBase(WacomProtocolLowLevelComm):
def set_paper_mode(self): def set_paper_mode(self):
self.p.execute(Interactions.SET_MODE, Mode.PAPER).execute() self.p.execute(Interactions.SET_MODE, Mode.PAPER).execute()
def is_data_available(self): def count_available_files(self):
n = self.p.execute(Interactions.GET_DATA_AVAILABLE).count n = self.p.execute(Interactions.AVAILABLE_FILES_COUNT).count
logger.debug(f'Drawings available: {n}') logger.debug(f'Drawings available: {n}')
return n > 0 return n
def get_stroke_data(self): def get_stroke_data(self):
msg = self.p.execute(Interactions.GET_STROKES) msg = self.p.execute(Interactions.GET_STROKES)
# logger.debug(f'cc returned {data} ') # logger.debug(f'cc returned {data} ')
return msg.count, msg.timestamp return msg.count, msg.timestamp
def start_reading(self): def start_downloading_oldest_file(self):
self.p.execute(Interactions.START_READING) self.p.execute(Interactions.DOWNLOAD_OLDEST_FILE)
def wait_nordic_unless_pen_data(self, opcode, timeout=None): def wait_nordic_unless_pen_data(self, opcode, timeout=None):
data = None data = None
@ -692,8 +692,8 @@ class WacomProtocolBase(WacomProtocolLowLevelComm):
except WacomEEAGAINException: except WacomEEAGAINException:
logger.warning('no data, please make sure the LED is blue and the button is pressed to switch it back to green') 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): def delete_oldest_file(self):
self.p.execute(Interactions.ACK_TRANSACTION) self.p.execute(Interactions.DELETE_OLDEST_FILE)
def get_coordinate(self, bitmask, n, data, v, dv): def get_coordinate(self, bitmask, n, data, v, dv):
# drop the first 2 bytes as they are not valuable here # drop the first 2 bytes as they are not valuable here
@ -745,17 +745,17 @@ class WacomProtocolBase(WacomProtocolLowLevelComm):
def read_offline_data(self): def read_offline_data(self):
self.set_paper_mode() self.set_paper_mode()
transaction_count = 0 transaction_count = 0
while self.is_data_available(): while self.count_available_files():
count, timestamp = self.get_stroke_data() 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))}') 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() pen_data = self.wait_for_end_read()
str_pen = binascii.hexlify(bytes(pen_data)) str_pen = binascii.hexlify(bytes(pen_data))
logger.info(f'received {str_pen}') logger.info(f'received {str_pen}')
drawing = self.parse_pen_data(pen_data, timestamp) drawing = self.parse_pen_data(pen_data, timestamp)
if drawing: if drawing:
self.emit('drawing', drawing) self.emit('drawing', drawing)
self.ack_transaction() self.delete_oldest_file()
transaction_count += 1 transaction_count += 1
return transaction_count return transaction_count