/********************************************************************* * @fn timeAppClockSet() * * @brief Set the clock. * * @param pData - Pointer to a Date Time characteristic structure * * @return none */ void timeAppClockSet( uint8 *pData ) { UTCTimeStruct time; // Parse time service structure to OSAL time structure time.year = BUILD_UINT16(pData[0], pData[1]); if ( time.year == 0 ) { time.year = 2000; } pData += 2; time.month = *pData++; if ( time.month > 0 ) { // time.month--; } time.day = *pData++; if ( time.day > 0 ) { // time.day--; } time.hour = *pData++; time.minutes = *pData++; time.seconds = *pData; // Update OSAL time osal_setClock( osal_ConvertUTCSecs( &time ) ); }
static void modbus_setUtcTime( uint8 *pBuf) { UTCTime utcSecs = 0; UTCTimeStruct utc; utc.hour = pBuf[1]; utc.minutes = pBuf[3]; utc.seconds = pBuf[5]; utc.month = pBuf[7] - 1; utc.day = pBuf[9] - 1; utc.year = BUILD_UINT16( pBuf[11], pBuf[10]); if ((utc.hour < 24) && (utc.minutes < 60) && (utc.seconds < 60) && (utc.month < 12) && (utc.day < 31) && (utc.year > 1999) && (utc.year < 2136)) { if ((utc.month != 1) || (utc.day < (IsLeapYear( utc.year ) ? 29 : 28))) { utcSecs = osal_ConvertUTCSecs( &utc ); } } if( utcSecs) { osal_setClock( utcSecs ); } }
/*************************************************************************************************** * @fn MT_SysSetUtcTime * * @brief Set the OSAL UTC Time. UTC rollover is: 06:28:16 02/07/2136 * * @param pBuf - pointer to time parameters * * @return None ***************************************************************************************************/ void MT_SysSetUtcTime(uint8 *pBuf) { uint8 cmdId; uint8 retStat; UTCTime utcSecs; /* Parse header */ cmdId = pBuf[MT_RPC_POS_CMD1]; pBuf += MT_RPC_FRAME_HDR_SZ; utcSecs = osal_build_uint32( pBuf, 4 ); if ( utcSecs == 0 ) { UTCTimeStruct utc; /* Skip past UTC time */ pBuf += 4; /* Get time and date parameters */ utc.hour = *pBuf++; utc.minutes = *pBuf++; utc.seconds = *pBuf++; utc.month = (*pBuf++) - 1; utc.day = (*pBuf++) - 1; utc.year = osal_build_uint16 ( pBuf ); if ((utc.hour < 24) && (utc.minutes < 60) && (utc.seconds < 60) && (utc.month < 12) && (utc.day < 31) && (utc.year > 1999) && (utc.year < 2136)) { /* Got past the course filter, now check for leap year */ if ((utc.month != 1) || (utc.day < (IsLeapYear( utc.year ) ? 29 : 28))) { /* Numbers look reasonable, convert to UTC */ utcSecs = osal_ConvertUTCSecs( &utc ); } } } if ( utcSecs == 0 ) { /* Bad parameter(s) */ retStat = ZInvalidParameter; } else { /* Parameters accepted, set the time */ osal_setClock( utcSecs ); retStat = ZSuccess; } /* Build and send back the response */ MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_SYS), cmdId, 1, &retStat); }
static void ther_handle_ps_event(unsigned char event, unsigned char *data, unsigned char *len) { struct ther_info *ti = &ther_info; UTCTimeStruct utc; uint16 high_temp_threshold; switch (event) { case THER_PS_GET_WARNING_ENABLED: *data = ti->warning_enabled; *len = 1; print(LOG_DBG, MODULE "get warning enabled: %d\n", *data); break; case THER_PS_SET_WARNING_ENABLED: ti->warning_enabled = *data; print(LOG_DBG, MODULE "set warning enabled: %d\n", *data); break; case THER_PS_CLEAR_WARNING: print(LOG_DBG, MODULE "clear warning: %d\n", *data); ther_clear_high_temp_warning(ti); break; case THER_PS_GET_HIGH_WARN_TEMP: memcpy(data, &ti->high_temp_threshold, sizeof(ti->high_temp_threshold)); *len = sizeof(ti->high_temp_threshold); print(LOG_DBG, MODULE "get high temp: %d\n", *(unsigned short *)data); break; case THER_PS_SET_HIGH_WARN_TEMP: memcpy(&high_temp_threshold, data, sizeof(high_temp_threshold)); if (storage_write_high_temp_threshold(high_temp_threshold)) { print(LOG_DBG, MODULE "set high temp: %d\n", high_temp_threshold); ti->high_temp_threshold = high_temp_threshold; ti->next_warning_threshold = ti->high_temp_threshold; } else { print(LOG_DBG, MODULE "set high temp: %d failed\n", high_temp_threshold); } break; case THER_PS_GET_TIME: osal_ConvertUTCTime(&utc, osal_getClock()); memcpy(data, &utc, sizeof(utc)); *len = sizeof(utc); print(LOG_DBG, MODULE "get time: %d-%02d-%02d %02d:%02d:%02d\n", utc.year, utc.month, utc.day, utc.hour, utc.minutes, utc.seconds); break; case THER_PS_SET_TIME: memcpy(&utc, data, sizeof(utc)); osal_setClock(osal_ConvertUTCSecs(&utc)); print(LOG_DBG, MODULE "set time: %d-%02d-%02d %02d:%02d:%02d\n", utc.year, utc.month, utc.day, utc.hour, utc.minutes, utc.seconds); ti->start_sec = osal_ConvertUTCSecs(&utc); break; case THER_PS_GET_DEBUG: { ti->mode = CAL_MODE; /* * stop temp measurement */ osal_stop_timerEx(ti->task_id, TH_TEMP_MEASURE_EVT); ther_temp_power_on(); ti->temp_measure_stage = TEMP_STAGE_SETUP; /* * stop batt measurement */ osal_stop_timerEx(ti->task_id, TH_BATT_EVT); } *(unsigned short *)data = ther_get_hw_adc(HAL_ADC_CHANNEL_0, FROM_CUSTOM); *len = 2; break; case THER_PS_SET_DEBUG: break; default: *len = 0; break; } }
/** * @fn sensorTag_ClockSet * * @brief for real time clock * * @param * * @return none */ static void sensorTag_ClockSet(UTCTimeStruct *tm) { osal_setClock(osal_ConvertUTCSecs(tm)); }