Created
July 31, 2022 00:16
-
-
Save jones2126/11557c73abbde5d32298918804950342 to your computer and use it in GitHub Desktop.
This was used to confirm the size of the structure and test using the memcpy function to copy from a structure to a buffer and then back again. This helped me clarify this concept would work in anticipation of including it in a LoRa radio master/slave setup.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This was used to confirm the size of the structure and test using the memcpy function to copy from a structure to a buffer and then back again. | |
* This helped me clarify this concept would work in anticipation of including it in a lora radio master/slave setup. | |
*/ | |
struct RadioControlStruct{ | |
int steering_val; | |
int throttle_val; | |
float press_norm ; | |
float press_hg; | |
float temp; | |
unsigned long counter; | |
}RadioControlData; | |
struct RadioControlStruct2{ | |
int steering_val; | |
int throttle_val; | |
float press_norm ; | |
float press_hg; | |
float temp; | |
unsigned long counter; | |
}RadioControlData2; | |
uint8_t RadioControlData_message_len = sizeof(RadioControlData); | |
uint8_t tx_RadioControlData_buf[sizeof(RadioControlData)] = {0}; | |
struct TractorDataStruct{ | |
float heading_val; | |
int speed_val; | |
unsigned long counter; | |
}TractorData; | |
byte tx_TractorData_buf[sizeof(TractorData)] = {0}; | |
void setup() { | |
// put your setup code here, to run once: | |
startSerial(); | |
Serial.println("sizeof(RadioControlData): "); Serial.println(sizeof(RadioControlData)); | |
Serial.println("sizeof(TractorData): "); Serial.println(sizeof(TractorData)); | |
RadioControlData.steering_val = 255; | |
RadioControlData.throttle_val = 4096; | |
RadioControlData.press_norm=1000.11; | |
RadioControlData.press_hg=0.59; | |
RadioControlData.temp=22.394; | |
RadioControlData.counter=65000; | |
Serial.println("sizeof(RadioControlData): "); Serial.println(sizeof(RadioControlData)); | |
Serial.println("sizeof(TractorData): "); Serial.println(sizeof(TractorData)); | |
memcpy(tx_RadioControlData_buf, &RadioControlData, RadioControlData_message_len); | |
// at this point you would transmit tx_RadioControlData_buf via lora radio | |
tx_RadioControlData_buf[sizeof(RadioControlData)] = {0}; // to demonstrate the array is cleared out | |
// then you would receive the transmission in a buffer and have to load the structure | |
memcpy(&RadioControlData2, tx_RadioControlData_buf, RadioControlData_message_len); | |
Serial.print("RadioControlData2.steering_val: "); Serial.println(RadioControlData2.steering_val); | |
Serial.print("RadioControlData2.throttle_val: "); Serial.println(RadioControlData2.throttle_val); | |
Serial.print("RadioControlData2.press_norm: "); Serial.println(RadioControlData2.press_norm); | |
Serial.print("RadioControlData2.press_hg: "); Serial.println(RadioControlData2.press_hg); | |
Serial.print("RadioControlData2.temp: "); Serial.println(RadioControlData2.temp); | |
Serial.print("RadioControlData2.counter: "); Serial.println(RadioControlData2.counter); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
} | |
void startSerial(){ | |
Serial.begin(115200); | |
while (!Serial) { | |
delay(1000); // loop forever and don't continue | |
} | |
Serial.println("starting: structure_size"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment