static int handle_argument(const char *var, const char *val, struct cmdarg *cmdargs) { // compare var against array of recognized arguments for(int i = 0; cmdargs[i].arg != NULL; i++) { struct cmdarg *a = &cmdargs[i]; if(!strncmp(var, a->arg, strlen(a->arg))) { switch(a->type) { case ArgType_Int: return handle_int(a->var.integer, val); case ArgType_UInt: return handle_uint(a->var.uinteger, val); case ArgType_Bool: return handle_bool(a->var.boolean, val); case ArgType_Custom: return a->var.handler(var, val); default: assert(!"Unknown type %d in kernel argument array!"); return -1; } } } return 0; }
void config_load (const char *cfg_name) { FILE *cfg = fopen (cfg_name, "rt"); char buffer [4096], var [4096], *val; cfg_var *cv; if (!cfg) { perror (cfg_name); return; } while (fgets (buffer, 4096, cfg)) { // Kill comments char *split = strrchr (buffer, '#'); char *cp1 = var, *cp2 = buffer; if (split) *split = '\0'; // remove trailing newline split = strrchr (buffer, '\n'); if (split) *split = '\0'; // Skip leading white space ... cp2 = skip_ws (cp2); // Silently ignore empty lines. if (!*cp2) continue; // search for '=' val = strchr (cp2, '='); if (!val) { fprintf (stderr, "%s: ignoring bad config line starting \"%s\" (missing '='!)\n", cfg_name, buffer); continue; } *val++ = '\0'; // front part basically must be a variable name. // To keep it simple we ignore *all* white space here - even if inside the variable name. while (*cp2) { if (!isspace (*cp2)) *cp1++ = toupper (*cp2); *cp2++; } *cp1 = '\0'; // remove leading and trailing white space off val val = skip_ws (val); if (!*val) { fprintf (stderr, "%s: ignoring bad config line starting \"%s\" (missing value!)\n", cfg_name, buffer); continue; } cp2 = strchr (val, '\0') - 1; while (cp2 > val && isspace (*cp2)) cp2--; cp2 [1] = '\0'; // search the variable for (cv = config; cv->name; cv++) if (strcmp (cv->name, var) == 0) break; if (!cv->name) fprintf (stderr, "%s: ignoring bad config line starting \"%s\" (variable '%s' unknown!)\n", cfg_name, buffer, var); else switch (cv->type) { case NUM: handle_num (var, cv->v_ptr, val); break; case BOOL: handle_bool (var, cv->v_ptr, val); break; case STRING: handle_string (var, cv->v_ptr, val); break; case N_ARRAY: handle_array (var, cv->v_ptr, cv->n_ptr, val); break; } } fclose (cfg); }
void notmain(void) { hardware_init(); ltc_reader_params_init(); output.console_output = ltc_reader_params_is_console_output(); output.lcd_output = ltc_reader_params_is_lcd_output(); output.midi_output = ltc_reader_params_is_midi_output(); output.artnet_output = ltc_reader_params_is_artnet_output(); if(output.midi_output) { midi_send_init(); } if (output.lcd_output) { output.lcd_output = lcd_detect(); } if (output.artnet_output) { output.artnet_output = wifi_detect(); } ltc_reader_init(&output); printf("[V%s] %s Compiled on %s at %s\n", SOFTWARE_VERSION, hardware_board_get_model(), __DATE__, __TIME__); printf("SMPTE TimeCode LTC Reader / Converter"); console_set_top_row(3); console_set_cursor(0, 12); console_puts("Console output : "); handle_bool(output.console_output); console_putc('\n'); console_puts("LCD output : "); handle_bool(output.lcd_output); console_putc('\n'); console_puts("MIDI output : "); handle_bool(output.midi_output); console_putc('\n'); console_puts("ArtNet output : "); handle_bool(output.artnet_output);console_puts(" (not implemented)\n"); if (output.artnet_output) { uint8_t mac_address[6]; struct ip_info ip_config; (void) ap_params_init(); const char *ap_password = ap_params_get_password(); console_status(CONSOLE_YELLOW, "Starting Wifi ..."); wifi_init(ap_password); printf("\nESP8266 information\n"); printf(" SDK : %s\n", system_get_sdk_version()); printf(" Firmware : %s\n\n", wifi_get_firmware_version()); if (network_params_init()) { console_status(CONSOLE_YELLOW, "Changing to Station mode ..."); if (network_params_is_use_dhcp()) { wifi_station(network_params_get_ssid(), network_params_get_password()); } else { ip_config.ip.addr = network_params_get_ip_address(); ip_config.netmask.addr = network_params_get_net_mask(); ip_config.gw.addr = network_params_get_default_gateway(); wifi_station_ip(network_params_get_ssid(), network_params_get_password(), &ip_config); } } const _wifi_mode opmode = wifi_get_opmode(); if (opmode == WIFI_STA) { printf("WiFi mode : Station\n"); } else { printf("WiFi mode : Access Point (authenticate mode : %s)\n", *ap_password == '\0' ? "Open" : "WPA_WPA2_PSK"); } if (wifi_get_macaddr(mac_address)) { printf(" MAC address : "MACSTR "\n", MAC2STR(mac_address)); } else { console_error("wifi_get_macaddr"); } printf(" Hostname : %s\n", wifi_station_get_hostname()); if (wifi_get_ip_info(&ip_config)) { printf(" IP-address : " IPSTR "\n", IP2STR(ip_config.ip.addr)); printf(" Netmask : " IPSTR "\n", IP2STR(ip_config.netmask.addr)); printf(" Gateway : " IPSTR "\n", IP2STR(ip_config.gw.addr)); if (opmode == WIFI_STA) { const _wifi_station_status status = wifi_station_get_connect_status(); printf(" Status : %s\n", wifi_station_status(status)); if (status != WIFI_STATION_GOT_IP){ console_error("Not connected!"); for(;;); } } } else { console_error("wifi_get_ip_info"); } console_status(CONSOLE_YELLOW, "Starting UDP ..."); udp_begin(6454); console_status(CONSOLE_GREEN, "Wifi is started"); } for (;;) { ltc_reader(); } }