refactor dhcp handling
This commit is contained in:
parent
60ad31bf5e
commit
6f4cc803be
@ -190,11 +190,11 @@ void my_setup_2() {
|
|||||||
|
|
||||||
wizInit();
|
wizInit();
|
||||||
|
|
||||||
frontendInit();
|
// frontendInit();
|
||||||
frontendSetThreshold(240);
|
// frontendSetThreshold(240);
|
||||||
|
|
||||||
schAdd(scheduleMBusRequest, NULL, 0, 1000);
|
// schAdd(scheduleMBusRequest, NULL, 0, 1000);
|
||||||
schAdd(triggerMBusRequest, NULL, 0, 100);
|
// schAdd(triggerMBusRequest, NULL, 0, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void my_loop() {
|
void my_loop() {
|
||||||
|
@ -78,39 +78,48 @@ static void wizDHCPUpdate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void wizDHCPHandler(void *handle) {
|
static void wizDHCPHandler(void *handle) {
|
||||||
static uint8_t lastStablePhyLink = 255;
|
coloredLog(LOG_RED, "wizdh");
|
||||||
|
|
||||||
static uint8_t lastDhcpRes = 255;
|
static uint8_t lastDhcpRes = 255;
|
||||||
static bool dhcpInitialized = false;
|
|
||||||
|
uint8_t res = DHCP_run();
|
||||||
|
|
||||||
|
if (lastDhcpRes != res) {
|
||||||
|
coloredMsg(LOG_RED, "wizdh, dhcp state has changed: %d", res);
|
||||||
|
lastDhcpRes = res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wizPhyLinkHandler(void *handle) {
|
||||||
|
static uint8_t lastStablePhyLink = 255;
|
||||||
|
|
||||||
uint8_t phyLink = 0;
|
uint8_t phyLink = 0;
|
||||||
int8_t res = ctlwizchip(CW_GET_PHYLINK, (void*) &phyLink);
|
int8_t res = ctlwizchip(CW_GET_PHYLINK, (void*) &phyLink);
|
||||||
if (lastStablePhyLink != phyLink) {
|
if (lastStablePhyLink != phyLink) {
|
||||||
coloredMsg(LOG_RED, "wizdh, ctlwizchip returns %d, phy link changed to %d", res, phyLink);
|
coloredMsg(LOG_RED, "wizplh, ctlwizchip returns %d, phy link changed to %d", res, phyLink);
|
||||||
lastStablePhyLink = phyLink;
|
lastStablePhyLink = phyLink;
|
||||||
wiz_PhyConf wpc;
|
|
||||||
wizphy_getphyconf(&wpc);
|
if (phyLink == PHY_LINK_ON) {
|
||||||
coloredMsg(LOG_RED, "wizdh, wpc: b:%02x, m:%02x, s:%02x, d:%02x",
|
// start DHCP handler
|
||||||
wpc.by, wpc.mode, wpc.speed, wpc.duplex);
|
|
||||||
|
|
||||||
} else if (phyLink == PHY_LINK_ON) {
|
|
||||||
if (! dhcpInitialized) {
|
|
||||||
memset(dhcpBuffer, 0, DHCP_BUFFER_SIZE);
|
memset(dhcpBuffer, 0, DHCP_BUFFER_SIZE);
|
||||||
reg_dhcp_cbfunc(wizDHCPAssign, wizDHCPUpdate, NULL);
|
reg_dhcp_cbfunc(wizDHCPAssign, wizDHCPUpdate, NULL);
|
||||||
DHCP_init(DHCP_SOCK, dhcpBuffer);
|
DHCP_init(DHCP_SOCK, dhcpBuffer);
|
||||||
coloredMsg(LOG_RED, "wizdh, DHCP initialized");
|
coloredMsg(LOG_RED, "wizplh, DHCP initialized");
|
||||||
dhcpInitialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t res = DHCP_run();
|
// run the dhcp handler the first time after 1s and then every 100ms
|
||||||
|
schAdd(wizDHCPHandler, NULL, 1000, 1000);
|
||||||
|
coloredMsg(LOG_RED, "wizplh, DHCP handler scheduled");
|
||||||
|
} else {
|
||||||
|
// stop DHCP handler
|
||||||
|
DHCP_stop();
|
||||||
|
coloredMsg(LOG_RED, "wizplh, DHCP stopped");
|
||||||
|
|
||||||
if (lastDhcpRes != res) {
|
schDel(wizDHCPHandler, NULL);
|
||||||
coloredMsg(LOG_RED, "wizdh, dhcp state has changed: %d", res);
|
coloredMsg(LOG_RED, "wizplh, DHCP handler unscheduled");
|
||||||
lastDhcpRes = res;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int wizInit() {
|
int wizInit() {
|
||||||
coloredMsg(LOG_RED, "wizI, resetting Ethernet module");
|
coloredMsg(LOG_RED, "wizI, resetting Ethernet module");
|
||||||
wizReset(true);
|
wizReset(true);
|
||||||
@ -155,8 +164,8 @@ int wizInit() {
|
|||||||
coloredMsg(LOG_RED, "wizI, CW_GET_ID: %d %02x %02x %02x %02x %02x %02x", res, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
|
coloredMsg(LOG_RED, "wizI, CW_GET_ID: %d %02x %02x %02x %02x %02x %02x", res, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
|
||||||
|
|
||||||
|
|
||||||
schAdd(wizDHCPHandler, NULL, 0, 1000);
|
schAdd(wizPhyLinkHandler, NULL, 0, 1000);
|
||||||
coloredMsg(LOG_RED, "wizI, DHCP handler scheduled");
|
coloredMsg(LOG_RED, "wizI, PhyLink handler scheduled");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user