/*! * \brief Load configuration from EEPROM. * * If no configuration is available, some preconfigured stations * are loaded. * * \return 0 on success, -1 if no configuration data had been found. */ int ConfigLoad(void) { int rc = -1; int addr = CONFAPP_EE_OFFSET; char *buf; uint8_t idx; RADIOSTATION *rsp; buf = malloc(MAXLEN_URL + 1); addr += ConfigLoadString(addr, buf, sizeof(CONFAPP_EE_NAME)); if (strcmp(buf, CONFAPP_EE_NAME) == 0) { ConfigCreate(); rc = 0; /* * Read radio settings from EEPROM. */ addr += ConfigLoadBinary(addr, &radio.rc_rstation, sizeof(radio.rc_rstation)); addr += ConfigLoadBinary(addr, &radio.rc_rvolume, sizeof(radio.rc_rvolume)); /* * Read station configuration from EEPROM. */ for (idx = 0; idx < MAXNUM_STATIONS; idx++) { rsp = &station[idx]; addr += ConfigLoadBinary(addr, &rsp->rs_port, sizeof(rsp->rs_port)); addr += ConfigLoadBinary(addr, &rsp->rs_ip, sizeof(rsp->rs_ip)); addr += ConfigLoadString(addr, buf, MAXLEN_URL); if (*buf) { rsp->rs_url = malloc(strlen(buf) + 1); strcpy(rsp->rs_url, buf); } } } free(buf); return rc; }
int main(int argc, char *argv[]) { Cs2ethStruct *Cs2eth; ConfigStruct *Config; pid_t ChildPid; time_t Now; int Ret, NumArgs; char **ValArgs; Config = ConfigCreate(); if (Config != (ConfigStruct *)NULL) { NumArgs = argc; ValArgs = argv; ConfigInit(Config, MRSYSTEM_CONFIG_FILE); ConfigReadfile(Config); #ifdef TRACE ConfigCmdLine(Config, "a:b:p:ftv?", NumArgs, ValArgs); #else ConfigCmdLine(Config, "a:b:p:fv?", NumArgs, ValArgs); #endif if (ConfigGetIntVal(Config, CfgUsageVal)) { usage(argv[0]); Ret = 1; } else if (ConfigGetIntVal(Config, CfgForkVal)) { ChildPid = fork(); if (ChildPid == -1) { if (ConfigGetIntVal(Config, CfgVerboseVal)) puts("ERROR: can not go to backgound"); ConfigExit(Config); ConfigDestroy(Config); Ret = 4; } else if (ChildPid == 0) { if (ConfigGetIntVal(Config, CfgVerboseVal)) puts("child running"); Cs2eth = Cs2ethCreate(); if (Cs2eth != (Cs2ethStruct *)NULL) { Cs2ethInit(Cs2eth, ConfigGetIntVal(Config, CfgVerboseVal), ConfigGetStrVal(Config, CfgIfaceVal), ConfigGetStrVal(Config, CfgAddrVal), ConfigGetIntVal(Config, CfgPortVal), ConfigGetIntVal(Config, CfgBcVal), ConfigGetStrVal(Config, CfgUdpBcVal) #ifdef TRACE , ConfigGetIntVal(Config, CfgTraceVal) #endif ); Cs2ethRun(Cs2eth); Cs2ethDestroy(Cs2eth); Ret = 0; } else { Ret = 2; } } else { if (ConfigGetIntVal(Config, CfgVerboseVal)) puts("parent terminates"); signal(SIGCHLD, SIG_IGN); Ret = 0; } } else { Now = time(NULL); if (ConfigGetIntVal(Config, CfgVerboseVal)) printf("start with no fork at %s\n", asctime(localtime(&Now))); Cs2eth = Cs2ethCreate(); if (Cs2eth != (Cs2ethStruct *)NULL) { Cs2ethInit(Cs2eth, ConfigGetIntVal(Config, CfgVerboseVal), ConfigGetStrVal(Config, CfgIfaceVal), ConfigGetStrVal(Config, CfgAddrVal), ConfigGetIntVal(Config, CfgPortVal), ConfigGetIntVal(Config, CfgBcVal), ConfigGetStrVal(Config, CfgUdpBcVal) #ifdef TRACE , ConfigGetIntVal(Config, CfgTraceVal) #endif ); Cs2ethRun(Cs2eth); Cs2ethDestroy(Cs2eth); Ret = 0; } else { Ret = 2; } } ConfigExit(Config); ConfigDestroy(Config); } else { Ret = 3; } return(Ret); }
/*! * \brief Reset configuration. */ void ConfigResetFactory(void) { ConfigCreate(); /* Initial radio control settings. */ radio.rc_rstation = 2; radio.rc_rvolume = 223; /* * Add pre-configured radio stations. */ /* Local server. */ ConfigStation(MAXNUM_STATIONS, "192.168.192.11:8000"); /* elDOradio 56 kbit */ ConfigStation(MAXNUM_STATIONS, "129.217.234.42/128:8000"); /* Virgin 32 kbit. */ ConfigStation(MAXNUM_STATIONS, "212.187.204.62:80"); /* qpop.nl 48 kbit */ ConfigStation(MAXNUM_STATIONS, "194.109.192.226:8010"); /* idobi 24 kbit */ ConfigStation(MAXNUM_STATIONS, "66.28.100.131:8004"); /* Radiosound-7-24 24 kbit. */ ConfigStation(MAXNUM_STATIONS, "64.202.98.51:7650"); /* DH Netradio 56 kbit */ ConfigStation(MAXNUM_STATIONS, "205.188.234.38:8030"); /* Cable radio 56 kbit. */ ConfigStation(MAXNUM_STATIONS, "62.25.96.7:8080"); /* MIBN1 40 kbit. */ ConfigStation(MAXNUM_STATIONS, "216.234.109.21:8000"); /* RFK 56 kbit */ ConfigStation(MAXNUM_STATIONS, "64.202.98.33:2530"); /* Braingell 24 kbit. */ ConfigStation(MAXNUM_STATIONS, "216.237.145.20:8000"); /* HipHop 48 kbit. */ ConfigStation(MAXNUM_STATIONS, "64.202.98.33:6150"); /* Flensburg 56 kbit */ ConfigStation(MAXNUM_STATIONS, "217.160.210.37:8000"); /* Boombastic 24 kbit. */ ConfigStation(MAXNUM_STATIONS, "212.43.230.20:8000"); /* Russia 24 kbit */ ConfigStation(MAXNUM_STATIONS, "62.118.255.5:9000"); /* Frequence3 16 kbit. */ ConfigStation(MAXNUM_STATIONS, "212.180.2.19:8010"); /* KCTI Country 16 kbit. */ ConfigStation(MAXNUM_STATIONS, "63.125.62.117:8000"); /* Klassik 40 kbit. */ ConfigStation(MAXNUM_STATIONS, "62.157.113.86:8000"); /* m2ktalk 8kbit */ ConfigStation(MAXNUM_STATIONS, "209.17.76.226:8010"); /* Christian Media 16 kbit. */ ConfigStation(MAXNUM_STATIONS, "64.202.98.32:6610"); /* Newsradio 24 kbit. */ ConfigStation(MAXNUM_STATIONS, "65.172.162.93:9191"); #ifdef ETHERNUT2 /* * These stations require Ethernut 2. */ /* Grapeshot 128 kbit. */ ConfigStation(MAXNUM_STATIONS, "66.28.45.159:8075"); /* Radiostorm 128 kbit. */ ConfigStation(MAXNUM_STATIONS, "64.236.34.141/stream/1014:80"); /* Digitally imported 128 kbit. */ ConfigStation(MAXNUM_STATIONS, "205.188.209.193/stream/1003:80"); /* SmoothJazz 128 kbit */ ConfigStation(MAXNUM_STATIONS, "64.236.34.141/stream/1005:80"); /* Tosh Jamaica 128 kbit. */ ConfigStation(MAXNUM_STATIONS, "38.144.33.148:8022"); /* weird 160 kbit */ ConfigStation(MAXNUM_STATIONS, "209.98.88.40:8007"); /* Stratovarius 192 kbit */ ConfigStation(MAXNUM_STATIONS, "210.120.247.22:1290"); /* Virgin 128 kbit. */ ConfigStation(MAXNUM_STATIONS, "64.236.34.72/stream/1031:80"); /* Virgin 128 kbit. */ ConfigStation(MAXNUM_STATIONS, "64.236.34.141/stream/1031:80"); #endif }
int main(int argc, char *argv[]) { Ms2Struct *Ms2Client; IoFktStruct *IoFunctions; ConfigStruct *Config; pid_t ChildPid; time_t Now; int Ret, NumArgs; char **ValArgs; Config = ConfigCreate(); if (Config != (ConfigStruct *)NULL) { NumArgs = argc; ValArgs = argv; ConfigInit(Config, MRSYSTEM_CONFIG_FILE); ConfigReadfile(Config); ConfigCmdLine(Config, "a:i:p:c:fs:vz:?", NumArgs, ValArgs); if (ConfigGetIntVal(Config, CfgUsageVal)) { usage(argv[0]); Ret = 1; } else if (ConfigGetIntVal(Config, CfgForkVal)) { ChildPid = fork(); if (ChildPid == -1) { puts("ERROR: can not go to backgound"); Ret = 4; } else if (ChildPid == 0) { if (ConfigGetIntVal(Config, CfgVerboseVal)) puts("child running"); IoFunctions = CanClientInit(ConfigGetIntVal(Config, CfgVerboseVal), ConfigGetStrVal(Config, CfgCanIfVal)); if (IoFunctions != (IoFktStruct *)NULL) { Ms2Client = Ms2Create(); if (Ms2Client != (Ms2Struct *)NULL) { Ms2Init(Ms2Client, ConfigGetIntVal(Config, CfgVerboseVal), ConfigGetStrVal(Config, CfgIfaceVal), ConfigGetStrVal(Config, CfgAddrVal), ConfigGetIntVal(Config, CfgPortVal), ConfigGetIntVal(Config, CfgZentraleVal), IoFunctions); Ms2Run(Ms2Client); Ms2Destroy(Ms2Client); Ret = 0; } else { puts("ERROR: can not create Ms2Client module"); Ret = 1; } CanClientExit(IoFunctions); } else { puts("ERROR: can not create IoFunctions module"); Ret = 1; } } else { puts("parent terminates"); signal(SIGCHLD, SIG_IGN); Ret = 0; } } else { Now = time(NULL); if (ConfigGetIntVal(Config, CfgVerboseVal)) printf("start with no fork at %s\n", asctime(localtime(&Now))); IoFunctions = CanClientInit(ConfigGetIntVal(Config, CfgVerboseVal), ConfigGetStrVal(Config, CfgCanIfVal)); if (IoFunctions != (IoFktStruct *)NULL) { Ms2Client = Ms2Create(); if (Ms2Client != (Ms2Struct *)NULL) { Ms2Init(Ms2Client, ConfigGetIntVal(Config, CfgVerboseVal), ConfigGetStrVal(Config, CfgIfaceVal), ConfigGetStrVal(Config, CfgAddrVal), ConfigGetIntVal(Config, CfgPortVal), ConfigGetIntVal(Config, CfgZentraleVal), IoFunctions); Ms2Run(Ms2Client); Ms2Destroy(Ms2Client); Ret = 0; } else { puts("ERROR: can not create Ms2Client module"); Ret = 1; } CanClientExit(IoFunctions); } else { puts("ERROR: can not create IoFunctions module"); Ret = 1; } } ConfigExit(Config); ConfigDestroy(Config); } else { puts("ERROR: can not create Config module"); Ret = 3; } return(Ret); }