Optimze time cmnd

This commit is contained in:
Norbert Richter 2021-01-21 09:34:35 +01:00
parent ab22a9e0e5
commit 52d42512ee
No known key found for this signature in database
GPG Key ID: 6628701A626FA674

View File

@ -1228,7 +1228,6 @@ bool NeoPoolCmnd(void)
{
char dt[20];
TIME_T tmpTime;
uint16_t t_low, t_high;
if (1 == params_cnt) {
uint32_t new_time = Rtc.local_time;
@ -1238,31 +1237,28 @@ bool NeoPoolCmnd(void)
if (value[1]>1) {
new_time = value[1];
}
t_low = (uint16_t)(new_time & 0xFFFF);
t_high = (uint16_t)((new_time>>16) & 0xFFFF);
data[0] = (uint16_t)(new_time & 0xFFFF);
data[1] = (uint16_t)((new_time>>16) & 0xFFFF);
#ifdef DEBUG_TASMOTA_SENSOR
AddLog_P(LOG_LEVEL_DEBUG, PSTR("NEO: set time to %ld (%04X%04X)"), new_time, t_low, t_high);
AddLog_P(LOG_LEVEL_DEBUG, PSTR("NEO: set time to %ld (%04X%04X)"), new_time, data[0], data[1]);
#endif // DEBUG_TASMOTA_SENSOR
serviced = (NEOPOOL_OK == NeoPoolWriteRegister(MBF_PAR_TIME_HIGH, &t_high, 1));
if (serviced) {
serviced = (NEOPOOL_OK == NeoPoolWriteRegister(MBF_PAR_TIME_LOW, &t_low, 1));
}
serviced = (NEOPOOL_OK == NeoPoolWriteRegister(MBF_PAR_TIME_LOW, data, 2));
if (serviced) {
uint16_t set=0;
serviced = (NEOPOOL_OK == NeoPoolWriteRegister(MBF_ACTION_COPY_TO_RTC, &set, 1));
}
}
else if (0 == params_cnt) {
serviced = (NEOPOOL_OK == NeoPoolReadRegister(MBF_PAR_TIME_LOW, &t_low, 1) && NEOPOOL_OK == NeoPoolReadRegister(MBF_PAR_TIME_HIGH, &t_high, 1));
serviced = (NEOPOOL_OK == NeoPoolReadRegister(MBF_PAR_TIME_LOW, data, 2));
#ifdef DEBUG_TASMOTA_SENSOR
AddLog_P(LOG_LEVEL_DEBUG, PSTR("NEO: time read 0x%04X%04X %ld"), t_high, t_low, (uint32_t)t_low + ((uint32_t)t_high << 16));
AddLog_P(LOG_LEVEL_DEBUG, PSTR("NEO: time read 0x%04X%04X %ld"), data[1], data[0], (uint32_t)data[0] + ((uint32_t)data[1] << 16));
#endif // DEBUG_TASMOTA_SENSOR
}
else {
serviced = false;
}
if (serviced) {
BreakTime((uint32_t)t_low + ((uint32_t)t_high << 16), tmpTime);
BreakTime((uint32_t)data[0] + ((uint32_t)data[1] << 16), tmpTime);
snprintf_P(dt, sizeof(dt), PSTR("%04d" D_YEAR_MONTH_SEPARATOR "%02d" D_MONTH_DAY_SEPARATOR "%02d" D_DATE_TIME_SEPARATOR "%02d" D_HOUR_MINUTE_SEPARATOR "%02d" D_MINUTE_SECOND_SEPARATOR "%02d"),
tmpTime.year +1970, tmpTime.month, tmpTime.day_of_month, tmpTime.hour, tmpTime.minute, tmpTime.second);
Response_P(PSTR("{\"" D_CMND_SENSOR "%d\":{\"" D_JSON_TIME "\":\"%s\"}}"), XSNS_83, dt);