diff --git a/binaries/AP_FW_1.54.bin b/binaries/AP_FW_1.54.bin index e3fc9405..d9dec2b6 100644 Binary files a/binaries/AP_FW_1.54.bin and b/binaries/AP_FW_1.54.bin differ diff --git a/binaries/AP_FW_Nodisplay.bin b/binaries/AP_FW_Nodisplay.bin index 9001e059..754c2993 100644 Binary files a/binaries/AP_FW_Nodisplay.bin and b/binaries/AP_FW_Nodisplay.bin differ diff --git a/binaries/AP_FW_Segmented_UK.bin b/binaries/AP_FW_Segmented_UK.bin index ee612e7b..3787fea3 100644 Binary files a/binaries/AP_FW_Segmented_UK.bin and b/binaries/AP_FW_Segmented_UK.bin differ diff --git a/binaries/Tag_FW_1.54.bin b/binaries/Tag_FW_1.54.bin index 58548752..501217f7 100644 Binary files a/binaries/Tag_FW_1.54.bin and b/binaries/Tag_FW_1.54.bin differ diff --git a/binaries/Tag_FW_2.9-uc8151.bin b/binaries/Tag_FW_2.9-uc8151.bin index e26a025a..65fd755f 100644 Binary files a/binaries/Tag_FW_2.9-uc8151.bin and b/binaries/Tag_FW_2.9-uc8151.bin differ diff --git a/binaries/Tag_FW_2.9.bin b/binaries/Tag_FW_2.9.bin index 58adde62..721ac750 100644 Binary files a/binaries/Tag_FW_2.9.bin and b/binaries/Tag_FW_2.9.bin differ diff --git a/binaries/Tag_FW_4.2.bin b/binaries/Tag_FW_4.2.bin index 84616106..1201bce6 100644 Binary files a/binaries/Tag_FW_4.2.bin and b/binaries/Tag_FW_4.2.bin differ diff --git a/zbs243_AP_FW/emulateTag.c b/zbs243_AP_FW/emulateTag.c index 4c8d2bd7..00e163e4 100755 --- a/zbs243_AP_FW/emulateTag.c +++ b/zbs243_AP_FW/emulateTag.c @@ -19,11 +19,13 @@ #include "uart.h" #include "wdt.h" -extern uint8_t __xdata fakeTagMac[8] = {0x0, 0x00, 0x55, 0xCE, 0xAC, 0x00, 0x00}; +uint8_t __xdata fakeTagMac[8] = {0x0, 0x00, 0x55, 0xCE, 0xAC, 0x00, 0x00}; + extern uint8_t __xdata radiorxbuffer[]; extern uint8_t __xdata blockbuffer[]; + extern void espNotifyAvailDataReq(const struct AvailDataReq *adr, const uint8_t *src); -extern void espBlockRequest(const struct blockRequest *br); +extern void espBlockRequest(const struct blockRequest *br, uint8_t *src); extern void espNotifyXferComplete(const uint8_t *src); extern void addCRC(void *p, uint8_t len); @@ -64,7 +66,7 @@ void fakeTagGetData() { struct blockRequest br; br.blockId = blockCount; br.ver = ad.dataVer; - espBlockRequest(&br); + espBlockRequest(&br, fakeTagMac); dataRequested = true; } } else { diff --git a/zbs243_AP_FW/main.c b/zbs243_AP_FW/main.c index e0d0fc5f..7e2878f9 100755 --- a/zbs243_AP_FW/main.c +++ b/zbs243_AP_FW/main.c @@ -47,6 +47,12 @@ struct espAvailDataReq { struct AvailDataReq adr; } __packed; +struct espSetChannelPower { + uint8_t checksum; + uint8_t channel; + uint8_t power; +} __packed; + // #define TIMER_TICKS_PER_MS 1333UL uint16_t __xdata version = 0x0012; @@ -196,6 +202,14 @@ void deleteAllPendingDataForVer(const uint8_t *ver) { if (slot != -1) pendingDataArr[slot].attemptsLeft = 0; } while (slot != -1); } +void deleteAllPendingDataForMac(const uint8_t *mac) { + int8_t slot = -1; + do { + slot = findSlotForMac(mac); + if (slot != -1) pendingDataArr[slot].attemptsLeft = 0; + } while (slot != -1); +} + void countSlots() { curPendingData = 0; curNoUpdate = 0; @@ -212,8 +226,9 @@ void countSlots() { // processing serial data #define ZBS_RX_WAIT_HEADER 0 -#define ZBS_RX_WAIT_SDA 1 -#define ZBS_RX_WAIT_CANCEL 2 +#define ZBS_RX_WAIT_SDA 1 // send data avail +#define ZBS_RX_WAIT_CANCEL 2 // cancel traffic for mac +#define ZBS_RX_WAIT_SCP 3 // set channel power extern uint8_t *__idata blockp; void processSerial(uint8_t lastchar) { @@ -251,6 +266,12 @@ void processSerial(uint8_t lastchar) { serialbufferp = serialbuffer; break; } + if (strncmp(cmdbuffer, "SCP>", 4) == 0) { + RXState = ZBS_RX_WAIT_SCP; + bytesRemain = sizeof(struct espSetChannelPower); + serialbufferp = serialbuffer; + break; + } if (strncmp(cmdbuffer, "VER?", 4) == 0) { pr("VER>%04X\n", version); } @@ -260,6 +281,7 @@ void processSerial(uint8_t lastchar) { if (strncmp(cmdbuffer, "RSET", 4) == 0) { wdtDeviceReset(); } + break; case ZBS_RX_WAIT_SDA: @@ -306,7 +328,8 @@ void processSerial(uint8_t lastchar) { pr("ACK>\n"); } else { #endif - deleteAllPendingDataForVer((uint8_t *)&pd->availdatainfo.dataVer); + // deleteAllPendingDataForVer((uint8_t *)&pd->availdatainfo.dataVer); + deleteAllPendingDataForMac((uint8_t *)&pd->targetMac); pr("ACK>\n"); #if (AP_EMULATE_TAG == 1) } @@ -318,11 +341,35 @@ void processSerial(uint8_t lastchar) { RXState = ZBS_RX_WAIT_HEADER; } break; + case ZBS_RX_WAIT_SCP: + *serialbufferp = lastchar; + serialbufferp++; + bytesRemain--; + if (bytesRemain == 0) { + if (checkCRC(serialbuffer, sizeof(struct espSetChannelPower))) { + struct espSetChannelPower *scp = (struct espSetChannelPower *)serialbuffer; + for (uint8_t c = 0; c < sizeof(channelList); c++) { + if (channelList[c] == scp->channel) goto SCPchannelFound; + } + goto SCPfailed; + SCPchannelFound: + curChannel = scp->channel; + radioSetChannel(scp->channel); + radioSetTxPower(scp->power); + radioRxEnable(true, true); + pr("ACK>\n"); + } else { + SCPfailed: + pr("NOK>\n"); + } + RXState = ZBS_RX_WAIT_HEADER; + } + break; } } // sending data to the ESP -void espBlockRequest(const struct blockRequest *br, uint8_t* src) { +void espBlockRequest(const struct blockRequest *br, uint8_t *src) { struct espBlockRequest *__xdata ebr = (struct espBlockRequest *)blockbuffer; uartTx('R'); uartTx('Q'); @@ -609,7 +656,8 @@ void sendPong(void *__xdata buf) { struct MacFrameBcast *rxframe = (struct MacFrameBcast *)buf; struct MacFrameNormal *frameHeader = (struct MacFrameNormal *)(radiotxbuffer + 1); radiotxbuffer[sizeof(struct MacFrameNormal) + 1] = PKT_PONG; - radiotxbuffer[0] = sizeof(struct MacFrameNormal) + 1 + RAW_PKT_PADDING; + radiotxbuffer[sizeof(struct MacFrameNormal) + 2] = curChannel; + radiotxbuffer[0] = sizeof(struct MacFrameNormal) + 1 + 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 @@ -663,6 +711,10 @@ void main(void) { } } +#if (AP_EMULATE_TAG == 1) + xMemCopy8(fakeTagMac, mSelfMac); // +#endif + // clear the array with pending information memset(pendingDataArr, 0, sizeof(pendingDataArr)); diff --git a/zbs243_Tag_FW/syncedproto.c b/zbs243_Tag_FW/syncedproto.c index b8056096..a85e847d 100755 --- a/zbs243_Tag_FW/syncedproto.c +++ b/zbs243_Tag_FW/syncedproto.c @@ -142,7 +142,8 @@ uint8_t detectAP(const uint8_t channel) { while (timerGet() < t) { int8_t __xdata ret = commsRxUnencrypted(inBuffer); if (ret > 1) { - if (getPacketType(inBuffer) == PKT_PONG) { + // dump(inBuffer+sizeof(struct MacFrameNormal),32); + if ((inBuffer[sizeof(struct MacFrameNormal) + 1] == channel) && (getPacketType(inBuffer) == PKT_PONG)) { if (pktIsUnicast(inBuffer)) { struct MacFrameNormal *__xdata f = (struct MacFrameNormal *)inBuffer; memcpy(APmac, f->src, 8); @@ -610,7 +611,6 @@ static bool downloadFWUpdate(const struct AvailDataInfo *__xdata avail) { uint16_t __xdata imageSize = 0; static bool downloadImageDataToEEPROM(const struct AvailDataInfo *__xdata avail) { - // check if we already started the transfer of this information & haven't completed it if (xMemEqual((const void *__xdata) & avail->dataVer, (const void *__xdata) & curDataInfo.dataVer, 8) && curDataInfo.dataSize) { // looks like we did. We'll carry on where we left off.