receiver.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <sys/time.h>
  6. #include "freertos/FreeRTOS.h"
  7. #include "freertos/task.h"
  8. #include "esp_sleep.h"
  9. #include "esp_log.h"
  10. #include "driver/uart.h"
  11. #include "driver/rtc_io.h"
  12. #include "esp_intr_alloc.h"
  13. #include "esp_attr.h"
  14. #include "driver/timer.h"
  15. #include <stddef.h>
  16. #include "esp_intr_alloc.h"
  17. #include "receiver.h"
  18. #include "transceiver.h"
  19. #include "rxTimer.h"
  20. #include "Sensors/ClasOSensor.h"
  21. #include "Sensors/proovesmartSensor.h"
  22. #include "Sensors/nexa.h"
  23. #include "Sensors/oregon.h"
  24. #include "led.h"
  25. #include "udp_client.h"
  26. #include "wifi.h"
  27. uint32_t dataArr[1000];
  28. uint32_t dataArrIdx = 0;
  29. static int convertToSignedTemp(unsigned int value)
  30. {
  31. //int signValue;
  32. return ( (value >> 11) == 0 )? value : ((-1 ^ 0xFFF) | value);
  33. }
  34. void receiverTask(void *pvParameter)
  35. {
  36. ESP_LOGI("RX", "Receiver task starting.");
  37. uint32_t width;
  38. char dataStr[UDP_QUEUE_OBJ_LENGTH];
  39. while (1) {
  40. while( xQueueReceive( rxQueue, &width, portMAX_DELAY ) == pdTRUE ) {
  41. dataArr[dataArrIdx++] = width;
  42. if( dataArrIdx == 1000 ) dataArrIdx=0;
  43. // Receive the Clas Ohlsson Sensors
  44. int64_t data = nextPulseClasOSensor(width);
  45. if( data != -1 ) {
  46. int value = convertToSignedTemp( data & 0xFFF );
  47. ESP_LOGI("RX", "ClasO: <TR%08llX> %d",data,value);
  48. sprintf(dataStr,"<TR%08llX>\n",data);
  49. #ifdef WIFI_ENABLED
  50. sendUDPMessage(dataStr);
  51. #endif
  52. }
  53. // Receive the Telldus / Proovesmart Sensors
  54. data = nextPulseProovesmartSensor(width);
  55. if( data != -1 ) {
  56. const int value = (data & 0x00FFF0000) >> 16;
  57. const int id = (data & 0xFF0000000) >> 28;
  58. ESP_LOGI("RX", "Proove: <Tr%016llX> ID:%d %d",data,id,value);
  59. sprintf(dataStr,"<Tr%016llX>\n",data);
  60. #ifdef WIFI_ENABLED
  61. sendUDPMessage(dataStr);
  62. #endif
  63. }
  64. // Receive the NEXA Sensors
  65. data = nextPulseNEXA(width);
  66. if( data != -1 ) {
  67. ESP_LOGI("RX", "NEXA: <NR%08llX>",data);
  68. sprintf(dataStr,"<NR%08llX>\n",data);
  69. #ifdef WIFI_ENABLED
  70. sendUDPMessage(dataStr);
  71. #endif
  72. }
  73. // Receive the Oregon (Rain) Sensor
  74. char *ch_data_p = nextPulseOregonSensor(width);
  75. if( ch_data_p != NULL ) {
  76. char ch_data[21];
  77. strncpy(ch_data,ch_data_p, sizeof(ch_data));
  78. ESP_LOGI("RX", "OREGON: <RR%s>", ch_data );
  79. Oregon_ResetDecoder();
  80. }
  81. }
  82. }
  83. vTaskDelete(NULL);
  84. }
  85. void initReceiver() {
  86. Oregon_ResetDecoder();
  87. ClasO_ResetDecoder();
  88. ProovesmartSensor_ResetDecoder();
  89. ESP_LOGI("RX", "Receiver has been initialized.");
  90. xTaskCreatePinnedToCore(&receiverTask, "receiverTask", 8192, NULL, tskIDLE_PRIORITY + 5, NULL, 0);
  91. }