diff options
author | cbdev <cb@cbcdn.com> | 2023-08-24 00:58:23 +0200 |
---|---|---|
committer | cbdev <cb@cbcdn.com> | 2023-08-24 00:58:23 +0200 |
commit | e9b7a6ef8fc575e0ee4f55ae16169d1917be9dea (patch) | |
tree | c99e9698f408f48587360324fa33b66020adb95f /twn3_test.c | |
download | libtwn-e9b7a6ef8fc575e0ee4f55ae16169d1917be9dea.tar.gz libtwn-e9b7a6ef8fc575e0ee4f55ae16169d1917be9dea.tar.bz2 libtwn-e9b7a6ef8fc575e0ee4f55ae16169d1917be9dea.zip |
Initial commit
Diffstat (limited to 'twn3_test.c')
-rw-r--r-- | twn3_test.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/twn3_test.c b/twn3_test.c new file mode 100644 index 0000000..583deca --- /dev/null +++ b/twn3_test.c @@ -0,0 +1,45 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include "libtwn3.h" + +#include <errno.h> +#include <string.h> + + +int main(int argc, char** argv){ + char data[1024]; + ssize_t bytes; + unsigned u; + + int device = twn3_open("/dev/ttyACM0"); + + printf("Device is at fd %d\n", device); + if(device < 0){ + printf("%s\n", strerror(errno)); + return EXIT_FAILURE; + } + + //check version + if(twn3_sync_read_version(device, 0, data, sizeof(data)) >= 0){ + printf("Connected reader firmware version: %s\n", data); + } + + //read eeprom + for(u = 0; u < 0x15; u++){ + uint8_t regdata = 0; + twn3_sync_read_eeprom(device, 0, u, ®data); + printf("Register %d has data %02X\n", u, regdata); + } + + //write some userdata + twn3_sync_write_eeprom(device, 0, 19, 0xAA); + + //store a key + uint8_t key[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + twn3_sync_storekey(device, 0, 12, key); + + close(device); + return EXIT_SUCCESS; +} |