@@ -847,18 +847,21 @@ String SARA_R5::clock(void)
847
847
}
848
848
*(clockEnd) = ' \0 ' ; // Set last quote to null char -- end string
849
849
850
+ String clock = String (clockBegin); // Extract the clock as a String _before_ freeing response
851
+
850
852
free (command);
851
853
free (response);
852
854
853
- return String (clockBegin );
855
+ return (clock );
854
856
}
855
857
856
858
SARA_R5_error_t SARA_R5::clock (uint8_t *y, uint8_t *mo, uint8_t *d,
857
- uint8_t *h, uint8_t *min, uint8_t *s, uint8_t *tz)
859
+ uint8_t *h, uint8_t *min, uint8_t *s, int8_t *tz)
858
860
{
859
861
SARA_R5_error_t err;
860
862
char *command;
861
863
char *response;
864
+ char tzPlusMinus;
862
865
863
866
int iy, imo, id, ih, imin, is, itz;
864
867
@@ -877,19 +880,22 @@ SARA_R5_error_t SARA_R5::clock(uint8_t *y, uint8_t *mo, uint8_t *d,
877
880
err = sendCommandWithResponse (command, SARA_R5_RESPONSE_OK,
878
881
response, SARA_R5_STANDARD_RESPONSE_TIMEOUT);
879
882
880
- // Response format: \r\n+CCLK: "YY/MM/DD,HH:MM:SS-TZ"\r\n\r\nOK\r\n
883
+ // Response format (if TZ is negative) : \r\n+CCLK: "YY/MM/DD,HH:MM:SS-TZ"\r\n\r\nOK\r\n
881
884
if (err == SARA_R5_ERROR_SUCCESS)
882
885
{
883
- if (sscanf (response, " \r\n +CCLK: \" %d/%d/%d,%d:%d:%d- %d\"\r\n " ,
884
- &iy, &imo, &id, &ih, &imin, &is, &itz) == 7 )
886
+ if (sscanf (response, " \r\n +CCLK: \" %d/%d/%d,%d:%d:%d%c %d\"\r\n " ,
887
+ &iy, &imo, &id, &ih, &imin, &is, &tzPlusMinus, & itz) == 8 )
885
888
{
886
889
*y = iy;
887
890
*mo = imo;
888
891
*d = id;
889
892
*h = ih;
890
893
*min = imin;
891
894
*s = is;
892
- *tz = itz;
895
+ if (tzPlusMinus == ' +' )
896
+ *tz = itz;
897
+ else
898
+ *tz = 0 - itz;
893
899
}
894
900
else
895
901
err = SARA_R5_ERROR_UNEXPECTED_RESPONSE;
@@ -3640,12 +3646,12 @@ SARA_R5_error_t SARA_R5::sendCommandWithResponse(
3640
3646
int index = 0 ;
3641
3647
int destIndex = 0 ;
3642
3648
unsigned int charsRead = 0 ;
3643
- // bool printedSomething = false;
3649
+ bool printedSomething = false ;
3644
3650
3645
- // if (_printDebug == true)
3646
- // _debugPort->print(F("sendCommandWithResponse: Command: "));
3647
- // if (_printDebug == true)
3648
- // _debugPort->println(String(command));
3651
+ if (_printDebug == true )
3652
+ _debugPort->print (F (" sendCommandWithResponse: Command: " ));
3653
+ if (_printDebug == true )
3654
+ _debugPort->println (String (command));
3649
3655
3650
3656
int backlogIndex = sendCommand (command, at); // Sending command needs to dump data to backlog buffer as well.
3651
3657
unsigned long timeIn = millis ();
@@ -3655,13 +3661,13 @@ SARA_R5_error_t SARA_R5::sendCommandWithResponse(
3655
3661
if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
3656
3662
{
3657
3663
char c = readChar ();
3658
- // if (_printDebug == true)
3659
- // {
3660
- // if (printedSomething == false)
3661
- // _debugPort->print(F("sendCommandWithResponse: Response: "));
3662
- // _debugPort->print(c);
3663
- // printedSomething = true;
3664
- // }
3664
+ if (_printDebug == true )
3665
+ {
3666
+ if (printedSomething == false )
3667
+ _debugPort->print (F (" sendCommandWithResponse: Response: " ));
3668
+ _debugPort->print (c);
3669
+ printedSomething = true ;
3670
+ }
3665
3671
if (responseDest != NULL )
3666
3672
{
3667
3673
responseDest[destIndex++] = c;
@@ -3686,9 +3692,9 @@ SARA_R5_error_t SARA_R5::sendCommandWithResponse(
3686
3692
}
3687
3693
}
3688
3694
3689
- // if (_printDebug == true)
3690
- // if (printedSomething)
3691
- // _debugPort->println();
3695
+ if (_printDebug == true )
3696
+ if (printedSomething)
3697
+ _debugPort->println ();
3692
3698
3693
3699
pruneBacklog (); // Prune any incoming non-actionable URC's and responses/errors from the backlog
3694
3700
0 commit comments