@@ -548,51 +548,77 @@ int ECCX08Class::nonce(const byte data[])
548
548
return challenge (data);
549
549
}
550
550
551
- long ECCX08Class::incrementCounter (int keyId )
551
+ int ECCX08Class::incrementCounter (int counterId, long & counter )
552
552
{
553
- uint32_t counter; // the counter can go up to 2,097,151
553
+ if (counterId < 0 || counterId > 1 ) {
554
+ return 0 ;
555
+ }
554
556
555
557
if (!wakeup ()) {
556
- return - 1 ;
558
+ return 0 ;
557
559
}
558
560
559
- if (!sendCommand (0x24 , 1 , keyId )) {
560
- return - 1 ;
561
+ if (!sendCommand (0x24 , 1 , counterId )) {
562
+ return 0 ;
561
563
}
562
564
563
565
delay (20 );
564
566
565
567
if (!receiveResponse (&counter, sizeof (counter))) {
566
- return - 1 ;
568
+ return 0 ;
567
569
}
568
570
569
571
delay (1 );
570
572
idle ();
571
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
+
572
585
return counter;
573
586
}
574
587
575
- long ECCX08Class::readCounter (int keyId )
588
+ int ECCX08Class::readCounter (int counterId, long & counter )
576
589
{
577
- uint32_t counter; // the counter can go up to 2,097,151
590
+ if (counterId < 0 || counterId > 1 ) {
591
+ return 0 ;
592
+ }
578
593
579
594
if (!wakeup ()) {
580
- return - 1 ;
595
+ return 0 ;
581
596
}
582
597
583
- if (!sendCommand (0x24 , 0 , keyId )) {
584
- return - 1 ;
598
+ if (!sendCommand (0x24 , 0 , counterId )) {
599
+ return 0 ;
585
600
}
586
601
587
602
delay (20 );
588
603
589
604
if (!receiveResponse (&counter, sizeof (counter))) {
590
- return - 1 ;
605
+ return 0 ;
591
606
}
592
607
593
608
delay (1 );
594
609
idle ();
595
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
+
596
622
return counter;
597
623
}
598
624
0 commit comments