-
Notifications
You must be signed in to change notification settings - Fork 50
Add counter support feature #50
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add counter support feature #50
Conversation
Memory usage change @ 0fe82c9
Click for full report table
Click for full report CSV
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @maihde Thanks for your contribution. I've added a couple of suggestions that i thing can improve how this new feature will integrate in the library.
Do you mind also adding an example Sketch?
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep changes aligned to the style of the library i would split this function in two:
- one basic function returning 0 or 1 and taking the counter value as argument;
- another one that wraps it and returns the counter value
Also, reading the docs it looks to me that keyId can be only 0 or 1 so i would add a check to keyId parameter.
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; | |
} | |
int ECCX08Class::incrementCounter(int keyId, long& counter) | |
{ | |
if (keyId < 0 || keyId > 1) { | |
return 0; | |
} | |
if (!wakeup()) { | |
return 0; | |
} | |
if (!sendCommand(0x24, 1, keyId)) { | |
return 0; | |
} | |
delay(20); | |
if (!receiveResponse(&counter, sizeof(counter))) { | |
return 0; | |
} | |
delay(1); | |
idle(); | |
return 1; | |
} | |
long ECCX08Class::incrementCounter(int keyId) | |
{ | |
long counter; // the counter can go up to 2,097,151 | |
if(!incrementCounter(keyId, counter)) { | |
return -1; | |
} | |
return counter; | |
} |
idle(); | ||
|
||
return counter; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do the same here
@@ -66,6 +66,9 @@ class ECCX08Class | |||
|
|||
int nonce(const byte data[]); | |||
|
|||
long incrementCounter(int keyId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And update methods declarations accordingly.
superseded by #53 |
No description provided.