| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include "nbus_impl.h"
- inline void setErrorResponse(nBus_TypeDef *nbus, uint8_t code){
- nbus->function_code.error = 1;
- nbus->tx_buffer[4] = code;
- nbus->tx_length += 1;
- }
- 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) {
- #if MODULE_MASTER
- 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.Date = nbus->rx_buffer[5];
- sDate.Month = nbus->rx_buffer[4];
- sDate.Year = nbus->rx_buffer[3];
- HAL_RTC_SetDate(nbus->periph->rtc, &sDate, RTC_FORMAT_BCD);
- }
- break;
- #endif
- case CMD_START:
- {
- nbus->measure_active = MEASURE_RUNNING;
- nbus->interface->start();
- HAL_GPIO_WritePin(nbus->periph->led->port, nbus->periph->led->pin, GPIO_PIN_SET);
- }
- break;
- case CMD_STOP:
- {
- nbus->measure_active = MEASURE_STOPPED;
- nbus->interface->stop();
- HAL_GPIO_WritePin(nbus->periph->led->port, nbus->periph->led->pin, GPIO_PIN_RESET);
- }
- break;
- default:
- ; // nothing
- }
- }
- nbus->send_response = NO_RESPONSE;
- }
|