nbus_impl_broadcast.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "nbus_impl.h"
  2. inline void setErrorResponse(nBus_TypeDef *nbus, uint8_t code){
  3. nbus->function_code.error = 1;
  4. nbus->tx_buffer[4] = code;
  5. nbus->tx_length += 1;
  6. }
  7. void nbus_broadcast(nBus_TypeDef *nbus, nBusCommandType_t request_type){
  8. if(request_type == BROADCAST_SPECIFIC_SENSORS) {
  9. }
  10. if(request_type == BROADCAST_GLOBAL) {
  11. switch(nbus->function_code.function) {
  12. #if MODULE_MASTER
  13. case CMD_SYNC:
  14. {
  15. if(nbus->rx_length < 11){
  16. return;
  17. }
  18. RTC_TimeTypeDef sTime = {0};
  19. RTC_DateTypeDef sDate = {0};
  20. sTime.Hours = nbus->rx_buffer[7];
  21. sTime.Minutes = nbus->rx_buffer[8];
  22. sTime.Seconds = nbus->rx_buffer[9];
  23. sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  24. sTime.StoreOperation = RTC_STOREOPERATION_RESET;
  25. HAL_RTC_SetTime(nbus->periph->rtc, &sTime, RTC_FORMAT_BCD);
  26. sDate.WeekDay = nbus->rx_buffer[6];
  27. sDate.Date = nbus->rx_buffer[5];
  28. sDate.Month = nbus->rx_buffer[4];
  29. sDate.Year = nbus->rx_buffer[3];
  30. HAL_RTC_SetDate(nbus->periph->rtc, &sDate, RTC_FORMAT_BCD);
  31. }
  32. break;
  33. #endif
  34. case CMD_START:
  35. {
  36. nbus->measure_active = MEASURE_RUNNING;
  37. nbus->interface->start();
  38. HAL_GPIO_WritePin(nbus->periph->led->port, nbus->periph->led->pin, GPIO_PIN_SET);
  39. }
  40. break;
  41. case CMD_STOP:
  42. {
  43. nbus->measure_active = MEASURE_STOPPED;
  44. nbus->interface->stop();
  45. HAL_GPIO_WritePin(nbus->periph->led->port, nbus->periph->led->pin, GPIO_PIN_RESET);
  46. }
  47. break;
  48. default:
  49. ; // nothing
  50. }
  51. }
  52. nbus->send_response = NO_RESPONSE;
  53. }