MAX20361 Demo Firmware
Dependencies: SX1276GenericLib USBDevice
Fork of PICO_LoRa_Module_developing by
Revision 6:51f492ca61a2, committed 2020-10-14
- Comitter:
- walterluu
- Date:
- Wed Oct 14 00:19:02 2020 +0000
- Parent:
- 5:9e751733a6f3
- Commit message:
- Firmware Oct13
Changed in this revision
diff -r 9e751733a6f3 -r 51f492ca61a2 AO19Lib/AO19_lib.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AO19Lib/AO19_lib.cpp Wed Oct 14 00:19:02 2020 +0000 @@ -0,0 +1,80 @@ + +#include "mbed.h" +#include "AO19_lib.h" + +// ***************************************************************************** +// AO19_write_register(char, char, char) writes single byte to AO19 +// char I2C address +// char AO19 register address +// char data byte to be writen +// returns 0 on success ACK, 1 on NACK +// ***************************************************************************** + +int AO19_write_register(I2C *i2c, char I2C_add, char reg_add, char byte){ + char data[2]; // char type ranges from 0 to 255 (8 bytes) + int error; + data[0] = reg_add; + data[1] = byte; + error = i2c->write(I2C_add,data,2); + //if(DEBUG)db.printf("wr[%02X %02X %d]\r\n", data[0], data[1], error); + return error; + +} + +/// **************************************************************************** +// AO19_write_register(char, char, char *, int) writes multiple bytes to AO19 +// char I2C address +// char AO19 register address +// char * data vector of bytes to be written +// int number of bytes to write +// returns 0 on success ACK, 1 on NACK +// ***************************************************************************** + +int AO19_write_register(I2C *i2c, char I2C_add, char reg_add, char *bytes, int n){ + int i; + //set start address + char data[16]; + int error; + data[0] = reg_add; + for(i=1;i<=n;i++){ + data[i] = bytes[i-1]; + } + error = i2c->write(I2C_add,data,n+1); // send n bytes of data + + return error; +} + +// ***************************************************************************** +// AO19_read_register(char, char, char *) reads single byte from AO19 +// char I2C address +// char AO19 register address +// char * data vector for read bytes to be stored in +// returns 0 on success, 1 on fail +// ***************************************************************************** + +int AO19_read_register(I2C *i2c, char I2C_add, char reg_add, char *bytes){ + int error; + error = i2c->write(I2C_add,®_add,1,1); + if(error)return error; + error = i2c->read(I2C_add,bytes,1); + //if(DEBUG)db.printf("rr e[%d]\r\n",error); + return error; +} + +// ***************************************************************************** +// AO19_read_register(char, char, char *, int) reads byte(s) from AO19 +// char I2C address +// char OT07 register address +// char * data vector for read bytes to be stored in +// int number of bytes to read +// returns 0 on success, 1 on fail +// ***************************************************************************** + +int AO19_read_register(I2C *i2c, char I2C_add, char reg_add, char *bytes, int n){ + int error; + error = i2c->write(I2C_add,®_add,1,1); + if(error)return error; + error = i2c->read(I2C_add,bytes,n); + //if(DEBUG)db.printf("rr e[%d]\r\n",error); + return error; +} \ No newline at end of file
diff -r 9e751733a6f3 -r 51f492ca61a2 AO19Lib/AO19_lib.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AO19Lib/AO19_lib.h Wed Oct 14 00:19:02 2020 +0000 @@ -0,0 +1,64 @@ +#include "mbed.h" + +//AO19 Registers +#define AO19_DEVICE_ID 0x00 // AO19 Chip ID +#define AO19_BB_CFG0 0x01 // AO19 Buck Boost Configure +#define AO19_BB_VSET 0x02 // AO19 Buck Boost Voltage Set +#define AO19_BB_ISET 0x03 // AO19 Buck Boost Current Set +#define AO19_BB_CFG1 0x04 // AO19 Buck Boost Configure 1 +#define AO19_STATUS 0x05 // AO19 Status Register +#define AO19_INT 0x06 // AO19 Interrupt +#define AO19_MSK 0x07 // AO19 Mask +#define AO19_LOCK_MSK 0x50 // AO19 Lock Mask +#define AO19_PASSWD 0x51 // AO19 Password + +#define DEVICE_ACK 0 +#define DEVICE_NACK 1 +#define DEVICE_BAD_RESP 2 + +#define MAX_DEVICES 64 // Maximum number of rom devices allowed +#define ID_LENGTH 6 // Rom ID length in bytes + +struct AO19_struct { + char rom_id[ID_LENGTH]; // device ROM ID + char I2C_address; // I2C addess, based on GPIO0 and GPIO1 at power up + // Why char? +}; + +// ***************************************************************************** +// AO19_write_register(char, char, char) writes single byte to AO19 +// char I2C address +// char AO19 register address +// char data byte to be writen +// returns 0 on success ACK, 1 on NACK +// ***************************************************************************** +int AO19_write_register(I2C *i2c, char I2C_add, char reg_add, char byte); + +/// **************************************************************************** +// AO19_write_register(char, char, char *, int) writes multiple bytes to AO19 +// char I2C address +// char AO19 register address +// char * data vector of bytes to be written +// int number of bytes to write +// returns 0 on success ACK, 1 on NACK +// ***************************************************************************** +int AO19_write_register(I2C *i2c, char I2C_add, char reg_add, char *bytes, int n); + +// ***************************************************************************** +// AO19_read_register(char, char, char *) reads single byte from AO19 +// char I2C address +// char AO19 register address +// char * data vector for read bytes to be stored in +// returns 0 on success, 1 on fail +// ***************************************************************************** +int AO19_read_register(I2C *i2c, char I2C_add, char reg_add, char *bytes); + +// ***************************************************************************** +// AO19_read_register(char, char, char *, int) reads byte(s) from AO19 +// char I2C address +// char OT07 register address +// char * data vector for read bytes to be stored in +// int number of bytes to read +// returns 0 on success, 1 on fail +// ***************************************************************************** +int AO19_read_register(I2C *i2c, char I2C_add, char reg_add, char *bytes, int n);
diff -r 9e751733a6f3 -r 51f492ca61a2 SX1276GenericPingPong/GenericPingPong2.cpp --- a/SX1276GenericPingPong/GenericPingPong2.cpp Tue Oct 13 00:45:46 2020 +0000 +++ b/SX1276GenericPingPong/GenericPingPong2.cpp Wed Oct 14 00:19:02 2020 +0000 @@ -19,7 +19,7 @@ #ifdef FEATURE_LORA // in main.cpp /* Set this flag to '1' to display debug messages on the console */ -#define DEBUG_MESSAGE 1 +#define DEBUG_MESSAGE 0 /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */ #define USE_MODEM_LORA 1 @@ -56,7 +56,8 @@ #endif -#define RX_TIMEOUT_VALUE 3500 // in ms +//#define RX_TIMEOUT_VALUE 3500 // in ms, default +#define RX_TIMEOUT_VALUE 333 // testing //#define RX_TIMEOUT_VALUE 333 // in ms //#define BUFFER_SIZE 32 // Define the payload size here
diff -r 9e751733a6f3 -r 51f492ca61a2 SX1276GenericPingPong/GenericPingPong2.h --- a/SX1276GenericPingPong/GenericPingPong2.h Tue Oct 13 00:45:46 2020 +0000 +++ b/SX1276GenericPingPong/GenericPingPong2.h Wed Oct 14 00:19:02 2020 +0000 @@ -34,8 +34,10 @@ */ -const uint8_t PingMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'I', 'N', 'G'};// "PING"; // 255, 255, 0, 0, 80, 73, 78, 71 -const uint8_t PongMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'O', 'N', 'G'};// "PONG"; // 255, 255, 0, 0, 80, 79, 78, 71 +//const uint8_t PingMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'I', 'N', 'G'};// "PING"; // 255, 255, 0, 0, 80, 73, 78, 71 +const uint8_t PingMsg[] = {0xff}; +//const uint8_t PongMsg[] = { 0xff, 0xff, 0x00, 0x00, 'P', 'O', 'N', 'G'};// "PONG"; // 255, 255, 0, 0, 80, 79, 78, 71 +const uint8_t PongMsg[] = {0x00}; // This keeps track of how many times a transmission times out. static int RxTimeoutCount = 0;
diff -r 9e751733a6f3 -r 51f492ca61a2 global_buffers.h --- a/global_buffers.h Tue Oct 13 00:45:46 2020 +0000 +++ b/global_buffers.h Wed Oct 14 00:19:02 2020 +0000 @@ -28,23 +28,23 @@ /*************************************************************************** * MASTER Device **************************************************************************/\ -#define MASTER 1 +//#define MASTER 1 /*************************************************************************** * SLAVE Device **************************************************************************/\ -//#define SLAVE 1 +#define SLAVE 1 /*************************************************************************** * Indexes for which byte specific data begins at in the payload buffer **************************************************************************/ /* size of ID data that defines what the signature of the device is */ -const uint8_t size_signature = 8; +const uint8_t size_signature = 1; /* size of data in bytes that is acquired by the master device */ //const uint8_t size_of_ble = 2; -const uint8_t size_of_dum = 2; +//const uint8_t size_of_dum = 2; /* size of data in bytes that is acquired by the slave device */ //const uint8_t size_of_grid_eye = 128; @@ -64,7 +64,8 @@ * is to be delivered and for data that is received. */ -const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = size_signature + size_of_dum; +const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = size_signature; +//const uint16_t PAYLOAD_BUFFER_SIZE_MASTER_TO_SLAVE = 0; const uint16_t PAYLOAD_BUFFER_SIZE_SLAVE_TO_MASTER = size_signature + size_of_MAX30208 + size_of_MAX44009 + size_of_MAX20361; /* determine the appropriate buffer sizes */ @@ -114,7 +115,7 @@ #if MASTER == 1 // Master Device /* These are indexs used to create the payload buffer to send to Slave */ const uint8_t tx_idx_signature = 0; // 1st buf in tx payload (begins at byte 0) - const uint8_t tx_idx_dum = tx_idx_signature + size_signature; // 2nd buf in tx payload +// const uint8_t tx_idx_dum = tx_idx_signature + size_signature; // 2nd buf in tx payload /* These are indexs used to deconstruct received payload buffer sent by the Slave */ const uint8_t rx_idx_signature = 0; // 1st buf in rx payload (begins at byte 0) @@ -133,7 +134,7 @@ /* These are indexs used to deconstruct received payload buffer sent by the Master */ const uint8_t rx_idx_signature = 0; // 1st buf in rx payload (begins at byte 0) - const uint8_t rx_idx_dum = rx_idx_signature + size_signature; // 2nd buf in rx payload +// const uint8_t rx_idx_dum = rx_idx_signature + size_signature; // 2nd buf in rx payload #endif @@ -151,10 +152,10 @@ * Dummy Data Buffers **************************************************************************/ #if MASTER == 1 // Master Device - static char curr_dum_data_to_slave[size_of_dum]; +// static char curr_dum_data_to_slave[size_of_dum]; #elif SLAVE == 1 // Slave Device - static char curr_dum_data_from_master[size_of_dum]; - static char prev_dum_data_from_master[size_of_dum]; +// static char curr_dum_data_from_master[size_of_dum]; +// static char prev_dum_data_from_master[size_of_dum]; #endif
diff -r 9e751733a6f3 -r 51f492ca61a2 main.cpp --- a/main.cpp Tue Oct 13 00:45:46 2020 +0000 +++ b/main.cpp Wed Oct 14 00:19:02 2020 +0000 @@ -22,6 +22,9 @@ // AO32 related #include "AO32_lib.h" +// AO19 related +#include "AO19_lib.h" + //#if defined(TARGET_MAX32630FTHR) // using the RFM95 board // #include "max32630fthr.h" // MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); @@ -58,17 +61,21 @@ I2C i2cBus0(P1_6, P1_7); // I2C of MAX32625PICO -bool get_data_flag = false; // used for data tramission frequency - +bool get_data_flag = false; // used for data tramission frequency on the SENSOR side +bool print_data_flag = false; // used for data display on the GATEWAY side //Timer setup -Ticker timer_1; // timer for data tramission frequency - +Ticker timer_1; // timer for data tramission frequency on the SENSOR side +Ticker timer_M; // timer for data print out on the GATEWAY side void onTimerInterrupt(){ get_data_flag = true; } +void onGatewayInterrupt(){ + print_data_flag = true; +} + int main() { /*************************************************************************** @@ -77,17 +84,17 @@ /* Setup begins here: */ #if MASTER == 1 // Master Device - pc.printf("MAX32625PICO: MASTER DEVICE\r\n"); - wait(1); +// pc.printf("MAX32625PICO: MASTER DEVICE\r\n"); +// wait(1); #elif SLAVE == 1 // Slave Device - pc.printf("MAX32625PICO: SLAVE DEVICE\r\n"); - wait(1); +// pc.printf("MAX32625PICO: SLAVE DEVICE\r\n"); +// wait(1); #endif /* Introduction text: */ - pc.printf("Welcome to the SX1276GenericLib\r\n"); +// pc.printf("Welcome to the SX1276GenericLib\r\n"); // wait(5); - pc.printf("Starting a simple LoRa PingPong\r\n"); +// pc.printf("Starting a simple LoRa PingPong\r\n"); // wait(5); /*************************************************************************** @@ -109,10 +116,10 @@ * Dummy Data Buffers **************************************************************************/ #if MASTER == 1 // Master Device - uint8_t curr_dum_to_slave[size_of_dum]; +// uint8_t curr_dum_to_slave[size_of_dum]; #elif SLAVE == 1 // Slave Device - uint8_t curr_dum_from_master[size_of_dum]; - uint8_t prev_dum_from_master[size_of_dum]; +// uint8_t curr_dum_from_master[size_of_dum]; +// uint8_t prev_dum_from_master[size_of_dum]; #endif /*************************************************************************** @@ -123,7 +130,7 @@ // uint8_t curr_raw_temp_from_slave[size_of_MAX30208]; char curr_raw_temp_from_slave[size_of_MAX30208]; // to match data type // uint8_t prev_MAX77650_from_slave[size_of_MAX77650]; -// uint8_t prev_raw_temp_from_slave[size_of_MAX30208]; + char prev_raw_temp_from_slave[size_of_MAX30208]; #elif SLAVE == 1 // Slave Device // uint8_t curr_MAX77650_to_master[size_of_MAX77650]; // bool chrg_status = false; //True = ON False = OFF @@ -137,7 +144,7 @@ #if MASTER == 1 // Master Device // uint8_t curr_raw_light_from_slave[size_of_MAX44009]; char curr_raw_light_from_slave[size_of_MAX44009]; // to match data type -// uint8_t prev_raw_light_from_slave[size_of_MAX44009]; + char prev_raw_light_from_slave[size_of_MAX44009]; // static int16_t conv_frame_data_from_slave[64]; #elif SLAVE == 1 // Slave Device uint8_t curr_raw_light_to_master[size_of_MAX44009]; @@ -151,7 +158,7 @@ #if MASTER == 1 // Master Device // uint8_t curr_raw_AO32_from_slave[size_of_MAX20361]; char curr_raw_AO32_from_slave[size_of_MAX20361]; // to match data type -// uint8_t prev_raw_AO32_from_slave[size_of_MAX20361]; + char prev_raw_AO32_from_slave[size_of_MAX20361]; // static int16_t conv_frame_data_from_slave[64]; #elif SLAVE == 1 // Slave Device uint8_t curr_raw_AO32_to_master[size_of_MAX20361]; @@ -187,39 +194,22 @@ // http://www.cplusplus.com/doc/tutorial/arrays/ #if MASTER == 1 // curr_dum_to_slave[0] = {33, 34}; - curr_dum_to_slave[0] = 33; - curr_dum_to_slave[1] = 34; +// curr_dum_to_slave[0] = 33; +// curr_dum_to_slave[1] = 34; #endif #if SLAVE == 1 -// curr_raw_temp_to_master[size_of_MAX30208] = {10, 13, 15, 17, 19}; + curr_raw_temp_to_master[0] = 99; curr_raw_temp_to_master[1] = 99; -// curr_raw_temp_to_master[2] = 15; -// curr_raw_temp_to_master[3] = 17; -// curr_raw_temp_to_master[4] = 19; -// curr_raw_light_to_master[size_of_MAX44009] = {25, 26, 27, 28, 29}; + curr_raw_light_to_master[0] = 25; curr_raw_light_to_master[1] = 26; -// curr_raw_light_to_master[2] = 27; -// curr_raw_light_to_master[3] = 28; -// curr_raw_light_to_master[4] = 29; -// curr_raw_AO32_to_master[size_of_MAX20361] = {99, 100, 101, 102, 103}; + curr_raw_AO32_to_master[0] = 99; curr_raw_AO32_to_master[1] = 100; curr_raw_AO32_to_master[2] = 101; - curr_raw_AO32_to_master[3] = 102; -// curr_raw_AO32_to_master[4] = 103; -// curr_raw_other_to_master[size_of_other] = {20, 30, 40, 50, 60, 70, 80}; -// curr_raw_other_to_master[0] = 20; -// curr_raw_other_to_master[1] = 30; -// curr_raw_other_to_master[2] = 40; -// curr_raw_other_to_master[3] = 50; -// curr_raw_other_to_master[4] = 60; -// curr_raw_other_to_master[5] = 70; -// curr_raw_other_to_master[6] = 80; - - + curr_raw_AO32_to_master[3] = 102; #endif /*************************************************************************** @@ -227,15 +217,19 @@ **************************************************************************/ int loopCnt = 0; + #if MASTER == 1 + //************* init ticker timer callbacks **************** + timer_M.attach(&onGatewayInterrupt, 3); //Gateway data print out frequency + + #endif + #if SLAVE == 1 //************* init ticker timer callbacks **************** - timer_1.attach(&onTimerInterrupt, 3); //LED3 toggles every 3 seconds + timer_1.attach(&onTimerInterrupt, 3); //Sensor data transmission frequency - //************* OT07 Variables **************** -// char data[5]; + //************* OT07 Variables **************** char rawtempdata[2]; char OT07_i2c_add = 0xA0; -// TempResponse T; //************* MAX44009 Variables **************** char rawluxdata[2]; @@ -246,22 +240,39 @@ char rawCntdata[2]; char AO32_i2c_add = 0x2A; // 0b0010 101x + //************* AO19 Settings **************** + // Enable AO19 + char AO19_i2c_add = 0xD0; // + char AO19_BB_CFG[2]; // store result of AO19's register 0x01 BBstCfg0 + int AO19_read = AO19_read_register(&i2cBus0, AO19_i2c_add, AO19_BB_CFG0, AO19_BB_CFG); + +// if (AO19_read) { +// pc.printf("AO19 Initial Read fail!\r\n"); +// } +// else { +// pc.printf("AO19 Initial Read success!\r\n"); +// } + + int AO19_en = AO19_write_register(&i2cBus0, AO19_i2c_add, AO19_BB_CFG0, AO19_BB_CFG[0]|0x80); + + // if (AO19_en) { +// pc.printf("AO19 Enabled fail!\r\n"); +// } +// else { +// pc.printf("AO19 Enabledsuccess!\r\n"); +// } + + #endif while (1) { - - // Application details: - //1. Set a fixed timer. - //2. Data sent from Master to Slave. - //3. Display data and repeat from 1. - - + #if SLAVE == 1 if(get_data_flag) { //reset the flag get_data_flag = false; - pc.printf("Timer interval reached!\r\n"); +// pc.printf("Timer interval reached!\r\n"); /*************************************************************************** * Temperature Sensor Data Measurement @@ -273,13 +284,13 @@ // pc.printf("OT07 add[%02X] data[%02X] data[%02X]\r\n", OT07_FIFO_DATA, rawtempdata[0], rawtempdata[1]); //calculate temperature from data - int count = (int)(rawtempdata[0]*256 + rawtempdata[1]); - if (count >= 32768)count = count - 65536; // 2s comp - double Temp = (double)count*0.005; - pc.printf("OT07 temperature[%.3f] status[%d]\r\n", Temp, temp_error); +// int count = (int)(rawtempdata[0]*256 + rawtempdata[1]); +// if (count >= 32768)count = count - 65536; // 2s comp +// double Temp = (double)count*0.005; +// pc.printf("OT07 temperature[%.3f] status[%d]\r\n", Temp, temp_error); double tempFinal = calc_temperature(rawtempdata); - pc.printf("OT07 Final temperature[%.3f] \r\n", tempFinal); - pc.printf("\r\n"); +// pc.printf("OT07 Final temperature[%.3f] \r\n", tempFinal); +// pc.printf("\r\n"); //fill raw temp data into the array @@ -296,15 +307,15 @@ // pc.printf("MAX44009 hi_add[%02X] hi_data[%02X] lo_add[%02X] lo_data[%02X]\r\n", MAX44009_LUX_HI, rawluxdata[0], MAX44009_LUX_LO, rawluxdata[1]); //calculate temperature from data - int exponent = int(rawluxdata[0] >> 4); - int mantissa = (int)((rawluxdata[0] << 4) & 0xF0) + (int)(rawluxdata[1]); - double lux = 0.045 * mantissa * pow((double) 2, exponent); +// int exponent = int(rawluxdata[0] >> 4); +// int mantissa = (int)((rawluxdata[0] << 4) & 0xF0) + (int)(rawluxdata[1]); +// double lux = 0.045 * mantissa * pow((double) 2, exponent); // pc.printf("MAX44009 exponent[%d] mantissa[%d]\r\n", exponent, mantissa); // pc.printf("MAX44009 lux[%.2f] status[%d] status[%d]\r\n", lux, lux_error1, lux_error2); - pc.printf("MAX44009 lux[%.2f] status[%d]\r\n", lux, lux_error); - double luxFinal = calc_lux(rawluxdata); - pc.printf("MAX44009 Final Lux[%.2f] \r\n", luxFinal); - pc.printf("\r\n"); +// pc.printf("MAX44009 lux[%.2f] status[%d]\r\n", lux, lux_error); + int luxFinal = (int) (calc_lux(rawluxdata)); +// pc.printf("MAX44009 Final Lux[%.2f] \r\n", luxFinal); +// pc.printf("\r\n"); //fill raw lux data into the array curr_raw_light_to_master[0] = rawluxdata[0]; @@ -326,19 +337,19 @@ //calculate open circuit voltage from data double voltage = (double)(rawOCVdata[0]) / 100; - pc.printf("AO32 OCV[%.2f] status[%d]\r\n", voltage, ocv_error); +// pc.printf("AO32 OCV[%.2f] status[%d]\r\n", voltage, ocv_error); double OCVFinal = calc_OCV(rawOCVdata); - pc.printf("AO32 Final OCV[%.2f] \r\n", OCVFinal); - pc.printf("\r\n"); +// pc.printf("AO32 Final OCV[%.2f] \r\n", OCVFinal); +// pc.printf("\r\n"); //calculate harvesting counts from data - int countHi = int(rawCntdata[0]) * 256; - int countLo = int(rawCntdata[1]); - int harvest_counts = countHi + countLo; - pc.printf("AO32 HarvesterCnt[%d] status[%d]\r\n", harvest_counts, cnt_error); +// int countHi = int(rawCntdata[0]) * 256; +// int countLo = int(rawCntdata[1]); +// int harvest_counts = countHi + countLo; +// pc.printf("AO32 HarvesterCnt[%d] status[%d]\r\n", harvest_counts, cnt_error); int countFinal = calc_Harvest(rawCntdata); - pc.printf("AO32 Final HarvesterCnt[%d]\r\n", countFinal); - pc.printf("\r\n"); +// pc.printf("AO32 Final HarvesterCnt[%d]\r\n", countFinal); +// pc.printf("\r\n"); //fill raw AO32 data into the array @@ -346,6 +357,9 @@ curr_raw_AO32_to_master[1] = rawCntdata[0]; // Fill Harvesting count high byte curr_raw_AO32_to_master[2] = rawCntdata[1]; // Fill Harvesting count low byte + // print out sensor data + pc.printf("SENSOR: [%.3f] [%d] [%.2f] [%d] [0]\r\n", tempFinal, luxFinal, OCVFinal, countFinal); + /*************************************************************************** * Fill Payload Buffer With Data From Main Program Buffers for next LoRa Transmition **************************************************************************/ @@ -376,15 +390,15 @@ **************************************************************************/ // SX1276SensorSend(); SX1276PingPong(); - int sendTime = TimeOnAirSend(); - pc.printf("Tx Time on Air: %d \r\n", sendTime); +// int sendTime = TimeOnAirSend(); +// pc.printf("Tx Time on Air: %d \r\n", sendTime); /*************************************************************************** * Fill Main Program Buffers With Data From Received Payload Buffer **************************************************************************/ // Slave Device - memcpy(ID_of_master, &BufferRx[rx_idx_signature], size_signature); - memcpy(curr_dum_from_master, &BufferRx[rx_idx_dum], size_of_dum); +// memcpy(ID_of_master, &BufferRx[rx_idx_signature], size_signature); +// memcpy(curr_dum_from_master, &BufferRx[rx_idx_dum], size_of_dum); /*************************************************************************** * Slave Device: Print out Master Data @@ -402,7 +416,7 @@ // } // print loop counter - pc.printf("Loop Counter Slave: %d \r\n", loopCnt); +// pc.printf("Loop Counter Slave: %d \r\n", loopCnt); loopCnt = loopCnt + 1; } // end of transmission frequency for slave #endif @@ -413,14 +427,14 @@ * Fill Payload Buffer With Data From Main Program Buffers for next LoRa Transmition **************************************************************************/ memcpy(&BufferTx[tx_idx_signature], PingMsg, size_signature); - memcpy(&BufferTx[tx_idx_dum], curr_dum_to_slave, size_of_dum); +// memcpy(&BufferTx[tx_idx_dum], curr_dum_to_slave, size_of_dum); /*************************************************************************** * LoRa Communication: Gateway Receive Sensor Data **************************************************************************/ // SX1276GateWayReceive(333); SX1276PingPong(); - int sendTime = TimeOnAirSend(); +// int sendTime = TimeOnAirSend(); // pc.printf("Tx Time on Air: %d \r\n", sendTime); /*************************************************************************** @@ -462,7 +476,7 @@ // pc.printf("[%02X] \r\n", curr_raw_light_from_slave[i]); // } - double luxResult = calc_lux(curr_raw_light_from_slave); + int luxResult = (int) calc_lux(curr_raw_light_from_slave); // pc.printf("MSG: [%.3f] [%.2f] [] [] []\r\n", tempResult, luxResult); // memcpy(curr_raw_AO32_from_slave, &BufferRx[rx_idx_MAX20361], size_of_MAX20361); @@ -480,160 +494,38 @@ double OCVResult = calc_OCV(OCVrawHex); int CntResult = calc_Harvest(CntrawHex); - pc.printf("MSG: [%.3f] [%.2f] [%.2f] [%d] []\r\n", tempResult, luxResult, OCVResult, CntResult); - - // memcpy(curr_raw_other_from_slave, &BufferRx[rx_idx_other], size_of_other); - //pc.printf("Print Other data\r\n"); -// for(int i = 0; i < sizeof(curr_raw_other_from_slave); i++){ -// pc.printf("%d \r\n", curr_raw_other_from_slave[i]); + + + // only print out new results +// int tempNew = memcmp(prev_raw_temp_from_slave, curr_raw_temp_from_slave, sizeof(size_of_MAX30208)); +// int luxNew = memcmp(prev_raw_light_from_slave, curr_raw_light_from_slave, sizeof(size_of_MAX44009)); +// int AO32New = memcmp(prev_raw_AO32_from_slave, curr_raw_AO32_from_slave, sizeof(size_of_MAX20361)); + +// if (tempNew != 0 || luxNew != 0 || AO32New != 0) { + +// pc.printf("MSG: [%.3f] [%d] [%.2f] [%d] [0]\r\n", tempResult, luxResult, OCVResult, CntResult); + // } + if(print_data_flag) { + + //reset the flag + print_data_flag = false; + pc.printf("MSG: [%.3f] [%d] [%.2f] [%d] [0]\r\n", tempResult, luxResult, OCVResult, CntResult); + + } + + // copy the current recceived data into previous data +// memcpy(prev_raw_temp_from_slave, curr_raw_temp_from_slave, sizeof(size_of_MAX30208)); +// memcpy(prev_raw_light_from_slave, c/urr_raw_light_from_slave, sizeof(size_of_MAX44009)); +// memcpy(prev_raw_AO32_from_slave, curr_raw_AO32_from_slave, sizeof(size_of_MAX20361)); + // print loop counter // pc.printf("Loop Counter Master: %d \r\n", loopCnt); loopCnt = loopCnt + 1; -// wait(3); - #endif - ///*************************************************************************** -// * Fill Payload Buffer With Data From Main Program Buffers for next LoRa Transmition -// **************************************************************************/ -// #if MASTER == 1 // Master Device -// memcpy(&BufferTx[tx_idx_signature], PingMsg, size_signature); -// memcpy(&BufferTx[tx_idx_dum], curr_dum_to_slave, size_of_dum); -// #elif SLAVE == 1 // Slave Device -// memcpy(&BufferTx[tx_idx_signature], PongMsg, size_signature); -// memcpy(&BufferTx[tx_idx_MAX30208], curr_raw_temp_to_master, size_of_MAX30208); -// memcpy(&BufferTx[tx_idx_MAX44009], curr_raw_light_to_master, size_of_MAX44009); -// memcpy(&BufferTx[tx_idx_MAX20361], curr_raw_AO32_to_master, size_of_MAX20361); -// memcpy(&BufferTx[tx_idx_other], curr_raw_other_to_master, size_of_other); -// #endif -// -// /*************************************************************************** -// * In case of OnRxTimeout -// **************************************************************************/ -// #if MASTER == 1 // Master Device, these are values when LoRa communication did not happen -// ID_of_slave[0] = 10; // -// ID_of_slave[1] = 11; // -// ID_of_slave[2] = 12; // -// ID_of_slave[3] = 13; // -// ID_of_slave[4] = 14; // -// ID_of_slave[5] = 15; // -// ID_of_slave[6] = 16; // -// ID_of_slave[7] = 17; // -// -// #elif SLAVE == 1 // Slave Device, these are values when LoRa communication did not happen -// ID_of_master[0] = 'N'; // 0x4E or 78 -// ID_of_master[1] = 'A'; // 0x41 or 65 -// ID_of_master[2] = 'C'; // 0x43 or 67 -// ID_of_master[3] = 'K'; // 0x4B or 75 -// ID_of_master[4] = 'M'; // 0x4D or 77 -// ID_of_master[5] = 'A'; // 0x41 or 65 -// ID_of_master[6] = 'S'; // 0x53 or 83 -// ID_of_master[7] = '!'; // 0x21 or 33 -// -// curr_dum_from_master[0] = 39; -// curr_dum_from_master[1] = 40; -// -// #endif -// -// -// /*************************************************************************** -// * Lora Communications -// **************************************************************************/ -// #if MASTER == 1 // Master Device -// SX1276GateWayReceive(); -// -// #elif SLAVE == 1 // Slave Device -// SX1276SensorSend(); -// int sendTime = TimeOnAirSend(); -// pc.printf("Tx Time on Air: %d \r\n", sendTime); -// #endif -// -//// SX1276PingPong(); // what changes here? -// -// -// /*************************************************************************** -// * Fill Main Program Buffers With Data From Received Payload Buffer -// **************************************************************************/ -// /* The master and slave devices will have different requirements for offloading payload */ -// #if MASTER == 1 // Master Device -// memcpy(ID_of_slave, &BufferRx[rx_idx_signature], size_signature); -// memcpy(curr_raw_temp_from_slave, &BufferRx[rx_idx_MAX30208], size_of_MAX30208); -// memcpy(curr_raw_light_from_slave, &BufferRx[rx_idx_MAX44009], size_of_MAX44009); -// memcpy(curr_raw_AO32_from_slave, &BufferRx[rx_idx_MAX20361], size_of_MAX20361); -// memcpy(curr_raw_other_from_slave, &BufferRx[rx_idx_other], size_of_other); -// #elif SLAVE == 1 // Slave Device -// memcpy(ID_of_master, &BufferRx[rx_idx_signature], size_signature); -// memcpy(curr_dum_from_master, &BufferRx[rx_idx_dum], size_of_dum); -// #endif -// -// -// /*************************************************************************** -// * Print Out Data Received -// **************************************************************************/ -// #if MASTER == 1 // Master Device -// -//// memcpy(ID_of_slave, &BufferRx[rx_idx_signature], size_signature); -// pc.printf("Print ID_of_slave\r\n"); -// for(int i = 0; i < sizeof(ID_of_slave); i++){ -// pc.printf("%d \r\n", ID_of_slave[i]); -// } -// -//// memcpy(curr_raw_temp_from_slave, &BufferRx[rx_idx_MAX30208], size_of_MAX30208); -// pc.printf("Print MAX30208 data\r\n"); -// for(int i = 0; i < sizeof(curr_raw_temp_from_slave); i++){ -// pc.printf("%d \r\n", curr_raw_temp_from_slave[i]); -// } -// -//// memcpy(curr_raw_light_from_slave, &BufferRx[rx_idx_MAX44009], size_of_MAX44009); -// pc.printf("Print MAX44009 data\r\n"); -// for(int i = 0; i < sizeof(curr_raw_light_from_slave); i++){ -// pc.printf("%d \r\n", curr_raw_light_from_slave[i]); -// } -// -//// memcpy(curr_raw_AO32_from_slave, &BufferRx[rx_idx_MAX20361], size_of_MAX20361); -// pc.printf("Print MAX20361 data\r\n"); -// for(int i = 0; i < sizeof(curr_raw_AO32_from_slave); i++){ -// pc.printf("%d \r\n", curr_raw_AO32_from_slave[i]); -// } -// -//// memcpy(curr_raw_other_from_slave, &BufferRx[rx_idx_other], size_of_other); -// pc.printf("Print Other data\r\n"); -// for(int i = 0; i < sizeof(curr_raw_other_from_slave); i++){ -// pc.printf("%d \r\n", curr_raw_other_from_slave[i]); -// } -// -// // print loop counter -// pc.printf("Loop Counter Master: %d \r\n", loopCnt); -// loopCnt = loopCnt + 1; -// -// #elif SLAVE == 1 // Slave Device -//// memcpy(ID_of_master, &BufferRx[rx_idx_signature], size_signature); -// pc.printf("Print ID_of_master\r\n"); -// for(int i = 0; i < sizeof(ID_of_master); i++){ -// pc.printf("%d \r\n", ID_of_master[i]); -// } -// -//// memcpy(curr_dum_from_master, &BufferRx[rx_idx_dum], size_of_dum); -// pc.printf("Print Dum From Master\r\n"); -// for(int i = 0; i < sizeof(curr_dum_from_master); i++){ -// pc.printf("%d \r\n", curr_dum_from_master[i]); -// } -// -// // print loop counter -// pc.printf("Loop Counter Slave: %d \r\n", loopCnt); -// loopCnt = loopCnt + 1; -// #endif - - // add delay to slow down - // wait(1); - - -// } //end of get_data_flag - } // end of while(1) loop -} // end of main() - +} // end of main() \ No newline at end of file