Team Walter / Mbed OS NonPingPong_PICO_LoRa

Dependencies:   SX1276GenericLib USBDevice

Fork of NonPingPong_PICO_LoRa by Walter Luu

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers global_buffers.h Source File

global_buffers.h

00001 /** Description:
00002  *  This File is responsible for defining the buffers that will be used in
00003  *  various areas of the program. The buffers that are defined here will be 
00004  *  refferenced in the main.cpp and will be filled with data in one of two ways:
00005  *  
00006  *  1.  The buffers will be filled with data upon receiving a successful payload
00007  *      transmission over LoRa. In GenericPingPong.cpp, the function OnRxDone() 
00008  *      will call the function fillGlobalBufsWithPayload() that is responsible for 
00009  *      filling the appropriate buffers with the payload data that was received
00010  *      by either the master or slave device by the other device that sent it.
00011  *      
00012  *  2.  The buffers will be used to fill up a payload buffer that will be sent
00013  *      over LoRa by either the master or slave device to the receiving device.
00014  *      The function fillPayloadWithGlobalBufs() will use the global buffers that
00015  *      are filled with data for various sensors in the main.cpp to construct a
00016  *      payload to deliver to the other device when SX1276PingPong() is called 
00017  *      in file GenericPingPong.cpp. 
00018  *     
00019  */
00020 
00021 #ifndef __GLOBAL_BUFFERS_H__
00022 #define __GLOBAL_BUFFERS_H__\
00023  
00024 #include "mbed.h"
00025 //#include "GenericPingPong2.h"
00026 
00027 /***************************************************************************
00028  * MASTER Device
00029  **************************************************************************/\
00030 //#define MASTER 1
00031 
00032 /***************************************************************************
00033  * SLAVE Device
00034  **************************************************************************/\
00035 #define SLAVE 1
00036 
00037 
00038 /***************************************************************************
00039  * Indexes for which byte specific data begins at in the payload buffer
00040  **************************************************************************/
00041 /* size of ID data that defines what the signature of the device is */
00042 //const uint8_t size_signature = 1;
00043 
00044 const uint8_t size_of_MAX30208  = 2;            // temperature data
00045 const uint8_t size_of_MAX44009  = 2;            // light data
00046 const uint8_t size_of_MAX20361  = 3;            // AO32 data
00047 
00048 
00049 /* These are the sizes of each payload in bytes. Since there is different amount 
00050  * of data being sent in each direction, we need to declare the total size of 
00051  * the payload so we can instatiate the correct buffer sizes to store data that 
00052  * is to be delivered and for data that is received. 
00053  */
00054 
00055 //const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = 0;
00056 const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = 1;             // can't be zero, otherwise internal error
00057 const uint16_t PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER = size_of_MAX30208 + size_of_MAX44009 + size_of_MAX20361;
00058 
00059 /* determine the appropriate buffer sizes */
00060 #if MASTER == 1     // Master Device 
00061     const uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE;
00062     const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER;
00063 #elif SLAVE == 1    // Slave Device
00064     const uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER;
00065     const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE;
00066 #endif    
00067 
00068 #if   MASTER == 1 // Master Device: Gateway Device, only receiving data from Slave
00069     
00070     /* These are indexs used to deconstruct received payload buffer sent by the Slave */
00071     const uint8_t rx_idx_MAX30208 = 0;                                      // 1st buf in rx payload (begins at byte 0), temp data
00072     const uint8_t rx_idx_MAX44009 = rx_idx_MAX30208 + size_of_MAX30208;     // 2nd buf in rx payload, lux data
00073     const uint8_t rx_idx_MAX20361 = rx_idx_MAX44009 + size_of_MAX44009;     // 3rd buf in rx payload, AO32 data
00074         
00075 #elif SLAVE == 1 // Slave Device: Sensor Node, only sending data to Master
00076     /* These are indexs used to create the payload buffer to send to Master */
00077     const uint8_t tx_idx_MAX30208  = 0;                                     // 1st buf in tx payload (begins at byte 0), temp data
00078     const uint8_t tx_idx_MAX44009  = tx_idx_MAX30208 + size_of_MAX30208;    // 2nd buf in tx payload, lux data
00079     const uint8_t tx_idx_MAX20361  = tx_idx_MAX44009 + size_of_MAX44009;    // 3rd buf in tx payload, AO32 data
00080 #endif
00081 
00082 /***************************************************************************
00083  * MAX30208 Data Buffers
00084  **************************************************************************/
00085 #if   MASTER == 1 // Master Device
00086     static char curr_raw_temp_data_from_slave[size_of_MAX30208];
00087     static char prev_raw_temp_data_from_slave[size_of_MAX30208];
00088 #elif SLAVE == 1 // Slave Device
00089     static char curr_raw_temp_data_to_master[size_of_MAX30208];
00090 #endif
00091 
00092 /***************************************************************************
00093  * MAX44009 Data Buffers
00094  **************************************************************************/
00095 #if   MASTER == 1 // Master Device
00096     static char curr_raw_light_data_from_slave[size_of_MAX44009];
00097     static char prev_raw_light_data_from_slave[size_of_MAX44009];
00098 #elif SLAVE == 1 // Slave Device
00099     static char curr_raw_light_data_to_master[size_of_MAX44009];
00100 #endif
00101 
00102 /***************************************************************************
00103  * MAX20361 Data Buffers
00104  **************************************************************************/
00105 #if   MASTER == 1 // Master Device
00106     static char curr_raw_AO32_data_from_slave[size_of_MAX20361];
00107     static char prev_raw_AO32_data_from_slave[size_of_MAX20361];
00108 #elif SLAVE == 1 // Slave Device
00109     static char curr_raw_AO32_data_to_master[size_of_MAX20361];
00110 #endif
00111 
00112 /** 
00113  * @brief This function constructs a payload buffer that is used in transmitting data in a LoRa Message
00114  */
00115 void fillPayloadWithGlobalBufs(uint8_t * payload_buffer_tx); 
00116 
00117 /** 
00118  * @brief This function deconstructs a payload buffer that contains data from a received LoRa Message
00119  */
00120 void fillGlobalBufsWithPayload(uint8_t * payload_buffer_rx); 
00121 
00122 #endif // __GLOBAL_BUFFERS_H__