MAX20361 Demo with LoRa Module on LP1 mode

Dependencies:   SX1276GenericLib USBDevice

Fork of NonPingPong_PICO_LoRa_LP1 by Walter Luu

Committer:
walterluu
Date:
Fri Oct 16 23:26:04 2020 +0000
Revision:
8:5ff74d7381dc
Parent:
7:6264bc5b6421
LP1 code with PingPong removal and 10 second transmission

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 //#include "support.h"
walterluu 3:85fc843a9d7d 27
walterluu 3:85fc843a9d7d 28 /***************************************************************************
walterluu 3:85fc843a9d7d 29 * MASTER Device
walterluu 3:85fc843a9d7d 30 **************************************************************************/\
walterluu 8:5ff74d7381dc 31 //#define MASTER 1
walterluu 3:85fc843a9d7d 32
walterluu 3:85fc843a9d7d 33 /***************************************************************************
walterluu 3:85fc843a9d7d 34 * SLAVE Device
walterluu 3:85fc843a9d7d 35 **************************************************************************/\
walterluu 8:5ff74d7381dc 36 #define SLAVE 1
walterluu 3:85fc843a9d7d 37
walterluu 3:85fc843a9d7d 38
walterluu 3:85fc843a9d7d 39 /***************************************************************************
walterluu 3:85fc843a9d7d 40 * Indexes for which byte specific data begins at in the payload buffer
walterluu 3:85fc843a9d7d 41 **************************************************************************/
walterluu 3:85fc843a9d7d 42 /* size of ID data that defines what the signature of the device is */
walterluu 8:5ff74d7381dc 43 const uint8_t size_signature = 0;
walterluu 3:85fc843a9d7d 44
walterluu 3:85fc843a9d7d 45 const uint8_t size_of_MAX30208 = 2; // temperature data
walterluu 3:85fc843a9d7d 46 const uint8_t size_of_MAX44009 = 2; // light data
walterluu 8:5ff74d7381dc 47 const uint8_t size_of_MAX20361 = 3; // AO32 data
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 8:5ff74d7381dc 55 //const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = size_signature;
walterluu 8:5ff74d7381dc 56 const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = 1; // can't be zero, will cause internal error
walterluu 6:51f492ca61a2 57 //const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = 0;
walterluu 3:85fc843a9d7d 58 const uint16_t PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER = size_signature + size_of_MAX30208 + size_of_MAX44009 + size_of_MAX20361;
walterluu 3:85fc843a9d7d 59
walterluu 3:85fc843a9d7d 60 /* determine the appropriate buffer sizes */
walterluu 3:85fc843a9d7d 61 #if MASTER == 1 // Master Device
walterluu 3:85fc843a9d7d 62 const uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE;
walterluu 3:85fc843a9d7d 63 const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER;
walterluu 3:85fc843a9d7d 64 #elif SLAVE == 1 // Slave Device
walterluu 3:85fc843a9d7d 65 const uint16_t BufferSizeTx = PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER;
walterluu 3:85fc843a9d7d 66 const uint16_t BufferSizeRx = PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE;
walterluu 3:85fc843a9d7d 67 #endif
walterluu 3:85fc843a9d7d 68
walterluu 3:85fc843a9d7d 69 #if MASTER == 1 // Master Device
walterluu 3:85fc843a9d7d 70 /* These are indexs used to create the payload buffer to send to Slave */
walterluu 3:85fc843a9d7d 71 const uint8_t tx_idx_signature = 0; // 1st buf in tx payload (begins at byte 0)
walterluu 3:85fc843a9d7d 72
walterluu 3:85fc843a9d7d 73 /* These are indexs used to deconstruct received payload buffer sent by the Slave */
walterluu 8:5ff74d7381dc 74 // const uint8_t rx_idx_signature = 0; // 1st buf in rx payload (begins at byte 0)
walterluu 8:5ff74d7381dc 75 // const uint8_t rx_idx_MAX30208 = rx_idx_signature + size_signature; // 2nd buf in rx payload
walterluu 8:5ff74d7381dc 76 // const uint8_t rx_idx_MAX44009 = rx_idx_MAX30208 + size_of_MAX30208; // 3rd buf in rx payload
walterluu 8:5ff74d7381dc 77 // const uint8_t rx_idx_MAX20361 = rx_idx_MAX44009 + size_of_MAX44009; // 4th buf in rx payload
walterluu 8:5ff74d7381dc 78
walterluu 8:5ff74d7381dc 79 const uint8_t rx_idx_MAX30208 = 0; // 1st buf in rx payload (begins at byte 0), temp data
walterluu 8:5ff74d7381dc 80 const uint8_t rx_idx_MAX44009 = rx_idx_MAX30208 + size_of_MAX30208; // 2nd buf in rx payload, lux data
walterluu 8:5ff74d7381dc 81 const uint8_t rx_idx_MAX20361 = rx_idx_MAX44009 + size_of_MAX44009; // 3rd buf in rx payload, AO32 data
walterluu 3:85fc843a9d7d 82
walterluu 3:85fc843a9d7d 83 #elif SLAVE == 1 // Slave Device: LoRa Controlled Robot
walterluu 3:85fc843a9d7d 84 /* These are indexs used to create the payload buffer to send to Master */
walterluu 8:5ff74d7381dc 85 // const uint8_t tx_idx_signature = 0; // 1st buf in tx payload (begins at byte 0)
walterluu 8:5ff74d7381dc 86 // const uint8_t tx_idx_MAX30208 = tx_idx_signature + size_signature; // 2nd buf in tx payload
walterluu 8:5ff74d7381dc 87 // const uint8_t tx_idx_MAX44009 = tx_idx_MAX30208 + size_of_MAX30208; // 3rd buf in tx payload
walterluu 8:5ff74d7381dc 88 // const uint8_t tx_idx_MAX20361 = tx_idx_MAX44009 + size_of_MAX44009 ; // 4th buf in tx payload
walterluu 8:5ff74d7381dc 89
walterluu 8:5ff74d7381dc 90 const uint8_t tx_idx_MAX30208 = 0; // 1st buf in tx payload (begins at byte 0), temp data
walterluu 8:5ff74d7381dc 91 const uint8_t tx_idx_MAX44009 = tx_idx_MAX30208 + size_of_MAX30208; // 2nd buf in tx payload, lux data
walterluu 8:5ff74d7381dc 92 const uint8_t tx_idx_MAX20361 = tx_idx_MAX44009 + size_of_MAX44009; // 3rd buf in tx payload, AO32 data
walterluu 3:85fc843a9d7d 93
walterluu 3:85fc843a9d7d 94 /* These are indexs used to deconstruct received payload buffer sent by the Master */
walterluu 3:85fc843a9d7d 95 const uint8_t rx_idx_signature = 0; // 1st buf in rx payload (begins at byte 0)
walterluu 3:85fc843a9d7d 96 #endif
walterluu 3:85fc843a9d7d 97
walterluu 3:85fc843a9d7d 98
walterluu 3:85fc843a9d7d 99
walterluu 3:85fc843a9d7d 100
walterluu 3:85fc843a9d7d 101 /***************************************************************************
walterluu 3:85fc843a9d7d 102 * MAX30208 Data Buffers
walterluu 3:85fc843a9d7d 103 **************************************************************************/
walterluu 3:85fc843a9d7d 104 #if MASTER == 1 // Master Device
walterluu 3:85fc843a9d7d 105 static char curr_raw_temp_data_from_slave[size_of_MAX30208];
walterluu 3:85fc843a9d7d 106 static char prev_raw_temp_data_from_slave[size_of_MAX30208];
walterluu 3:85fc843a9d7d 107 // static int16_t conv_frame_data_from_slave[64];
walterluu 3:85fc843a9d7d 108 #elif SLAVE == 1 // Slave Device
walterluu 3:85fc843a9d7d 109 static char curr_raw_temp_data_to_master[size_of_MAX30208];
walterluu 3:85fc843a9d7d 110 // static char prev_raw_temp_data_to_master[size_of_MAX30208];
walterluu 3:85fc843a9d7d 111 // static int16_t conv_frame_data_to_master[64];
walterluu 3:85fc843a9d7d 112 #endif
walterluu 3:85fc843a9d7d 113
walterluu 3:85fc843a9d7d 114 /***************************************************************************
walterluu 3:85fc843a9d7d 115 * MAX44009 Data Buffers
walterluu 3:85fc843a9d7d 116 **************************************************************************/
walterluu 3:85fc843a9d7d 117 #if MASTER == 1 // Master Device
walterluu 3:85fc843a9d7d 118 static char curr_raw_light_data_from_slave[size_of_MAX44009];
walterluu 3:85fc843a9d7d 119 static char prev_raw_light_data_from_slave[size_of_MAX44009];
walterluu 3:85fc843a9d7d 120 // static int16_t conv_frame_data_from_slave[64];
walterluu 3:85fc843a9d7d 121 #elif SLAVE == 1 // Slave Device
walterluu 3:85fc843a9d7d 122 static char curr_raw_light_data_to_master[size_of_MAX44009];
walterluu 3:85fc843a9d7d 123 // static char prev_raw_light_data_to_master[size_of_MAX44009];
walterluu 3:85fc843a9d7d 124 // static int16_t conv_frame_data_to_master[64];
walterluu 3:85fc843a9d7d 125 #endif
walterluu 3:85fc843a9d7d 126
walterluu 3:85fc843a9d7d 127 /***************************************************************************
walterluu 3:85fc843a9d7d 128 * MAX20361 Data Buffers
walterluu 3:85fc843a9d7d 129 **************************************************************************/
walterluu 3:85fc843a9d7d 130 #if MASTER == 1 // Master Device
walterluu 3:85fc843a9d7d 131 static char curr_raw_AO32_data_from_slave[size_of_MAX20361];
walterluu 3:85fc843a9d7d 132 static char prev_raw_AO32_data_from_slave[size_of_MAX20361];
walterluu 3:85fc843a9d7d 133 // static int16_t conv_frame_data_from_slave[64];
walterluu 3:85fc843a9d7d 134 #elif SLAVE == 1 // Slave Device
walterluu 3:85fc843a9d7d 135 static char curr_raw_AO32_data_to_master[size_of_MAX20361];
walterluu 3:85fc843a9d7d 136 // static char prev_raw_AO32_data_to_master[size_of_MAX20361];
walterluu 3:85fc843a9d7d 137 // static int16_t conv_frame_data_to_master[64];
walterluu 3:85fc843a9d7d 138 #endif
walterluu 3:85fc843a9d7d 139
walterluu 3:85fc843a9d7d 140 /**
walterluu 3:85fc843a9d7d 141 * @brief This function constructs a payload buffer that is used in transmitting data in a LoRa Message
walterluu 3:85fc843a9d7d 142 */
walterluu 3:85fc843a9d7d 143 void fillPayloadWithGlobalBufs(uint8_t * payload_buffer_tx);
walterluu 3:85fc843a9d7d 144
walterluu 3:85fc843a9d7d 145 /**
walterluu 3:85fc843a9d7d 146 * @brief This function deconstructs a payload buffer that contains data from a received LoRa Message
walterluu 3:85fc843a9d7d 147 */
walterluu 3:85fc843a9d7d 148 void fillGlobalBufsWithPayload(uint8_t * payload_buffer_rx);
walterluu 3:85fc843a9d7d 149
walterluu 3:85fc843a9d7d 150 #endif // __GLOBAL_BUFFERS_H__