do firmwaru jsem se rozhodl implementovat načtení IP adres atp z SD karty. Ale veznu popořadě.
Kód: Vybrať všetko
FLAG ReadConfigFileFromSD(char **_ip_address, char **_ip_mask, char **_ip_gateway,
char **_ip_sntp, char **_ip_modbus, int32_t *_port_modbus) {
FIL file;
FRESULT fresult;
char SD_Buffer[16*1024];
volatile uint32_t NumberLines;
int32_t temp_val;
//
InfoPrint("opening SDCARD file -> /code/ip.conf ...");
// try to open - read only
fresult = f_open((FIL*) &file, (char*) "0:/code/ip.config", FA_READ);
// open and valid ?
if (FR_OK != fresult) {
ErrPrint("FILE NOT FOUND on sd-card -> FAIL");
return FALSE;
}
/* Read the file */
fresult = f_read((FIL*) &file, SD_Buffer, sizeof SD_Buffer, NULL);
/* Close file */
fresult = f_close((FIL*) &file);
/* split buffer for lines */
char** arr = strsplit(SD_Buffer, "\n");
for (uint32_t i = 0; SD_Buffer[i] != '\0'; ++i) {
if ('\n' == SD_Buffer[i])
++NumberLines;
}
for(uint8_t i=0; i <= NumberLines; i++)
{
if (strstr(arr[i], "IP_ADDR") != NULL) {
char **temp = strsplit(arr[i], " ");
//InfoPrint("IP ADRESA: %s", temp[1]);
*_ip_address = temp[1];
free(temp);
}
if (strstr(arr[i], "IP_MASK") != NULL) {
char **temp = strsplit(arr[i], " ");
//InfoPrint("IP MASK: %s", temp[1]);
*_ip_mask = temp[1];
free(temp);
}
if (strstr(arr[i], "IP_GTW") != NULL) {
char **temp = strsplit(arr[i], " ");
//InfoPrint("IP GATEWAY: %s", temp[1]);
*_ip_gateway = temp[1];
free(temp);
}
if (strstr(arr[i], "IP_SNTP") != NULL) {
char **temp = strsplit(arr[i], " ");
//InfoPrint("IP SNTP: %s", temp[1]);
*_ip_sntp = temp[1];
free(temp);
}
if (strstr(arr[i], "IP_MODBUS") != NULL) {
char **temp = strsplit(arr[i], " ");
//InfoPrint("IP MODBUS: %s", temp[1]);
*_ip_modbus = temp[1];
free(temp);
}
if (strstr(arr[i], "PORT_MODBUS") != NULL) {
char **temp = strsplit(arr[i], " ");
//InfoPrint("PORT MODBUS: %s", temp[1]);
temp_val = atoi(temp[1]);
*_port_modbus = temp_val;
free(temp);
}
}
//InfoPrint("%s", ip_address_str[ip_adrr]);
free(arr);
return TRUE;
}
Kód: Vybrať všetko
strsplit
Kód: Vybrať všetko
void vCoreTask(void *pvParameters) {
char *ip_address, *ip_mask, *ip_gateway, *ip_sntp, *ip_modbus, *ip_syslog, *ip_influx;
int32_t port_modbus;
ip_address = (char*)malloc(18*sizeof(char));
ip_mask = (char*)malloc(18*sizeof(char));
ip_gateway = (char*)malloc(18*sizeof(char));
ip_sntp = (char*)malloc(18*sizeof(char));
ip_modbus = (char*)malloc(18*sizeof(char));
if (ReadConfigFileFromSD(&ip_address, &ip_mask, &ip_gateway, &ip_sntp,
&ip_modbus, &port_modbus, &ip_syslog, &port_syslog, &ip_influx,
&port_influx, &port_azimuth) == TRUE)
{
InfoPrint("read IP addresses from memory: OK");
}
else
{
ErrPrint("read IP addresses from memory: FAIL");
}
InfoPrint("IP: %s", ip_address);
InfoPrint("MASK: %s", ip_mask);
InfoPrint("GTW: %s", ip_gateway);
InfoPrint("SNTP: %s", ip_sntp);
InfoPrint("MOD: %s", ip_modbus);
InfoPrint("PMOD: %d", port_modbus);
while(1)
{}
}
- IP: "10.1.1.7"
MASK: _PORT
GTW: PORT
SNTP: ORT
MOD: T
PMOD: 502
Kód: Vybrať všetko
# Nastaveni IP adresy desky
IP_BOARD "10.1.1.7"
IP_BOARD "255.255.255.0"
IP_GTW "10.1.1.2"
# Nastaveni IP adresy ntp serveru
IP_SNTP "10.1.1.106"
# Nastaveni IP adresy a portu pro MODbus
IP_MODBUS "10.1.1.30"
PORT_MODBUS 502