MAX20361 System Demo with Low Power 2 mode

Dependencies:   SX1276GenericLib USBDevice

Fork of NonPingPong_PICO_LoRa by Walter Luu

Committer:
walterluu
Date:
Tue Oct 20 00:00:20 2020 +0000
Revision:
7:62c868478eef
Parent:
6:51f492ca61a2
MAX20361 System Demo firmware with Low Power 2 mode

Who changed what in which revision?

UserRevisionLine numberNew contents of line
walterluu 3:85fc843a9d7d 1 /** Description:
walterluu 3:85fc843a9d7d 2 * This File is responsible for defining the buffers that will be used in
walterluu 3:85fc843a9d7d 3 * various areas of the program. The buffers that are defined here will be
walterluu 3:85fc843a9d7d 4 * refferenced in the main.cpp and will be filled with data in one of two ways:
walterluu 3:85fc843a9d7d 5 *
walterluu 3:85fc843a9d7d 6 * 1. The buffers will be filled with data upon receiving a successful payload
walterluu 3:85fc843a9d7d 7 * transmission over LoRa. In GenericPingPong.cpp, the function OnRxDone()
walterluu 3:85fc843a9d7d 8 * will call the function fillGlobalBufsWithPayload() that is responsible for
walterluu 3:85fc843a9d7d 9 * filling the appropriate buffers with the payload data that was received
walterluu 3:85fc843a9d7d 10 * by either the master or slave device by the other device that sent it.
walterluu 3:85fc843a9d7d 11 *
walterluu 3:85fc843a9d7d 12 * 2. The buffers will be used to fill up a payload buffer that will be sent
walterluu 3:85fc843a9d7d 13 * over LoRa by either the master or slave device to the receiving device.
walterluu 3:85fc843a9d7d 14 * The function fillPayloadWithGlobalBufs() will use the global buffers that
walterluu 3:85fc843a9d7d 15 * are filled with data for various sensors in the main.cpp to construct a
walterluu 3:85fc843a9d7d 16 * payload to deliver to the other device when SX1276PingPong() is called
walterluu 3:85fc843a9d7d 17 * in file GenericPingPong.cpp.
walterluu 3:85fc843a9d7d 18 *
walterluu 3:85fc843a9d7d 19 */
walterluu 3:85fc843a9d7d 20
walterluu 3:85fc843a9d7d 21 #ifndef __GLOBAL_BUFFERS_H__
walterluu 3:85fc843a9d7d 22 #define __GLOBAL_BUFFERS_H__\
walterluu 3:85fc843a9d7d 23
walterluu 3:85fc843a9d7d 24 #include "mbed.h"
walterluu 3:85fc843a9d7d 25 //#include "GenericPingPong2.h"
walterluu 3:85fc843a9d7d 26
walterluu 3:85fc843a9d7d 27 /***************************************************************************
walterluu 3:85fc843a9d7d 28 * MASTER Device
walterluu 3:85fc843a9d7d 29 **************************************************************************/\
walterluu 6:51f492ca61a2 30 //#define MASTER 1
walterluu 3:85fc843a9d7d 31
walterluu 3:85fc843a9d7d 32 /***************************************************************************
walterluu 3:85fc843a9d7d 33 * SLAVE Device
walterluu 3:85fc843a9d7d 34 **************************************************************************/\
walterluu 6:51f492ca61a2 35 #define SLAVE 1
walterluu 3:85fc843a9d7d 36
walterluu 3:85fc843a9d7d 37
walterluu 3:85fc843a9d7d 38 /***************************************************************************
walterluu 3:85fc843a9d7d 39 * Indexes for which byte specific data begins at in the payload buffer
walterluu 3:85fc843a9d7d 40 **************************************************************************/
walterluu 3:85fc843a9d7d 41 /* size of ID data that defines what the signature of the device is */
walterluu 7:62c868478eef 42 //const uint8_t size_signature = 1;
walterluu 3:85fc843a9d7d 43
walterluu 3:85fc843a9d7d 44 const uint8_t size_of_MAX30208 = 2; // temperature data
walterluu 3:85fc843a9d7d 45 const uint8_t size_of_MAX44009 = 2; // light data
walterluu 7:62c868478eef 46 const uint8_t size_of_MAX20361 = 3; // AO32 data
walterluu 3:85fc843a9d7d 47
walterluu 3:85fc843a9d7d 48
walterluu 3:85fc843a9d7d 49 /* These are the sizes of each payload in bytes. Since there is different amount
walterluu 3:85fc843a9d7d 50 * of data being sent in each direction, we need to declare the total size of
walterluu 3:85fc843a9d7d 51 * the payload so we can instatiate the correct buffer sizes to store data that
walterluu 3:85fc843a9d7d 52 * is to be delivered and for data that is received.
walterluu 3:85fc843a9d7d 53 */
walterluu 3:85fc843a9d7d 54
walterluu 6:51f492ca61a2 55 //const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = 0;
walterluu 7:62c868478eef 56 const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = 1; // can't be zero, otherwise internal error
walterluu 7:62c868478eef 57 const uint16_t PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER = size_of_MAX30208 + size_of_MAX44009 + size_of_MAX20361;
walterluu 3:85fc843a9d7d 58
walterluu 3:85fc843a9d7d 59 /* determine the appropriate buffer sizes */
walterluu 3:85fc843a9d7d 60 #if MASTER == 1 // Master Device
walterluu 3:85fc843a9d7d 61 const uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE;
walterluu 3:85fc843a9d7d 62 const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER;
walterluu 3:85fc843a9d7d 63 #elif SLAVE == 1 // Slave Device
walterluu 3:85fc843a9d7d 64 const uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER;
walterluu 3:85fc843a9d7d 65 const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE;
walterluu 3:85fc843a9d7d 66 #endif
walterluu 3:85fc843a9d7d 67
walterluu 7:62c868478eef 68 #if MASTER == 1 // Master Device: Gateway Device, only receiving data from Slave
walterluu 3:85fc843a9d7d 69
walterluu 3:85fc843a9d7d 70 /* These are indexs used to deconstruct received payload buffer sent by the Slave */
walterluu 7:62c868478eef 71 const uint8_t rx_idx_MAX30208 = 0; // 1st buf in rx payload (begins at byte 0), temp data
walterluu 7:62c868478eef 72 const uint8_t rx_idx_MAX44009 = rx_idx_MAX30208 + size_of_MAX30208; // 2nd buf in rx payload, lux data
walterluu 7:62c868478eef 73 const uint8_t rx_idx_MAX20361 = rx_idx_MAX44009 + size_of_MAX44009; // 3rd buf in rx payload, AO32 data
walterluu 3:85fc843a9d7d 74
walterluu 7:62c868478eef 75 #elif SLAVE == 1 // Slave Device: Sensor Node, only sending data to Master
walterluu 3:85fc843a9d7d 76 /* These are indexs used to create the payload buffer to send to Master */
walterluu 7:62c868478eef 77 const uint8_t tx_idx_MAX30208 = 0; // 1st buf in tx payload (begins at byte 0), temp data
walterluu 7:62c868478eef 78 const uint8_t tx_idx_MAX44009 = tx_idx_MAX30208 + size_of_MAX30208; // 2nd buf in tx payload, lux data
walterluu 7:62c868478eef 79 const uint8_t tx_idx_MAX20361 = tx_idx_MAX44009 + size_of_MAX44009; // 3rd buf in tx payload, AO32 data
walterluu 3:85fc843a9d7d 80 #endif
walterluu 3:85fc843a9d7d 81
walterluu 3:85fc843a9d7d 82 /***************************************************************************
walterluu 3:85fc843a9d7d 83 * MAX30208 Data Buffers
walterluu 3:85fc843a9d7d 84 **************************************************************************/
walterluu 3:85fc843a9d7d 85 #if MASTER == 1 // Master Device
walterluu 3:85fc843a9d7d 86 static char curr_raw_temp_data_from_slave[size_of_MAX30208];
walterluu 3:85fc843a9d7d 87 static char prev_raw_temp_data_from_slave[size_of_MAX30208];
walterluu 3:85fc843a9d7d 88 #elif SLAVE == 1 // Slave Device
walterluu 3:85fc843a9d7d 89 static char curr_raw_temp_data_to_master[size_of_MAX30208];
walterluu 3:85fc843a9d7d 90 #endif
walterluu 3:85fc843a9d7d 91
walterluu 3:85fc843a9d7d 92 /***************************************************************************
walterluu 3:85fc843a9d7d 93 * MAX44009 Data Buffers
walterluu 3:85fc843a9d7d 94 **************************************************************************/
walterluu 3:85fc843a9d7d 95 #if MASTER == 1 // Master Device
walterluu 3:85fc843a9d7d 96 static char curr_raw_light_data_from_slave[size_of_MAX44009];
walterluu 3:85fc843a9d7d 97 static char prev_raw_light_data_from_slave[size_of_MAX44009];
walterluu 3:85fc843a9d7d 98 #elif SLAVE == 1 // Slave Device
walterluu 3:85fc843a9d7d 99 static char curr_raw_light_data_to_master[size_of_MAX44009];
walterluu 3:85fc843a9d7d 100 #endif
walterluu 3:85fc843a9d7d 101
walterluu 3:85fc843a9d7d 102 /***************************************************************************
walterluu 3:85fc843a9d7d 103 * MAX20361 Data Buffers
walterluu 3:85fc843a9d7d 104 **************************************************************************/
walterluu 3:85fc843a9d7d 105 #if MASTER == 1 // Master Device
walterluu 3:85fc843a9d7d 106 static char curr_raw_AO32_data_from_slave[size_of_MAX20361];
walterluu 3:85fc843a9d7d 107 static char prev_raw_AO32_data_from_slave[size_of_MAX20361];
walterluu 3:85fc843a9d7d 108 #elif SLAVE == 1 // Slave Device
walterluu 3:85fc843a9d7d 109 static char curr_raw_AO32_data_to_master[size_of_MAX20361];
walterluu 3:85fc843a9d7d 110 #endif
walterluu 3:85fc843a9d7d 111
walterluu 3:85fc843a9d7d 112 /**
walterluu 3:85fc843a9d7d 113 * @brief This function constructs a payload buffer that is used in transmitting data in a LoRa Message
walterluu 3:85fc843a9d7d 114 */
walterluu 3:85fc843a9d7d 115 void fillPayloadWithGlobalBufs(uint8_t * payload_buffer_tx);
walterluu 3:85fc843a9d7d 116
walterluu 3:85fc843a9d7d 117 /**
walterluu 3:85fc843a9d7d 118 * @brief This function deconstructs a payload buffer that contains data from a received LoRa Message
walterluu 3:85fc843a9d7d 119 */
walterluu 3:85fc843a9d7d 120 void fillGlobalBufsWithPayload(uint8_t * payload_buffer_rx);
walterluu 3:85fc843a9d7d 121
walterluu 3:85fc843a9d7d 122 #endif // __GLOBAL_BUFFERS_H__