@@ -442,8 +442,8 @@ bool IridiumSBD::waitForATResponse(char *response, int responseSize, const char
442
442
bool done = false ;
443
443
int matchPromptPos = 0 ; // Matches chars in prompt
444
444
int matchTerminatorPos = 0 ; // Matches chars in terminator
445
- // 0=prompt not seen, 1=prompt seen, gathering response, 2=response gathered, looking for terminator
446
- int promptState = prompt ? 0 : 2 ;
445
+ enum {LOOKING_FOR_PROMPT, GATHERING_RESPONSE, LOOKING_FOR_TERMINATOR}
446
+ int promptState = prompt ? LOOKING_FOR_PROMPT : LOOKING_FOR_TERMINATOR ;
447
447
console (F (" << " ));
448
448
for (unsigned long start=millis (); millis () - start < 1000UL * atTimeout;)
449
449
{
@@ -457,12 +457,12 @@ bool IridiumSBD::waitForATResponse(char *response, int responseSize, const char
457
457
if (prompt)
458
458
switch (promptState)
459
459
{
460
- case 0 : // matching prompt
460
+ case LOOKING_FOR_PROMPT:
461
461
if (c == prompt[matchPromptPos])
462
462
{
463
463
++matchPromptPos;
464
464
if (prompt[matchPromptPos] == ' \0 ' )
465
- promptState = 1 ;
465
+ promptState = GATHERING_RESPONSE ;
466
466
}
467
467
468
468
else
@@ -471,12 +471,12 @@ bool IridiumSBD::waitForATResponse(char *response, int responseSize, const char
471
471
}
472
472
473
473
break ;
474
- case 1 : // gathering reponse from end of prompt to first \r
474
+ case GATHERING_RESPONSE : // gathering reponse from end of prompt to first \r
475
475
if (response)
476
476
{
477
477
if (c == ' \r ' || responseSize < 2 )
478
478
{
479
- promptState = 2 ;
479
+ promptState = LOOKING_FOR_TERMINATOR ;
480
480
}
481
481
else
482
482
{
@@ -610,14 +610,16 @@ int IridiumSBD::doSBDRB(uint8_t *rxBuffer, size_t *prxBufferSize)
610
610
console (F (" [Binary size:" ));
611
611
console (size);
612
612
console (F (" ]" ));
613
- for (int i=0 ; i<size; ++i)
613
+
614
+ for (uint16_t bytesRead = 0 ; bytesRead < size;)
614
615
{
615
616
if (cancelled ())
616
617
return ISBD_CANCELLED;
617
618
618
619
if (stream.available ())
619
620
{
620
621
uint8_t c = stream.read ();
622
+ bytesRead++;
621
623
if (rxBuffer && prxBufferSize)
622
624
if (*prxBufferSize > 0 )
623
625
{
@@ -661,14 +663,16 @@ void IridiumSBD::power(bool on)
661
663
{
662
664
static unsigned long lastPowerOnTime = 0UL ;
663
665
666
+ this ->asleep = !on;
667
+
664
668
if (this ->sleepPin == -1 )
665
669
return ;
666
670
671
+ pinMode (this ->sleepPin , OUTPUT);
672
+
667
673
if (on)
668
674
{
669
675
dbg (F (" Powering on RockBLOCK...!\r\n " ));
670
- this ->asleep = false ;
671
- pinMode (this ->sleepPin , OUTPUT);
672
676
digitalWrite (this ->sleepPin , HIGH); // HIGH = awake
673
677
lastPowerOnTime = millis ();
674
678
}
@@ -682,8 +686,6 @@ void IridiumSBD::power(bool on)
682
686
delay (elapsed);
683
687
684
688
dbg (F (" Powering off RockBLOCK...!\r\n " ));
685
- this ->asleep = true ;
686
- pinMode (this ->sleepPin , OUTPUT);
687
689
digitalWrite (this ->sleepPin , LOW); // LOW = asleep
688
690
}
689
691
}
0 commit comments