fix coloredMsg
This commit is contained in:
parent
b3431fafa7
commit
c691620ff7
@ -5,7 +5,7 @@
|
||||
#include <spi.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define CONFIG_MAGIC 0xdead0003
|
||||
#define CONFIG_MAGIC 0xdead0004
|
||||
|
||||
typedef struct __attribute__((__packed__)) s_configBlock {
|
||||
uint32_t configMagic;
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
t_configBlock defaultConfigBlock = {
|
||||
.configMagic = CONFIG_MAGIC,
|
||||
.deviceName = "MBGW3",
|
||||
.macAddress = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0E },
|
||||
.deviceName = "MainsCnt",
|
||||
.macAddress = { 0x00, 0xA0, 0x57, 0x05, 0x3E, 0x0F },
|
||||
.filler = { 0 }
|
||||
};
|
||||
|
||||
@ -26,25 +26,25 @@ t_configBlock* getConfig() {
|
||||
|
||||
|
||||
void configInit() {
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci Reading configuration block from eeprom");
|
||||
coloredMsg(LOG_BLUE, "cfg ci Reading configuration block from eeprom");
|
||||
eepromReadConfigBlock(&mainConfigBlock);
|
||||
|
||||
if (mainConfigBlock.configMagic != CONFIG_MAGIC) {
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci Invalid configuration block read from eeprom");
|
||||
coloredMsg(LOG_BLUE, "cfg ci Invalid configuration block read from eeprom");
|
||||
|
||||
eepromWriteConfigBlock(&defaultConfigBlock);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci Default configuration block written to eeprom");
|
||||
coloredMsg(LOG_BLUE, "cfg ci Default configuration block written to eeprom");
|
||||
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci Reading configuration block from eeprom again");
|
||||
coloredMsg(LOG_BLUE, "cfg ci Reading configuration block from eeprom again");
|
||||
eepromReadConfigBlock(&mainConfigBlock);
|
||||
}
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci configMagic: %lx", mainConfigBlock.configMagic);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci deviceName: %s", mainConfigBlock.deviceName);
|
||||
coloredMsg(LOG_BLUE, false, "cfg ci MAC address: %02x:%02x:%02x:%02x:%02x:%02x", mainConfigBlock.macAddress[0],
|
||||
coloredMsg(LOG_BLUE, "cfg ci configMagic: %lx", mainConfigBlock.configMagic);
|
||||
coloredMsg(LOG_BLUE, "cfg ci deviceName: %s", mainConfigBlock.deviceName);
|
||||
coloredMsg(LOG_BLUE, "cfg ci MAC address: %02x:%02x:%02x:%02x:%02x:%02x", mainConfigBlock.macAddress[0],
|
||||
mainConfigBlock.macAddress[1],
|
||||
mainConfigBlock.macAddress[2],
|
||||
mainConfigBlock.macAddress[3],
|
||||
mainConfigBlock.macAddress[4],
|
||||
mainConfigBlock.macAddress[5]);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,6 @@ void logFree() {
|
||||
|
||||
#ifdef LOGGER_OUTPUT_BY_INTERRUPT
|
||||
void debugTxCpltCallback(UART_HandleTypeDef *huart) {
|
||||
int c = ringbufferGetOne(&logBuffer);
|
||||
if (c > 0) {
|
||||
singleOctetTXBuffer = (uint8_t) c;
|
||||
HAL_UART_Transmit_IT(&debugUart, &singleOctetTXBuffer, 1);
|
||||
|
@ -29,7 +29,7 @@ void my_errorHandler() {
|
||||
}
|
||||
|
||||
void second_tick(void *handle) {
|
||||
coloredMsg(LOG_BLUE, false, "Tick");
|
||||
coloredMsg(LOG_GREEN, "Tick");
|
||||
}
|
||||
|
||||
|
||||
@ -102,4 +102,4 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) {
|
||||
state = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,37 +69,37 @@ static void wizReset(bool b) {
|
||||
|
||||
|
||||
static void wizDHCPAssign() {
|
||||
coloredMsg(LOG_BLUE, false, "wizda");
|
||||
coloredMsg(LOG_BLUE, "wizda");
|
||||
getIPfromDHCP(netInfo.ip);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, IP: %d.%d.%d.%d", netInfo.ip[0], netInfo.ip[1], netInfo.ip[2], netInfo.ip[3]);
|
||||
coloredMsg(LOG_BLUE, "wizda, IP: %d.%d.%d.%d", netInfo.ip[0], netInfo.ip[1], netInfo.ip[2], netInfo.ip[3]);
|
||||
getGWfromDHCP(netInfo.gw);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, GW: %d.%d.%d.%d", netInfo.gw[0], netInfo.gw[1], netInfo.gw[2], netInfo.gw[3]);
|
||||
coloredMsg(LOG_BLUE, "wizda, GW: %d.%d.%d.%d", netInfo.gw[0], netInfo.gw[1], netInfo.gw[2], netInfo.gw[3]);
|
||||
getSNfromDHCP(netInfo.sn);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, SN: %d.%d.%d.%d", netInfo.sn[0], netInfo.sn[1], netInfo.sn[2], netInfo.sn[3]);
|
||||
coloredMsg(LOG_BLUE, "wizda, SN: %d.%d.%d.%d", netInfo.sn[0], netInfo.sn[1], netInfo.sn[2], netInfo.sn[3]);
|
||||
getDNSfromDHCP(netInfo.dns);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, DNS: %d.%d.%d.%d", netInfo.dns[0], netInfo.dns[1], netInfo.dns[2], netInfo.dns[3]);
|
||||
coloredMsg(LOG_BLUE, "wizda, DNS: %d.%d.%d.%d", netInfo.dns[0], netInfo.dns[1], netInfo.dns[2], netInfo.dns[3]);
|
||||
|
||||
wizchip_setnetinfo(&netInfo);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, set netinfo again");
|
||||
coloredMsg(LOG_BLUE, "wizda, set netinfo again");
|
||||
|
||||
networkAvailable = true;
|
||||
show(LED_GREEN, ON);
|
||||
coloredMsg(LOG_BLUE, false, "wizda, network is available");
|
||||
coloredMsg(LOG_BLUE, "wizda, network is available");
|
||||
}
|
||||
|
||||
static void wizDHCPUpdate() {
|
||||
coloredMsg(LOG_BLUE, false, "wizdu");
|
||||
coloredMsg(LOG_BLUE, "wizdu");
|
||||
getIPfromDHCP(netInfo.ip);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, IP: %d.%d.%d.%d", netInfo.ip[0], netInfo.ip[1], netInfo.ip[2], netInfo.ip[3]);
|
||||
coloredMsg(LOG_BLUE, "wizdu, IP: %d.%d.%d.%d", netInfo.ip[0], netInfo.ip[1], netInfo.ip[2], netInfo.ip[3]);
|
||||
getGWfromDHCP(netInfo.gw);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, GW: %d.%d.%d.%d", netInfo.gw[0], netInfo.gw[1], netInfo.gw[2], netInfo.gw[3]);
|
||||
coloredMsg(LOG_BLUE, "wizdu, GW: %d.%d.%d.%d", netInfo.gw[0], netInfo.gw[1], netInfo.gw[2], netInfo.gw[3]);
|
||||
getSNfromDHCP(netInfo.sn);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, SN: %d.%d.%d.%d", netInfo.sn[0], netInfo.sn[1], netInfo.sn[2], netInfo.sn[3]);
|
||||
coloredMsg(LOG_BLUE, "wizdu, SN: %d.%d.%d.%d", netInfo.sn[0], netInfo.sn[1], netInfo.sn[2], netInfo.sn[3]);
|
||||
getDNSfromDHCP(netInfo.dns);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, DNS: %d.%d.%d.%d", netInfo.dns[0], netInfo.dns[1], netInfo.dns[2], netInfo.dns[3]);
|
||||
coloredMsg(LOG_BLUE, "wizdu, DNS: %d.%d.%d.%d", netInfo.dns[0], netInfo.dns[1], netInfo.dns[2], netInfo.dns[3]);
|
||||
|
||||
wizchip_setnetinfo(&netInfo);
|
||||
coloredMsg(LOG_BLUE, false, "wizdu, netinfo updated");
|
||||
coloredMsg(LOG_BLUE, "wizdu, netinfo updated");
|
||||
}
|
||||
|
||||
static void wizDHCPHandler(void *handle) {
|
||||
@ -108,19 +108,19 @@ static void wizDHCPHandler(void *handle) {
|
||||
uint8_t res = DHCP_run();
|
||||
|
||||
if (lastDhcpRes != res) {
|
||||
coloredMsg(LOG_BLUE, false, "wizdh, dhcp state has changed: %d", res);
|
||||
coloredMsg(LOG_BLUE, "wizdh, dhcp state has changed: %d", res);
|
||||
lastDhcpRes = res;
|
||||
}
|
||||
}
|
||||
|
||||
bool wizDnsQuery(char *name, uint8_t *ip) {
|
||||
bool retCode = false;
|
||||
coloredMsg(LOG_BLUE, false, "wizdq, querying for %s", name);
|
||||
coloredMsg(LOG_BLUE, "wizdq, querying for %s", name);
|
||||
int8_t res = DNS_run(netInfo.dns, (uint8_t*) name, ip);
|
||||
coloredMsg(LOG_BLUE, false, "wizdq, DNS_run returns %d", res);
|
||||
coloredMsg(LOG_BLUE, "wizdq, DNS_run returns %d", res);
|
||||
retCode = (res == 1);
|
||||
if (retCode) {
|
||||
coloredMsg(LOG_BLUE, false, "wizdq, got address %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
||||
coloredMsg(LOG_BLUE, "wizdq, got address %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
||||
}
|
||||
return retCode;
|
||||
}
|
||||
@ -135,7 +135,7 @@ static void wizPhyLinkHandler(void *handle) {
|
||||
uint8_t phyLink = 0;
|
||||
int8_t res = ctlwizchip(CW_GET_PHYLINK, (void*) &phyLink);
|
||||
if (lastStablePhyLink != phyLink) {
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, ctlwizchip returns %d, phy link changed to %d", res, phyLink);
|
||||
coloredMsg(LOG_BLUE, "wizplh, ctlwizchip returns %d, phy link changed to %d", res, phyLink);
|
||||
lastStablePhyLink = phyLink;
|
||||
|
||||
if (phyLink == PHY_LINK_ON) {
|
||||
@ -143,25 +143,25 @@ static void wizPhyLinkHandler(void *handle) {
|
||||
memset(dhcpBuffer, 0, DHCP_BUFFER_SIZE);
|
||||
reg_dhcp_cbfunc(wizDHCPAssign, wizDHCPUpdate, NULL);
|
||||
DHCP_init(DHCP_SOCK, dhcpBuffer);
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, DHCP initialized");
|
||||
coloredMsg(LOG_BLUE, "wizplh, DHCP initialized");
|
||||
|
||||
// run the dhcp handler the first time after 1s and then every 100ms
|
||||
schAdd(wizDHCPHandler, NULL, 1000, 1000);
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, DHCP handler scheduled");
|
||||
coloredMsg(LOG_BLUE, "wizplh, DHCP handler scheduled");
|
||||
|
||||
dhcpInitialized = true;
|
||||
} else {
|
||||
networkAvailable = false;
|
||||
show(LED_GREEN, BLINK);
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, network is unavailable");
|
||||
coloredMsg(LOG_BLUE, "wizplh, network is unavailable");
|
||||
|
||||
// stop DHCP handler
|
||||
if (dhcpInitialized) {
|
||||
DHCP_stop();
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, DHCP stopped");
|
||||
coloredMsg(LOG_BLUE, "wizplh, DHCP stopped");
|
||||
|
||||
schDel(wizDHCPHandler, NULL);
|
||||
coloredMsg(LOG_BLUE, false, "wizplh, DHCP handler unscheduled");
|
||||
coloredMsg(LOG_BLUE, "wizplh, DHCP handler unscheduled");
|
||||
|
||||
dhcpInitialized = false;
|
||||
}
|
||||
@ -175,29 +175,29 @@ int wizInit() {
|
||||
netInfo.dhcp = NETINFO_DHCP;
|
||||
memcpy(netInfo.mac, config->macAddress, 6);
|
||||
|
||||
coloredMsg(LOG_BLUE, false, "wizI, resetting Ethernet module");
|
||||
coloredMsg(LOG_BLUE, "wizI, resetting Ethernet module");
|
||||
wizReset(true);
|
||||
activeDelay(2);
|
||||
wizReset(false);
|
||||
activeDelay(50);
|
||||
|
||||
coloredMsg(LOG_BLUE, false, "wizI, registering callbacks");
|
||||
coloredMsg(LOG_BLUE, "wizI, registering callbacks");
|
||||
reg_wizchip_cs_cbfunc(wiz_cs_select, wiz_cs_deselect);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, cs funcs registed");
|
||||
coloredMsg(LOG_BLUE, "wizI, cs funcs registed");
|
||||
reg_wizchip_spi_cbfunc(wiz_spi_readbyte, wiz_spi_writebyte);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, spi funcs registed");
|
||||
coloredMsg(LOG_BLUE, "wizI, spi funcs registed");
|
||||
reg_wizchip_spiburst_cbfunc(wiz_spi_readburst, wiz_spi_writeburst);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, spi burst funcs registed");
|
||||
coloredMsg(LOG_BLUE, "wizI, spi burst funcs registed");
|
||||
|
||||
|
||||
coloredMsg(LOG_BLUE, false, "wizI, initializing Ethernet module");
|
||||
coloredMsg(LOG_BLUE, "wizI, initializing Ethernet module");
|
||||
uint8_t bufSizes[] = { 2, 2, 2, 2, 2, 2, 2, 2 };
|
||||
int8_t res = wizchip_init(bufSizes, bufSizes);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, module driver returned %d", res);
|
||||
coloredMsg(LOG_BLUE, "wizI, module driver returned %d", res);
|
||||
|
||||
wizphy_reset();
|
||||
activeDelay(5);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, reset phy");
|
||||
coloredMsg(LOG_BLUE, "wizI, reset phy");
|
||||
|
||||
wiz_PhyConf wpc;
|
||||
wpc.mode = PHY_MODE_MANUAL;
|
||||
@ -205,22 +205,22 @@ int wizInit() {
|
||||
wpc.duplex = PHY_DUPLEX_FULL;
|
||||
wizphy_setphyconf(&wpc);
|
||||
activeDelay(5);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, phy config set");
|
||||
coloredMsg(LOG_BLUE, "wizI, phy config set");
|
||||
|
||||
wizchip_setnetinfo(&netInfo);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, netinfo set to Ethernet module");
|
||||
coloredMsg(LOG_BLUE, "wizI, netinfo set to Ethernet module");
|
||||
|
||||
res = wizchip_setnetmode(NM_FORCEARP); // and not NM_PINGBLOCK
|
||||
coloredMsg(LOG_BLUE, false, "wizI, set netmode, result is %d", res);
|
||||
coloredMsg(LOG_BLUE, "wizI, set netmode, result is %d", res);
|
||||
|
||||
uint8_t buf[6];
|
||||
res = ctlwizchip(CW_GET_ID, (void*) buf);
|
||||
coloredMsg(LOG_BLUE, false, "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_BLUE, "wizI, CW_GET_ID: %d %02x %02x %02x %02x %02x %02x", res, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
|
||||
|
||||
DNS_init(DNS_SOCK, dnsBuffer);
|
||||
|
||||
schAdd(wizPhyLinkHandler, NULL, 0, 1000);
|
||||
coloredMsg(LOG_BLUE, false, "wizI, PhyLink handler scheduled");
|
||||
coloredMsg(LOG_BLUE, "wizI, PhyLink handler scheduled");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user