Skip to content

Commit

Permalink
ZBS Tag Return-data support
Browse files Browse the repository at this point in the history
  • Loading branch information
jjwbruijn committed Sep 8, 2023
1 parent 36c3c45 commit 4176252
Show file tree
Hide file tree
Showing 34 changed files with 173 additions and 242 deletions.
Binary file modified binaries/AP_FW_1.54.bin
Binary file not shown.
Binary file modified binaries/AP_FW_2.9.bin
Binary file not shown.
Binary file modified binaries/AP_FW_Nodisplay.bin
Binary file not shown.
Binary file modified binaries/AP_FW_Pack.bin
Binary file not shown.
Binary file modified binaries/AP_FW_Segmented_UK.bin
Binary file not shown.
Binary file modified binaries/Tag_FW_1.54.bin
Binary file not shown.
Binary file modified binaries/Tag_FW_2.9-uc8151.bin
Binary file not shown.
Binary file modified binaries/Tag_FW_2.9.bin
Binary file not shown.
Binary file modified binaries/Tag_FW_4.2.bin
Binary file not shown.
Binary file modified binaries/Tag_FW_Pack.bin
Binary file not shown.
5 changes: 3 additions & 2 deletions zbs243_AP_FW/APDisplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include "comms.h"
#include "cpu.h"
#include "printf.h"
#include "proto.h"
#include "../oepl-definitions.h"
#include "../oepl-proto.h"
#include "radio.h"
#include "screen.h"
#include "timer.h"
Expand Down Expand Up @@ -104,4 +105,4 @@ void epdShowRun() {

#endif

#endif
#endif
4 changes: 2 additions & 2 deletions zbs243_AP_FW/comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string.h>
#include "asmUtil.h"
#include "printf.h"
#include "proto.h"
#include "../oepl-definitions.h"
#include "radio.h"

static uint8_t __xdata mCommsBuf[127];
Expand Down Expand Up @@ -46,4 +46,4 @@ bool commsTxUnencrypted(const void __xdata *packetP, uint8_t len) {

bool commsTxNoCpy(const void __xdata *packetp) {
return radioTx(packetp);
}
}
6 changes: 3 additions & 3 deletions zbs243_AP_FW/emulateTag.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#include "asmUtil.h"
#include "comms.h"
#include "cpu.h"
#include "printf.h"
#include "proto.h"
#include "../oepl-definitions.h"
#include "../oepl-proto.h"
#include "radio.h"
#include "screen.h"
#include "timer.h"
Expand Down Expand Up @@ -174,4 +174,4 @@ void fakeTagCheckIn() {
espNotifyAvailDataReq(adr, fakeTagMac);
}

#endif
#endif
62 changes: 56 additions & 6 deletions zbs243_AP_FW/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
#include <stdio.h>
#include <string.h>

#include "../oepl-definitions.h"
#include "../oepl-proto.h"
#include "../oepl-esp-ap-proto.h"

#include "asmUtil.h"
#include "board.h"
#include "comms.h"
#include "cpu.h"
#include "printf.h"
#include "proto.h"
#include "radio.h"
#include "timer.h"
#include "uart.h"
Expand All @@ -30,7 +33,7 @@
struct pendingData __xdata pendingDataArr[MAX_PENDING_MACS];

// VERSION GOES HERE!
uint16_t __xdata version = 0x0017;
uint16_t __xdata version = 0x0019;

#define RAW_PKT_PADDING 2

Expand Down Expand Up @@ -61,6 +64,7 @@ uint8_t *__xdata blockXferBuffer = blockbuffer;
#define CONCURRENT_REQUEST_DELAY 1200UL * TIMER_TICKS_PER_MS
uint32_t __xdata lastBlockRequest = 0;
uint8_t __xdata lastBlockMac[8];
uint8_t __xdata lastTagReturn[8];

uint8_t __xdata curChannel = 11;
uint8_t __xdata curPower = 10;
Expand Down Expand Up @@ -416,9 +420,32 @@ void espNotifyAPInfo() {
countSlots();
pr("PEN>%02X\n", curPendingData);
pr("NOP>%02X\n", curNoUpdate);
//#if (AP_EMULATE_TAG == 1)
// fakeTagCheckIn(); // removed this for now to ensure IP info is properly displayed; first tag check in now happens after the first round of housekeeping (30s)
//#endif
// #if (AP_EMULATE_TAG == 1)
// fakeTagCheckIn(); // removed this for now to ensure IP info is properly displayed; first tag check in now happens after the first round of housekeeping (30s)
// #endif
}
void espNotifyTagReturnData(uint8_t *src, uint8_t len) {
struct tagReturnData *trd = (struct tagReturnData *)(radiorxbuffer + sizeof(struct MacFrameBcast) + 1); // oh how I'd love to pass this as an argument, but sdcc won't let me
struct espTagReturnData *etrd = (struct espTagReturnData *)radiotxbuffer;

if (memcmp((void *__xdata) & trd->dataVer, lastTagReturn, 8) == 0) {
return;
} else {
xMemCopyShort((void *__xdata)lastTagReturn, (void *__xdata) & trd->dataVer, 8);
}

memcpy(etrd->src, src, 8);
etrd->len = len;
memcpy((void*)etrd->returnData, trd, len);
addCRC(etrd, len+10);

uartTx('T');
uartTx('R');
uartTx('D');
uartTx('>');
for (uint8_t c = 0; c < len+10; c++) {
uartTx(((uint8_t *)etrd)[c]);
}
}

// process data from tag
Expand Down Expand Up @@ -581,6 +608,25 @@ void processXferComplete(uint8_t *buffer) {
if (slot != -1) pendingDataArr[slot].attemptsLeft = 0;
}
}
void processTagReturnData(uint8_t *buffer, uint8_t len) {
struct MacFrameBcast *rxframe = (struct MacFrameBcast *)buffer;
struct MacFrameNormal *frameHeader = (struct MacFrameNormal *)(radiotxbuffer + 1);

if (!checkCRC((buffer + sizeof(struct MacFrameBcast) + 1), len - (sizeof(struct MacFrameBcast) + 1))) {
return;
}
radiotxbuffer[sizeof(struct MacFrameNormal) + 1] = PKT_TAG_RETURN_DATA_ACK;
radiotxbuffer[0] = sizeof(struct MacFrameNormal) + 1 + RAW_PKT_PADDING;
memcpy(frameHeader->src, mSelfMac, 8);
memcpy(frameHeader->dst, rxframe->src, 8);
radiotxbuffer[1] = 0x41; // fast way to set the appropriate bits
radiotxbuffer[2] = 0xCC; // normal frame
frameHeader->seq = seq++;
frameHeader->pan = rxframe->srcPan;
radioTx(radiotxbuffer);

espNotifyTagReturnData(rxframe->src, len - (sizeof(struct MacFrameBcast) + 1));
}

// send block data to the tag
void sendPart(uint8_t partNo) {
Expand Down Expand Up @@ -769,8 +815,11 @@ void main(void) {
processAvailDataReq(radiorxbuffer);
}
break;
case PKT_TAG_RETURN_DATA:
processTagReturnData(radiorxbuffer, ret);
break;
default:
pr("t=%02X\n", getPacketType(radiorxbuffer));
// pr("t=%02X\n", getPacketType(radiorxbuffer));
break;
}
loopCount = 10000;
Expand Down Expand Up @@ -805,6 +854,7 @@ void main(void) {
#if (AP_EMULATE_TAG == 1)
fakeTagCheckIn();
#endif
memset(&lastTagReturn, 0, 8);
for (uint8_t __xdata c = 0; c < MAX_PENDING_MACS; c++) {
if (pendingDataArr[c].attemptsLeft == 1) {
if (pendingDataArr[c].availdatainfo.dataType != DATATYPE_NOUPDATE) {
Expand Down
1 change: 0 additions & 1 deletion zbs243_AP_FW/proto.h

This file was deleted.

2 changes: 0 additions & 2 deletions zbs243_Tag_FW/comms.c
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#define __packed

#include <string.h>

#include "proto.h"
#include "asmUtil.h"
#include "printf.h"
#include "radio.h"
Expand Down
2 changes: 1 addition & 1 deletion zbs243_Tag_FW/drawing.c
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "eeprom.h"
#include "screen.h"
#include "printf.h"
#include "proto.h"
#include "../oepl-definitions.h"
#include "screen.h"
#include "timer.h"
#include "userinterface.h" // for addIcons
Expand Down
5 changes: 4 additions & 1 deletion zbs243_Tag_FW/i2cdevices.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
#include "i2c.h"
#include "printf.h"
#include "timer.h"
#include "proto.h"

#define __packed
#include "../oepl-definitions.h"
#include "../oepl-proto.h"

extern void dump(uint8_t* __xdata a, uint16_t __xdata l); // remove me when done

Expand Down
15 changes: 14 additions & 1 deletion zbs243_Tag_FW/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "i2cdevices.h"
#include "powermgt.h"
#include "printf.h"
#include "proto.h"

#include "radio.h"
#include "screen.h"
#include "settings.h"
Expand All @@ -21,6 +21,10 @@
#include "userinterface.h"
#include "wdt.h"

#include "../oepl-definitions.h"
#include "../oepl-proto.h"


// #define DEBUG_MODE

static const uint64_t __code __at(0x008b) mVersionRom = 0x1000011300000000ull;
Expand Down Expand Up @@ -255,6 +259,15 @@ void TagAssociated() {
}
} else {
powerUp(INIT_RADIO);



#ifdef ENABLE_RETURN_DATA
// example code to send data back to the AP. Up to 90 bytes can be sent in one packet
uint8_t __xdata blaat[2] = {0xAB, 0xBA};
sendTagReturnData(blaat, 2, 0x55);
#endif

avail = getShortAvailDataInfo();
powerDown(INIT_RADIO);
}
Expand Down
3 changes: 2 additions & 1 deletion zbs243_Tag_FW/powermgt.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#include "i2c.h"
#include "i2cdevices.h"
#include "printf.h"
#include "proto.h"
#include "../oepl-definitions.h"
#include "../oepl-proto.h"
#include "radio.h"
#include "screen.h"
#include "settings.h"
Expand Down
2 changes: 2 additions & 0 deletions zbs243_Tag_FW/powermgt.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#define VOLTAGE_CHECK_INTERVAL 288 // How often the tag should do a battery voltage check (multiplied by LONG_DATAREQ_INTERVAL)
#define BATTERY_VOLTAGE_MINIMUM 2450 // 2600 or below is the best we can do on the EPD

#define MAX_RETURN_DATA_ATTEMPTS 15

// power saving when no AP's were found (scanning every X)
#define VOLTAGEREADING_DURING_SCAN_INTERVAL 2 // how often we should read voltages; this is done every scan attempt in interval bracket 3
#define INTERVAL_1_TIME 3600UL // Try every hour
Expand Down
1 change: 0 additions & 1 deletion zbs243_Tag_FW/proto.h

This file was deleted.

4 changes: 4 additions & 0 deletions zbs243_Tag_FW/settings.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define __packed
#include "settings.h"

#include <flash.h>
Expand All @@ -7,10 +8,13 @@
#include <stdio.h>
#include <string.h>


#include "asmUtil.h"
#include "powermgt.h"
#include "printf.h"
#include "syncedproto.h"
#include "../oepl-definitions.h"
#include "../oepl-proto.h"

struct tagsettings __xdata tagSettings = {0};
extern uint8_t __xdata blockXferBuffer[];
Expand Down
8 changes: 6 additions & 2 deletions zbs243_Tag_FW/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

#include <stdint.h>

#define FW_VERSION 20 // version number (max 2.5.5 :) )
#define FW_VERSION_SUFFIX "-DSLP" // suffix, like -RC1 or whatever.
#define FW_VERSION 21 // version number (max 2.5.5 :) )
#define FW_VERSION_SUFFIX "-RET" // suffix, like -RC1 or whatever.
// #define DEBUGBLOCKS // uncomment to enable extra debug information on the block transfers
// #define PRINT_LUT // uncomment if you want the tag to print the LUT for the current temperature bracket

// #define ENABLE_RETURN_DATA // enables the tag to send blocks of data back. Enabling this costs about 4 IRAM bytes

#define SETTINGS_STRUCT_VERSION 0x01

#define DEFAULT_SETTING_FASTBOOT 0
Expand All @@ -17,6 +19,7 @@
#define DEFAULT_SETTING_LOWBATSYMBOL 1
#define DEFAULT_SETTING_NORFSYMBOL 1

/*
struct tagsettings {
uint8_t settingsVer; // the version of the struct as written to the infopage
uint8_t enableFastBoot; // default 0; if set, it will skip splashscreen
Expand All @@ -31,6 +34,7 @@ struct tagsettings {
uint16_t minimumCheckInTime; // defaults to BASE_INTERVAL from powermgt.h
uint8_t fixedChannel; // default 0; if set to a valid channel number, the tag will stick to that channel
} __packed;
*/

extern struct tagsettings tagSettings;

Expand Down
49 changes: 47 additions & 2 deletions zbs243_Tag_FW/syncedproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#include "i2cdevices.h"
#include "powermgt.h"
#include "printf.h"
#include "proto.h"
#include "../oepl-definitions.h"
#include "../oepl-proto.h"
#include "radio.h"
#include "screen.h"
#include "settings.h"
Expand Down Expand Up @@ -50,7 +51,7 @@ uint8_t __xdata currentChannel = 0;
static uint8_t __xdata inBuffer[128] = {0};
static uint8_t __xdata outBuffer[128] = {0};

extern void executeCommand(uint8_t cmd); // this is defined in main.c
extern void executeCommand(uint8_t cmd); // this is defined in main.c

// tools
static uint8_t __xdata getPacketType(const void *__xdata buffer) {
Expand Down Expand Up @@ -251,6 +252,50 @@ struct AvailDataInfo *__xdata getShortAvailDataInfo() {
dataReqLastAttempt = DATA_REQ_MAX_ATTEMPTS;
return NULL;
}

#ifdef ENABLE_RETURN_DATA
static void sendTagReturnDataPacket(const uint8_t *data, uint8_t len, uint8_t type) {
struct MacFrameBcast __xdata *txframe = (struct MacFrameBcast *)(outBuffer + 1);
memset(outBuffer, 0, sizeof(struct MacFrameBcast) + sizeof(struct AvailDataReq) + 2 + 4);
struct tagReturnData *__xdata trd = (struct tagReturnData *)(outBuffer + 2 + sizeof(struct MacFrameBcast));
outBuffer[0] = sizeof(struct MacFrameBcast) + 11 + len + 1 + 2;
outBuffer[sizeof(struct MacFrameBcast) + 1] = PKT_TAG_RETURN_DATA;
memcpy(txframe->src, mSelfMac, 8);
txframe->fcs.frameType = 1;
txframe->fcs.ackReqd = 1;
txframe->fcs.destAddrType = 2;
txframe->fcs.srcAddrType = 3;
txframe->seq = seq++;
txframe->dstPan = PROTO_PAN_ID;
txframe->dstAddr = 0xFFFF;
txframe->srcPan = PROTO_PAN_ID;
memcpy(trd->data, data, len);
trd->dataType = type;
memcpy(&trd->dataVer, mSelfMac, 8);
memcpy(&trd->dataVer, data, 4);
addCRC(trd, 11 + len);
commsTxNoCpy(outBuffer);
}

bool sendTagReturnData(uint8_t __xdata *data, uint8_t len, uint8_t type) {
radioRxEnable(true, true);
uint32_t __xdata t;
for (uint8_t c = 0; c < MAX_RETURN_DATA_ATTEMPTS; c++) {
sendTagReturnDataPacket(data, len, type);
t = timerGet() + (TIMER_TICKS_PER_MS * DATA_REQ_RX_WINDOW_SIZE);
while (timerGet() < t) {
int8_t __xdata ret = commsRxUnencrypted(inBuffer);
if (ret > 1) {
if ((getPacketType(inBuffer) == PKT_TAG_RETURN_DATA_ACK) && (pktIsUnicast(inBuffer))) {
return true;
}
}
}
}
return false;
}
#endif

static bool processBlockPart(const struct blockPart *bp) {
uint16_t __xdata start = bp->blockPart * BLOCK_PART_DATA_SIZE;
uint16_t __xdata size = BLOCK_PART_DATA_SIZE;
Expand Down
Loading

0 comments on commit 4176252

Please sign in to comment.