#include "nbus_impl.h" nBus_functionCode_t* nbus_unicastToSensor(nBus_TypeDef *nbus, nBus_functionCode_t *code){ return code; } nBus_functionCode_t* nbus_unicastToModule(nBus_TypeDef *nbus, nBus_functionCode_t *code){ switch(nbus->function_code.function){ case CMD_VERSION: { nbus->tx_buffer[4] = VERSION_MAJOR; nbus->tx_buffer[5] = '.'; nbus->tx_buffer[6] = VERSION_MINOR; nbus->tx_length += 3; } break; case CMD_ECHO: { for(uint8_t i=3 ; irx_length-1 ; i++){ nbus->tx_buffer[i+1] = nbus->rx_buffer[i]; } nbus->tx_length += (nbus->rx_length-4); } break; default: { code->error = 1; nbus->tx_buffer[4] = ILLEGAL_FUNCTION; nbus->tx_length += 1; } } return code; } void nbus_broadcast(nBus_TypeDef *nbus, nBusCommandType_t request_type){ if(request_type == BROADCAST_SPECIFIC_SENSORS) { } if(request_type == BROADCAST_GLOBAL) { switch(nbus->function_code.function) { case CMD_SYNC: { if(nbus->rx_length < 11){ return; } RTC_TimeTypeDef sTime = {0}; RTC_DateTypeDef sDate = {0}; sTime.Hours = nbus->rx_buffer[7]; sTime.Minutes = nbus->rx_buffer[8]; sTime.Seconds = nbus->rx_buffer[9]; sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; sTime.StoreOperation = RTC_STOREOPERATION_RESET; HAL_RTC_SetTime(nbus->periph->rtc, &sTime, RTC_FORMAT_BCD); sDate.WeekDay = nbus->rx_buffer[6]; sDate.Month = nbus->rx_buffer[4]; sDate.Date = nbus->rx_buffer[5]; sDate.Year = nbus->rx_buffer[3]; HAL_RTC_SetDate(nbus->periph->rtc, &sDate, RTC_FORMAT_BCD); } break; case CMD_START: { nbus->measure_active = MEASURE_RUNNING; } break; case CMD_STOP: { nbus->measure_active = MEASURE_STOPPED; } break; default: ; // nothing } } nbus->send_response = NO_RESPONSE; }