@@ -847,18 +847,21 @@ String SARA_R5::clock(void)
847847 }
848848 *(clockEnd) = ' \0 ' ; // Set last quote to null char -- end string
849849
850+ String clock = String (clockBegin); // Extract the clock as a String _before_ freeing response
851+
850852 free (command);
851853 free (response);
852854
853- return String (clockBegin );
855+ return (clock );
854856}
855857
856858SARA_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)
858860{
859861 SARA_R5_error_t err;
860862 char *command;
861863 char *response;
864+ char tzPlusMinus;
862865
863866 int iy, imo, id, ih, imin, is, itz;
864867
@@ -877,19 +880,22 @@ SARA_R5_error_t SARA_R5::clock(uint8_t *y, uint8_t *mo, uint8_t *d,
877880 err = sendCommandWithResponse (command, SARA_R5_RESPONSE_OK,
878881 response, SARA_R5_STANDARD_RESPONSE_TIMEOUT);
879882
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
881884 if (err == SARA_R5_ERROR_SUCCESS)
882885 {
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 )
885888 {
886889 *y = iy;
887890 *mo = imo;
888891 *d = id;
889892 *h = ih;
890893 *min = imin;
891894 *s = is;
892- *tz = itz;
895+ if (tzPlusMinus == ' +' )
896+ *tz = itz;
897+ else
898+ *tz = 0 - itz;
893899 }
894900 else
895901 err = SARA_R5_ERROR_UNEXPECTED_RESPONSE;
@@ -3640,12 +3646,12 @@ SARA_R5_error_t SARA_R5::sendCommandWithResponse(
36403646 int index = 0 ;
36413647 int destIndex = 0 ;
36423648 unsigned int charsRead = 0 ;
3643- // bool printedSomething = false;
3649+ bool printedSomething = false ;
36443650
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));
36493655
36503656 int backlogIndex = sendCommand (command, at); // Sending command needs to dump data to backlog buffer as well.
36513657 unsigned long timeIn = millis ();
@@ -3655,13 +3661,13 @@ SARA_R5_error_t SARA_R5::sendCommandWithResponse(
36553661 if (hwAvailable () > 0 ) // hwAvailable can return -1 if the serial port is NULL
36563662 {
36573663 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+ }
36653671 if (responseDest != NULL )
36663672 {
36673673 responseDest[destIndex++] = c;
@@ -3686,9 +3692,9 @@ SARA_R5_error_t SARA_R5::sendCommandWithResponse(
36863692 }
36873693 }
36883694
3689- // if (_printDebug == true)
3690- // if (printedSomething)
3691- // _debugPort->println();
3695+ if (_printDebug == true )
3696+ if (printedSomething)
3697+ _debugPort->println ();
36923698
36933699 pruneBacklog (); // Prune any incoming non-actionable URC's and responses/errors from the backlog
36943700
0 commit comments