diff --git a/tag_fw/comms.c b/tag_fw/comms.c index 4bb915f1..10c6557c 100644 --- a/tag_fw/comms.c +++ b/tag_fw/comms.c @@ -21,8 +21,8 @@ static uint8_t __xdata mCommsBuf[127]; static uint8_t __xdata mSeq = 0; -static uint8_t __xdata mLastLqi = 0; -static int8_t __xdata mLastRSSI = 0; +uint8_t __xdata mLastLqi = 0; +int8_t __xdata mLastRSSI = 0; uint8_t commsGetLastPacketLQI(void) { diff --git a/tag_fw/comms.h b/tag_fw/comms.h index 1753c45a..c80f0113 100644 --- a/tag_fw/comms.h +++ b/tag_fw/comms.h @@ -11,11 +11,8 @@ #define COMMS_MAX_PACKET_SZ (127) -#pragma callee_saves commsGetLastPacketLQI -uint8_t commsGetLastPacketLQI(void); - -#pragma callee_saves commsGetLastPacketRSSI -int8_t commsGetLastPacketRSSI(void); +extern uint8_t __xdata mLastLqi; +extern int8_t __xdata mLastRSSI; int8_t commsRxUnencrypted(void __xdata *data); bool commsTxUnencrypted(const void __xdata *packetP, uint8_t len); diff --git a/tag_fw/main.c b/tag_fw/main.c index eaf257b1..b17711d3 100644 --- a/tag_fw/main.c +++ b/tag_fw/main.c @@ -7,17 +7,16 @@ #include "asmUtil.h" #include "eeprom.h" +#include "epd.h" +#include "powermgt.h" #include "printf.h" #include "proto.h" #include "radio.h" +#include "comms.h" // for mLastLqi and mLastRSSI #include "syncedproto.h" #include "timer.h" -#include "wdt.h" -#include "powermgt.h" - #include "userinterface.h" -#include "epd.h" - +#include "wdt.h" void mainProtocolLoop(void) { clockingAndIntsInit(); @@ -55,7 +54,7 @@ void mainProtocolLoop(void) { initializeProto(); } - // initialize attempt-array with the default value; + // initialize Powers-saving-attempt-array with the default value; initPowerSaving(); // show the splashscreen @@ -65,6 +64,14 @@ void mainProtocolLoop(void) { eepromDeepPowerDown(); initRadio(); + for (uint8_t c = 25; c > 10; c--) { + if (probeChannel(c)) { + pr("Channel: %d - LQI: %d RSSI %d\n", c, mLastLqi, mLastRSSI); + } else { + pr("Channel %d - nothing.\n", c); + } + } + P1CHSTA &= ~(1 << 0); while (1) { diff --git a/tag_fw/powermgt.c b/tag_fw/powermgt.c index 37be9fd8..df441448 100644 --- a/tag_fw/powermgt.c +++ b/tag_fw/powermgt.c @@ -37,23 +37,6 @@ void initPowerSaving() { } // init/sleep -void initRadio() { - radioInit(); - radioRxFilterCfg(mSelfMac, 0x10000, PROTO_PAN_ID); - radioSetChannel(RADIO_FIRST_CHANNEL); - radioSetTxPower(10); -} -void killRadio() { - radioRxEnable(false, true); - RADIO_IRQ4_pending = 0; - UNK_C1 &= ~0x81; - TCON &= ~0x20; - uint8_t __xdata cfgPg = CFGPAGE; - CFGPAGE = 4; - RADIO_command = 0xCA; - RADIO_command = 0xC5; - CFGPAGE = cfgPg; -} void initAfterWake() { clockingAndIntsInit(); timerInit(); @@ -106,10 +89,4 @@ uint16_t getNextSleep() { if (noNetwork == true) return INTERVAL_NO_SIGNAL; avg /= POWER_SAVING_SMOOTHING; return avg; -} - -void initRadio(); -void killRadio(); -void initAfterWake(); -void doSleep(uint32_t __xdata t); -uint16_t getNextSleep(); +} \ No newline at end of file diff --git a/tag_fw/powermgt.h b/tag_fw/powermgt.h index 6135d00d..7f641671 100644 --- a/tag_fw/powermgt.h +++ b/tag_fw/powermgt.h @@ -13,8 +13,6 @@ #define POWER_SAVING_SMOOTHING 8 // How many samples we should use to smooth the data request interval #define MINIMUM_INTERVAL 45 // IMPORTANT: Minimum interval for check-in; this determines overal battery life! -extern void initRadio(); -extern void killRadio(); extern void initAfterWake(); extern void doSleep(uint32_t __xdata t); extern uint16_t getNextSleep(); diff --git a/tag_fw/soc/radioCommon.h b/tag_fw/soc/radioCommon.h index 9c931a86..99937234 100644 --- a/tag_fw/soc/radioCommon.h +++ b/tag_fw/soc/radioCommon.h @@ -7,7 +7,7 @@ //radio cfg #define RADIO_FIRST_CHANNEL (11) //2.4-GHz channels start at 11 -#define RADIO_NUM_CHANNELS (1) +#define RADIO_NUM_CHANNELS (15) #define RADIO_MAX_PACKET_LEN (125) //useful payload, not including the crc diff --git a/tag_fw/syncedproto.c b/tag_fw/syncedproto.c index 6a3b6900..f0aa3d85 100644 --- a/tag_fw/syncedproto.c +++ b/tag_fw/syncedproto.c @@ -1,11 +1,14 @@ #define __packed #include "syncedproto.h" + #include #include #include #include #include + #include "asmUtil.h" +#include "comms.h" #include "cpu.h" #include "drawing.h" #include "eeprom.h" @@ -13,14 +16,12 @@ #include "powermgt.h" #include "printf.h" #include "proto.h" -#include "comms.h" #include "radio.h" +#include "settings.h" #include "sleep.h" #include "timer.h" #include "userinterface.h" #include "wdt.h" -#include "powermgt.h" -#include "settings.h" // download-stuff bool __xdata dataPending = true; @@ -48,6 +49,7 @@ uint8_t __xdata APmac[8] = {0}; uint16_t __xdata APsrcPan = 0; uint8_t __xdata mSelfMac[8] = {0}; uint8_t __xdata seq = 0; +uint8_t __xdata currentChannel = 0; // buffer we use to prepare/read packets // static uint8_t __xdata mRxBuf[130]; @@ -106,6 +108,38 @@ void addCRC(void *p, uint8_t len) { ((uint8_t *)p)[0] = total; } +// radio stuff +void initRadio() { + radioInit(); + radioRxFilterCfg(mSelfMac, 0x10000, PROTO_PAN_ID); + if (currentChannel >= 11 && currentChannel <= 25) { + radioSetChannel(currentChannel); + } else { + radioSetChannel(RADIO_FIRST_CHANNEL); + } + radioSetTxPower(10); +} +void killRadio() { + radioRxEnable(false, true); + RADIO_IRQ4_pending = 0; + UNK_C1 &= ~0x81; + TCON &= ~0x20; + uint8_t __xdata cfgPg = CFGPAGE; + CFGPAGE = 4; + RADIO_command = 0xCA; + RADIO_command = 0xC5; + CFGPAGE = cfgPg; +} +bool probeChannel(uint8_t channel) { + radioRxEnable(false, true); + radioRxFlush(); + radioSetChannel(channel); + radioRxEnable(true, true); + getAvailDataInfo(); + return(dataReqLastAttempt != DATA_REQ_MAX_ATTEMPTS); + +} + // data xfer stuff void sendAvailDataReq() { struct MacFrameBcast __xdata *txframe = (struct MacFrameBcast *)(outBuffer + 1); @@ -121,7 +155,7 @@ void sendAvailDataReq() { txframe->seq = seq++; txframe->dstPan = 0xFFFF; txframe->dstAddr = 0xFFFF; - txframe->srcPan = 0x4447; + txframe->srcPan = PROTO_PAN_ID; // TODO: send some meaningful data availreq->softVer = 1; if (P1CHSTA && (1 << 0)) { diff --git a/tag_fw/syncedproto.h b/tag_fw/syncedproto.h index dc0278df..0093d02f 100644 --- a/tag_fw/syncedproto.h +++ b/tag_fw/syncedproto.h @@ -4,10 +4,13 @@ #include +extern void initRadio(); +extern void killRadio(); + extern uint8_t __xdata mSelfMac[]; extern struct AvailDataInfo *__xdata getAvailDataInfo(); extern bool doDataDownload(struct AvailDataInfo *__xdata avail); extern void initializeProto(); - - +extern struct AvailDataInfo *__xdata getAvailDataInfo(); +bool probeChannel(uint8_t channel); #endif \ No newline at end of file