@@ -548,51 +548,77 @@ int ECCX08Class::nonce(const byte data[])
548548 return challenge (data);
549549}
550550
551- long ECCX08Class::incrementCounter (int keyId )
551+ int ECCX08Class::incrementCounter (int counterId, long & counter )
552552{
553- uint32_t counter; // the counter can go up to 2,097,151
553+ if (counterId < 0 || counterId > 1 ) {
554+ return 0 ;
555+ }
554556
555557 if (!wakeup ()) {
556- return - 1 ;
558+ return 0 ;
557559 }
558560
559- if (!sendCommand (0x24 , 1 , keyId )) {
560- return - 1 ;
561+ if (!sendCommand (0x24 , 1 , counterId )) {
562+ return 0 ;
561563 }
562564
563565 delay (20 );
564566
565567 if (!receiveResponse (&counter, sizeof (counter))) {
566- return - 1 ;
568+ return 0 ;
567569 }
568570
569571 delay (1 );
570572 idle ();
571573
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+
572585 return counter;
573586}
574587
575- long ECCX08Class::readCounter (int keyId )
588+ int ECCX08Class::readCounter (int counterId, long & counter )
576589{
577- uint32_t counter; // the counter can go up to 2,097,151
590+ if (counterId < 0 || counterId > 1 ) {
591+ return 0 ;
592+ }
578593
579594 if (!wakeup ()) {
580- return - 1 ;
595+ return 0 ;
581596 }
582597
583- if (!sendCommand (0x24 , 0 , keyId )) {
584- return - 1 ;
598+ if (!sendCommand (0x24 , 0 , counterId )) {
599+ return 0 ;
585600 }
586601
587602 delay (20 );
588603
589604 if (!receiveResponse (&counter, sizeof (counter))) {
590- return - 1 ;
605+ return 0 ;
591606 }
592607
593608 delay (1 );
594609 idle ();
595610
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+
596622 return counter;
597623}
598624
0 commit comments