|
@@ -760,6 +760,115 @@ void getNowDatetime(uint8_t *data)
|
|
|
sprintf((char*)data, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
|
|
}
|
|
|
|
|
|
+int syncDateTimeRTC(uint8_t *data)
|
|
|
+{
|
|
|
+ struct ParsingResult
|
|
|
+ {
|
|
|
+ int result;
|
|
|
+ int scanedElement;
|
|
|
+ int year;
|
|
|
+ int month;
|
|
|
+ int mday;
|
|
|
+ int hour;
|
|
|
+ int min;
|
|
|
+ int sec;
|
|
|
+ int tz_hour;
|
|
|
+ int tz_min;
|
|
|
+ float minSec;
|
|
|
+ }result;
|
|
|
+ struct tm tmOrg;
|
|
|
+ struct tm *tmTarget;
|
|
|
+ struct timeb tbTarget;
|
|
|
+ char buf[128];
|
|
|
+
|
|
|
+ memset(&result, 0x00, sizeof(struct ParsingResult));
|
|
|
+ result.result = PASS;
|
|
|
+
|
|
|
+ if(strstr((char*)data, ".") != NULL)
|
|
|
+ {
|
|
|
+ // Original data with mini second
|
|
|
+ if(strstr((char*)data, "Z") != NULL)
|
|
|
+ {
|
|
|
+ // Original data with Z
|
|
|
+ result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%fZ",
|
|
|
+ &result.year,
|
|
|
+ &result.month,
|
|
|
+ &result.mday,
|
|
|
+ &result.hour,
|
|
|
+ &result.min,
|
|
|
+ &result.sec,
|
|
|
+ &result.minSec);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Original data without Z
|
|
|
+ result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d.%f%d:%d",
|
|
|
+ &result.year,
|
|
|
+ &result.month,
|
|
|
+ &result.mday,
|
|
|
+ &result.hour,
|
|
|
+ &result.min,
|
|
|
+ &result.sec,
|
|
|
+ &result.minSec,
|
|
|
+ &result.tz_hour,
|
|
|
+ &result.tz_min);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Original data without mini second
|
|
|
+ if(strstr((char*)data, "Z") != NULL)
|
|
|
+ {
|
|
|
+ // Original data with Z
|
|
|
+ result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%dZ",
|
|
|
+ &result.year,
|
|
|
+ &result.month,
|
|
|
+ &result.mday,
|
|
|
+ &result.hour,
|
|
|
+ &result.min,
|
|
|
+ &result.sec);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Original data without Z
|
|
|
+ result.scanedElement = sscanf((char*)data, "%d-%d-%dT%d:%d:%d%d:%d",
|
|
|
+ &result.year,
|
|
|
+ &result.month,
|
|
|
+ &result.mday,
|
|
|
+ &result.hour,
|
|
|
+ &result.min,
|
|
|
+ &result.sec,
|
|
|
+ &result.tz_hour,
|
|
|
+ &result.tz_min);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ tmOrg.tm_year = result.year - 1900;
|
|
|
+ tmOrg.tm_mon = result.month - 1;
|
|
|
+ tmOrg.tm_mday = result.mday;
|
|
|
+ tmOrg.tm_hour = result.hour;
|
|
|
+ tmOrg.tm_min = result.min;
|
|
|
+ tmOrg.tm_sec = result.sec;
|
|
|
+ tmOrg.tm_gmtoff = 0;
|
|
|
+ tbTarget.time = mktime(&tmOrg);
|
|
|
+ tbTarget.timezone = 0;
|
|
|
+
|
|
|
+ tbTarget.time -= (result.tz_hour*3600) + (result.tz_min*60*(result.tz_hour>=0?1:-1));
|
|
|
+ tmTarget = gmtime(&tbTarget.time);
|
|
|
+
|
|
|
+ sprintf(buf, "date -s '%04d-%02d-%02d %02d:%02d:%02d'", (tmTarget->tm_year+1900), (tmTarget->tm_mon+1), tmTarget->tm_mday, tmTarget->tm_hour, tmTarget->tm_min, tmTarget->tm_sec);
|
|
|
+ //DEBUG_INFO(" org date time: %s\n", data);
|
|
|
+ //DEBUG_INFO("parse date time: %s\n", buf);
|
|
|
+
|
|
|
+ system(buf);
|
|
|
+ system("/sbin/hwclock -w --systohc");
|
|
|
+
|
|
|
+ if(result.scanedElement < 6)
|
|
|
+ result.result = FAIL;
|
|
|
+
|
|
|
+ return result.result;
|
|
|
+}
|
|
|
+
|
|
|
//==========================================
|
|
|
// GetCompositeSchedule logic related function
|
|
|
//==========================================
|
|
@@ -11529,9 +11638,6 @@ void handleBootNotificationResponse(char *payload, int gun_index)
|
|
|
char statusStr[12]={0};
|
|
|
char currentTimeStr[30]={0};
|
|
|
int intervalInt = 0;
|
|
|
- struct tm tp;
|
|
|
- char buf[28]={0};
|
|
|
- char timebuf[50]={0};
|
|
|
|
|
|
DEBUG_INFO("handleBootNotificationResponse...\n");
|
|
|
|
|
@@ -11566,22 +11672,10 @@ void handleBootNotificationResponse(char *payload, int gun_index)
|
|
|
{
|
|
|
server_pending = TRUE;
|
|
|
}
|
|
|
-
|
|
|
- strptime((const char *)ShmOCPP16Data->BootNotification.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
|
|
|
- tp.tm_isdst = -1;
|
|
|
- //time_t utc = mktime(&tp);
|
|
|
-
|
|
|
- strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
|
|
|
- memset(timebuf, 0, ARRAY_SIZE(timebuf));
|
|
|
- sprintf(timebuf,"date -s '%s'",buf);
|
|
|
- system(timebuf);
|
|
|
+ syncDateTimeRTC(ShmOCPP16Data->BootNotification.ResponseCurrentTime);
|
|
|
|
|
|
srand(time(NULL));
|
|
|
clientTime.Heartbeat = time((time_t*)NULL) - (ShmOCPP16Data->BootNotification.ResponseHeartbeatInterval-((rand()%8)+3));
|
|
|
- //==============================================
|
|
|
- // RTC sync
|
|
|
- //==============================================
|
|
|
- system("/sbin/hwclock -w --systohc");
|
|
|
|
|
|
SetOcppConnStatus(TRUE);
|
|
|
ShmOCPP16Data->SpMsg.bits.BootNotificationConf = 1;
|
|
@@ -11632,9 +11726,6 @@ void handleFirmwareStatusNotificationResponse(char *payload, int gun_index)
|
|
|
void handleHeartbeatResponse(char *payload, int gun_index)
|
|
|
{
|
|
|
mtrace();
|
|
|
- struct tm tp;
|
|
|
- char buf[28]={0};
|
|
|
- char timebuf[50]={0};
|
|
|
|
|
|
DEBUG_INFO("handleHeartbeatResponse...\n");
|
|
|
json_object *Heartbeat;
|
|
@@ -11655,18 +11746,7 @@ void handleHeartbeatResponse(char *payload, int gun_index)
|
|
|
HeartBeatWithNOResponse = 0;
|
|
|
clientTime.Heartbeat=time((time_t*)NULL);
|
|
|
|
|
|
- strptime((const char *)ShmOCPP16Data->Heartbeat.ResponseCurrentTime, "%Y-%m-%dT%H:%M:%S", &tp);
|
|
|
- tp.tm_isdst = -1;
|
|
|
- //time_t utc = mktime(&tp);
|
|
|
- strftime(buf, 28, "%Y-%m-%d %H:%M:%S", &tp);
|
|
|
- memset(timebuf, 0, ARRAY_SIZE(timebuf));
|
|
|
- sprintf(timebuf,"date -s '%s'",buf);
|
|
|
- system(timebuf);
|
|
|
-
|
|
|
- //==============================================
|
|
|
- // RTC sync
|
|
|
- //==============================================
|
|
|
- system("/sbin/hwclock -w --systohc");
|
|
|
+ syncDateTimeRTC(ShmOCPP16Data->Heartbeat.ResponseCurrentTime);
|
|
|
}
|
|
|
|
|
|
void handleMeterValuesResponse(char *payload, int gun_index)
|