📄 config.c
字号:
/*!
* Copyright (C) 2006-2007 by egnite Software GmbH. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
* SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* For additional information see http://www.ethernut.de/
*/
/*!
* \file config.c
* \brief Radio configuration.
*
* \verbatim
*
* $Log$
*
* \endverbatim
*/
#include <cfg/os.h>
#include <cfg/clock.h>
#include <dev/board.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.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 "config.h"
#include "webradio.h"
HTTP_PROXY proxy;
STATIONCONF *station;
/*!
* \brief Configure a station list entry.
*
* \param idx Index of the entry. Use MAXNUM_STATIONS to add an entry.
* \param url URL of the station.
*
* \return 0 on success, -1 otherwise.
*/
int ConfigStation(u_char idx, CONST char *symbol, CONST char * url)
{
u_long ip;
u_short port = 80;
char *buf;
char *cp;
if (idx >= MAXNUM_STATIONS) {
/* New entry. Find a free slot. */
idx = 0;
while (idx < MAXNUM_STATIONS && station[idx].rs_port) {
idx++;
}
}
if (idx >= MAXNUM_STATIONS) {
/* We are full. */
return -1;
}
buf = malloc(strlen(url) + 1);
/* Extract IP address. */
cp = buf;
while (*url && *url != '/' && *url != ':')
*cp++ = *url++;
*cp = 0;
if ((int) (ip = inet_addr(buf)) == -1)
idx = -1;
else {
/* Extract URL path. */
cp = buf;
if (*url == '/') {
url++;
while (*url && *url != ':')
*cp++ = *url++;
}
*cp = 0;
/* Extract port. */
if (*url == ':') {
port = atoi(url + 1);
}
if (port) {
station[idx].rs_ip = ip;
station[idx].rs_port = port;
if (*buf) {
station[idx].rs_url_path = malloc(strlen(buf) + 1);
strcpy(station[idx].rs_url_path, buf);
}
if (symbol && *symbol) {
station[idx].rs_symbol = malloc(strlen(symbol) + 1);
strcpy(station[idx].rs_symbol, symbol);
}
else {
station[idx].rs_symbol = NULL;
}
}
}
free(buf);
return idx;
}
/*!
* \brief Allocate heap memory for configuration structure.
*/
static void ConfigCreate(void)
{
u_char idx;
if (station == 0)
station = malloc(MAXNUM_STATIONS * sizeof(STATIONCONF));
else {
/* Release all memory occupied by the current configuration. */
for (idx = 0; idx < MAXNUM_STATIONS; idx++) {
if (station[idx].rs_port == 0)
break;
if (station[idx].rs_url_path) {
free(station[idx].rs_url_path);
}
}
}
memset(station, 0, MAXNUM_STATIONS * sizeof(STATIONCONF));
}
/*!
* \brief Reset configuration.
*
* Actually we didn't implement non-volatile memory for this application.
* This routine will be called on each power-up.
*/
void ConfigResetFactory(void)
{
ConfigCreate();
/* Set HTTP proxy. */
#ifdef MY_PROXY_IP
proxy.proxy_ip = inet_addr(MY_PROXY_IP);
proxy.proxy_port = MY_PROXY_PORT;
#endif
/*
* Add pre-configured radio stations.
*/
/* SAM7X low bandwidth. */
ConfigStation(MAXNUM_STATIONS, NULL, "195.210.39.28:8000"); //Sky.FM Smooth Jazz
ConfigStation(MAXNUM_STATIONS, NULL, "24.226.190.4:8000");
/* Initially start this one. */
radio.rc_rstation = ConfigStation(MAXNUM_STATIONS, NULL, "66.225.205.99:80");
ConfigStation(MAXNUM_STATIONS, NULL, "201.245.105.98:8000");
ConfigStation(MAXNUM_STATIONS, NULL, "207.134.25.235:8000");
ConfigStation(MAXNUM_STATIONS, NULL, "189.166.28.170:8000");
#if defined(AT91SAM9260_EK)
ConfigStation(MAXNUM_STATIONS, "AfriRhythms", "38.96.148.26:8155"); ConfigStation(MAXNUM_STATIONS, "AnimeNfo", "213.251.163.188:15220"); ConfigStation(MAXNUM_STATIONS, "Atlantic Sound Factory", "64.62.166.165:3000"); ConfigStation(MAXNUM_STATIONS, "BigB", "70.87.68.38:9000"); ConfigStation(MAXNUM_STATIONS, "BigB", "74.52.7.164:9000"); ConfigStation(MAXNUM_STATIONS, "BigB", "67.19.249.226:8000"); ConfigStation(MAXNUM_STATIONS, "China Classic", "72.21.49.122:8202"); ConfigStation(MAXNUM_STATIONS, "CorBinA", "80.237.155.22:8016"); //256kbps 44100 stereo ConfigStation(MAXNUM_STATIONS, "CorBinA", "85.21.79.9:8000"); //256kbps 44100 stereo ConfigStation(MAXNUM_STATIONS, "CorBinA", "85.21.79.5:8000"); //256kbps 44100 stereo ConfigStation(MAXNUM_STATIONS, "DopeLabs", "72.36.193.82:8000"); ConfigStation(MAXNUM_STATIONS, "EL POTOSI", "189.167.34.93:8000"); ConfigStation(MAXNUM_STATIONS, "Flensburg", "85.25.143.134:8165"); /* Start with a reliable station. */ radio.rc_rstation = ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "88.191.22.199:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "194.158.114.68:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "194.158.114.67:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "193.251.154.243:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "213.186.56.206:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "194.158.114.66:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "213.186.41.160:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "88.191.11.19:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "62.4.21.91:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "212.129.62.140:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "194.117.194.66:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "213.186.37.124:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "80.65.234.120:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "213.161.201.21:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "213.186.60.54:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "193.251.154.242:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "83.143.18.76:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "193.17.192.35:8000"); ConfigStation(MAXNUM_STATIONS, "FREQUENCE3", "193.222.128.135:8000");
ConfigStation(MAXNUM_STATIONS, "JP HiP", "83.149.104.21:2112"); ConfigStation(MAXNUM_STATIONS, "JP HiP", "220.95.232.121:7188"); ConfigStation(MAXNUM_STATIONS, "JP HiP", "67.19.219.94:7188"); ConfigStation(MAXNUM_STATIONS, "KPLU Jazz", "205.234.238.46:80"); //24000 mono ConfigStation(MAXNUM_STATIONS, "Plusz", "80.95.64.86:8002"); //256kbps 44100 stereo ConfigStation(MAXNUM_STATIONS, "Radio from the Ether", "66.32.148.136:8000"); ConfigStation(MAXNUM_STATIONS, "Radio Space", "142.169.126.180:8438"); ConfigStation(MAXNUM_STATIONS, "Radio Space", "208.53.158.162:8000"); ConfigStation(MAXNUM_STATIONS, "SKY.FM Classic", "128.177.3.80:4078"); //16000 mono ConfigStation(MAXNUM_STATIONS, "SKY.FM Classic", "66.90.113.135:8010"); //16000 mono ConfigStation(MAXNUM_STATIONS, "SKY.FM Classic", "206.98.167.99:8406"); //16000 mono ConfigStation(MAXNUM_STATIONS, "SKY.FM Hits", "212.23.5.99:8006"); ConfigStation(MAXNUM_STATIONS, "SKY.FM Hits", "160.79.128.62:6628"); ConfigStation(MAXNUM_STATIONS, "SKY.FM Hits", "64.74.207.40:8628"); ConfigStation(MAXNUM_STATIONS, "SKY.FM Jazz", "207.200.96.227/stream/1030"); ConfigStation(MAXNUM_STATIONS, "WGBH Classic", "64.71.145.106:8004"); //44100 stereo with intro ConfigStation(MAXNUM_STATIONS, "WHYY 91FM", "207.245.67.204:80"); ConfigStation(MAXNUM_STATIONS, "WNYC FM", "66.225.205.136:80"); ConfigStation(MAXNUM_STATIONS, "WNYC FM", "66.225.205.135:80"); ConfigStation(MAXNUM_STATIONS, "WNYC FM", "66.225.205.59:80");
ConfigStation(MAXNUM_STATIONS, ".977 Hitz Channel", "64.236.34.97/stream/1074"); ConfigStation(MAXNUM_STATIONS, ".977 Hitz Channel", "205.188.215.230:8002"); ConfigStation(MAXNUM_STATIONS, "181.fm", "205.188.215.230:8000"); ConfigStation(MAXNUM_STATIONS, "YEKAROO", "216.75.63.56:8000"); ConfigStation(MAXNUM_STATIONS, "Zhong Shuo", "64.71.150.28:16838"); //AAC Test ConfigStation(MAXNUM_STATIONS, "NetClassix", "67.43.161.248:80");#endif
/* Initial radio control settings. */
radio.rc_rvolume = -32;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -