calculate and print the checksum, update/tidy commenting
This commit is contained in:
parent
a86d7eec28
commit
f43f092a00
2 changed files with 44 additions and 31 deletions
|
|
@ -200,11 +200,12 @@ int main() {
|
||||||
melopero.enablelWs2812(true);
|
melopero.enablelWs2812(true);
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
// simple LED on
|
// simple LED on whilst loop body is executing
|
||||||
gpio_put(23, 1);
|
gpio_put(23, 1);
|
||||||
|
|
||||||
printf("\n============================================\n");
|
printf("\n============================================\n");
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
// print out the battery charging state, also set LED colour code
|
// print out the battery charging state, also set LED colour code
|
||||||
printf("Battery: %d (", melopero.getChargerStatus());
|
printf("Battery: %d (", melopero.getChargerStatus());
|
||||||
if (melopero.isCharging()) {
|
if (melopero.isCharging()) {
|
||||||
|
|
@ -227,22 +228,27 @@ int main() {
|
||||||
// red
|
// red
|
||||||
melopero.setWs2812Color(255, 0, 0, 0.1);
|
melopero.setWs2812Color(255, 0, 0, 0.1);
|
||||||
}
|
}
|
||||||
// NOTE: there seems to be an error in the charging on these
|
|
||||||
// boards where it never reaches full charge and then hits a
|
|
||||||
// timeout and enters non-recoverable error, but then this is
|
|
||||||
// reset by external power loss (i.e. no light on solar
|
|
||||||
// overnight) - though this doesn't help if you're using
|
|
||||||
// solar+battery as the external power source.
|
|
||||||
//
|
|
||||||
// NOTE2: if there is no battery plugged in this just flips
|
|
||||||
// between charging and charged status.
|
|
||||||
|
|
||||||
|
// Note: If there is no battery plugged in this just flips between
|
||||||
|
// charging and charged status. If there it a battery but no input
|
||||||
|
// power then it seems to always report 'fully charged' so I think for
|
||||||
|
// full power state awareness you also need to be able to check supply
|
||||||
|
// voltage and ideally also battery/charge voltage. I have experienced
|
||||||
|
// some slight oddness from the charging circuit where it sometimes
|
||||||
|
// never fully charges, hits a timeout, and reports
|
||||||
|
// non-recoverable-error... this status is reset by flipping the
|
||||||
|
// external power off-and-on-again.
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
// check the temperature of the RP2350
|
// check the temperature of the RP2350
|
||||||
float voltage = readADCVoltage( 4 );
|
float voltage = readADCVoltage( 4 );
|
||||||
float temp = 27.0 - ((voltage - 0.706) / 0.001721); // values from RP2350 documentation
|
float temp = 27.0 - ((voltage - 0.706) / 0.001721); // values from RP2350 documentation
|
||||||
printf( "RP2350 Temperature: %0.2f C\n", temp );
|
printf( "RP2350 Temperature: %0.2f C\n", temp );
|
||||||
|
|
||||||
// read received LoRa data, if available
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
// read received LoRa data, and if available print receive data
|
||||||
uint8_t rxbuff[sizeof(struct rxdata)]; // at least big enough for our *expected* data
|
uint8_t rxbuff[sizeof(struct rxdata)]; // at least big enough for our *expected* data
|
||||||
size_t rxbuff_ptr = 0;
|
size_t rxbuff_ptr = 0;
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
|
|
@ -267,17 +273,22 @@ int main() {
|
||||||
if (verbose) printf("\n");
|
if (verbose) printf("\n");
|
||||||
} while (melopero.checkRxFifo(500)); // Keep checking the FIFO for new data
|
} while (melopero.checkRxFifo(500)); // Keep checking the FIFO for new data
|
||||||
|
|
||||||
// NOTE: the length could be < or > actual buffer length
|
// NOTE: the rxbuff_ptr could be < or > actual buffer length
|
||||||
printf( "Received Data:\nlength=%d\ndata={", rxbuff_ptr );
|
printf( "Received Data:\n length=%d (buflen=%d)\n data={", rxbuff_ptr, sizeof(rxbuff) );
|
||||||
for (size_t i = 0; i < sizeof(rxbuff); i++) {
|
uint32_t checksum = 0;
|
||||||
|
size_t safelen = (rxbuff_ptr < sizeof(rxbuff)) ? rxbuff_ptr : sizeof(rxbuff);
|
||||||
|
for (size_t i = 0; i < safelen ; i++) {
|
||||||
|
if ( i < (safelen - 1) ) checksum += rxbuff[i];
|
||||||
printf("0x%02X ", rxbuff[i]);
|
printf("0x%02X ", rxbuff[i]);
|
||||||
}
|
}
|
||||||
printf("}\n");
|
printf("}\n");
|
||||||
|
checksum &= 0x000000ff;
|
||||||
|
printf( " checksum=%02X\n", checksum );
|
||||||
|
|
||||||
struct rxdata rxd = {};
|
struct rxdata rxd = {};
|
||||||
deseralise_rxdata( rxbuff, &rxd );
|
deseralise_rxdata( rxbuff, &rxd );
|
||||||
|
|
||||||
printf( "Received\n" );
|
printf( "Received:\n" );
|
||||||
printf( " Data Length: %u bytes\n", rxd.length );
|
printf( " Data Length: %u bytes\n", rxd.length );
|
||||||
printf( " Options: 0x%08X (bitfield)\n", rxd.options );
|
printf( " Options: 0x%08X (bitfield)\n", rxd.options );
|
||||||
printf( " WTF: 0x%02X (undocumented field?)\n", rxd.wtf );
|
printf( " WTF: 0x%02X (undocumented field?)\n", rxd.wtf );
|
||||||
|
|
|
||||||
|
|
@ -198,14 +198,9 @@ int main() {
|
||||||
melopero.enablelWs2812(true);
|
melopero.enablelWs2812(true);
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
// simple LED on whilst executing the loop body
|
||||||
// do a litte dance
|
|
||||||
|
|
||||||
// simple LED on
|
|
||||||
gpio_put(23, 1);
|
gpio_put(23, 1);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
// read sensor values
|
|
||||||
printf("\n============================================\n");
|
printf("\n============================================\n");
|
||||||
|
|
||||||
// the sensor data struct
|
// the sensor data struct
|
||||||
|
|
@ -214,6 +209,7 @@ int main() {
|
||||||
txd.options = 0;
|
txd.options = 0;
|
||||||
txd.dest = 0xFFFF; // broadcast "address"
|
txd.dest = 0xFFFF; // broadcast "address"
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
// print out the battery charging state
|
// print out the battery charging state
|
||||||
txd.charge_state = melopero.getChargerStatus();
|
txd.charge_state = melopero.getChargerStatus();
|
||||||
printf("Battery: %d (", txd.charge_state);
|
printf("Battery: %d (", txd.charge_state);
|
||||||
|
|
@ -237,16 +233,19 @@ int main() {
|
||||||
// red
|
// red
|
||||||
melopero.setWs2812Color(255, 0, 0, 0.1);
|
melopero.setWs2812Color(255, 0, 0, 0.1);
|
||||||
}
|
}
|
||||||
// NOTE: there seems to be an error in the charging on these
|
|
||||||
// boards where it never reaches full charge and then hits a
|
|
||||||
// timeout and enters non-recoverable error, but then this is
|
|
||||||
// reset by external power loss (i.e. no light on solar
|
|
||||||
// overnight) - though this doesn't help if you're using
|
|
||||||
// solar+battery as the external power source.
|
|
||||||
//
|
|
||||||
// NOTE2: if there is no battery plugged in this just flips
|
|
||||||
// between charging and charged status.
|
|
||||||
|
|
||||||
|
// Note: If there is no battery plugged in this just flips between
|
||||||
|
// charging and charged status. If there it a battery but no input
|
||||||
|
// power then it seems to always report 'fully charged' so I think for
|
||||||
|
// full power state awareness you also need to be able to check supply
|
||||||
|
// voltage and ideally also battery/charge voltage. I have experienced
|
||||||
|
// some slight oddness from the charging circuit where it sometimes
|
||||||
|
// never fully charges, hits a timeout, and reports
|
||||||
|
// non-recoverable-error... this status is reset by flipping the
|
||||||
|
// external power off-and-on-again.
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
// flip the enable on the VSEN on/off each iteration, this is just
|
// flip the enable on the VSEN on/off each iteration, this is just
|
||||||
// testing it can turn an LED on/off if you like, or enable/disable
|
// testing it can turn an LED on/off if you like, or enable/disable
|
||||||
// other external hardware (thus saving power, only power on sensors
|
// other external hardware (thus saving power, only power on sensors
|
||||||
|
|
@ -260,6 +259,9 @@ int main() {
|
||||||
gpio_put( 0, 1 );
|
gpio_put( 0, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////
|
||||||
|
// read sensor values
|
||||||
// check the temperature of the RP2350
|
// check the temperature of the RP2350
|
||||||
float voltage = readADCVoltage( 4 );
|
float voltage = readADCVoltage( 4 );
|
||||||
txd.mcu_temp = 27.0 - ((voltage - 0.706) / 0.001721);
|
txd.mcu_temp = 27.0 - ((voltage - 0.706) / 0.001721);
|
||||||
|
|
@ -275,7 +277,7 @@ int main() {
|
||||||
txd.vin = (adc1_v * (98600 + 14890)) / 14890; // measured values of volage divider
|
txd.vin = (adc1_v * (98600 + 14890)) / 14890; // measured values of volage divider
|
||||||
printf( "Supply Voltage: %0.2fV\n", txd.vin );
|
printf( "Supply Voltage: %0.2fV\n", txd.vin );
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
// send some data
|
// send some data
|
||||||
uint8_t sendbuf[sizeof(txdata)]; // at least big enough...
|
uint8_t sendbuf[sizeof(txdata)]; // at least big enough...
|
||||||
size_t data_length = serialise_txdata(&txd, sendbuf);
|
size_t data_length = serialise_txdata(&txd, sendbuf);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue