+static time_t timestampToSec(uint32_t time_stamp, uint32_t date_stamp)
+{
+ struct tm t;
+ uint16_t msec;
+ uint16_t tmr[3];
+ uint16_t date[3];
+
+ memset(&t, 0, sizeof(t));
+ memset(&tmr, 0, sizeof(tmr));
+ memset(&date, 0, sizeof(date));
+
+ LOG_INFO("time_s[%u],date[%u]\n", time_stamp, date_stamp);
+ uint32_t res = time_stamp / 1000;
+ uint32_t all = time_stamp;
+ msec = all - res * 1000;
+ for (int i = 0; i < 3; i++)
+ {
+ all = res;
+ res = all / 100;
+ tmr[i] = all - res * 100;
+ LOG_INFO("t[%d]%d\n", tmr[i],i);
+ }
+
+ t.tm_sec = tmr[0] + (ROUND_UP(msec, 1000) / 1000);
+ t.tm_min = tmr[1];
+ t.tm_hour = tmr[2];
+ t.tm_mday = 1;
+ t.tm_mon = 1;
+ t.tm_year = 70;
+
+ if (date_stamp)
+ {
+ res = all = date_stamp;
+ for (int i = 0; i < 3; i++)
+ {
+ all = res;
+ res = all / 100;
+ date[i] = all - res * 100;
+ LOG_INFO("d[%d]%d\n", date[i],i);
+ }
+ t.tm_mday = date[2];
+ t.tm_mon = date[1] - 1; // time struct count month from 0 to 11;
+ // we should specific number of years from 1900, but the year field
+ // is only two cipher, so we sum 100 (2000 - 1900)..
+ t.tm_year = date[0] + 100;
+ }
+ LOG_INFO("times=%d,%d,%d,%d,%d,%d\n",t.tm_sec, t.tm_min, t.tm_hour, t.tm_year, t.tm_mon, t.tm_mday);
+
+ return mktime(&t);
+}
+
+