Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include "drivers/event.h"
  4. #include "drivers/task.h"
  5. #include "drivers/rf.h"
  6.  
  7. #include "myTask.h"
  8.  
  9. /*** local struct definitions ***/
  10.  
  11. typedef struct sensorData{
  12.     uint32_t address;
  13.     uint32_t totalPacketsReceived;
  14. }
  15.  
  16.  
  17. // Standard format of data from sensors [sourceAddress][data]
  18. typedef struct sensorPacket{
  19.     uint32_t sourceAddress;
  20.     uint16_t data;
  21. }
  22.  
  23.  
  24. /*** Global variable declarations ***/
  25.  
  26. static sensorPacket latestPacket;   // A global variable to store the more recently received packet
  27.  
  28.  
  29. /************************************/
  30.  
  31. /*** Initialise our task and event ***/
  32. void myTask_init(void){
  33.  
  34.     // Create a new event and event handle
  35.     event_create(&myEvent)
  36.     myEventHandle = event_handle(&myEvent);
  37.  
  38.     // Create a new task which will start immediately at 'myTaskFunction()'
  39.     task_create(&myTask, myTaskFunction);
  40.  
  41. }
  42.  
  43.  
  44. /*** This is our main task function ***/
  45. static void myTask_function(void){
  46.  
  47.     // ...
  48.     sensorData sensorList[8];
  49.  
  50.  
  51.     while(1){
  52.  
  53.         // ...
  54.         uint32_t events = event_pend(myEventHandle);
  55.  
  56.         if(events == EVENT_NEW_STANDARD_DATA_PACKET){}
  57.  
  58.             // Create a function to update the sensorList table with the new packet receieved count
  59.             // - Assume there is already data from that sensor in the table and it can be identified by the 'address' field
  60.  
  61.             //
  62.  
  63.         }
  64.  
  65.         if(events == EVENT_ADD_NEW_SENSOR){
  66.  
  67.             // ...
  68.  
  69.         }
  70.  
  71.  
  72.     }
  73.  
  74. }
  75.  
  76.  
  77. // This callback occurs when we receive wireless data
  78. void packetReceivedCallback(uint32_t address, uint16_t data){
  79.  
  80.     // Copy the packet data into a global variable
  81.     latestPacket.sourceAddress = address;
  82.     latestPacket.data = data;
  83.  
  84.     // ...
  85.     event_post(&myEventHandle, EVENT_NEW_STANDARD_DATA_PACKET)
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement