Implement the fingerprint function.
This commit is contained in:
parent
c1745cc535
commit
49301d1b28
@ -43,6 +43,9 @@
|
|||||||
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
rc == -1 ? DEVICE_STATUS_IO : DEVICE_STATUS_TIMEOUT \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#define FP_OFFSET 0
|
||||||
|
#define FP_SIZE 8
|
||||||
|
|
||||||
#define ACK 0x5A
|
#define ACK 0x5A
|
||||||
#define NAK 0xA5
|
#define NAK 0xA5
|
||||||
|
|
||||||
@ -64,8 +67,10 @@
|
|||||||
typedef struct oceanic_atom2_device_t {
|
typedef struct oceanic_atom2_device_t {
|
||||||
device_t base;
|
device_t base;
|
||||||
struct serial *port;
|
struct serial *port;
|
||||||
|
unsigned char fingerprint[FP_SIZE];
|
||||||
} oceanic_atom2_device_t;
|
} oceanic_atom2_device_t;
|
||||||
|
|
||||||
|
static device_status_t oceanic_atom2_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size);
|
||||||
static device_status_t oceanic_atom2_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
static device_status_t oceanic_atom2_device_version (device_t *abstract, unsigned char data[], unsigned int size);
|
||||||
static device_status_t oceanic_atom2_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
static device_status_t oceanic_atom2_device_read (device_t *abstract, unsigned int address, unsigned char data[], unsigned int size);
|
||||||
static device_status_t oceanic_atom2_device_write (device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size);
|
static device_status_t oceanic_atom2_device_write (device_t *abstract, unsigned int address, const unsigned char data[], unsigned int size);
|
||||||
@ -75,7 +80,7 @@ static device_status_t oceanic_atom2_device_close (device_t *abstract);
|
|||||||
|
|
||||||
static const device_backend_t oceanic_atom2_device_backend = {
|
static const device_backend_t oceanic_atom2_device_backend = {
|
||||||
DEVICE_TYPE_OCEANIC_ATOM2,
|
DEVICE_TYPE_OCEANIC_ATOM2,
|
||||||
NULL, /* set_fingerprint */
|
oceanic_atom2_device_set_fingerprint, /* set_fingerprint */
|
||||||
NULL, /* handshake */
|
NULL, /* handshake */
|
||||||
oceanic_atom2_device_version, /* version */
|
oceanic_atom2_device_version, /* version */
|
||||||
oceanic_atom2_device_read, /* read */
|
oceanic_atom2_device_read, /* read */
|
||||||
@ -246,6 +251,7 @@ oceanic_atom2_device_open (device_t **out, const char* name)
|
|||||||
|
|
||||||
// Set the default values.
|
// Set the default values.
|
||||||
device->port = NULL;
|
device->port = NULL;
|
||||||
|
memset (device->fingerprint, 0, FP_SIZE);
|
||||||
|
|
||||||
// Open the device.
|
// Open the device.
|
||||||
int rc = serial_open (&device->port, name);
|
int rc = serial_open (&device->port, name);
|
||||||
@ -287,6 +293,26 @@ oceanic_atom2_device_open (device_t **out, const char* name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static device_status_t
|
||||||
|
oceanic_atom2_device_set_fingerprint (device_t *abstract, const unsigned char data[], unsigned int size)
|
||||||
|
{
|
||||||
|
oceanic_atom2_device_t *device = (oceanic_atom2_device_t*) abstract;
|
||||||
|
|
||||||
|
if (! device_is_oceanic_atom2 (abstract))
|
||||||
|
return DEVICE_STATUS_TYPE_MISMATCH;
|
||||||
|
|
||||||
|
if (size && size != FP_SIZE)
|
||||||
|
return DEVICE_STATUS_ERROR;
|
||||||
|
|
||||||
|
if (size)
|
||||||
|
memcpy (device->fingerprint, data, FP_SIZE);
|
||||||
|
else
|
||||||
|
memset (device->fingerprint, 0, FP_SIZE);
|
||||||
|
|
||||||
|
return DEVICE_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static device_status_t
|
static device_status_t
|
||||||
oceanic_atom2_device_close (device_t *abstract)
|
oceanic_atom2_device_close (device_t *abstract)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user