nbus_impl.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include "nbus_impl.h"
  2. void nbus_unicastToSensorGet(nBus_TypeDef *nbus){
  3. ;
  4. }
  5. void nbus_unicastToSensorSet(nBus_TypeDef *nbus){
  6. ;
  7. }
  8. void nbus_unicastToModuleGet(nBus_TypeDef *nbus){
  9. switch(nbus->function_code.function){
  10. case CMD_VERSION:
  11. {
  12. nbus->tx_buffer[4] = VERSION_MAJOR;
  13. nbus->tx_buffer[5] = '.';
  14. nbus->tx_buffer[6] = VERSION_MINOR;
  15. nbus->tx_length += 3;
  16. }
  17. break;
  18. case CMD_ECHO:
  19. {
  20. for(uint8_t i=3 ; i<nbus->rx_length-1 ; i++){
  21. nbus->tx_buffer[i+1] = nbus->rx_buffer[i];
  22. }
  23. nbus->tx_length += (nbus->rx_length-4);
  24. }
  25. break;
  26. case CMD_PARAM:
  27. {
  28. nbus->tx_buffer[4] = OK_CODE;
  29. nbus->tx_length += 1;
  30. }
  31. break;
  32. default:
  33. {
  34. nbus->function_code.error = 1;
  35. nbus->tx_buffer[4] = ILLEGAL_FUNCTION;
  36. nbus->tx_length += 1;
  37. }
  38. }
  39. }
  40. void nbus_unicastToModuleSet(nBus_TypeDef *nbus){
  41. switch(nbus->function_code.function){
  42. case CMD_PARAM:
  43. {
  44. nbus->tx_buffer[4] = OK_CODE;
  45. nbus->tx_length += 1;
  46. }
  47. break;
  48. case CMD_SLEEP:
  49. {
  50. nbus->tx_buffer[4] = OK_CODE;
  51. nbus->tx_length += 1;
  52. }
  53. break;
  54. case CMD_WAKEUP:
  55. {
  56. nbus->tx_buffer[4] = OK_CODE;
  57. nbus->tx_length += 1;
  58. }
  59. break;
  60. default:
  61. {
  62. nbus->function_code.error = 1;
  63. nbus->tx_buffer[4] = ILLEGAL_FUNCTION;
  64. nbus->tx_length += 1;
  65. }
  66. }
  67. }
  68. void nbus_broadcast(nBus_TypeDef *nbus, nBusCommandType_t request_type){
  69. if(request_type == BROADCAST_SPECIFIC_SENSORS) {
  70. }
  71. if(request_type == BROADCAST_GLOBAL) {
  72. switch(nbus->function_code.function) {
  73. #if MODULE_MASTER
  74. case CMD_SYNC:
  75. {
  76. if(nbus->rx_length < 11){
  77. return;
  78. }
  79. RTC_TimeTypeDef sTime = {0};
  80. RTC_DateTypeDef sDate = {0};
  81. sTime.Hours = nbus->rx_buffer[7];
  82. sTime.Minutes = nbus->rx_buffer[8];
  83. sTime.Seconds = nbus->rx_buffer[9];
  84. sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  85. sTime.StoreOperation = RTC_STOREOPERATION_RESET;
  86. HAL_RTC_SetTime(nbus->periph->rtc, &sTime, RTC_FORMAT_BCD);
  87. sDate.WeekDay = nbus->rx_buffer[6];
  88. sDate.Date = nbus->rx_buffer[5];
  89. sDate.Month = nbus->rx_buffer[4];
  90. sDate.Year = nbus->rx_buffer[3];
  91. HAL_RTC_SetDate(nbus->periph->rtc, &sDate, RTC_FORMAT_BCD);
  92. }
  93. break;
  94. #endif
  95. case CMD_START:
  96. {
  97. nbus->measure_active = MEASURE_RUNNING;
  98. }
  99. break;
  100. case CMD_STOP:
  101. {
  102. nbus->measure_active = MEASURE_STOPPED;
  103. }
  104. break;
  105. default:
  106. ; // nothing
  107. }
  108. }
  109. nbus->send_response = NO_RESPONSE;
  110. }