Commit Graph

31 Commits (master)

Author SHA1 Message Date
Peter Hutterer 4ff7da5d41 protocol: handle the pen id packet correctly
We were re-using the header byte of the stroke header to count the bits.
Where that header is anything but 0xff we got out of sync and raised an
error. Fix this by renaming things so we don't accidentally use the
wrong fields.

Fixes #283

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-01-31 12:29:31 +10:00
Peter Hutterer 27164aba52 Fix flake8 errors - f-string without placeholders
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-01-22 17:09:27 +10:00
Peter Hutterer 53e2cebaf8 protocol: fix a flake8 issue
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-01-08 10:08:36 +10:00
Niclas Hoyer f5ea08f171 Add support for long device names
If the device name is longer than one reply, the registration will crash.
This adds support for a variable number of replies until the reply ends
with `0x0a`.
2020-01-07 11:05:13 +10:00
Peter Hutterer bffe41fbb6 protocol: handle 0xb3 automatically
0xb3 is the generic error code (or success, where applicable). Let's handle
those by default so that the rest of the messages only have to care about
replies with message-specific opcodes.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-29 12:38:21 +10:00
Peter Hutterer 6c0ddd96bc protocol: add missing space for NordicData's str()
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-28 15:33:28 +10:00
Peter Hutterer 827ccbfa07 protcol: just print the class name during str()
<class '....'> doesn't make things easier to debug

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-28 15:33:28 +10:00
Peter Hutterer 1fb36ebc40 protocol: fix typo in printing a NordicData object
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-28 15:33:28 +10:00
Peter Hutterer db87390c48 protocol: use __str__, not __repr__ for the various messages
str() is the preferred one, though I can't find a good explanation when to use
what.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-28 15:33:28 +10:00
Peter Hutterer 79480b867d protocol: store the interaction name in the NordicData where appropriate
This means the data logger can then access that name without needing a
separate lookup table.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-26 09:05:17 +10:00
Peter Hutterer 44d2018f1c protocol: assume the initial stroke point to be 0, 0, 0
Reproduced on the Spark, first bytes in a new file recording were
- file header: 0x62, 0x38, 0x62, 0x74
- stroke point: 0xbf, 0xff, 0xff, 0x4a, 0x14, 0x29, 0x31, 0x6a
- stroke delta: 0xa8, 0x02, 0x04, 0xc3,

The initial point thus has a delta pressure value 0x6a which must be added to
*something*. And zero is the most sensible *something* that I can think of.

Fixes #111

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-23 10:44:55 +02:00
Peter Hutterer c466c7d431 protocol: handle error code 0x7
Deprecated, but still exists on the Slate so let's wrap the connect attempt
so we throw the right error.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-23 10:38:36 +02:00
Peter Hutterer f21af42131 protocol: on the spark treat a general error during connect as wrong uuid
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-23 10:38:36 +02:00
Peter Hutterer 7a121cfe6c protocol: print the DeviceError as something useful
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-23 10:38:36 +02:00
Peter Hutterer 1ddf899d3e protocol: augment the new exceptions with errnos
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-23 10:38:36 +02:00
Peter Hutterer 77048d572d protocol: use a MisingReplyError instead of timeout exceptions
It's caused by a timeout but the underlying issue is that we never got the
reply that we wanted.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-23 10:38:36 +02:00
Peter Hutterer 4eee838d94 protocol: implement the message to wait for the end of pen data
This pushes the CRC fetching into the messages, making the caller code more
generic.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-23 10:38:36 +02:00
Peter Hutterer 9fcd2b9517 protocol: make the auth error a subclass of our protocol error
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-22 10:52:30 +10:00
Peter Hutterer 6e4b190169 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>
2019-08-22 09:59:14 +10:00
Peter Hutterer e420b04fda protocol: add stroke parsing
This is a slightly different model as the messages, primarily because it's not
quite as model-specific. So there's only one parse function and it can handle
both file types that we currently support (intuos pro and the spark/slate
bits).

All wrapped into their own classes to make future extensions a bit easier.
It's not a 1:1 implementation of the tuhi/wacom.py bits either because we now
know about a few extra bits like the flags in stroke headers.

Most importantly though, this can be easily tested now, with one test case
searching for raw logs in $XDG_DATA_HOME/tuhi/raw and parsing all of those. So
the more files are sitting in there (i.e. the more the tablet is used), the
better the test suite becomes.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-21 09:31:52 +02:00
Peter Hutterer 643dd34476 protocol: add the message for getting the point size
The dimensions of the tablet are in device units, the point size tells us how
big the actual tablet is.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-20 12:02:30 +10:00
Peter Hutterer 57aa0de954 protocol: the spark doesn't support get width/height
Let's make those noop messages that return the hardcoded width/height instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-20 12:02:30 +10:00
Peter Hutterer ff2618e68a protocol: add helper functions for converting to/from little endians
A few messages where we assumed the argument is a single byte are actually
little-endian 16 bits. let's add easy-to-use wrappers.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-20 12:02:30 +10:00
Peter Hutterer d73da09e26 protocol: 0xc7 on the spark seems to be in big-endian
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-15 15:10:25 +10:00
Peter Hutterer 1ea89d2f09 protocol: split GET_DIMENSIONS up into two messages
It's the same message with a different argument, let's try not to do
gymnastics in the Msg code just so we can return a tuple.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer 73bc782a53 protocol: 0xec is simply the GATT selection for file transfers
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer c39c20ede2 protocol: drop the UNKNOWN_B1 class
0xb1 is the SetMode command, the rest is just the argument for which mode we
want

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer 5e4ab89f41 Drop the semi-duplicate separate Protocol class
We can hook into the ProtocolVersion here, so let's de-duplicate this.
Should be backwards-compatible for config files but new config files will have
the uppercase name written now.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer b34f8794e4 wacom: switch registering the device to the new protocol handling
This is still a bit awkward because the communication of the spark especially
is so strange. It sends a (rejected) uuid, then a single command to register
that UUID. The Slate and the IntuosPro are more sensible, they seem to have a
special message to register a UUID - that one either fails or succeeds.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer 6e20faa737 protocol: add a timeout argument to the new protocol handlers
The default timeout is too short for registering a button, let's control this
from the message.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00
Peter Hutterer a817d10cc7 protocol: start a new attempt at handling the protocol
This is only the framework for a new protocol handler that should simplify
adding, extending and debugging the actual protocol messages.

The summary is:
- each protocol interaction is a subclass of Msg() that handles the data sent
  and received from the device.
- the list of messages for each device is stored in a dictionary the caller
  initializes by providing the protocol version
- those messages are addressable via the Interactions enum through the
  Protocol class
- the messages can be run via execute(), taking and setting the obvious
  properties on the object
- actual communication is done via a single callback that takes/returns a
  NordicData object for the request/reply.

So after the basic setup, the caller can do this:
   p = Protocol(ProtocolVersion.INTUOS_PRO)
   name = p.execute(Interactions.GET_NAME).name
   p.execute(Interactions.SET_TIME, time.time())

This completely separates the protocol from the implementation where we want
the result of that exchange, ideally paving the way for better testing and
easier debugging of what's happening on the wire. Well, ether.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-14 07:37:30 +10:00