mirror of
https://github.com/OpenEPaperLink/OpenEPaperLink.git
synced 2026-03-21 06:06:23 +01:00
moved some stuff, scanning zigbee channels
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#define __packed
|
||||
#include "syncedproto.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#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)) {
|
||||
|
||||
@@ -4,10 +4,13 @@
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user