receiver.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 "led.h"
  24. #include "udp_client.h"
  25. #include "wifi.h"
  26. uint32_t dataArr[1000];
  27. uint32_t dataArrIdx = 0;
  28. static int convertToSignedTemp(unsigned int value)
  29. {
  30. //int signValue;
  31. return ( (value >> 11) == 0 )? value : ((-1 ^ 0xFFF) | value);
  32. }
  33. void receiverTask(void *pvParameter)
  34. {
  35. ESP_LOGI("RX", "Receiver task starting.");
  36. uint32_t width;
  37. char dataStr[UDP_QUEUE_OBJ_LENGTH];
  38. while (1) {
  39. while( xQueueReceive( rxQueue, &width, portMAX_DELAY ) == pdTRUE ) {
  40. dataArr[dataArrIdx++] = width;
  41. if( dataArrIdx == 1000 ) dataArrIdx=0;
  42. // Receive the Clas Ohlsson Sensors
  43. int64_t data = nextPulseClasOSensor(width);
  44. if( data != -1 ) {
  45. int value = convertToSignedTemp( data & 0xFFF );
  46. ESP_LOGI("RX", "ClasO: <TR%08llX> %d",data,value);
  47. sprintf(dataStr,"<TR%08llX>\n",data);
  48. #ifdef WIFI_ENABLED
  49. sendUDPMessage(dataStr);
  50. #endif
  51. }
  52. // Receive the Telldus / Proovesmart Sensors
  53. data = nextPulseProovesmartSensor(width);
  54. if( data != -1 ) {
  55. const int value = (data & 0x00FFF0000) >> 16;
  56. const int id = (data & 0xFF0000000) >> 28;
  57. ESP_LOGI("RX", "Proove: <Tr%016llX> ID:%d %d",data,id,value);
  58. sprintf(dataStr,"<Tr%016llX>\n",data);
  59. #ifdef WIFI_ENABLED
  60. sendUDPMessage(dataStr);
  61. #endif
  62. }
  63. // Receive the NEXA Sensors
  64. data = nextPulseNEXA(width);
  65. if( data != -1 ) {
  66. ESP_LOGI("RX", "NEXA: <NR%08llX>",data);
  67. sprintf(dataStr,"<NR%08llX>\n",data);
  68. #ifdef WIFI_ENABLED
  69. sendUDPMessage(dataStr);
  70. #endif
  71. }
  72. }
  73. }
  74. vTaskDelete(NULL);
  75. }
  76. void initReceiver() {
  77. ESP_LOGI("RX", "Receiver has been initialized.");
  78. xTaskCreatePinnedToCore(&receiverTask, "receiverTask", 8192, NULL, tskIDLE_PRIORITY + 5, NULL, 0);
  79. }