From cbcf89417c2fc668e35172abb63a2c3fb2e68f69 Mon Sep 17 00:00:00 2001 From: maihde Date: Sun, 16 Jul 2023 18:54:18 -0400 Subject: [PATCH 1/2] Update ECCX08.h with method description --- src/ECCX08.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ECCX08.h b/src/ECCX08.h index 54fdc3a..ead8468 100644 --- a/src/ECCX08.h +++ b/src/ECCX08.h @@ -66,6 +66,9 @@ class ECCX08Class int nonce(const byte data[]); + long incrementCounter(int keyId); + long readCounter(int keyId); + private: int wakeup(); int sleep(); From 0fe82c9ca32fa51020a1db64abc8f4989970419d Mon Sep 17 00:00:00 2001 From: maihde Date: Sun, 16 Jul 2023 18:57:03 -0400 Subject: [PATCH 2/2] Update ECCX08.cpp with counter functions --- src/ECCX08.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/ECCX08.cpp b/src/ECCX08.cpp index 0164343..3b7383e 100644 --- a/src/ECCX08.cpp +++ b/src/ECCX08.cpp @@ -548,6 +548,54 @@ int ECCX08Class::nonce(const byte data[]) return challenge(data); } +long ECCX08Class::incrementCounter(int keyId) +{ + uint32_t counter; // the counter can go up to 2,097,151 + + if (!wakeup()) { + return -1; + } + + if (!sendCommand(0x24, 1, keyId)) { + return -1; + } + + delay(20); + + if (!receiveResponse(&counter, sizeof(counter))) { + return -1; + } + + delay(1); + idle(); + + return counter; +} + +long ECCX08Class::readCounter(int keyId) +{ + uint32_t counter; // the counter can go up to 2,097,151 + + if (!wakeup()) { + return -1; + } + + if (!sendCommand(0x24, 0, keyId)) { + return -1; + } + + delay(20); + + if (!receiveResponse(&counter, sizeof(counter))) { + return -1; + } + + delay(1); + idle(); + + return counter; +} + int ECCX08Class::wakeup() { _wire->setClock(_wakeupFrequency); @@ -892,4 +940,4 @@ uint16_t ECCX08Class::crc16(const byte data[], size_t length) ECCX08Class ECCX08(CRYPTO_WIRE, 0x60); #else ECCX08Class ECCX08(Wire, 0x60); -#endif \ No newline at end of file +#endif