* * $Log$ * *
Definition in file webradio.c.
#include <cfg/os.h>
#include <cfg/clock.h>
#include <dev/board.h>
#include <dev/st7036.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <fcntl.h>
#include <io.h>
#include <sys/version.h>
#include <sys/confnet.h>
#include <sys/atom.h>
#include <sys/heap.h>
#include <sys/thread.h>
#include <sys/timer.h>
#include <sys/event.h>
#include <sys/socket.h>
#include <hxmp3/mp3dec.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <net/route.h>
#include <pro/dhcp.h>
#include <pro/sntp.h>
#include <pro/discover.h>
#include "tlv320dac.h"
#include "config.h"
#include "shoutcast.h"
#include "player.h"
#include "httpserv.h"
#include "userif.h"
Include dependency graph for webradio.c:
Go to the source code of this file.
Defines | |
#define | MY_MAC { 0x00, 0x06, 0x98, 0x30, 0x00, 0x35 } |
#define | MY_IPADDR "192.168.192.35" |
#define | MY_IPMASK "255.255.255.0" |
#define | MY_IPGATE "192.168.192.1" |
#define | USE_DISCOVERY |
#define | MY_TZ -1 |
Functions | |
static int | QueryTimeServer (void) |
int | InitEthernetDevice (void) |
int | main (void) |
Main application routine. | |
Variables | |
RADIOCONTROL | radio |
|
Definition at line 97 of file webradio.c. Referenced by InitEthernetDevice(). |
|
Definition at line 104 of file webradio.c. Referenced by InitEthernetDevice(). |
|
Definition at line 111 of file webradio.c. Referenced by InitEthernetDevice(). |
|
Definition at line 118 of file webradio.c. Referenced by InitEthernetDevice(). |
|
Definition at line 124 of file webradio.c. |
|
Definition at line 138 of file webradio.c. Referenced by QueryTimeServer(). |
|
Definition at line 146 of file webradio.c. References MY_TZ. 00148 { 00149 int rc = -1; 00150 00151 #ifdef MY_TIMED 00152 int retries = 5; 00153 00154 _timezone = MY_TZ * 60L * 60L; 00155 while (retries--) { 00156 time_t now; 00157 u_long timeserver = inet_addr(MY_TIMED); 00158 00159 /* Query network time service and set the system time. */ 00160 printf("Query time from %s...", MY_TIMED); 00161 if(NutSNTPGetTime(×erver, &now) == 0) { 00162 puts("OK"); 00163 rc = 0; 00164 stime(&now); 00165 break; 00166 } 00167 else { 00168 puts("failed"); 00169 } 00170 } 00171 #endif 00172 00173 return rc;
|
|
Definition at line 175 of file webradio.c. References MY_IPADDR, MY_IPGATE, MY_IPMASK, and MY_MAC. 00177 { 00178 u_long ip_addr = inet_addr(MY_IPADDR); 00179 u_long ip_mask = inet_addr(MY_IPMASK); 00180 u_long ip_gate = inet_addr(MY_IPGATE); 00181 u_char mac[6] = MY_MAC; 00182 00183 for (;;) { 00184 printf("Register %s...", DEV_ETHER_NAME); 00185 if (NutRegisterDevice(&DEV_ETHER, 0x8300, 5) == 0) { 00186 puts("OK"); 00187 break; 00188 } 00189 puts("No Ethernet, retry"); 00190 } 00191 00192 printf("Configure %s...", DEV_ETHER_NAME); 00193 if (NutDhcpIfConfig(DEV_ETHER_NAME, 0, 60000) == 0) { 00194 puts("OK"); 00195 return 0; 00196 } 00197 printf("initial boot..."); 00198 if (NutDhcpIfConfig(DEV_ETHER_NAME, mac, 60000) == 0) { 00199 puts("OK"); 00200 return 0; 00201 } 00202 printf("No DHCP..."); 00203 NutNetIfConfig(DEV_ETHER_NAME, mac, ip_addr, ip_mask); 00204 /* Without DHCP we had to set the default gateway manually.*/ 00205 if(ip_gate) { 00206 printf("hard coded gate..."); 00207 NutIpRouteAdd(0, 0, ip_gate, &DEV_ETHER); 00208 } 00209 puts("OK"); 00210 00211 return 0;
|
|
Main application routine.
Definition at line 216 of file webradio.c. 00218 { 00219 u_long baud = 115200; 00220 u_long ipgate; 00221 u_int failcnt = 0; 00222 00223 /* 00224 * Register and open the DBGU device, which we will use for debug 00225 * output via stdout. 00226 */ 00227 NutRegisterDevice(&DEV_DEBUG, 0, 0); 00228 freopen(DEV_DEBUG_NAME, "w", stdout); 00229 _ioctl(_fileno(stdout), UART_SETSPEED, &baud); 00230 00231 /* 00232 * Display some general information. 00233 */ 00234 printf("\n\nSAM Internet Radio %s - Nut/OS %s\n", VERSION, NutVersionString()); 00235 printf("%u bytes free\n", (u_int)NutHeapAvailable()); 00236 printf("CPU Clock : %lu\n", NutGetCpuClock()); 00237 printf("Master Clock: %lu\n", At91GetMasterClock()); 00238 00239 /* 00240 * Initialize the user interface, LCD and 3 buttons. 00241 */ 00242 if (NutRegisterDevice(&devSbiLcd, 0, 0)) { 00243 puts("Failed to register LCD"); 00244 } 00245 if (UserIfInit("sbilcd")) { 00246 puts("LCD init failure\n"); 00247 } 00248 00249 /* 00250 * Initialize the Ethernet device and print our IP setting. 00251 */ 00252 InitEthernetDevice(); 00253 printf("IP Addr: %s\n", inet_ntoa(confnet.cdn_ip_addr)); 00254 printf("IP Mask: %s\n", inet_ntoa(confnet.cdn_ip_mask)); 00255 NutIpRouteQuery(0, &ipgate); 00256 printf("IP Gate: %s\n", inet_ntoa(ipgate)); 00257 00258 /* 00259 * Register a discovery responder. This optional feature 00260 * allows to discover all Nut/OS devices in a local network. 00261 */ 00262 #ifdef USE_DISCOVERY 00263 printf("Start Responder..."); 00264 if (NutRegisterDiscovery((u_long)-1, 0, DISF_INITAL_ANN)) { 00265 puts("failed"); 00266 } 00267 else { 00268 puts("OK"); 00269 } 00270 #endif 00271 00272 /* 00273 * Try to get current date and time from an SNTP server. 00274 */ 00275 if (QueryTimeServer() == 0) { 00276 time_t now = time(0); 00277 struct _tm *lot = localtime(&now); 00278 printf("Date: %02u.%02u.%u\n", lot->tm_mday, lot->tm_mon + 1, 1900 + lot->tm_year); 00279 printf("Time: %02u:%02u:%02u\n", lot->tm_hour, lot->tm_min, lot->tm_sec); 00280 #ifdef USE_HTTPSERVER 00281 h_timevalid = 1; 00282 #endif 00283 } 00284 00285 #ifdef USE_HTTPSERVER 00286 HttpServerStart(); 00287 #endif 00288 00289 ConfigResetFactory(); 00290 00291 /* 00292 * Create all required receiver and player instances. 00293 */ 00294 radio.rc_rip = ReceiverCreate(&rpiShoutcast); 00295 radio.rc_pip = PlayerCreate(&ppiMp3); 00296 00297 /* 00298 * Never ending application loop. 00299 */ 00300 for (;;) { 00301 if (failcnt > 3) { 00302 printf("Too many failures. Select next station.\n"); 00303 radio.rc_rstation = StationSelect(radio.rc_cstation, 1); 00304 failcnt = 0; 00305 } 00306 radio.rc_cstation = radio.rc_rstation; 00307 printf("Trying station entry %u\n", radio.rc_cstation); 00308 00309 /* 00310 * Connect station. 00311 */ 00312 UserIfShowStatus(DIST_CONNECTING); 00313 radio.rc_sip = StationConnect(&station[radio.rc_cstation]); 00314 if (radio.rc_sip == NULL) { 00315 /* Connection failed. */ 00316 UserIfShowStatus(DIST_DEAD); 00317 NutSleep(1000); 00318 radio.rc_rstation = StationSelect(radio.rc_cstation, 0); 00319 failcnt++; 00320 continue; 00321 } 00322 00323 /* 00324 * Station connected. 00325 */ 00326 printf("Connected: %u bytes free\n", (u_int)NutHeapAvailable()); 00327 if (ReceiverStart(radio.rc_rip, radio.rc_sip) == 0) { 00328 UserIfShowStatus(DIST_CONNECTED); 00329 if (radio.rc_sip->si_ptype == PLAYER_TYPE_MP3) { 00330 if (PlayerStart(radio.rc_pip, radio.rc_rip) == 0) { 00331 failcnt = 0; 00332 NutSleep(1000); 00333 while (radio.rc_cstation == radio.rc_rstation) { 00334 if (PlayerStatus(radio.rc_pip) != PSTAT_RUNNING) { 00335 radio.rc_rstation = StationSelect(radio.rc_cstation, 0); 00336 failcnt++; 00337 break; 00338 } 00339 NutSleep(1000); 00340 } 00341 printf("\nStop player "); 00342 PlayerStop(radio.rc_pip); 00343 } 00344 else { 00345 radio.rc_rstation = StationSelect(radio.rc_cstation, 0); 00346 failcnt++; 00347 } 00348 } 00349 else { 00350 printf("Bad content type\n"); 00351 radio.rc_rstation = StationSelect(radio.rc_cstation, 0); 00352 failcnt++; 00353 } 00354 printf("\nStop receiver "); 00355 ReceiverStop(radio.rc_rip); 00356 } 00357 else { 00358 radio.rc_rstation = StationSelect(radio.rc_cstation, 0); 00359 failcnt++; 00360 } 00361 printf("\nDisconnect station "); 00362 StationDisconnect(radio.rc_sip); 00363 radio.rc_sip = NULL; 00364 }
|
|
Definition at line 141 of file webradio.c. Referenced by CgiControl(). |