From 8cc5ae23af86aaa15f6a74b07123b4bb6c39a10c Mon Sep 17 00:00:00 2001 From: Jelmer Date: Sat, 4 Feb 2023 02:20:22 +0100 Subject: [PATCH] removd bitfield as it turned out to be inefficient --- ap_fw/main.c | 23 ++++++++++++----------- tag_fw/epd.h | 2 +- tag_fw/main.c | 5 ++++- tag_fw/powermgt.c | 14 ++++++++++++++ tag_fw/powermgt.h | 6 ++++++ tag_fw/proto.h | 23 +++++++++++++---------- tag_fw/syncedproto.c | 5 ++++- 7 files changed, 54 insertions(+), 24 deletions(-) diff --git a/ap_fw/main.c b/ap_fw/main.c index 6a1f9288..cae4bd0e 100644 --- a/ap_fw/main.c +++ b/ap_fw/main.c @@ -40,7 +40,7 @@ struct MacFrameBcast { uint16_t srcPan; uint8_t src[8]; } __packed; - +#define PKT_AVAIL_DATA_REQ_SHORT 0xE4 #define PKT_AVAIL_DATA_REQ 0xE5 #define PKT_AVAIL_DATA_INFO 0xE6 #define PKT_BLOCK_PARTIAL_REQUEST 0xE7 @@ -55,14 +55,15 @@ struct MacFrameBcast { struct AvailDataReq { uint8_t checksum; - uint8_t lastPacketLQI : 7; - uint8_t lastPacketRSSI : 7; // is negative - int8_t temperature : 7; // zero if not reported/not supported to be reported. else, this minus CHECKIN_TEMP_OFFSET is temp in degrees C - uint16_t batteryMv : 12; - uint8_t hwType : 5; // 32 types of tags supported - uint8_t wakeupReason : 2; // supports 4 types of wakeup reasons - uint8_t capabilities; -} __packed; // 7 bytes + uint8_t lastPacketLQI; + int8_t lastPacketRSSI; + int8_t temperature; + uint16_t batteryMv; + uint8_t hwType; + uint8_t wakeupReason; + uint8_t capabilities; // undefined, as of now +} __packed; + #define DATATYPE_NOUPDATE 0 #define DATATYPE_IMG 1 @@ -73,8 +74,8 @@ struct AvailDataInfo { uint8_t checksum; uint64_t dataVer; // MD5 of potential traffic uint32_t dataSize; - uint8_t dataType : 4; // allows for 16 different datatypes - uint8_t dataTypeArgument : 4; // extra specification or instruction for the tag (LUT to be used for drawing image) + uint8_t dataType; // allows for 16 different datatypes + uint8_t dataTypeArgument; // extra specification or instruction for the tag (LUT to be used for drawing image) uint16_t nextCheckIn; // when should the tag check-in again? Measured in minutes } __packed; diff --git a/tag_fw/epd.h b/tag_fw/epd.h index b7cfc94b..a702d455 100644 --- a/tag_fw/epd.h +++ b/tag_fw/epd.h @@ -35,6 +35,7 @@ void epdSetup(); void epdEnterSleep(); +uint16_t epdGetBattery(); void setWindowX(uint16_t start, uint16_t end); void setWindowY(uint16_t start, uint16_t end); @@ -48,7 +49,6 @@ void drawNoWait(); void epdWaitRdy(); void drawLineHorizontal(bool color, uint16_t x1, uint16_t x2, uint16_t y); void drawLineVertical(bool color, uint16_t x, uint16_t y1, uint16_t y2); - void beginFullscreenImage(); void beginWriteFramebuffer(bool color); void endWriteFramebuffer(); diff --git a/tag_fw/main.c b/tag_fw/main.c index 86d989e7..21166f36 100644 --- a/tag_fw/main.c +++ b/tag_fw/main.c @@ -20,6 +20,8 @@ //#define DEBUG_MODE + + uint8_t showChannelSelect() { uint8_t __xdata result[16]; memset(result, 0, sizeof(result)); @@ -49,7 +51,6 @@ uint8_t showChannelSelect() { mLastLqi = highestLqi; return highestSlot; } - void mainProtocolLoop(void) { clockingAndIntsInit(); timerInit(); @@ -83,6 +84,8 @@ void mainProtocolLoop(void) { initPowerSaving(); #ifndef DEBUG_MODE // show the splashscreen + getExtraData(); + showSplashScreen(); eepromDeepPowerDown(); diff --git a/tag_fw/powermgt.c b/tag_fw/powermgt.c index 68306d43..d9c1e212 100644 --- a/tag_fw/powermgt.c +++ b/tag_fw/powermgt.c @@ -30,12 +30,25 @@ uint8_t __xdata dataReqLastAttempt = 0; uint16_t __xdata nextCheckInFromAP = 0; uint8_t __xdata wakeUpReason = 0; +extern int8_t adcSampleTemperature(void); //in degrees C + void initPowerSaving() { for (uint8_t c = 0; c < POWER_SAVING_SMOOTHING; c++) { dataReqAttemptArr[c] = INTERVAL_BASE; } } +int8_t __xdata temperature = 0; +uint16_t __xdata batteryVoltage = 0; + +void getExtraData(){ + batteryVoltage = epdGetBattery(); + temperature = adcSampleTemperature(); + pr("temp = %d volt = %d\n", temperature, batteryVoltage); +} + + + // init/sleep void initAfterWake() { clockingAndIntsInit(); @@ -45,6 +58,7 @@ void initAfterWake() { epdEnterSleep(); irqsOn(); boardInitStage2(); + getExtraData(); initRadio(); } void doSleep(uint32_t __xdata t) { diff --git a/tag_fw/powermgt.h b/tag_fw/powermgt.h index 65889c0c..9e7757ef 100644 --- a/tag_fw/powermgt.h +++ b/tag_fw/powermgt.h @@ -28,9 +28,15 @@ extern void initAfterWake(); extern void doSleep(uint32_t __xdata t); extern uint16_t getNextSleep(); extern void initPowerSaving(); +extern void getExtraData(); + extern uint8_t __xdata wakeUpReason; + extern uint16_t __xdata nextCheckInFromAP; extern uint8_t __xdata dataReqLastAttempt; +extern int8_t __xdata temperature; +extern uint16_t __xdata batteryVoltage; + #endif \ No newline at end of file diff --git a/tag_fw/proto.h b/tag_fw/proto.h index 3f46b0eb..1297a671 100644 --- a/tag_fw/proto.h +++ b/tag_fw/proto.h @@ -90,6 +90,7 @@ struct MacFrameBcast { uint8_t src[8]; } __packed; +#define PKT_AVAIL_DATA_REQ_SHORT 0xE4 #define PKT_AVAIL_DATA_REQ 0xE5 #define PKT_AVAIL_DATA_INFO 0xE6 #define PKT_BLOCK_PARTIAL_REQUEST 0xE7 @@ -104,14 +105,15 @@ struct MacFrameBcast { struct AvailDataReq { uint8_t checksum; - uint8_t lastPacketLQI : 7; - uint8_t lastPacketRSSI : 7; // is negative - int8_t temperature : 7; // zero if not reported/not supported to be reported. else, this minus CHECKIN_TEMP_OFFSET is temp in degrees C - uint16_t batteryMv : 12; - uint8_t hwType : 5; // 32 types of tags supported - uint8_t wakeupReason : 2; // supports 4 types of wakeup reasons - uint8_t capabilities; -} __packed; // 7 bytes + uint8_t lastPacketLQI; + int8_t lastPacketRSSI; + int8_t temperature; + uint16_t batteryMv; + uint8_t hwType; + uint8_t wakeupReason; + uint8_t capabilities; // undefined, as of now +} __packed; + #define DATATYPE_NOUPDATE 0 #define DATATYPE_IMG 1 @@ -122,11 +124,12 @@ struct AvailDataInfo { uint8_t checksum; uint64_t dataVer; // MD5 of potential traffic uint32_t dataSize; - uint8_t dataType : 4; // allows for 16 different datatypes - uint8_t dataTypeArgument : 4; // extra specification or instruction for the tag (LUT to be used for drawing image) + uint8_t dataType; + uint8_t dataTypeArgument; // extra specification or instruction for the tag (LUT to be used for drawing image) uint16_t nextCheckIn; // when should the tag check-in again? Measured in minutes } __packed; + struct blockPart { uint8_t checksum; uint8_t blockId; diff --git a/tag_fw/syncedproto.c b/tag_fw/syncedproto.c index 5e6d72d3..99539e90 100644 --- a/tag_fw/syncedproto.c +++ b/tag_fw/syncedproto.c @@ -202,7 +202,10 @@ void sendAvailDataReq() { // TODO: send some (more) meaningful data availreq->hwType = HW_TYPE; availreq->wakeupReason = wakeUpReason; - + availreq->lastPacketRSSI = (uint8_t)(-1*mLastRSSI); + availreq->lastPacketLQI = mLastLqi; + availreq->temperature = temperature; + availreq->batteryMv = batteryVoltage; addCRC(availreq, sizeof(struct AvailDataReq)); commsTxNoCpy(outBuffer); }