2437 lines
63 KiB
C
Executable File
2437 lines
63 KiB
C
Executable File
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <sys/stat.h>
|
|
#include <netdb.h>
|
|
#include <unistd.h>
|
|
#include <time.h>
|
|
#include <errno.h>
|
|
#include <ctype.h>
|
|
|
|
|
|
#include "../inc/iweb_task.h"
|
|
#include "../inc/lcd_task.h"
|
|
#include "../inc/msg.h"
|
|
#include "../inc/main.h"
|
|
#include "../inc/i2c_drv.h"
|
|
#include "../inc/log_task.h"
|
|
#include "../inc/upgrade.h"
|
|
#include "../inc/tsoip.h"
|
|
#include "../inc/eeprom.h"
|
|
#include "../inc/fpga.h"
|
|
#include "../inc/isys_com.h"
|
|
#include "../inc/isys_config.h"
|
|
#include "../inc/dac38j82.h"
|
|
#include "../inc/dpd_proc.h"
|
|
#include "../inc/upgrade.h"
|
|
#include "../inc/http_get.h"
|
|
#include "../inc/os_task.h"
|
|
#include "../inc/iq_rx.h"
|
|
|
|
|
|
#if 1//__usr__
|
|
|
|
#define _WEB_PRT_DBG_ 1
|
|
|
|
#if _WEB_PRT_DBG_
|
|
#define PR(...) printf(__VA_ARGS__)
|
|
#else
|
|
#define PR(...)
|
|
#endif
|
|
|
|
extern char release_ver[30];
|
|
extern S_ATSC_PARA atsc_para;
|
|
extern S_IP2TS_PARA ip2ts[2];
|
|
extern S_TSOIP_CONFIG_PARA i2c_para_bak;
|
|
extern S_EXTEND_SYS_STATE st_extend_state;
|
|
|
|
static char sendValBuf[1024]={0};
|
|
static char recvValBuf[1024]={0};
|
|
static char gb_upgrade_flg = 0;
|
|
void http_load_atsc_sytem_key(S_SN_PARA *pkey);
|
|
extern void save_user_para(void *psave);
|
|
|
|
#define SH_CHECK_NTP_SYNC_CMD "sh /usr/sbin/check_ntp_sync.sh"
|
|
#define SH_RESTART_NTP_SERVER_CMD "sh /usr/sbin/restart_ntp_server.sh"
|
|
|
|
#endif//__usr__
|
|
|
|
|
|
|
|
|
|
#define __usr_web_com__ 1
|
|
#if __usr_web_com__
|
|
|
|
int32 conv_locPower_to_db_amp100(uint16 power)
|
|
{
|
|
uint16 temp;
|
|
int32 pow_db_amp;
|
|
|
|
temp = power;
|
|
temp = temp>=RF_POWER_ZERO?(temp-RF_POWER_ZERO):(RF_POWER_ZERO-temp);
|
|
|
|
//ppara->power[0] = (power>RF_POWER_ZERO)?0:1;
|
|
//ppara->power[1] = temp/20;
|
|
//ppara->power[2] = temp%20;
|
|
|
|
pow_db_amp = (uint32)(temp/20)*100 + temp%20*5;
|
|
|
|
if(power>RF_POWER_ZERO){//+
|
|
pow_db_amp = pow_db_amp;
|
|
}
|
|
else{//-
|
|
pow_db_amp = -pow_db_amp;
|
|
}
|
|
|
|
return pow_db_amp;
|
|
}
|
|
int32 conv_webPower_to_db_amp100(uint8 web_sign,uint8 web_int,uint8 web_dec)
|
|
{
|
|
int32 pow_db_amp;
|
|
|
|
pow_db_amp=web_int*100+web_dec*5;
|
|
|
|
if(web_sign==0){//+
|
|
pow_db_amp = pow_db_amp;
|
|
}
|
|
else{//-
|
|
pow_db_amp = -pow_db_amp;
|
|
}
|
|
|
|
return pow_db_amp;
|
|
}
|
|
|
|
|
|
|
|
uint16 get_factor(en_FACTOR en_factor)
|
|
{
|
|
uint16 factor=1;
|
|
switch(en_factor)
|
|
{
|
|
case FACTOR_1:
|
|
factor = 1;
|
|
break;
|
|
case FACTOR_100:
|
|
factor = 100;
|
|
break;
|
|
default:
|
|
factor = 1;
|
|
break;
|
|
}
|
|
return factor;
|
|
}
|
|
void getParaFormList(st_CGI_PARA *pList,char *pbuf,short bufMaxLen)
|
|
{
|
|
char dataBuf[1024]={0};
|
|
char tempBuf[50] ={0};
|
|
uint16 dataLen = 0;
|
|
uint16 tempLen =0;
|
|
char *pdatabuf = NULL;
|
|
st_CGI_PARA *plistPara = NULL;
|
|
char tempflg = 0;
|
|
if(!pList)
|
|
return;
|
|
|
|
pdatabuf = dataBuf;
|
|
|
|
for(plistPara=pList; plistPara->paraVal!=NULL; plistPara++)
|
|
{
|
|
memset(tempBuf,0,sizeof(tempBuf));
|
|
|
|
switch(plistPara->paraType)
|
|
{
|
|
case TYPE_U8:
|
|
sprintf(tempBuf,"#%d",*(uint8*)plistPara->paraVal/get_factor(plistPara->paraFactor));
|
|
tempflg=1;
|
|
break;
|
|
case TYPE_I8:
|
|
sprintf(tempBuf,"#%d",*(int8*)plistPara->paraVal/get_factor(plistPara->paraFactor));
|
|
tempflg=1;
|
|
break;
|
|
case TYPE_U16:
|
|
sprintf(tempBuf,"#%d",*(uint16*)plistPara->paraVal/get_factor(plistPara->paraFactor));
|
|
tempflg=1;
|
|
break;
|
|
case TYPE_I16:
|
|
sprintf(tempBuf,"#%d",*(int16*)plistPara->paraVal/get_factor(plistPara->paraFactor));
|
|
tempflg=1;
|
|
break;
|
|
case TYPE_U32:
|
|
sprintf(tempBuf,"#%d",*(int32*)plistPara->paraVal/get_factor(plistPara->paraFactor));
|
|
tempflg=1;
|
|
break;
|
|
case TYPE_I32:
|
|
sprintf(tempBuf,"#%d",*(int32*)(plistPara->paraVal)/get_factor(plistPara->paraFactor));
|
|
tempflg=1;
|
|
break;
|
|
case TYPE_FLOAT:
|
|
sprintf(tempBuf,"#%.6f",*(float*)(plistPara->paraVal)/get_factor(plistPara->paraFactor));
|
|
tempflg=1;
|
|
break;
|
|
case TYPE_DOUBLE:
|
|
sprintf(tempBuf,"#%.6f",*(double*)(plistPara->paraVal)/get_factor(plistPara->paraFactor));
|
|
tempflg=1;
|
|
break;
|
|
case TYPE_STRING:
|
|
sprintf(tempBuf,"#%s",(plistPara->paraVal));
|
|
tempflg=1;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
tempLen = strlen(tempBuf);
|
|
if(tempLen>=sizeof(tempBuf)){
|
|
log_printf(LOG_DEBUG,I_NOUSED," singleData over length. \n");
|
|
return;
|
|
}
|
|
dataLen+=tempLen;
|
|
if(dataLen>=bufMaxLen){
|
|
log_printf(LOG_DEBUG,I_NOUSED,"allData over length. \n");
|
|
return;
|
|
}
|
|
memcpy(pdatabuf,tempBuf,tempLen);
|
|
pdatabuf = pdatabuf + tempLen;
|
|
}
|
|
|
|
memcpy(pbuf,dataBuf,strlen(dataBuf));
|
|
|
|
}
|
|
|
|
|
|
int find_match_char_num(char str[], int strLen, char chr)
|
|
{
|
|
int i = 0;
|
|
int matchCnt = 0;
|
|
|
|
if(!str)return 0;
|
|
|
|
for(i = 0; i < strLen; i++){
|
|
if(str[i] == chr){
|
|
matchCnt++;
|
|
}
|
|
}
|
|
|
|
return matchCnt;
|
|
}
|
|
|
|
/*
|
|
src 源字符串的首地址(buf的地址)
|
|
separator 指定的分割字符
|
|
dest 接收子字符串的数组
|
|
num 分割后子字符串的个数
|
|
*/
|
|
void split(char *src,const char *separator,char **dest,int *num)
|
|
{
|
|
char *pNext;
|
|
int count = 0;
|
|
if (src == NULL || strlen(src) == 0) //如果传入的地址为空或长度为0,直接终止
|
|
return;
|
|
if (separator == NULL || strlen(separator) == 0) //如未指定分割的字符串,直接终止
|
|
return;
|
|
pNext = (char *)strtok(src,separator); //必须使用(char *)进行强制类型转换(虽然不写有的编译器中不会出现指针错误)
|
|
while(pNext != NULL)
|
|
{
|
|
*dest++ = pNext;
|
|
++count;
|
|
pNext = (char *)strtok(NULL,separator); //必须使用(char *)进行强制类型转换
|
|
}
|
|
*num = count;
|
|
}
|
|
|
|
static char* paraBuf[1024]={NULL};
|
|
|
|
int splitStrPara(char *src,char **paraBuf)
|
|
{
|
|
int paraNum = 0;
|
|
if( !paraBuf )
|
|
return 0;
|
|
|
|
memset(paraBuf,0,sizeof(paraBuf));
|
|
split(src,"#",paraBuf,¶Num); //调用函数进行分割
|
|
return paraNum;
|
|
}
|
|
|
|
|
|
void setParaAccordList(st_CGI_PARA *pList,char *pbuf,short bufMaxLen)
|
|
{
|
|
char dataBuf[1024]={0};
|
|
char tempBuf[50] ={0};
|
|
uint16 dataLen = 0;
|
|
uint16 tempLen = 0;
|
|
char *pdatabuf = NULL;
|
|
st_CGI_PARA *plistPara = NULL;
|
|
|
|
int paraNum1 = 0;
|
|
int paraNum = 0;
|
|
int i;
|
|
int paraCnt;
|
|
char tempflg = 0;
|
|
if(!pList)return;
|
|
if(bufMaxLen>1024)return;
|
|
pdatabuf = dataBuf;
|
|
|
|
// #1#2#3#4#5#6#7#8#9
|
|
//paraNum1 = find_match_char_num(pdatabuf, strlen(pdatabuf), '#');
|
|
//printf("paraNum1=%d\n",paraNum1);
|
|
// 分割设置值
|
|
paraNum = splitStrPara(pbuf,paraBuf);
|
|
//printf("web setParaNum=%d\n",paraNum);
|
|
|
|
/*for(i = 0;i < paraNum; i ++) {
|
|
//lr_output_message("%s\n",revbuf[i]);
|
|
printf(" webData [num %2d] [%s]\n",i,paraBuf[i]);
|
|
}*/
|
|
|
|
//printf("ram setPara\n");
|
|
// 将设置值填入到表中
|
|
for(plistPara=pList,paraCnt=0; plistPara->paraVal; plistPara++,paraCnt++)
|
|
{
|
|
if(paraCnt > paraNum)break;
|
|
|
|
if(!paraBuf[paraCnt])
|
|
{
|
|
log_printf(LOG_ERR,I_NOUSED,"set intData invalid. \n");
|
|
break;
|
|
}
|
|
switch(plistPara->paraType)
|
|
{
|
|
case TYPE_U8:
|
|
*(uint8*)plistPara->paraVal = atoi(paraBuf[paraCnt]) * get_factor(plistPara->paraFactor);
|
|
//printf(" setData u8 =[num %2d][%d]\n",paraCnt,*(uint8*)plistPara->paraVal);
|
|
break;
|
|
case TYPE_I8:
|
|
*(int8*)plistPara->paraVal = atoi(paraBuf[paraCnt]) * get_factor(plistPara->paraFactor);
|
|
//printf(" setData i8 =[num %2d][%d]\n",paraCnt,*(int8*)plistPara->paraVal);
|
|
break;
|
|
case TYPE_U16:
|
|
*(uint16*)plistPara->paraVal = atoi(paraBuf[paraCnt]) * get_factor(plistPara->paraFactor);
|
|
//printf(" setData u16 =[num %2d][%d]\n",paraCnt,*(uint16*)plistPara->paraVal);
|
|
break;
|
|
case TYPE_I16:
|
|
*(int16*)plistPara->paraVal = atoi(paraBuf[paraCnt]) * get_factor(plistPara->paraFactor);
|
|
//printf(" setData i16 =[num %2d][%d]\n",paraCnt,*(int16*)plistPara->paraVal);
|
|
break;
|
|
case TYPE_U32:
|
|
*(uint32*)plistPara->paraVal = atoi(paraBuf[paraCnt]) * get_factor(plistPara->paraFactor);
|
|
//printf(" setData u32 =[num %2d][%d]\n",paraCnt,*(uint32*)plistPara->paraVal);
|
|
break;
|
|
case TYPE_I32:
|
|
*(int32*)plistPara->paraVal = atoi(paraBuf[paraCnt]) * get_factor(plistPara->paraFactor);
|
|
//printf(" setData i32 =[num %2d][%d]\n",paraCnt,*(int32*)plistPara->paraVal);
|
|
break;
|
|
case TYPE_FLOAT:
|
|
*(float*)plistPara->paraVal = atoi(paraBuf[paraCnt]) * get_factor(plistPara->paraFactor);
|
|
//printf(" setData ft =[num %2d][%d]\n",paraCnt,*(float*)plistPara->paraVal);
|
|
break;
|
|
case TYPE_DOUBLE:
|
|
*(double*)plistPara->paraVal = atoi(paraBuf[paraCnt]) * get_factor(plistPara->paraFactor);
|
|
//printf(" setData db =[num %2d][%d]\n",paraCnt,*(double*)plistPara->paraVal);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//void output_err(const char* error)
|
|
//{
|
|
// printf("Content-Type: text/plain\n\n");
|
|
// printf("%s\n", error);
|
|
//}
|
|
/*
|
|
int executeCMD(const char *cmd, char *result)
|
|
{
|
|
char buf_ps[1024];
|
|
char ps[1024]={0};
|
|
FILE *ptr;
|
|
strcpy(ps, cmd);
|
|
if((ptr=popen(ps, "r")) != NULL)
|
|
{
|
|
while(fgets(buf_ps, 1024, ptr) != NULL)
|
|
{
|
|
strcat(result, buf_ps);
|
|
if(strlen(result)>1024)
|
|
break;
|
|
}
|
|
pclose(ptr);
|
|
ptr = NULL;
|
|
}
|
|
else
|
|
{
|
|
log_printf(LOG_ERR,I_NOUSED,"popen %s error\n", ps);
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
*/
|
|
int executeCMD(const char *cmd, char *result, u16 result_size)
|
|
{
|
|
char buf_ps[1024];
|
|
FILE *ptr;
|
|
|
|
// 初始化 result
|
|
memset(result, 0, result_size);
|
|
|
|
if ((ptr = popen(cmd, "r")) != NULL) {
|
|
while (fgets(buf_ps, sizeof(buf_ps), ptr) != NULL) {
|
|
// 移除换行符
|
|
buf_ps[strcspn(buf_ps, "\n")] = 0;
|
|
|
|
// 检查剩余空间
|
|
size_t remaining_space = result_size - strlen(result) - 1;
|
|
if (remaining_space > 0) {
|
|
strncat(result, buf_ps, remaining_space);
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
pclose(ptr);
|
|
ptr = NULL;
|
|
} else {
|
|
// 记录错误日志
|
|
fprintf(stderr, "popen %s error\n", cmd);
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
S_CGI_STATUS cgi_status = {0,};
|
|
S_CGI_TUNER cgi_tuner = {0,};
|
|
#if ATSC_USA_AMP
|
|
S_CGI_AMP cgi_amp = {0,};
|
|
#endif
|
|
S_CGI_GPS cgi_gps = {0,};
|
|
|
|
|
|
#endif//__usr_web_com__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------
|
|
|
|
int function_vod(char *pbuf,short bufMaxLen)
|
|
{
|
|
|
|
}
|
|
|
|
#define __usr_http_load__ 1
|
|
|
|
#if __usr_http_load__
|
|
static BOOL net_auto_adpc = FALSE;
|
|
extern BOOL udp_adj_auto_adpc;
|
|
|
|
|
|
void http_load_status_tsoip(int index, S_CGI_STATE_PARA_TSOIP *pstatus)
|
|
{
|
|
index = index & 0x01;
|
|
|
|
if(ip2ts[index].tsoip_log_para.ts_in_flag)
|
|
{
|
|
pstatus->ip_out = TS_OUTPUT_STATUS_OK;
|
|
pstatus->ip_out_rate_kbps = ip2ts[index].tsoip_log_para.ip_out_rate_kbps;
|
|
}
|
|
else
|
|
{
|
|
pstatus->ip_out = TS_OUTPUT_STATUS_ERR;
|
|
pstatus->ip_out_rate_kbps = 0;
|
|
}
|
|
|
|
if(ip2ts[index].tsoip_log_para.ts_out_flag)
|
|
{
|
|
pstatus->asi_out = TS_OUTPUT_STATUS_OK;
|
|
pstatus->asi_out_rate_kbps = ip2ts[index].tsoip_log_para.asi_out_rate_kbps;
|
|
}
|
|
else
|
|
{
|
|
pstatus->asi_out = TS_OUTPUT_STATUS_ERR;
|
|
pstatus->asi_out_rate_kbps = 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#if USE_PSTS
|
|
void http_load_psip(S_PSTS_PARA *ppara)
|
|
{
|
|
memcpy(ppara,&atsc_para.psts_para,sizeof(S_PSTS_PARA));
|
|
}
|
|
#endif
|
|
|
|
#endif//__usr_http_load__
|
|
|
|
|
|
//-------------------------------------------
|
|
#define __get_webc__ 1
|
|
#if __get_webc__
|
|
|
|
|
|
int get_web_title(char *pbuf,short bufMaxLen){
|
|
|
|
sprintf(pbuf, "#%s",
|
|
atsc_para.system_para.web_title // TITLE
|
|
);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int get_sys_status(char *pbuf,short bufMaxLen)
|
|
{
|
|
uint8 buf1_rate[30];
|
|
uint8 buf2_temp[10];
|
|
char mh_buf[8];
|
|
uint32 ltemp;
|
|
S_SYS_TIME time;
|
|
|
|
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
|
|
http_load_status(&cgi_status);
|
|
|
|
//----------------------------------------
|
|
//ts_rate
|
|
memset(buf1_rate,0,sizeof(buf1_rate));
|
|
if(cgi_status.ts_under)
|
|
sprintf((char*)buf1_rate,"UnderFlow");
|
|
else{
|
|
if(cgi_status.ts_rate&1)
|
|
sprintf((char*)buf1_rate,"OverFlow");
|
|
else
|
|
sprintf((char*)buf1_rate,"%02ld.%06ld",cgi_status.ts_rate/1000000,cgi_status.ts_rate%1000000);//ts_rate;
|
|
}
|
|
//printf("buf1_rate=%s\n",buf1_rate);
|
|
|
|
//temp
|
|
memset(buf2_temp,0,sizeof(buf2_temp));
|
|
if(cgi_status.temp==(uint32)-1)
|
|
sprintf((char*)buf2_temp,"HIGH");
|
|
else
|
|
{
|
|
if(cgi_status.temp & 0x10000) { //-
|
|
cgi_status.temp &= 0x1ff; //去掉符号位
|
|
|
|
if(get_temp_unit()==1){
|
|
sprintf((char*)buf2_temp,"-%02d.%02d",cgi_status.temp/4,cgi_status.temp%4*25);
|
|
}
|
|
else{
|
|
ltemp = ((cgi_status.temp/4)*100) + (cgi_status.temp%4)*25;
|
|
ltemp = -ltemp;
|
|
ltemp = degree2fah(ltemp);
|
|
sprintf((char*)buf2_temp,"%02ld.%02d",ltemp/100,math_abs(ltemp)%100);
|
|
}
|
|
|
|
|
|
}
|
|
else{
|
|
if(get_temp_unit()==1){
|
|
sprintf((char*)buf2_temp,"%02d.%02d",cgi_status.temp/4,cgi_status.temp%4*25);
|
|
}
|
|
else{
|
|
ltemp =((cgi_status.temp/4)*100)+((cgi_status.temp%4)*25);
|
|
ltemp = degree2fah(ltemp);
|
|
sprintf((char*)buf2_temp,"%02ld.%02d",ltemp/100,math_abs(ltemp)%100);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//mh_buf
|
|
/* if(atsc_para.log_para.mh<10)
|
|
sprintf(mh_buf,"0.%ld",atsc_para.log_para.mh);
|
|
else
|
|
sprintf(mh_buf,"%ld",atsc_para.log_para.mh/10);
|
|
*/
|
|
//----------------------------------------
|
|
|
|
uint8 buf_date[30];
|
|
uint8 buf_time[30];
|
|
|
|
get_sys_time(&time);
|
|
|
|
memset(buf_date,0,sizeof(buf_date));
|
|
memset(buf_time,0,sizeof(buf_time));
|
|
if(cgi_status.ntp_en){
|
|
memset(buf_date,0,sizeof(buf_date));
|
|
sprintf(buf_date,"%04d-%02d-%02d",time.year, time.month, time.date);
|
|
|
|
memset(buf_time,0,sizeof(buf_time));
|
|
sprintf(buf_time,"%02d-%02d-%02d",time.hour, time.min, time.sec);
|
|
}
|
|
else{
|
|
memset(buf_date,0,sizeof(buf_date));
|
|
sprintf(buf_date,"NA-NA-NA");
|
|
|
|
memset(buf_time,0,sizeof(buf_time));
|
|
sprintf(buf_time,"NA-NA-NA");
|
|
}
|
|
//printf("buf_date=%s\n",buf_date);
|
|
//printf("buf_time=%s\n",buf_time);
|
|
//printf("buf1_rate=%s\n",buf1_rate);
|
|
//printf("buf2_temp=%s\n",buf2_temp);
|
|
//PR("> [%s,%d]\n", __FUNCTION__,__LINE__);
|
|
|
|
sprintf(pbuf,
|
|
"#%d#%d#%d#%s#%s"
|
|
"#%d#%d#%d#%lu#%d"
|
|
"#%d#%d#%d#%d#%d"
|
|
"#%d#%d"
|
|
"#%d#%d#%d#%d#%d"
|
|
"#%s#%s#%d#%d#%d#%d",
|
|
cgi_status.input, cgi_status.status, cgi_status.agc, buf1_rate, buf2_temp,
|
|
cgi_status.syserr, cgi_status.txfreq, cgi_status.hz_, cgi_status.hz, cgi_status.fwd,
|
|
cgi_status.tsnr, cgi_status.l_imd, cgi_status.u_imd, atsc_para.system_para.ctrl, cgi_status.amp,
|
|
cgi_status.a_fssi, cgi_status.b_fssi,
|
|
//sntp
|
|
cgi_status.ntp_en, cgi_status.ntp_sip[0], cgi_status.ntp_sip[1], cgi_status.ntp_sip[2], cgi_status.ntp_sip[3],
|
|
buf_date, buf_time, atsc_para.system_para.ab_mode, cgi_status.temp_unit,
|
|
cgi_status.agc_state, cgi_status.agc_adj
|
|
);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int get_sys_version(char *pbuf,short bufMaxLen)
|
|
{
|
|
uint8 tbuf_dryloop[10];
|
|
uint8 tmp_ver[20];
|
|
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
#if USE_DRY_LOOP
|
|
|
|
memset(tbuf_dryloop,0,sizeof(tbuf_dryloop));
|
|
memcpy(tbuf_dryloop,atsc_para.rg_para.dryloop,sizeof(atsc_para.rg_para.dryloop));
|
|
#else
|
|
memset(tbuf_dryloop,0,sizeof(tbuf_dryloop));
|
|
sprintf(tbuf_dryloop,"NA",sizeof("NA"));
|
|
#endif
|
|
|
|
memset(tmp_ver, 0, sizeof(tmp_ver));
|
|
u8 len = strlen(atsc_para.rg_para.attr);
|
|
if(g_ca_value==1){
|
|
memcpy(tmp_ver, atsc_para.rg_para.attr, len);
|
|
sprintf(&tmp_ver[len], "%s" ,".0");
|
|
}
|
|
else{
|
|
memcpy(tmp_ver, atsc_para.rg_para.attr, len);
|
|
}
|
|
//printf("ver:%s %d\n", tmp_ver, g_ca_value);
|
|
|
|
char tmp_str[16];
|
|
|
|
memset(tmp_str,0,sizeof(tmp_str));
|
|
sprintf((char *)tmp_str,"V%01d.%1dA_I_%02d%02d%02d",
|
|
atsc_para.fpga_ver_tmp[1]/10,atsc_para.fpga_ver_tmp[1]%10,
|
|
atsc_para.fpga_ver_tmp[2],atsc_para.fpga_ver_tmp[3],atsc_para.fpga_ver_tmp[4]);
|
|
|
|
sprintf(pbuf, "#%s#%s#%s#%s",
|
|
tmp_ver,//atsc_para.rg_para.attr,
|
|
tmp_str,//atsc_para.rg_para.fpga,
|
|
release_ver,//atsc_para.rg_para.mcu,
|
|
tbuf_dryloop);
|
|
|
|
//PR("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int get_state_tuner(char *pbuf,short bufMaxLen)
|
|
{
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
http_load_tuner_info(&cgi_tuner);
|
|
|
|
sprintf(pbuf, "#%d#%d#%d#%d",
|
|
cgi_tuner.rxfreq, cgi_tuner.rssi, cgi_tuner.rsnr, cgi_tuner.lock_status);
|
|
|
|
//PR("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int get_state_pac(char *pbuf,short bufMaxLen)
|
|
{
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
http_load_pac(&cgi_amp);
|
|
|
|
sprintf(pbuf, "#%d#%d#%d#%d#%d"
|
|
"#%d#%d#%d#%d#%d"
|
|
"#%d#%d#%d#%d",
|
|
cgi_amp.vol_9v, cgi_amp.vol_12v, cgi_amp.vol_50v, cgi_amp.pa_fwd, cgi_amp.pa_reflect,
|
|
cgi_amp.vswr, cgi_amp.temp_pa,cgi_amp.pa_in, cgi_amp.cur1_50v,cgi_amp.cur2_50v,
|
|
cgi_amp.cur3_50v,cgi_amp.cur4_50v,cgi_amp.gv_881,cgi_amp.pac_lev);
|
|
|
|
//PR("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int get_state_gps(char *pbuf,short bufMaxLen)
|
|
{
|
|
uint8 buf_freq[30];
|
|
uint8 buf_date[30];
|
|
uint8 buf_time[30];
|
|
S_SYS_TIME time={0};
|
|
uint8 gps_sv =0;
|
|
GPGSA_T *gps_gsa = NULL;
|
|
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
gps_gsa = gps_get_sa();
|
|
|
|
http_load_gps(&cgi_gps);
|
|
|
|
get_sys_time(&time);
|
|
|
|
memset(buf_freq,0,sizeof(buf_freq));
|
|
if(cgi_gps.freq[0])
|
|
sprintf((char*)buf_freq,"-%dE-%02d",(cgi_gps.freq[1]&0xf0)>>4,cgi_gps.freq[1]&0x0f);
|
|
else
|
|
sprintf((char*)buf_freq,"+%dE-%02d",(cgi_gps.freq[1]&0xf0)>>4,cgi_gps.freq[1]&0x0f);
|
|
|
|
if((cgi_gps.gps_use)&&(atsc_para.system_para.gps)){//INT 模式
|
|
memset(buf_date,0,sizeof(buf_date));
|
|
sprintf(buf_date,"%04d-%02d-%02d",time.year, time.month, time.date);
|
|
}
|
|
else{
|
|
memset(buf_date,0,sizeof(buf_date));
|
|
sprintf(buf_date,"NA-NA-NA");
|
|
}
|
|
|
|
memset(buf_time,0,sizeof(buf_time));
|
|
sprintf(buf_time,"%02d-%02d-%02d",time.hour, time.min, time.sec);
|
|
#if USE_GPS
|
|
gps_sv = gps_gsa->sv;
|
|
#endif
|
|
|
|
sprintf(pbuf,"#%d#%d#%s#%s#%d"
|
|
"#%d#%s",
|
|
cgi_gps.gps_lock, cgi_gps.gps_use, buf_date, buf_time, gps_sv,
|
|
cgi_gps.status, buf_freq);
|
|
|
|
//PR("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int get_state_mac_sn(char *pbuf,short bufMaxLen)
|
|
{
|
|
uint8 buf_mac[16];
|
|
uint8 buf_sn[16];
|
|
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
memset(buf_mac,0,sizeof(buf_mac));
|
|
sprintf((char *)buf_mac,"%06X%02X%02X%02X",0x9440A2,atsc_para.wk_para.mac[0],
|
|
atsc_para.wk_para.mac[1],atsc_para.wk_para.mac[2]);
|
|
|
|
memset(buf_sn,0,sizeof(buf_sn));
|
|
sprintf((char *)buf_sn,"%013lld", atsc_para.sn_para.sn);
|
|
|
|
sprintf(pbuf, "#%s#%s",
|
|
buf_mac, buf_sn
|
|
);
|
|
|
|
//PR("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int get_sys_cfg(char *pbuf,short bufMaxLen)
|
|
{
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
uint8 input = atsc_para.system_para.input;
|
|
|
|
//printf("adpc=%d\n", atsc_para.system_para.adpc);
|
|
|
|
sprintf(pbuf, "#%u#%u#%u#%u#%u#%s#%u#%u#%u#%u#%u#0x%04X#%u#%u#%u#%u",
|
|
input, // 通道选择
|
|
atsc_para.system_para.gps, // 时钟源
|
|
atsc_para.system_para.adpc>=ADPC_UPDATE3?ADPC_UPDATE3:atsc_para.system_para.adpc, //预校正
|
|
0,//adpc_sta
|
|
atsc_para.system_para.ctrl,//CTL
|
|
atsc_para.system_para.web_title, // TITLE
|
|
atsc_para.ad3_para.fwd_cal,
|
|
atsc_para.config_para.pa_link_ctrl_rf,
|
|
atsc_para.dpd_para.dpd_test,
|
|
atsc_para.wl_para.roll_off_sel,
|
|
atsc_para.system_para.ab_mode,
|
|
atsc_para.dpd_para.gl,
|
|
atsc_para.sn_para.eas_key_valid,
|
|
atsc_para.system_para.agc_att,
|
|
atsc_para.system_para.adrv9009_att,
|
|
atsc_para.system_para.orx_manu_gain
|
|
);
|
|
|
|
#if CGI_PRINT
|
|
//printf("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
#endif
|
|
return 0;
|
|
|
|
}
|
|
|
|
//将十六进制的字符串转换成整数
|
|
int htoi(char* str)
|
|
{
|
|
int n = 0;
|
|
if (str == NULL) return -1;
|
|
if (*str == '0' && (*(str + 1) == 'x' || *(str + 1) == 'X'))
|
|
{
|
|
str += 2;
|
|
}
|
|
while (1)
|
|
{
|
|
if (*str >= '0' && *str <= '9')
|
|
{
|
|
n = 16 * n + (*str - '0');
|
|
}
|
|
else if (*str >= 'A' && *str <= 'F')//十六进制还要判断字符是不是在A-F或者a-f之间
|
|
{
|
|
n = 16 * n + (*str - 'A' + 10);
|
|
}
|
|
else if (*str >= 'a' && *str <= 'f')
|
|
{
|
|
n = 16 * n + (*str - 'a' + 10);
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
str++;
|
|
}
|
|
return n;
|
|
}
|
|
|
|
int set_sys_cfg(char *pbuf, short bufMaxLen)
|
|
{
|
|
S_CGI_SET *p_cgi_sys_para = NULL;
|
|
static MSG msg ;
|
|
int paraNum = 0;
|
|
float rate_threshold;
|
|
int i = 0;
|
|
float f_att;
|
|
|
|
if( !pbuf || bufMaxLen <= 0)
|
|
return -1;
|
|
|
|
|
|
p_cgi_sys_para = malloc((size_t)sizeof(S_CGI_SET));
|
|
if(p_cgi_sys_para == NULL){
|
|
log_printf(LOG_ERR, I_NOUSED, "malloc p_cgi_sys_para failed.\n");
|
|
return -1;
|
|
}
|
|
log_printf(LOG_INFO, I_USER_CFG, "set_sys_cfg: %s\n",pbuf);
|
|
|
|
http_load_default_para(WEB_SET, p_cgi_sys_para);
|
|
|
|
paraNum = splitStrPara(pbuf,paraBuf);
|
|
|
|
|
|
p_cgi_sys_para->ctrl = (uint8)atoi(paraBuf[3]);
|
|
if(atsc_para.system_para.ctrl==CTRL_REMOTE)
|
|
{
|
|
p_cgi_sys_para->input= (uint8)atoi(paraBuf[0]); // asi
|
|
p_cgi_sys_para->gps = (uint8)atoi(paraBuf[1]); // gps
|
|
p_cgi_sys_para->adpc = (uint8)atoi(paraBuf[2]); // adp
|
|
|
|
p_cgi_sys_para->fwd_cal = (uint8)atoi(paraBuf[4]); // fwd_cal
|
|
p_cgi_sys_para->pa_link_ctrl_rf = (uint8)atoi(paraBuf[5]); // pa_crf
|
|
|
|
p_cgi_sys_para->sys_reset = (uint8)atoi(paraBuf[6]); // sys_reset //@NEED_ADD_FUNC
|
|
p_cgi_sys_para->dpd_tst = (uint16)atoi(paraBuf[7]);
|
|
memset(p_cgi_sys_para->web_title, 0, ATSC_TITLE_LEN);
|
|
memcpy(p_cgi_sys_para->web_title,paraBuf[8],strlen(paraBuf[8]));
|
|
p_cgi_sys_para->roll_off_sel = (uint16)atoi(paraBuf[9]);
|
|
p_cgi_sys_para->ab_mode = (uint16)atoi(paraBuf[10]);
|
|
|
|
p_cgi_sys_para->gl = htoi(paraBuf[11]);
|
|
|
|
#if USE_NEW_POWER_CFG
|
|
f_att = atsc_para.system_para.agc_att * (-0.5);
|
|
p_cgi_sys_para->agc_att = atsc_para.system_para.agc_att;
|
|
p_cgi_sys_para->adrv9009_att = atsc_para.system_para.adrv9009_att;
|
|
#else
|
|
f_att = atof(paraBuf[12]);
|
|
if(f_att<-31.5){
|
|
f_att = -31.5;
|
|
}
|
|
if(f_att>0){
|
|
f_att = 0;
|
|
}
|
|
p_cgi_sys_para->agc_att = f_att/(-0.5);
|
|
p_cgi_sys_para->adrv9009_att = (uint16)atoi(paraBuf[13]);
|
|
#endif
|
|
p_cgi_sys_para->orx_manu_gain = (uint16)atoi(paraBuf[14]);
|
|
}
|
|
|
|
#if 1
|
|
log_printf(LOG_INFO, I_USER_CFG, "asi=%d\n", p_cgi_sys_para->input);
|
|
log_printf(LOG_INFO, I_USER_CFG, "gps=%d\n", p_cgi_sys_para->gps);
|
|
log_printf(LOG_INFO, I_USER_CFG, "adpc=%d\n", p_cgi_sys_para->adpc);
|
|
log_printf(LOG_INFO, I_USER_CFG, "ctl=%d\n", p_cgi_sys_para->ctrl);
|
|
//log_printf(LOG_INFO, I_USER_CFG, "sntp_en=%d\n", p_cgi_sys_para->sntp_en);
|
|
//log_printf(LOG_INFO, I_USER_CFG, "sntp_ip=%d.%d.%d.%d\n", p_cgi_sys_para->sntp_sip[0],p_cgi_sys_para->sntp_sip[1],p_cgi_sys_para->sntp_sip[2],p_cgi_sys_para->sntp_sip[3]);
|
|
log_printf(LOG_INFO, I_USER_CFG, "fwd_cal=%d\n", p_cgi_sys_para->fwd_cal);
|
|
log_printf(LOG_INFO, I_USER_CFG, "pa_crf=%d\n", p_cgi_sys_para->pa_link_ctrl_rf);
|
|
log_printf(LOG_INFO, I_USER_CFG, "sys_reset=%d\n", p_cgi_sys_para->sys_reset);
|
|
log_printf(LOG_INFO, I_USER_CFG, "dpd_tst=%d\n", p_cgi_sys_para->dpd_tst);
|
|
log_printf(LOG_INFO, I_USER_CFG, "title=%s\n", p_cgi_sys_para->web_title);
|
|
log_printf(LOG_INFO, I_USER_CFG, "roll_off_sel=%d\n", p_cgi_sys_para->roll_off_sel);
|
|
log_printf(LOG_INFO, I_USER_CFG, "ab_mode=%d\n", p_cgi_sys_para->ab_mode);
|
|
log_printf(LOG_INFO, I_USER_CFG, "gl=0x%X agcatt=%fdb %d adrv_att=%d orxgain=%d\n",
|
|
p_cgi_sys_para->gl,
|
|
f_att,
|
|
p_cgi_sys_para->agc_att,
|
|
p_cgi_sys_para->adrv9009_att,
|
|
p_cgi_sys_para->orx_manu_gain
|
|
);
|
|
#endif
|
|
|
|
|
|
msg.type = MSG_WEB_SAVE_PARA;
|
|
msg.need_free = MSG_NO_NEED_FREE;
|
|
msg.wPara = WEB_SET;
|
|
msg.lPara = (uint32)p_cgi_sys_para;
|
|
msg_send_to_lcd(&msg);
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static uint32 ssi_get_adpc_err_infor_atsc(void)
|
|
{
|
|
uint32 ret = 0;
|
|
uint8 err_num=0;
|
|
|
|
err_num = conv_adpc_err_output(atsc_para.system_para.adpc_err);
|
|
if(err_num==0){
|
|
ret = atsc_para.system_para.adpc_err;
|
|
}
|
|
else{
|
|
ret = err_num;
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
int get_sys_dpd_state(char *pbuf,short bufMaxLen)
|
|
{
|
|
if( !pbuf )
|
|
return -1;
|
|
S_SYSTEM_PARA syspara;
|
|
|
|
memcpy(&syspara, &atsc_para.system_para, sizeof(S_SYSTEM_PARA));
|
|
sprintf(pbuf, "%u#%u#%u#%u#%u#%u#%u#",
|
|
ssi_get_adpc_err_infor_atsc(),
|
|
syspara.dpd_phase,
|
|
syspara.tsnr,
|
|
syspara.maxp,
|
|
syspara.save_load_data_percent,
|
|
syspara.flash_get_err_num,
|
|
syspara.final_stage
|
|
|
|
);
|
|
|
|
#if CGI_PRINT
|
|
//printf("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
#endif
|
|
return 0;
|
|
|
|
}
|
|
|
|
int get_systime(char *pbuf, short bufMaxLen)
|
|
{
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
time_t time_cur = 0;
|
|
struct tm tmBJ;
|
|
int zone_dffset = atsc_para.wj_para.gmt;
|
|
|
|
memset(&tmBJ, 0, sizeof(struct tm));
|
|
time_cur = time(NULL);
|
|
|
|
utc2localtime(time_cur, &tmBJ, zone_dffset);
|
|
|
|
sprintf(pbuf, "#%d#%02d#%02d#%d#%d#%d",
|
|
tmBJ.tm_year,
|
|
tmBJ.tm_mon,
|
|
tmBJ.tm_mday,
|
|
tmBJ.tm_hour,
|
|
tmBJ.tm_min,
|
|
tmBJ.tm_sec);
|
|
|
|
log_printf(LOG_DEBUG, I_NOUSED, "%s\n", pbuf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
int get_sys_net(char *pbuf,short bufMaxLen)
|
|
{
|
|
if( !pbuf )
|
|
return -1;
|
|
S_CONFIG_PARA param;
|
|
memcpy(¶m, &atsc_para.config_para, sizeof(S_CONFIG_PARA));
|
|
|
|
sprintf(pbuf, "#%d#%d#%d#%d#%d#%u#%u#%u#%u#%u#%u#%u",
|
|
param.ip[0],
|
|
param.ip[1],
|
|
param.ip[2],
|
|
param.ip[3],
|
|
param.gateway[0],
|
|
param.gateway[1],
|
|
param.gateway[2],
|
|
param.gateway[3],
|
|
param.mask[0],
|
|
param.mask[1],
|
|
param.mask[2],
|
|
param.mask[3]
|
|
);
|
|
|
|
//PR("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
|
|
return 0;
|
|
|
|
}
|
|
int set_sys_net(char *pbuf, short bufMaxLen)
|
|
{
|
|
S_CONFIG_PARA *ppara = NULL;
|
|
MSG msg ;
|
|
int paraNum = 0;
|
|
float rate_threshold;
|
|
int i = 0;
|
|
|
|
if( !pbuf || bufMaxLen <= 0)
|
|
return -1;
|
|
|
|
if(atsc_para.system_para.ctrl==CTRL_LOCAL)
|
|
{
|
|
return 0;
|
|
}
|
|
log_printf(LOG_INFO, I_USER_CFG, "web set %s\n", pbuf);
|
|
|
|
ppara = (S_CONFIG_PARA *)malloc((size_t)sizeof(S_CONFIG_PARA));
|
|
if(ppara == NULL){
|
|
log_printf(LOG_ERR, I_NOUSED," malloc memory failed\n");
|
|
return -1;
|
|
}
|
|
http_load_default_para(CGI_CTTB_SYS_ADMIN_IPCFG, ppara);
|
|
|
|
paraNum = splitStrPara(pbuf,paraBuf);
|
|
|
|
ppara->ip[0] = (uint8)atoi(paraBuf[i++]);
|
|
ppara->ip[1] = (uint8)atoi(paraBuf[i++]);
|
|
ppara->ip[2] = (uint8)atoi(paraBuf[i++]);
|
|
ppara->ip[3] = (uint8)atoi(paraBuf[i++]);
|
|
ppara->gateway[0] = (uint8)atoi(paraBuf[i++]);
|
|
ppara->gateway[1] = (uint8)atoi(paraBuf[i++]);
|
|
ppara->gateway[2] = (uint8)atoi(paraBuf[i++]);
|
|
ppara->gateway[3] = (uint8)atoi(paraBuf[i++]);
|
|
ppara->mask[0] = (uint8)atoi(paraBuf[i++]);
|
|
ppara->mask[1] = (uint8)atoi(paraBuf[i++]);
|
|
ppara->mask[2] = (uint8)atoi(paraBuf[i++]);
|
|
ppara->mask[3] = (uint8)atoi(paraBuf[i++]);
|
|
|
|
#if 1//WEB_MSG_CFG
|
|
msg.type = MSG_WEB_SAVE_PARA;
|
|
msg.need_free = MSG_NO_NEED_FREE;
|
|
msg.wPara = WEB_IP_CFG;
|
|
msg.lPara = (uint32)ppara;
|
|
msg_send_to_lcd(&msg);
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
int set_sys_rst(char *pbuf, short bufMaxLen)
|
|
{
|
|
S_CGI_SET *p_cgi_sys_para = NULL;
|
|
static MSG msg ;
|
|
int paraNum = 0;
|
|
float rate_threshold;
|
|
int i = 0;
|
|
|
|
if( !pbuf || bufMaxLen <= 0)
|
|
return -1;
|
|
|
|
log_printf(LOG_INFO, I_USER_CFG, "web set reset system\n");
|
|
|
|
p_cgi_sys_para = malloc((size_t)sizeof(S_CGI_SET));
|
|
if(p_cgi_sys_para == NULL){
|
|
log_printf(LOG_ERR, I_NOUSED, "malloc p_cgi_sys_para memory failed\n");
|
|
return -1;
|
|
}
|
|
http_load_default_para(WEB_SET, p_cgi_sys_para);
|
|
paraNum = splitStrPara(pbuf,paraBuf);
|
|
|
|
if(atsc_para.system_para.ctrl==CTRL_REMOTE)
|
|
{
|
|
p_cgi_sys_para->sys_reset = (uint8)atoi(paraBuf[0]);
|
|
}
|
|
|
|
msg.type = MSG_WEB_SAVE_PARA;
|
|
msg.need_free = MSG_NO_NEED_FREE;
|
|
msg.wPara = WEB_SET;
|
|
msg.lPara = (uint32)p_cgi_sys_para;
|
|
msg_send_to_lcd(&msg);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int set_systime(char *pbuf,short bufMaxLen)
|
|
{
|
|
int paraNum = 0;
|
|
char cmd[100] = {0};
|
|
struct tm usr_tm;
|
|
struct tm *p_utc_tm;
|
|
S_SYS_TIME tmp_time={0};
|
|
int i = 0;
|
|
|
|
if( !pbuf || bufMaxLen == 0 )
|
|
return -1;
|
|
|
|
log_printf(LOG_INFO, I_USER_CFG, "set rtc time [%s]\n");
|
|
|
|
paraNum = splitStrPara(pbuf, paraBuf);
|
|
tmp_time.year = atoi(paraBuf[i++])-1900;
|
|
tmp_time.month = atoi(paraBuf[i++]);
|
|
tmp_time.date = atoi(paraBuf[i++]);
|
|
tmp_time.hour = atoi(paraBuf[i++]);
|
|
tmp_time.min = atoi(paraBuf[i++]);
|
|
tmp_time.sec = atoi(paraBuf[i++]);
|
|
|
|
usr_set_sys_rtc_time(&tmp_time);
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
int get_rf_cfg(char *pbuf,short bufMaxLen)
|
|
{
|
|
S_CGI_RF cgi_rf = {0,};
|
|
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
http_load_rf(&cgi_rf);
|
|
|
|
sprintf(pbuf, "#%d#%d#%d#%d#%d"
|
|
"#%d#%d#%d#%d",
|
|
cgi_rf.power[0],
|
|
cgi_rf.power[1],
|
|
cgi_rf.power[2],
|
|
cgi_rf.rf,
|
|
cgi_rf.agc,
|
|
//
|
|
cgi_rf.rc_cmd,
|
|
cgi_rf.tx,
|
|
cgi_rf.txfreq-2,
|
|
cgi_rf.rxfreq-2
|
|
);
|
|
|
|
#if CGI_PRINT
|
|
// printf("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
#endif
|
|
return 0;
|
|
|
|
}
|
|
int set_rf_cfg(char *pbuf,short bufMaxLen)
|
|
{
|
|
S_CGI_RF *ppara = NULL;
|
|
uint32 value = 0;
|
|
int paraNum = 0;
|
|
int i = 0;
|
|
uint32 simbol;
|
|
uint32 pw[2];
|
|
int32 fpower;
|
|
int32 loc_pow=0;
|
|
int32 web_pow=0;
|
|
uint8 lcl_freq;
|
|
MSG msg;
|
|
u8 rx_freq = 0;
|
|
|
|
int agc_force_close=0;
|
|
|
|
log_printf(LOG_INFO, I_USER_CFG,"%s\n", pbuf);
|
|
|
|
if( !pbuf || bufMaxLen == 0)
|
|
return -1;
|
|
|
|
if(atsc_para.system_para.ctrl==CTRL_LOCAL) {
|
|
return 0;
|
|
}
|
|
|
|
ppara = malloc((size_t)sizeof(S_CGI_RF));
|
|
if(ppara == NULL){
|
|
log_printf(LOG_ERR, I_NOUSED, "malloc ppara memory failed\n");
|
|
return -1;
|
|
}
|
|
|
|
http_load_default_para(WEB_RF,ppara);
|
|
|
|
paraNum = splitStrPara(pbuf, paraBuf);
|
|
pw[0]=ppara->power[0];
|
|
pw[1]=ppara->power[1];
|
|
pw[2]=ppara->power[2];
|
|
|
|
ppara->power[0]=atoi(paraBuf[0]);
|
|
ppara->power[1]=atoi(paraBuf[1]);
|
|
ppara->power[2]=atoi(paraBuf[2]);
|
|
if(!(pw[0]==ppara->power[0]&&pw[1]==ppara->power[1]&&pw[2]==ppara->power[2])){
|
|
agc_force_close++;
|
|
}
|
|
loc_pow = conv_locPower_to_db_amp100(atsc_para.rf_para.power);
|
|
web_pow = conv_webPower_to_db_amp100(ppara->power[0],ppara->power[1],ppara->power[2]);
|
|
if(web_pow <= loc_pow+100) {
|
|
|
|
}
|
|
ppara->rf =atoi(paraBuf[3]);
|
|
ppara->agc=atoi(paraBuf[4]);
|
|
//ppara->rc_cmd=atoi(paraBuf[5]);
|
|
|
|
if( (atsc_para.wh_para.func==0)&&(atsc_para.ad3_para.rc_cmd) ) {
|
|
ppara->tx=atoi(paraBuf[6]);
|
|
}
|
|
|
|
i=0;
|
|
lcl_freq = (atoi(paraBuf[7])+FREQ_MIN_V1);
|
|
if((FREQ_MIN_V1<=lcl_freq) && (lcl_freq<=FREQ_6M_MAX_U)){
|
|
if(atsc_para.rf_para.txfreq != lcl_freq){
|
|
ppara->power[0]=1; // 1:- 0:+
|
|
ppara->power[1]=25;
|
|
ppara->power[2]=0;
|
|
|
|
agc_force_close++;
|
|
ppara->txfreq = lcl_freq;
|
|
i=1;
|
|
}
|
|
}
|
|
|
|
rx_freq = (atoi(paraBuf[8])+FREQ_MIN_V1);
|
|
if((FREQ_MIN_V1<=rx_freq) && (rx_freq<=FREQ_6M_MAX_U)) {
|
|
ppara->rxfreq = rx_freq;
|
|
}
|
|
|
|
printf("web cfg tfreq=%d rfreq=%d (pwr=%d)\n", ppara->txfreq, ppara->rxfreq, i);
|
|
if(ppara->rf!=atsc_para.rf_para.rf){
|
|
agc_force_close++;
|
|
}
|
|
|
|
if(agc_force_close!=0){
|
|
ppara->agc=0;
|
|
}
|
|
|
|
msg.type = MSG_WEB_SAVE_PARA;
|
|
msg.need_free = MSG_NO_NEED_FREE;
|
|
msg.wPara = WEB_RF;
|
|
msg.lPara = (uint32)ppara;
|
|
msg_send_to_lcd(&msg);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* PR07: 10 MHz reference-clock output enable.
|
|
* Backed by FPGA reg_map_dpd seg5 0x1f bit0 (m10_out_en). Live toggle applied
|
|
* straight over i2c (fpga_byte_write/read are internally mutexed, so this is
|
|
* safe from the web thread). Not persisted: the FPGA resets it to 0 on every
|
|
* power-up, which is the required default (10 MHz off after boot). */
|
|
int get_m10_cfg(char *pbuf,short bufMaxLen)
|
|
{
|
|
uint8 en;
|
|
if( !pbuf )
|
|
return -1;
|
|
en = fpga_byte_read(0x05, 0x1f) & 0x01;
|
|
sprintf(pbuf, "#%d", en);
|
|
return 0;
|
|
}
|
|
int set_m10_cfg(char *pbuf,short bufMaxLen)
|
|
{
|
|
char *p = pbuf;
|
|
uint8 en;
|
|
if( !pbuf || bufMaxLen == 0 )
|
|
return -1;
|
|
/* value arrives as a bare "0"/"1"; tolerate a stray '#' or spaces */
|
|
while(*p && (*p < '0' || *p > '9')) p++;
|
|
en = (atoi(p) != 0) ? 1 : 0;
|
|
fpga_byte_write(0x05, 0x1f, en);
|
|
log_printf(LOG_INFO, I_USER_CFG, "10M ref output enable = %d\n", en);
|
|
return 0;
|
|
}
|
|
|
|
int get_spec_cfg(char *pbuf,short bufMaxLen)
|
|
{
|
|
if (!pbuf || bufMaxLen == 0) return -1;
|
|
sprintf(pbuf, "#1");
|
|
return 0;
|
|
}
|
|
|
|
int set_spec_cfg(char *pbuf,short bufMaxLen)
|
|
{
|
|
if (!pbuf || bufMaxLen == 0) return -1;
|
|
atsc_para.system_para.spec_enable = 1;
|
|
c256_bytewrite(EEPROM_SPEC_ENABLE, atsc_para.system_para.spec_enable);
|
|
iq_spec_set_enable(1);
|
|
log_printf(LOG_INFO, I_USER_CFG, "spectrum enable fixed on\n");
|
|
return 0;
|
|
}
|
|
|
|
int get_tsid_psip(char *pbuf,short bufMaxLen)
|
|
{
|
|
|
|
#if USE_PSTS
|
|
S_PSTS_PARA *psip = &atsc_para.psts_para;
|
|
#endif
|
|
|
|
if( !pbuf || bufMaxLen == 0)
|
|
return -1;
|
|
|
|
sprintf(pbuf,
|
|
"#%d#%d#%d"
|
|
"#%d#%s#%d#%d" // 0
|
|
"#%d#%s#%d#%d" // 1
|
|
"#%d#%s#%d#%d" // 2
|
|
"#%d#%s#%d#%d" // 3
|
|
"#%d#%s#%d#%d" // 4
|
|
"#%d#%s#%d#%d" // 5
|
|
"#%d#%s#%d#%d" // 6
|
|
"#%d#%s#%d#%d" // 7
|
|
"#%d#%s#%d#%d" // 8
|
|
"#%d#%s#%d#%d" // 9
|
|
"#%d#%s#%d#%d" // 10
|
|
"#%d#%s#%d#%d" // 11
|
|
"#%d#%s#%d#%d",// 12
|
|
psip->ts_ctrl,psip->tsid,psip->channel_max,
|
|
psip->sip_para[0].channel_num,psip->sip_para[0].sht_name,psip->sip_para[0].maj_num,psip->sip_para[0].min_num,
|
|
psip->sip_para[1].channel_num,psip->sip_para[1].sht_name,psip->sip_para[1].maj_num,psip->sip_para[1].min_num,
|
|
psip->sip_para[2].channel_num,psip->sip_para[2].sht_name,psip->sip_para[2].maj_num,psip->sip_para[2].min_num,
|
|
psip->sip_para[3].channel_num,psip->sip_para[3].sht_name,psip->sip_para[3].maj_num,psip->sip_para[3].min_num,
|
|
psip->sip_para[4].channel_num,psip->sip_para[4].sht_name,psip->sip_para[4].maj_num,psip->sip_para[4].min_num,
|
|
psip->sip_para[5].channel_num,psip->sip_para[5].sht_name,psip->sip_para[5].maj_num,psip->sip_para[5].min_num,
|
|
psip->sip_para[6].channel_num,psip->sip_para[6].sht_name,psip->sip_para[6].maj_num,psip->sip_para[6].min_num,
|
|
psip->sip_para[7].channel_num,psip->sip_para[7].sht_name,psip->sip_para[7].maj_num,psip->sip_para[7].min_num,
|
|
psip->sip_para[8].channel_num,psip->sip_para[8].sht_name,psip->sip_para[8].maj_num,psip->sip_para[8].min_num,
|
|
psip->sip_para[9].channel_num,psip->sip_para[9].sht_name,psip->sip_para[9].maj_num,psip->sip_para[9].min_num,
|
|
psip->sip_para[10].channel_num,psip->sip_para[10].sht_name,psip->sip_para[10].maj_num,psip->sip_para[10].min_num,
|
|
psip->sip_para[11].channel_num,psip->sip_para[11].sht_name,psip->sip_para[11].maj_num,psip->sip_para[11].min_num,
|
|
psip->sip_para[12].channel_num,psip->sip_para[12].sht_name,psip->sip_para[12].maj_num,psip->sip_para[12].min_num
|
|
);
|
|
|
|
#if CGI_PRINT
|
|
//printf("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
#endif
|
|
//printf("0get ts_ctl=%d\n",psip->ts_ctrl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int set_tsid_psip(char *pbuf,short bufMaxLen)
|
|
{
|
|
|
|
S_PSTS_PARA *ppara = NULL;
|
|
int paraNum = 0;
|
|
int i = 0;
|
|
MSG msg;
|
|
|
|
log_printf(LOG_INFO, I_USER_CFG,"web set :%s\n", pbuf);
|
|
|
|
if( !pbuf || bufMaxLen == 0)
|
|
return -1;
|
|
if(atsc_para.system_para.ctrl==CTRL_LOCAL)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
ppara = malloc((size_t)sizeof(S_PSTS_PARA));
|
|
if(ppara == NULL){
|
|
log_printf(LOG_ERR, I_USER_CFG,"malloc ppara memory failed\n");
|
|
return -1;
|
|
}
|
|
|
|
http_load_default_para(WEB_PSIP,ppara);
|
|
|
|
paraNum = splitStrPara(pbuf, paraBuf);
|
|
|
|
ppara->ts_ctrl=atoi(paraBuf[0]);
|
|
ppara->tsid =atoi(paraBuf[1]);
|
|
|
|
|
|
#if 1
|
|
msg.type = MSG_WEB_SAVE_PARA;
|
|
msg.need_free = MSG_NO_NEED_FREE;
|
|
msg.wPara = WEB_PSIP;
|
|
msg.lPara = (uint32)ppara;
|
|
msg_send_to_lcd(&msg);
|
|
#endif
|
|
}
|
|
|
|
int set_tsid_psip_cfg(char *pbuf,short bufMaxLen)
|
|
{
|
|
|
|
S_PSTS_PARA *ppara = NULL;
|
|
int paraNum = 0;
|
|
int i = 0;
|
|
MSG msg;
|
|
|
|
log_printf(LOG_INFO, I_USER_CFG,"web set %s\n", pbuf);
|
|
|
|
if( !pbuf || bufMaxLen == 0)
|
|
return -1;
|
|
|
|
if(atsc_para.system_para.ctrl==CTRL_LOCAL) {
|
|
return 0;
|
|
}
|
|
|
|
ppara = malloc((size_t)sizeof(S_PSTS_PARA));
|
|
if(ppara == NULL){
|
|
log_printf(LOG_ERR, I_USER_CFG,"malloc ppara memory failed\n");
|
|
return -1;
|
|
}
|
|
|
|
http_load_default_para(WEB_PSIP,ppara);
|
|
|
|
paraNum = splitStrPara(pbuf, paraBuf);
|
|
|
|
//psip0
|
|
ppara->sip_para[0].channel_num = atoi(paraBuf[0]);
|
|
memcpy(ppara->sip_para[0].sht_name,paraBuf[1],strlen(paraBuf[1]));
|
|
ppara->sip_para[0].maj_num = atoi(paraBuf[2]);
|
|
ppara->sip_para[0].min_num = atoi(paraBuf[3]);
|
|
log_printf(LOG_INFO, I_USER_CFG,"1.set sht_name=%s\n",ppara->sip_para[0].sht_name);
|
|
log_printf(LOG_INFO, I_USER_CFG,"1.set sht_namelst=%s\n",ppara->sip_para[12].sht_name);
|
|
|
|
//psip1
|
|
ppara->sip_para[1].channel_num = atoi(paraBuf[4]);
|
|
memcpy(ppara->sip_para[1].sht_name,paraBuf[5],strlen(paraBuf[5]));
|
|
ppara->sip_para[1].maj_num = atoi(paraBuf[6]);
|
|
ppara->sip_para[1].min_num = atoi(paraBuf[7]);
|
|
|
|
//psip2
|
|
ppara->sip_para[2].channel_num = atoi(paraBuf[8]);
|
|
memcpy(ppara->sip_para[2].sht_name,paraBuf[9],strlen(paraBuf[9]));
|
|
ppara->sip_para[2].maj_num = atoi(paraBuf[10]);
|
|
ppara->sip_para[2].min_num = atoi(paraBuf[11]);
|
|
|
|
//psip3
|
|
ppara->sip_para[3].channel_num = atoi(paraBuf[12]);
|
|
memcpy(ppara->sip_para[3].sht_name,paraBuf[13],strlen(paraBuf[13]));
|
|
ppara->sip_para[3].maj_num = atoi(paraBuf[14]);
|
|
ppara->sip_para[3].min_num = atoi(paraBuf[15]);
|
|
|
|
//psip4
|
|
ppara->sip_para[4].channel_num = atoi(paraBuf[16]);
|
|
memcpy(ppara->sip_para[4].sht_name,paraBuf[17],strlen(paraBuf[17]));
|
|
ppara->sip_para[4].maj_num = atoi(paraBuf[18]);
|
|
ppara->sip_para[4].min_num = atoi(paraBuf[19]);
|
|
|
|
//psip5
|
|
ppara->sip_para[5].channel_num = atoi(paraBuf[20]);
|
|
memcpy(ppara->sip_para[5].sht_name,paraBuf[21],strlen(paraBuf[21]));
|
|
ppara->sip_para[5].maj_num = atoi(paraBuf[22]);
|
|
ppara->sip_para[5].min_num = atoi(paraBuf[23]);
|
|
|
|
//psip6
|
|
ppara->sip_para[6].channel_num = atoi(paraBuf[24]);
|
|
memcpy(ppara->sip_para[6].sht_name,paraBuf[25],strlen(paraBuf[25]));
|
|
ppara->sip_para[6].maj_num = atoi(paraBuf[26]);
|
|
ppara->sip_para[6].min_num = atoi(paraBuf[27]);
|
|
|
|
//psip7
|
|
ppara->sip_para[7].channel_num = atoi(paraBuf[28]);
|
|
memcpy(ppara->sip_para[7].sht_name,paraBuf[29],strlen(paraBuf[29]));
|
|
ppara->sip_para[7].maj_num = atoi(paraBuf[30]);
|
|
ppara->sip_para[7].min_num = atoi(paraBuf[31]);
|
|
|
|
//psip8
|
|
ppara->sip_para[8].channel_num = atoi(paraBuf[32]);
|
|
memcpy(ppara->sip_para[8].sht_name,paraBuf[33],strlen(paraBuf[33]));
|
|
ppara->sip_para[8].maj_num = atoi(paraBuf[34]);
|
|
ppara->sip_para[8].min_num = atoi(paraBuf[35]);
|
|
|
|
//psip9
|
|
ppara->sip_para[9].channel_num = atoi(paraBuf[36]);
|
|
memcpy(ppara->sip_para[9].sht_name,paraBuf[37],strlen(paraBuf[37]));
|
|
ppara->sip_para[9].maj_num = atoi(paraBuf[38]);
|
|
ppara->sip_para[9].min_num = atoi(paraBuf[39]);
|
|
|
|
//psip10
|
|
ppara->sip_para[10].channel_num= atoi(paraBuf[40]);
|
|
memcpy(ppara->sip_para[10].sht_name,paraBuf[41],strlen(paraBuf[41]));
|
|
ppara->sip_para[10].maj_num = atoi(paraBuf[42]);
|
|
ppara->sip_para[10].min_num = atoi(paraBuf[43]);
|
|
|
|
//psip11
|
|
ppara->sip_para[11].channel_num= atoi(paraBuf[44]);
|
|
memcpy(ppara->sip_para[11].sht_name,paraBuf[45],strlen(paraBuf[45]));
|
|
ppara->sip_para[11].maj_num = atoi(paraBuf[46]);
|
|
ppara->sip_para[11].min_num = atoi(paraBuf[47]);
|
|
|
|
//psip12
|
|
ppara->sip_para[12].channel_num= atoi(paraBuf[48]);
|
|
memcpy(ppara->sip_para[12].sht_name,paraBuf[49],strlen(paraBuf[49]));
|
|
ppara->sip_para[12].maj_num = atoi(paraBuf[50]);
|
|
ppara->sip_para[12].min_num = atoi(paraBuf[51]);
|
|
|
|
log_printf(LOG_INFO, I_USER_CFG,"2.set sht_name=%s\n",ppara->sip_para[0].sht_name);
|
|
log_printf(LOG_INFO, I_USER_CFG,"2.set sht_namelst=%s\n",ppara->sip_para[12].sht_name);
|
|
|
|
#if 1//WEB_MSG_CFG
|
|
msg.type = MSG_WEB_SAVE_PARA;
|
|
msg.need_free = MSG_NO_NEED_FREE;
|
|
msg.wPara = WEB_PSIP;
|
|
msg.lPara = (uint32)ppara;
|
|
msg_send_to_lcd(&msg);
|
|
#endif
|
|
|
|
}
|
|
|
|
int get_tsoip_num(char *pbuf,short bufMaxLen)
|
|
{
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
sprintf(pbuf, "#%d", 1);
|
|
|
|
#if CGI_PRINT
|
|
// printf("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
#endif
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
int get_tsoip_info(char *pbuf,short bufMaxLen)
|
|
{
|
|
S_CGI_STATE_PARA_TSOIP cgi_status_para_tsoip[2];
|
|
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
if(1){
|
|
http_load_status_tsoip(TSOIP_1, &cgi_status_para_tsoip[TSOIP_1]);
|
|
|
|
sprintf(pbuf, "#%d#%d#%d#%d",
|
|
cgi_status_para_tsoip[TSOIP_1].ip_out, // tsoip 1
|
|
cgi_status_para_tsoip[TSOIP_1].ip_out_rate_kbps,
|
|
cgi_status_para_tsoip[TSOIP_1].asi_out,
|
|
cgi_status_para_tsoip[TSOIP_1].asi_out_rate_kbps);
|
|
|
|
//PR("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
int get_tsoip_systs1(char *pbuf, short bufMaxLen)
|
|
{
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
S_TSOIP_CONFIG_PARA *pnet = &ip2ts[TSOIP_1].tsoip_config_para;
|
|
|
|
sprintf(pbuf, "#%d#%d#%d#%d#%d#%d#94:40:A2:%02X:%02X:%02X#%d#%d#%d#%d#%d#%d#%d#%d#%d#%d#%d#%d#%d",
|
|
pnet->ip[0],
|
|
(pnet->ip[1]<<16)|(pnet->ip[2]<<8)|pnet->ip[3],
|
|
pnet->gateway[0],
|
|
(pnet->gateway[1]<<16)|(pnet->gateway[2]<<8)|pnet->gateway[3],
|
|
pnet->mask[0],
|
|
(pnet->mask[1]<<16)|(pnet->mask[2]<<8)|pnet->mask[3],
|
|
pnet->mac[0],pnet->mac[1],pnet->mac[2],
|
|
pnet->multi_address[0],
|
|
(pnet->multi_address[1]<<16)|(pnet->multi_address[2]<<8)|pnet->multi_address[3],
|
|
pnet->port,
|
|
((pnet->udp_rtp&0xff)<<16)|((pnet->packet_len&0xff)<<8)|(pnet->receive_type&0xff),
|
|
pnet->fec,
|
|
pnet->delay,
|
|
pnet->col,
|
|
pnet->row,
|
|
pnet->dest_ip[0],
|
|
(pnet->dest_ip[1]<<16)|(pnet->dest_ip[2]<<8)|pnet->dest_ip[3],
|
|
pnet->dest_port,
|
|
pnet->phy_type,
|
|
pnet->sfn_mfn_sel
|
|
|
|
);
|
|
|
|
#if CGI_PRINT
|
|
//printf("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
#endif
|
|
return 0;
|
|
}
|
|
int get_log_file(char *pbuf,short bufMaxLen)
|
|
{
|
|
int ret = 0;
|
|
if( !pbuf || bufMaxLen == 0)
|
|
return -1;
|
|
|
|
log_printf(LOG_INFO, I_USER_CFG, "web shell cmd log-output ret=%d\n",ret);
|
|
ret = pox_system(OUTPUT_LOG_FILE_SHELL);
|
|
if(ret<0){
|
|
log_printf(LOG_ERR, I_NOUSED, "get log cmdshell failed\n");
|
|
}
|
|
sprintf(pbuf,"#999");
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
int set_tsoip_systs1(char *pbuf,short bufMaxLen)
|
|
{
|
|
S_TSOIP_CONFIG_PARA *ppara = NULL;
|
|
int paraNum = 0;
|
|
int i = 0;
|
|
MSG msg;
|
|
|
|
|
|
if( !pbuf || bufMaxLen == 0)
|
|
return -1;
|
|
|
|
if(atsc_para.system_para.ctrl==CTRL_LOCAL)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
log_printf(LOG_INFO, I_USER_CFG, "pbuf=%s\n",pbuf);
|
|
|
|
ppara = malloc((size_t)sizeof(S_TSOIP_CONFIG_PARA));
|
|
if(ppara == NULL){
|
|
printf("[%s] malloc ppara memory failed\n", __FUNCTION__);
|
|
return -1;
|
|
}
|
|
|
|
http_load_default_para(CGI_CTTB_WEB_TS2IP_1, ppara);
|
|
|
|
paraNum = splitStrPara(pbuf, paraBuf);
|
|
|
|
ppara->multi_address[0] = atoi(paraBuf[i++]);
|
|
ppara->multi_address[1] = atoi(paraBuf[i++]);
|
|
ppara->multi_address[2] = atoi(paraBuf[i++]);
|
|
ppara->multi_address[3] = atoi(paraBuf[i++]);
|
|
ppara->port = atoi(paraBuf[i++]);
|
|
ppara->udp_rtp = atoi(paraBuf[i++]);
|
|
ppara->packet_len = atoi(paraBuf[i++]);
|
|
ppara->receive_type = atoi(paraBuf[i++]);
|
|
|
|
ppara->fec = atoi(paraBuf[i++]);
|
|
ppara->delay = atoi(paraBuf[i++]);
|
|
ppara->row = atoi(paraBuf[i++]);
|
|
ppara->col = atoi(paraBuf[i++]);
|
|
ppara->sfn_mfn_sel = atoi(paraBuf[i++]);
|
|
|
|
|
|
|
|
msg.type = MSG_WEB_SAVE_PARA;//CGI_CTTB_WEB_TS2IP_1
|
|
msg.need_free = MSG_NO_NEED_FREE;
|
|
msg.lPara = (uint32)ppara;
|
|
msg.wPara = WEB_TS2IP1;//TSOIP_1_ETH_INDEX
|
|
msg_send_to_lcd(&msg);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int set_tsoip_net1(char *pbuf,short bufMaxLen)
|
|
{
|
|
S_TSOIP_CONFIG_PARA *ppara = NULL;
|
|
int paraNum = 0;
|
|
int i = 0;
|
|
MSG msg;
|
|
|
|
|
|
if( !pbuf || bufMaxLen == 0)
|
|
return -1;
|
|
|
|
if(atsc_para.system_para.ctrl==CTRL_LOCAL)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
log_printf(LOG_INFO, I_USER_CFG, "pbuf=%s\n",pbuf);
|
|
|
|
ppara = malloc((size_t)sizeof(S_TSOIP_CONFIG_PARA));// free at msg recv
|
|
if(ppara == NULL){
|
|
log_printf(LOG_ERR, I_USER_CFG,"malloc ppara memory failed\n");
|
|
return -1;
|
|
}
|
|
|
|
http_load_default_para(CGI_CTTB_WEB_TS2IP_1, ppara);
|
|
|
|
|
|
paraNum = splitStrPara(pbuf, paraBuf);
|
|
|
|
ppara->ip[0] = atoi(paraBuf[i++]);
|
|
ppara->ip[1] = atoi(paraBuf[i++]);
|
|
ppara->ip[2] = atoi(paraBuf[i++]);
|
|
ppara->ip[3] = atoi(paraBuf[i++]);
|
|
|
|
ppara->gateway[0] = atoi(paraBuf[i++]);
|
|
ppara->gateway[1] = atoi(paraBuf[i++]);
|
|
ppara->gateway[2] = atoi(paraBuf[i++]);
|
|
ppara->gateway[3] = atoi(paraBuf[i++]);
|
|
|
|
ppara->mask[0] = atoi(paraBuf[i++]);
|
|
ppara->mask[1] = atoi(paraBuf[i++]);
|
|
ppara->mask[2] = atoi(paraBuf[i++]);
|
|
ppara->mask[3] = atoi(paraBuf[i++]);
|
|
|
|
ppara->phy_type = atoi(paraBuf[i++]);
|
|
|
|
msg.type = MSG_WEB_SAVE_PARA;
|
|
msg.need_free = MSG_NO_NEED_FREE;
|
|
msg.lPara = (uint32)ppara;
|
|
msg.wPara = WEB_TS2IP1;
|
|
msg_send_to_lcd(&msg);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
void tst_func_for_web()
|
|
{
|
|
#if 0
|
|
char buf[1024]={0};
|
|
|
|
printf("ready to state\n");
|
|
get_sys_status(buf, 1024);
|
|
|
|
//ok
|
|
//printf("ready to version\n");
|
|
//get_sys_version(buf, 1024);
|
|
|
|
//printf("ready to gps\n");
|
|
//get_state_gps(buf, 1024);
|
|
|
|
//ok
|
|
//printf("ready to pac\n");
|
|
//get_state_pac(buf, 1024);
|
|
|
|
//ok
|
|
//printf("ready to mac_sn\n");
|
|
//get_state_mac_sn(buf, 1024);
|
|
|
|
printf("end tst_func_for_web\n");
|
|
#endif
|
|
}
|
|
|
|
#endif//__get_webc__
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------
|
|
|
|
#define __set_webc__ 1
|
|
|
|
#if __set_webc__
|
|
|
|
int start_upgrade(char *value,short maxlen)
|
|
{
|
|
if(atsc_para.system_para.ctrl==CTRL_LOCAL)
|
|
{
|
|
return 0;
|
|
}
|
|
log_printf(LOG_INFO, I_USER_CFG, "get upgrade cmd form web.\n");
|
|
set_upgrade_flg(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif//__set_webc__
|
|
|
|
int get_license(char *pbuf,short bufMaxLen)
|
|
{
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
S_SN_PARA tmpsn;
|
|
memcpy(&tmpsn, &atsc_para.sn_para, sizeof(S_SN_PARA));
|
|
|
|
sprintf(pbuf, "#%d#%d#%d#%d",
|
|
0,//tmpsn.gui_key_valid,
|
|
tmpsn.psip_key_valid,
|
|
0,//tmpsn.tsoip_key_valid,
|
|
tmpsn.eas_key_valid);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int get_atsc1_sytem_key(char *pbuf,short bufMaxLen)
|
|
{
|
|
S_SN_PARA cgi_key;
|
|
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
http_load_atsc_sytem_key(&cgi_key);
|
|
|
|
sprintf(pbuf, "#%lu#%lu#%lu",
|
|
cgi_key.eas_key,
|
|
0,//cgi_key.tsoip_key,
|
|
cgi_key.psip_key
|
|
);
|
|
|
|
return 0;
|
|
}
|
|
|
|
#if 1
|
|
|
|
|
|
void ntp_manual_sync(void)
|
|
{
|
|
if(atsc_para.system_para.ntp_switch==1){
|
|
printf("manual ntp sync restart_ntp_server start\n");
|
|
system(SH_RESTART_NTP_SERVER_CMD);
|
|
printf("manual ntp sync restart_ntp_server end\n");
|
|
}
|
|
}
|
|
|
|
// /etc/chrony.conf
|
|
// server 114.67.237.130 iburst
|
|
int set_ntp_server_ip_to_system(u8 *pip, u8 ntp_switch, u8 only_manual_sync)
|
|
{
|
|
char buf[100]={0};
|
|
int ret = 0;
|
|
char msg[20];
|
|
|
|
if(only_manual_sync==1){
|
|
if(ntp_switch){
|
|
printf("web trigger manual sync \n");
|
|
atsc_para.log_para.ntp_manual_sync = 1;
|
|
}
|
|
}
|
|
else{
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
sprintf(buf, "sed -i.bak '/server/d' /etc/chrony.conf");
|
|
system(buf);
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
sprintf(buf, "sed -i '2i server %d.%d.%d.%d iburst' /etc/chrony.conf",
|
|
pip[0],pip[1],pip[2],pip[3]);
|
|
system(buf);
|
|
|
|
if(ntp_switch){
|
|
system(SH_RESTART_NTP_SERVER_CMD);
|
|
printf("restart_ntp_server\n");
|
|
}
|
|
else{
|
|
system("killall chronyd");
|
|
printf("kill_ntp_server\n");
|
|
}
|
|
printf("set_ntp_server_ip_to_system finished! %d\n", ret);
|
|
}
|
|
|
|
atsc_para.log_para.ntp_ip_chg_flg = 1;
|
|
atsc_para.log_para.ntp_sync_delay = 10;
|
|
}
|
|
|
|
int set_ntp_server(char *pbuf, short bufMaxLen)
|
|
{
|
|
int paraNum = 0;
|
|
int i = 0;
|
|
int ret = 0;
|
|
|
|
uint8 ntp_ser_ip[4]={0};
|
|
uint8 *pip = ntp_ser_ip;
|
|
uint8 ntp_switch;
|
|
uint8 change_flg = 0;
|
|
uint8 ntp_manual_sync=0;
|
|
|
|
if( !pbuf || bufMaxLen <= 0)
|
|
return -1;
|
|
|
|
if(atsc_para.system_para.ctrl==CTRL_LOCAL) {
|
|
return 0;
|
|
}
|
|
log_printf(LOG_INFO, I_USER_CFG, "web set %s\n", pbuf);
|
|
|
|
|
|
memcpy(ntp_ser_ip, atsc_para.system_para.ntp_ip, 4);
|
|
|
|
paraNum = splitStrPara(pbuf,paraBuf);
|
|
|
|
pip[0] = (uint8)atoi(paraBuf[i++]);
|
|
pip[1] = (uint8)atoi(paraBuf[i++]);
|
|
pip[2] = (uint8)atoi(paraBuf[i++]);
|
|
pip[3] = (uint8)atoi(paraBuf[i++]);
|
|
ntp_switch = (uint8)atoi(paraBuf[i++]);
|
|
ntp_manual_sync = (uint8)atoi(paraBuf[i++]);
|
|
|
|
printf("web ip=%d.%d.%d.%d sw=%d manual_sync=%d\n",
|
|
pip[0],pip[1],pip[2],pip[3], ntp_switch,ntp_manual_sync
|
|
);
|
|
|
|
change_flg = 0;
|
|
|
|
if(ntp_manual_sync==0){
|
|
if(ntp_switch!=atsc_para.system_para.ntp_switch){
|
|
atsc_para.system_para.ntp_switch = ntp_switch;
|
|
c256_bytewrite(EEPROM_NTP_SWITCH, atsc_para.system_para.ntp_switch);
|
|
change_flg=1;
|
|
}
|
|
|
|
ret = memcmp(atsc_para.system_para.ntp_ip, pip, sizeof(atsc_para.system_para.ntp_ip));
|
|
if(ret!=0){
|
|
memcpy(atsc_para.system_para.ntp_ip, pip, sizeof(atsc_para.system_para.ntp_ip));
|
|
c256_bytewrite(EEPROM_NTP_SERVER_IP, atsc_para.system_para.ntp_ip[0]);
|
|
c256_bytewrite(EEPROM_NTP_SERVER_IP+1, atsc_para.system_para.ntp_ip[1]);
|
|
c256_bytewrite(EEPROM_NTP_SERVER_IP+2, atsc_para.system_para.ntp_ip[2]);
|
|
c256_bytewrite(EEPROM_NTP_SERVER_IP+3, atsc_para.system_para.ntp_ip[3]);
|
|
change_flg = 1;
|
|
}
|
|
|
|
if(change_flg){
|
|
set_ntp_server_ip_to_system(atsc_para.system_para.ntp_ip, atsc_para.system_para.ntp_switch, 0);
|
|
}
|
|
}
|
|
else{
|
|
if(atsc_para.system_para.ntp_switch==1){
|
|
set_ntp_server_ip_to_system(atsc_para.system_para.ntp_ip, atsc_para.system_para.ntp_switch, 1);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
int get_ntp_server(char *pbuf,short bufMaxLen)
|
|
{
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
uint8 *pip = &atsc_para.system_para.ntp_ip[0];
|
|
|
|
sprintf(pbuf, "#%d#%d#%d#%d#%d#%d",
|
|
pip[0],
|
|
pip[1],
|
|
pip[2],
|
|
pip[3],
|
|
atsc_para.system_para.ntp_switch,
|
|
atsc_para.log_para.ntp_state
|
|
);
|
|
|
|
//PR("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int set_timezone(char *pbuf, short bufMaxLen)
|
|
{
|
|
int paraNum = 0;
|
|
int i;
|
|
int8 timezone_timeoffset;
|
|
|
|
if( !pbuf || bufMaxLen <= 0)
|
|
return -1;
|
|
|
|
if(atsc_para.system_para.ctrl==CTRL_LOCAL) {
|
|
return 0;
|
|
}
|
|
log_printf(LOG_INFO, I_USER_CFG, "web set %s\n", pbuf);
|
|
|
|
|
|
paraNum = splitStrPara(pbuf,paraBuf);
|
|
|
|
timezone_timeoffset = (int8)atoi(paraBuf[i++]);
|
|
|
|
if((timezone_timeoffset>=-12&&timezone_timeoffset<=12) &&atsc_para.wj_para.gmt!=timezone_timeoffset){
|
|
atsc_para.wj_para.gmt = timezone_timeoffset;
|
|
c256_bytewrite(EEPROM_WJ_ADDR,timezone_timeoffset);
|
|
printf("web set timezone_offset %d\n", timezone_timeoffset);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
int get_timezone(char *pbuf,short bufMaxLen)
|
|
{
|
|
if( !pbuf )
|
|
return -1;
|
|
|
|
int16 timezone_offset = atsc_para.wj_para.gmt;
|
|
|
|
sprintf(pbuf, "#%d",
|
|
timezone_offset);
|
|
|
|
//PR("[%s,%d] %s\n", __FUNCTION__,__LINE__,pbuf);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void check_ntp_sync_state(void)
|
|
{
|
|
char msg[100];
|
|
int ret;
|
|
int sync_state;
|
|
static u8 old_sync_state = 0;
|
|
static int stc_cnt=0;
|
|
|
|
stc_cnt++;
|
|
|
|
//printf("\nrdy to check ntp_sync %d\n", stc_cnt);
|
|
memset(msg,0,sizeof(msg));
|
|
|
|
ret = executeCMD(SH_CHECK_NTP_SYNC_CMD, msg, sizeof(msg));
|
|
if(ret==0){
|
|
sync_state = atoi(msg);
|
|
printf("check check_ntp_sync_state %d\n", sync_state);
|
|
}
|
|
else{
|
|
sync_state = 0;
|
|
}
|
|
|
|
atsc_para.log_para.ntp_state = sync_state;
|
|
|
|
if(atsc_para.log_para.ntp_state_last!=atsc_para.log_para.ntp_state){
|
|
printf("ntp_sync_changed %d->%d\n", atsc_para.log_para.ntp_state_last, atsc_para.log_para.ntp_state);
|
|
/*if(atsc_para.log_para.ntp_state_last==0 && atsc_para.log_para.ntp_state==1){
|
|
atsc_para.state.sync_time_snd_cnt = 0;
|
|
}*/
|
|
}
|
|
atsc_para.log_para.ntp_state_last = atsc_para.log_para.ntp_state;
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
void http_load_atsc_sytem_key(S_SN_PARA *pkey)
|
|
{
|
|
memcpy(pkey, &atsc_para.sn_para, sizeof(atsc_para.sn_para));
|
|
}
|
|
|
|
int hex_to_u32(const char *key_buf, uint32 *out) {
|
|
char *end;
|
|
errno = 0;
|
|
|
|
unsigned long val = strtoul(key_buf, &end, 16);
|
|
|
|
if (errno != 0 || *end != '\0' || val > UINT32_MAX) {
|
|
return -1; // 失败
|
|
}
|
|
|
|
*out = (uint32)val;
|
|
return 0; // 成功
|
|
}
|
|
|
|
|
|
|
|
void save_lckey_para(void *psave)
|
|
{
|
|
S_SN_PARA *ppara = (S_SN_PARA *)psave;
|
|
e2rom_save_sn(ppara);
|
|
memcpy(&atsc_para.sn_para,ppara,sizeof(atsc_para.sn_para));
|
|
}
|
|
|
|
void load_usr_name_passwd(S_USER_INFO *ppara)
|
|
{
|
|
memcpy(ppara, &atsc_para.reg_user_info[0], sizeof(S_USER_INFO));
|
|
}
|
|
|
|
int is_valid_str(const char *s) {
|
|
if (s == NULL || strlen(s) == 0)
|
|
return 0;
|
|
while (*s) {
|
|
if (!isprint(*s)) return 0;
|
|
s++;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int set_usr_name_passwd(char *pbuf,short bufMaxLen)
|
|
{
|
|
S_USER_INFO usr_para={0};
|
|
S_USER_INFO *ppara = &usr_para;
|
|
uint32 u32_value = 0;
|
|
int paraNum = 0;
|
|
int i = 0;
|
|
int ret;
|
|
int chg_flg=0;
|
|
|
|
|
|
log_printf(LOG_INFO, I_USER_CFG,"%s\n", pbuf);
|
|
|
|
if( !pbuf || bufMaxLen == 0)
|
|
return -1;
|
|
|
|
/*if(atsc_para.system_para.ctrl==CTRL_LOCAL) {
|
|
return 0;
|
|
}*/
|
|
|
|
load_usr_name_passwd(ppara);
|
|
|
|
paraNum = splitStrPara(pbuf, paraBuf);
|
|
|
|
char cur_usr_len=strlen(paraBuf[0]);
|
|
char new_usr_len=strlen(paraBuf[1]);
|
|
char new_pass_len=strlen(paraBuf[2]);
|
|
|
|
if((cur_usr_len>0 && cur_usr_len<=16) && (new_usr_len>0 && new_usr_len<=16)&& (new_pass_len>0 && new_pass_len<=16)){
|
|
if(is_valid_str(paraBuf[1]) && is_valid_str(paraBuf[2])){
|
|
|
|
printf("input: %s %s %s\n", paraBuf[0], paraBuf[1], paraBuf[2]);
|
|
memset(ppara->name,0,MAX_USER_NAME_LEN);
|
|
memcpy(ppara->name, paraBuf[1], new_usr_len);
|
|
|
|
memset(ppara->password,0,MAX_USER_NAME_LEN);
|
|
memcpy(ppara->password, paraBuf[2], new_pass_len);
|
|
|
|
save_user_para(ppara);
|
|
printf("name=%s passwd=%s\n", atsc_para.reg_user_info[0].name, atsc_para.reg_user_info[0].password);
|
|
}
|
|
else{
|
|
printf("cfg not valid!\n");
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
int set_atsc1_sytem_key(char *pbuf,short bufMaxLen)
|
|
{
|
|
S_SN_PARA sn_para;
|
|
S_SN_PARA *ppara = &sn_para;
|
|
uint32 u32_value = 0;
|
|
int paraNum = 0;
|
|
int i = 0;
|
|
int ret;
|
|
int chg_flg=0;
|
|
|
|
log_printf(LOG_INFO, I_USER_CFG,"%s\n", pbuf);
|
|
|
|
if( !pbuf || bufMaxLen == 0)
|
|
return -1;
|
|
|
|
if(atsc_para.system_para.ctrl==CTRL_LOCAL) {
|
|
return 0;
|
|
}
|
|
|
|
http_load_atsc_sytem_key(ppara);
|
|
|
|
paraNum = splitStrPara(pbuf, paraBuf);
|
|
|
|
if(strlen(paraBuf[0])>0 && strlen(paraBuf[1])>0 && strlen(paraBuf[2])>0){
|
|
|
|
ret = hex_to_u32(paraBuf[0], &u32_value);
|
|
if(ret==0){
|
|
if(ppara->eas_key != u32_value)
|
|
chg_flg = 1;
|
|
ppara->eas_key = u32_value;
|
|
}
|
|
/*ret = hex_to_u32(paraBuf[1], &u32_value);
|
|
if(ret==0){
|
|
if(ppara->tsoip_key != u32_value)
|
|
chg_flg = 1;
|
|
ppara->tsoip_key = u32_value;
|
|
}*/
|
|
ret = hex_to_u32(paraBuf[2], &u32_value);
|
|
if(ret==0){
|
|
if(ppara->psip_key != u32_value)
|
|
chg_flg = 1;
|
|
ppara->psip_key = u32_value;
|
|
}
|
|
if(chg_flg){
|
|
save_lckey_para(ppara);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//-------------------------------------------
|
|
|
|
#define __usr_confirm_webc__ 1
|
|
|
|
#if __usr_confirm_webc__
|
|
|
|
|
|
struct cgi_func_list svr_func_table[] =
|
|
{
|
|
/* upgrade sys */
|
|
{WEB_UPGRADE, function_vod, start_upgrade},
|
|
|
|
/* sysstatus */
|
|
{CGIKEY_SYS_STATUS, get_sys_status, NULL},
|
|
{CGIKEY_SYS_VER, get_sys_version, NULL},
|
|
|
|
{CGIKEY_STATUS_TUNER, get_state_tuner, NULL},
|
|
{CGIKEY_STATUS_PAC, get_state_pac, NULL},
|
|
{CGIKEY_STATUS_GPS, get_state_gps, NULL},
|
|
{CGIKEY_STATUS_MAC_SN, get_state_mac_sn, NULL},
|
|
|
|
|
|
/* sys cfg */
|
|
{CGIKEY_SYS_CFG, get_sys_cfg, set_sys_cfg},
|
|
{CGIKEY_SYS_NET, get_sys_net, set_sys_net},
|
|
{CGIKEY_SYS_DPD_STATE, get_sys_dpd_state, NULL},
|
|
{CGIKEY_SYS_RST, NULL, set_sys_rst},
|
|
{CGIKEY_SYS_TIME, get_systime, set_systime},
|
|
|
|
|
|
/* RF cfg */
|
|
{CGIKEY_RF_CFG, get_rf_cfg, set_rf_cfg},
|
|
|
|
/* 10 MHz reference output enable (PR07) */
|
|
{CGIKEY_M10_CFG, get_m10_cfg, set_m10_cfg},
|
|
{CGIKEY_SPEC_CFG, get_spec_cfg, set_spec_cfg},
|
|
|
|
/* tsid psip */
|
|
{CGIKEY_TSID_PSIP, get_tsid_psip, set_tsid_psip},
|
|
{CGIKEY_TSID_PSIP_CFG, NULL, set_tsid_psip_cfg},
|
|
|
|
/* tsoip */
|
|
{CGIKEY_TSOIP_NUM, get_tsoip_num, NULL},
|
|
{CGIKEY_TSOIP_INFO, get_tsoip_info, NULL},
|
|
{CGIKEY_TSOIP_SYSTS1, get_tsoip_systs1, set_tsoip_systs1},
|
|
{CGIKEY_TSOIP_NET1, NULL, set_tsoip_net1},
|
|
|
|
{LOG_FILE_OUTPUT, get_log_file, NULL},
|
|
{CGIKEY_WEB_TITLE, get_web_title, NULL},
|
|
#if 0
|
|
|
|
/* Mode cfg */
|
|
{CGIKEY_MODE_MFN_CFG, get_mode_mfn_cfg, set_mode_mfn_cfg},
|
|
{CGIKEY_MODE_SFN_CFG, get_mode_sfn_cfg, set_mode_sfn_cfg},
|
|
#endif
|
|
{CGIKEY_ATSC1_LICENCES, get_license, NULL},
|
|
{CGIKEY_ATSC1_SYSTEM_KEY, get_atsc1_sytem_key, set_atsc1_sytem_key},
|
|
{CGIKEY_SYS_NTP, get_ntp_server, set_ntp_server},
|
|
{CGIKEY_SYS_TIMEZONE, get_timezone, set_timezone},
|
|
|
|
{CGIKEY_CFG_USR_PASSWD, NULL, set_usr_name_passwd},
|
|
|
|
{END_KEY, NULL, NULL}
|
|
};
|
|
|
|
|
|
|
|
cgi_func_list *socketDataParse(uint16 keyNum)
|
|
{
|
|
struct cgi_key_list *node = NULL;
|
|
struct cgi_func_list *pTable = svr_func_table;
|
|
|
|
if( !keyNum )
|
|
return NULL;
|
|
|
|
for(pTable=svr_func_table; pTable->keyNum!=END_KEY; pTable++)//pTable->keyNum!=END_KEY
|
|
{
|
|
if(pTable->keyNum==keyNum)//(!strcmp(pTable->key,key))
|
|
{
|
|
return pTable;
|
|
}
|
|
}
|
|
log_printf(LOG_DEBUG,I_NOUSED,"end of key list,return.\n");
|
|
return pTable;
|
|
}
|
|
|
|
|
|
int socketServer(void)
|
|
{
|
|
int port = TCP_SOCKET_SERVER_PORT;
|
|
struct sockaddr_in sin;
|
|
struct sockaddr_in pin;
|
|
int sock_fp;
|
|
int temp_sock_fp=-1;
|
|
int iCnt=0;
|
|
int runing=1;
|
|
int size_of_addr;
|
|
char *msg="hello internet!";
|
|
struct cgi_func_list *pTable=NULL;
|
|
|
|
msg_t msg_client;
|
|
msg_t msg_server;
|
|
|
|
st_CGI_SOCK_PKG msg_client_pkg;
|
|
st_CGI_SOCK_PKG msg_server_pkg;
|
|
|
|
char replyFlg=0;
|
|
|
|
int minCnt;
|
|
int bkp_minCnt=-1;
|
|
int minCnt2;
|
|
int bkp_minCnt2=-1;
|
|
|
|
/* creat socket */
|
|
sock_fp = socket(AF_INET,SOCK_STREAM,0);
|
|
if(sock_fp==-1){
|
|
log_printf(LOG_ERR, I_NOUSED, "socket fail\n");
|
|
return -1;
|
|
}
|
|
|
|
int on=1;
|
|
int s = setsockopt(sock_fp,SOL_SOCKET,SO_REUSEADDR,&on,sizeof(on));
|
|
if(s<0){
|
|
log_printf(LOG_ERR, I_NOUSED, "setsockopt err.\n");
|
|
}
|
|
|
|
bzero(&sin,sizeof(sin));
|
|
sin.sin_family = AF_INET;
|
|
sin.sin_addr.s_addr= INADDR_ANY;
|
|
sin.sin_port = htons(port);
|
|
|
|
if(bind(sock_fp,(struct sockaddr *)&sin,sizeof(sin))==-1){
|
|
log_printf(LOG_ERR, I_NOUSED, ">=========================\n");
|
|
log_printf(LOG_ERR, I_NOUSED, "socket server bind fail\n");
|
|
log_printf(LOG_ERR, I_NOUSED, "errno=%d, Mesg=%s\n", errno, strerror(errno));
|
|
log_printf(LOG_ERR, I_NOUSED, "<=========================\n");
|
|
close(sock_fp);
|
|
return -1;
|
|
}
|
|
if(listen(sock_fp,20)==-1){
|
|
log_printf(LOG_ERR, I_NOUSED, "socket server listen fail.\n");
|
|
close(sock_fp);
|
|
return -1;
|
|
}
|
|
|
|
log_printf(LOG_INFO, I_SYS_STATUS, "imxWebServer Ready to accept.\n");
|
|
|
|
while(runing)
|
|
{
|
|
iCnt++;
|
|
|
|
/* block untill client connected */
|
|
temp_sock_fp=accept(sock_fp,(struct sockaddr *)&pin,&size_of_addr);
|
|
if(temp_sock_fp==-1)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if(recv(temp_sock_fp,&msg_client_pkg,sizeof(msg_client_pkg),0)==-1)
|
|
{
|
|
close(temp_sock_fp);
|
|
continue;
|
|
}
|
|
|
|
/* parse */
|
|
switch(msg_client_pkg.method)//switch(msg_client.msgtype)
|
|
{
|
|
case GET_METHOD://get
|
|
pTable=socketDataParse(msg_client_pkg.keyType);
|
|
if(pTable->get_func)
|
|
{
|
|
memset(sendValBuf, 0, sizeof(sendValBuf));
|
|
pTable->get_func(sendValBuf,1024);
|
|
memcpy((void *)&msg_server_pkg,(void *)&msg_client_pkg,sizeof(st_CGI_SOCK_PKG));
|
|
memset((void *)&msg_server_pkg.data,0,sizeof(msg_server_pkg.data));
|
|
replyFlg = 1;
|
|
}
|
|
break;
|
|
|
|
case SET_METHOD://set
|
|
pTable=socketDataParse(msg_client_pkg.keyType);
|
|
if(pTable->set_func && strlen(msg_client_pkg.data))
|
|
{
|
|
//printf("===set_func run.\n");
|
|
memset(recvValBuf, 0, sizeof(recvValBuf));
|
|
memcpy(recvValBuf, msg_client_pkg.data, strlen(msg_client_pkg.data));
|
|
|
|
pTable->set_func(recvValBuf,1024);
|
|
replyFlg = 0;
|
|
}
|
|
break;
|
|
case UPDATE_METHOD://
|
|
break;
|
|
|
|
default:
|
|
log_printf(LOG_INFO, I_SYS_STATUS, "run to default.\n");
|
|
break;
|
|
}
|
|
|
|
|
|
/* reply */
|
|
if(replyFlg)
|
|
{
|
|
replyFlg = 0;
|
|
memcpy(msg_server_pkg.data, sendValBuf, strlen(sendValBuf));
|
|
if(send(temp_sock_fp,&msg_server_pkg,sizeof(st_CGI_SOCK_PKG),0)==-1)
|
|
{
|
|
log_printf(LOG_INFO, I_SYS_STATUS, "reply send failed.\n");
|
|
}
|
|
}
|
|
|
|
close(temp_sock_fp);
|
|
}
|
|
log_printf(LOG_INFO, I_SYS_STATUS, "---out thread---\n");
|
|
sleep(2);
|
|
close(sock_fp);
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
#if ALARM_USE_UDP
|
|
struct sockaddr_in alarm_clientaddr;//sockaddr_in
|
|
int alarm_sockfd;
|
|
#endif
|
|
|
|
|
|
#if ALARM_USE_UDP
|
|
void udp_alarm_init(void)
|
|
{
|
|
alarm_sockfd = socket(AF_INET, SOCK_DGRAM, 0);
|
|
if(alarm_sockfd == -1){
|
|
log_printf(LOG_ERR, I_NOUSED, "[.thr.] udp_alarm_sock_fd socket fail\n");
|
|
}
|
|
memset(&alarm_clientaddr, 0, sizeof(alarm_clientaddr));
|
|
alarm_clientaddr.sin_family = AF_INET;
|
|
alarm_clientaddr.sin_addr.s_addr=*(uint32 *)atsc_para.wk_para.alarm_ip;
|
|
alarm_clientaddr.sin_port = htons(TCP_COMM_PORT);
|
|
//lwip_sendto(alarm_sockfd, (char *)"hello", 5, 0,(struct sockaddr *)&alarm_clientaddr, sizeof(alarm_clientaddr));
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
void *web_thr(void *ppara)
|
|
{
|
|
int ret;
|
|
|
|
log_printf(LOG_INFO, I_SYS_STATUS, "[.thr.] web_thr Start\n");
|
|
|
|
#if ALARM_USE_UDP
|
|
udp_alarm_init();
|
|
#endif
|
|
|
|
while(1)
|
|
{
|
|
/* 该函数内部阻塞 */
|
|
ret = socketServer();
|
|
if(ret < 0){
|
|
log_printf(LOG_ERR, I_NOUSED, "web_thr err, thread exit now!\n");
|
|
return NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif//__usr_confirm_webc__
|