@@ -548,6 +548,80 @@ int ECCX08Class::nonce(const byte data[])
548548 return challenge (data);
549549}
550550
551+ int ECCX08Class::incrementCounter (int counterId, long & counter)
552+ {
553+ if (counterId < 0 || counterId > 1 ) {
554+ return 0 ;
555+ }
556+
557+ if (!wakeup ()) {
558+ return 0 ;
559+ }
560+
561+ if (!sendCommand (0x24 , 1 , counterId)) {
562+ return 0 ;
563+ }
564+
565+ delay (20 );
566+
567+ if (!receiveResponse (&counter, sizeof (counter))) {
568+ return 0 ;
569+ }
570+
571+ delay (1 );
572+ idle ();
573+
574+ return 1 ;
575+ }
576+
577+ long ECCX08Class::incrementCounter (int counterId)
578+ {
579+ long counter; // the counter can go up to 2,097,151
580+
581+ if (!incrementCounter (counterId, counter)) {
582+ return -1 ;
583+ }
584+
585+ return counter;
586+ }
587+
588+ int ECCX08Class::readCounter (int counterId, long & counter)
589+ {
590+ if (counterId < 0 || counterId > 1 ) {
591+ return 0 ;
592+ }
593+
594+ if (!wakeup ()) {
595+ return 0 ;
596+ }
597+
598+ if (!sendCommand (0x24 , 0 , counterId)) {
599+ return 0 ;
600+ }
601+
602+ delay (20 );
603+
604+ if (!receiveResponse (&counter, sizeof (counter))) {
605+ return 0 ;
606+ }
607+
608+ delay (1 );
609+ idle ();
610+
611+ return 1 ;
612+ }
613+
614+ long ECCX08Class::readCounter (int counterId)
615+ {
616+ long counter; // the counter can go up to 2,097,151
617+
618+ if (!readCounter (counterId, counter)) {
619+ return -1 ;
620+ }
621+
622+ return counter;
623+ }
624+
551625int ECCX08Class::wakeup ()
552626{
553627 _wire->setClock (_wakeupFrequency);
@@ -892,4 +966,4 @@ uint16_t ECCX08Class::crc16(const byte data[], size_t length)
892966ECCX08Class ECCX08 (CRYPTO_WIRE, 0x60 );
893967#else
894968ECCX08Class ECCX08 (Wire, 0x60 );
895- #endif
969+ #endif
0 commit comments