提交SMOD ATSC IMX APP版本 V122
This commit is contained in:
@@ -0,0 +1,708 @@
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h> /* netdb is necessary for struct hostent */
|
||||
|
||||
|
||||
|
||||
#include "../inc/isys_com.h"
|
||||
#include "../inc/isys_config.h"
|
||||
#include "../inc/main.h"
|
||||
#include "../inc/mq.h"
|
||||
#include "../inc/lcd_task.h"
|
||||
#include "../inc/tcp_task.h"
|
||||
#include "../inc/iweb_task.h"
|
||||
#include "../inc/uart_user.h"
|
||||
#include "../inc/tcp_autocal.h"
|
||||
#include "../inc/config.h"
|
||||
#include "../inc/type.h"
|
||||
#include "../inc/dpd_proc.h"
|
||||
#include "../inc/os_task.h"
|
||||
|
||||
#include "../inc/http_get.h"
|
||||
|
||||
|
||||
//#include "http_get.h"
|
||||
#define USE_AUTO_CALIBRATION 1
|
||||
|
||||
#if USE_AUTO_CALIBRATION
|
||||
st_AUTO_CAL_PARA st_autocal;
|
||||
S_AUTOCAL_BASE_PARA acal_base;
|
||||
st_DEV_LINK dev_link;
|
||||
|
||||
#pragma pack(4)
|
||||
static uint8 tcp_input_buf[TCP_AUTOCAL_REMOTE_MAX_REC_LEN] = {0};
|
||||
static uint8 tcp_output_buf[TCP_AUTOCAL_REMOTE_MAX_SEND_LEN] = {0};
|
||||
//static uint8 tcp_pro_buf[TCP_AUTOCAL_REMOTE_MAX_PRO_LEN] = {0};
|
||||
#pragma pack()
|
||||
|
||||
|
||||
extern void udp_trigger_adpc(uint8 adpc);
|
||||
|
||||
//extern S_CTTB_PARA cttb_para;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32 fwd_power;
|
||||
uint32 freq_ch;
|
||||
uint32 band;
|
||||
|
||||
uint32 lmid;
|
||||
uint32 umid;
|
||||
uint32 snr;
|
||||
uint32 adpc;
|
||||
uint32 adpc_err;
|
||||
uint32 rf;
|
||||
|
||||
}S_DEV_EXC_PARA2;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16 ts_in;
|
||||
uint16 ts_state;
|
||||
uint32 ts_rate;
|
||||
uint16 ts_under;
|
||||
uint16 reserved;
|
||||
}S_DEV_AOTD_EXC_PARA;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32 band;
|
||||
uint32 freq_ch;
|
||||
uint32 fwd_power;
|
||||
uint32 adpc;
|
||||
uint32 rf;
|
||||
}S_EXC_SET_PARA2;
|
||||
|
||||
#define NET_BW_6M 0x0c
|
||||
#define NET_BW_7M 0x0b
|
||||
#define NET_BW_8M 0x0a
|
||||
|
||||
|
||||
|
||||
#if 1
|
||||
|
||||
// -10.0dBm -1000
|
||||
int32 conv_exc_power_to_db(uint16 inpow)//放大100被
|
||||
{
|
||||
int32 outpow;
|
||||
uint16 power;
|
||||
power = inpow;
|
||||
//power -25到+5可调 内部值 0-600 0-500 -25~0 500-600 0~5 一个代表0.05db
|
||||
if(inpow >RF_POWER_P_C_ON)
|
||||
inpow = RF_POWER_P_C_ON;
|
||||
inpow = inpow>=RF_POWER_ZERO?(inpow-RF_POWER_ZERO):(RF_POWER_ZERO - inpow);
|
||||
|
||||
outpow = ((uint16)(inpow/20)*100+(inpow%20)*5);
|
||||
|
||||
if(power>RF_POWER_ZERO)outpow=outpow;
|
||||
else outpow=-outpow;
|
||||
|
||||
return outpow;
|
||||
}
|
||||
|
||||
|
||||
uint32 get_check_sum_long(const void *p,uint32 len)
|
||||
{
|
||||
uint32 sum = 0;
|
||||
uint8 *pstr = (uint8*)p;
|
||||
|
||||
while(len--)
|
||||
sum+=*pstr++;
|
||||
return sum;
|
||||
}
|
||||
|
||||
static void* tcp_frame_checkout_pro(const uint8 *pinbuf,const uint32 rec_len,uint32* pret)
|
||||
{
|
||||
S_AUTOCAL_TCP_FRAME *pframe;
|
||||
uint8* pusebuf;
|
||||
uint16 calc_sum;
|
||||
uint16 frame_sum;
|
||||
uint32 i;
|
||||
|
||||
if(rec_len<TCP_AUTOCAL_FRAME_LEN_WITHOUT_DATA)
|
||||
{
|
||||
*pret = TCP_AUTOCAL_ERR_UNKNOW_FRAME;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pusebuf = (uint8*)pinbuf;
|
||||
for(i=0;i<=rec_len-TCP_AUTOCAL_FRAME_LEN_WITHOUT_DATA;i++,pusebuf++)
|
||||
{
|
||||
//非4字节对齐地址,不做处理
|
||||
/*if(((uint32)pusebuf)&3)
|
||||
{
|
||||
continue;
|
||||
}*/
|
||||
pframe = (S_AUTOCAL_TCP_FRAME*)pusebuf;
|
||||
|
||||
if(pframe->header!=TCP_AUTOCAL_FRAME_HEADER)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(pframe->length>=TCP_AUTOCAL_REMOTE_MAX_REC_LEN)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(pframe->length>rec_len)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
//if(pframe->dst_dev_id!=dev_id){
|
||||
// continue;
|
||||
//}
|
||||
//命令类型不为读或写
|
||||
if((pframe->cmd_type&0xfff)>=CMD_TYPE_END)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
//更具体的可到读写函数中再做判断
|
||||
if((pframe->cmd_index>E_READ_DEV_CMD_END)&&(pframe->cmd_index>E_WRITE_DEV_CMD_END))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
//小端序,低字节在前,高字节在后
|
||||
calc_sum = get_check_sum_long(pinbuf,pframe->length-TCP_AUTOCAL_FRAME_NOT_SUM_LEN);
|
||||
frame_sum = (pinbuf[pframe->length-4])|(pinbuf[pframe->length-3]<<8);
|
||||
if(calc_sum!=frame_sum)
|
||||
{
|
||||
*pret = TCP_AUTOCAL_ERR_CHECK_SUM;
|
||||
return pframe;
|
||||
}
|
||||
if( ((pinbuf[pframe->length-2])|(pinbuf[pframe->length-1]<<8))!=TCP_AUTOCAL_FRAME_TAIL)
|
||||
{
|
||||
*pret = TCP_AUTOCAL_ERR_FRAME_FORAMT;
|
||||
return pframe;
|
||||
}
|
||||
*pret = TCP_AUTOCAL_ERR_NONE;
|
||||
return pframe;
|
||||
}
|
||||
*pret = TCP_AUTOCAL_ERR_FRAME_FORAMT;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void tcp_frame_sum_tail(uint8* pout,uint32 frame_len)
|
||||
{
|
||||
uint16 calc_sum = 0;
|
||||
|
||||
calc_sum = get_check_sum_long(pout,frame_len-TCP_AUTOCAL_FRAME_NOT_SUM_LEN);
|
||||
|
||||
pout[frame_len-4] = calc_sum;
|
||||
pout[frame_len-3] = calc_sum>>8;
|
||||
pout[frame_len-2] = (uint8)TCP_AUTOCAL_FRAME_TAIL;
|
||||
pout[frame_len-1] = TCP_AUTOCAL_FRAME_TAIL>>8;
|
||||
}
|
||||
|
||||
static uint32 tcp_frame_ret_err_pro2(S_AUTOCAL_TCP_FRAME* pinframe,S_AUTOCAL_TCP_FRAME* poutframe,uint32 err_code,uint16 dev_type)
|
||||
{
|
||||
if(pinframe==NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
poutframe->header = TCP_AUTOCAL_FRAME_HEADER;
|
||||
poutframe->length = TCP_AUTOCAL_FRAME_LEN_WITHOUT_DATA+4;
|
||||
|
||||
if(dev_type==DEV_METER_ID){
|
||||
poutframe->src_dev_id = DEV_METER_ID;
|
||||
poutframe->dst_dev_id = DEV_REMOTE_PC_ID;
|
||||
}
|
||||
else if(dev_type==DEV_PA_ID){
|
||||
poutframe->src_dev_id = DEV_PA_ID;
|
||||
poutframe->dst_dev_id = DEV_REMOTE_PC_ID;
|
||||
}
|
||||
else if(dev_type==DEV_EXCITER_ID){
|
||||
poutframe->src_dev_id = DEV_EXCITER_ID;
|
||||
poutframe->dst_dev_id = DEV_REMOTE_PC_ID;
|
||||
}
|
||||
|
||||
poutframe->data[0] = err_code;
|
||||
poutframe->cmd_type = (pinframe->cmd_type&0xfff)|TCP_AUTOCAL_RET_TYPE_RET|TCP_AUTOCAL_FRAME_ERR;
|
||||
poutframe->cmd_index = pinframe->cmd_index;
|
||||
tcp_frame_sum_tail((uint8*)poutframe,poutframe->length);
|
||||
|
||||
return poutframe->length;
|
||||
}
|
||||
|
||||
|
||||
static uint32 tcp_frame_ret_ok_pro2(S_AUTOCAL_TCP_FRAME* pinframe,S_AUTOCAL_TCP_FRAME* poutframe,uint32 data_len,uint16 dev_type)
|
||||
{
|
||||
if((pinframe==NULL)||(poutframe==NULL))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
poutframe->header = TCP_AUTOCAL_FRAME_HEADER;
|
||||
poutframe->length = TCP_AUTOCAL_FRAME_LEN_WITHOUT_DATA+data_len;
|
||||
|
||||
if(dev_type==DEV_METER_ID){
|
||||
poutframe->src_dev_id = DEV_METER_ID;
|
||||
poutframe->dst_dev_id = DEV_REMOTE_PC_ID;
|
||||
}
|
||||
else if(dev_type==DEV_PA_ID){
|
||||
poutframe->src_dev_id = DEV_PA_ID;
|
||||
poutframe->dst_dev_id = DEV_REMOTE_PC_ID;
|
||||
}
|
||||
else if(dev_type==DEV_EXCITER_ID){
|
||||
poutframe->src_dev_id = DEV_EXCITER_ID;
|
||||
poutframe->dst_dev_id = DEV_REMOTE_PC_ID;
|
||||
}
|
||||
|
||||
poutframe->cmd_type = (pinframe->cmd_type&0x7fff)|TCP_AUTOCAL_RET_TYPE_RET;
|
||||
poutframe->cmd_index = pinframe->cmd_index;
|
||||
|
||||
tcp_frame_sum_tail((uint8*)poutframe,poutframe->length);
|
||||
|
||||
return poutframe->length;
|
||||
}
|
||||
|
||||
static uint32 tcp_read_aodt_exc_para(S_AUTOCAL_TCP_FRAME* pinframe,uint8* poutbuf)
|
||||
{
|
||||
S_AUTOCAL_TCP_FRAME *poutframe = (S_AUTOCAL_TCP_FRAME*)poutbuf;
|
||||
S_DEV_AOTD_EXC_PARA *pinfo = (S_DEV_AOTD_EXC_PARA*)poutframe->data;
|
||||
|
||||
uint16 total_cur=0;
|
||||
int32 loc_db;
|
||||
|
||||
S_ATSC_PARA *pSysPara = &atsc_para;
|
||||
|
||||
memset(pinfo,0,sizeof(S_DEV_AOTD_EXC_PARA));
|
||||
|
||||
pinfo->ts_in = pSysPara->log_para.asi_input;
|
||||
pinfo->ts_state = pSysPara->log_para.input_ok_flag;
|
||||
pinfo->ts_rate = pSysPara->log_para.ts_rate;
|
||||
|
||||
pinfo->ts_under = (pSysPara->log_para.ts_under&0x1);
|
||||
pinfo->reserved = 0;
|
||||
|
||||
return tcp_frame_ret_ok_pro2(pinframe,poutframe,sizeof(S_DEV_AOTD_EXC_PARA),DEV_EXCITER_ID);
|
||||
}
|
||||
|
||||
static uint32 tcp_read_exc_para2(S_AUTOCAL_TCP_FRAME* pinframe,uint8* poutbuf)
|
||||
{
|
||||
S_AUTOCAL_TCP_FRAME *poutframe = (S_AUTOCAL_TCP_FRAME*)poutbuf;
|
||||
S_DEV_EXC_PARA2 *pinfo = (S_DEV_EXC_PARA2*)poutframe->data;
|
||||
uint16 total_cur=0;
|
||||
int32 loc_db;
|
||||
|
||||
S_ATSC_PARA *pSysPara = &atsc_para;
|
||||
|
||||
memset(pinfo,0,sizeof(S_DEV_EXC_PARA2));
|
||||
|
||||
loc_db = conv_exc_power_to_db(pSysPara->rf_para.power);//cttb_para.rf_para.power
|
||||
|
||||
pinfo->fwd_power = loc_db;
|
||||
pinfo->freq_ch = pSysPara->rf_para.txfreq; //cttb_para.rf_para.txfreq;
|
||||
pinfo->band = NET_BW_6M;
|
||||
|
||||
/*if(cttb_para.system_para.baud_width==BW_8M)
|
||||
pinfo->band = NET_BW_8M;
|
||||
else if(cttb_para.system_para.baud_width==BW_7M)
|
||||
pinfo->band = NET_BW_7M;
|
||||
else if(cttb_para.system_para.baud_width==BW_6M)
|
||||
pinfo->band = NET_BW_6M;*/
|
||||
|
||||
pinfo->lmid = pSysPara->log_para.l_imd/2;//cttb_para.log_para.lid;
|
||||
pinfo->umid = pSysPara->log_para.u_imd/2;//cttb_para.log_para.uid;
|
||||
pinfo->snr = pSysPara->log_para.tsnr; //cttb_para.log_para.snr;
|
||||
|
||||
pinfo->adpc = pSysPara->system_para.adpc; //cttb_para.system_para.adpc;//atsc_para.log_para.adpc;
|
||||
pinfo->adpc_err = pSysPara->system_para.adpc_err;//cttb_para.system_para.adpc_err;
|
||||
pinfo->rf = pSysPara->rf_para.rf; //cttb_para.rf_para.rf;
|
||||
|
||||
return tcp_frame_ret_ok_pro2(pinframe,poutframe,sizeof(S_DEV_EXC_PARA2),DEV_EXCITER_ID);
|
||||
}
|
||||
|
||||
|
||||
static uint32 tcp_remote_read_exc_pro2(S_AUTOCAL_TCP_FRAME* pinframe,uint8* poutbuf)
|
||||
{
|
||||
if(pinframe->cmd_index>=E_READ_DEV_CMD_END)
|
||||
return tcp_frame_ret_err_pro2(pinframe,(S_AUTOCAL_TCP_FRAME*)poutbuf,TCP_AUTOCAL_ERR_CMD_INDEX,DEV_PA_ID);
|
||||
|
||||
switch(pinframe->cmd_index)
|
||||
{
|
||||
/*case 0x1001://功率计
|
||||
return tcp_read_meter_para(pinframe,tcp_output_buf);
|
||||
break;*/
|
||||
/*case 0x2001://功放
|
||||
return tcp_read_pa_para(pinframe,tcp_output_buf);
|
||||
break;
|
||||
case 0x2002://功放
|
||||
return tcp_read_pa_para2(pinframe,tcp_output_buf);
|
||||
break;*/
|
||||
|
||||
case 0x3002://激励器
|
||||
return tcp_read_exc_para2(pinframe,poutbuf);
|
||||
break;
|
||||
|
||||
case 0x3006://激励器-室外机自动接口检测
|
||||
return tcp_read_aodt_exc_para(pinframe,poutbuf);
|
||||
break;
|
||||
|
||||
default:break;
|
||||
}
|
||||
|
||||
return tcp_frame_ret_err_pro2(pinframe,(S_AUTOCAL_TCP_FRAME*)poutbuf,TCP_AUTOCAL_ERR_CMD_INDEX,DEV_PA_ID);
|
||||
}
|
||||
|
||||
|
||||
void udp_set_exc_db_power(int16 db_power)
|
||||
{
|
||||
uint16 temp;
|
||||
uint8 int_val;
|
||||
uint8 dec_val;
|
||||
uint8 sign;
|
||||
|
||||
//set db
|
||||
if(db_power>0){
|
||||
sign = 0;
|
||||
temp = db_power;
|
||||
}
|
||||
else{
|
||||
sign = 1;
|
||||
temp = -db_power;
|
||||
|
||||
}
|
||||
int_val = temp/100;
|
||||
dec_val = (temp%100)*20/100;
|
||||
|
||||
//设置功率
|
||||
//Net_write_Power(sign,int_val,dec_val);
|
||||
|
||||
/*if(tmp_power<=RF_POWER_P_C_ON)
|
||||
{
|
||||
if(atsc_para.wj_para.p_c)
|
||||
{
|
||||
if(tmp_power>RF_POWER_P_C_ON)
|
||||
tmp_power = RF_POWER_P_C_ON;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(tmp_power>RF_POWER_MAX)
|
||||
tmp_power = RF_POWER_MAX;
|
||||
}
|
||||
rf_power_set_new(tmp_power);
|
||||
}*/
|
||||
}
|
||||
#if 0//cttb_6.0
|
||||
uint32 usr_Net_write_RF(uint8 param)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void usr_load_default_rf_t(S_CGI_RF_PARA_T *ppara)
|
||||
{
|
||||
ppara->hz = cttb_para.rf_para.hz;
|
||||
ppara->power = cttb_para.rf_para.power;
|
||||
ppara->txfreq= cttb_para.rf_para.txfreq;
|
||||
ppara->cw = cttb_para.rf_para.cw;
|
||||
ppara->rf = cttb_para.rf_para.rf;
|
||||
ppara->agc = cttb_para.rf_para.agc;
|
||||
}
|
||||
|
||||
static void usr_save_rf_para(S_CGI_RF_PARA_T *ppara)
|
||||
{
|
||||
|
||||
if((cttb_para.rf_para.agc==ppara->agc)&&(ppara->agc))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
remote_set_power_process(ppara->power);
|
||||
|
||||
cttb_para.rf_para.txfreq = ppara->txfreq;
|
||||
cttb_para.rf_para.hz = ppara->hz; //hz power 已经在接收时处理好
|
||||
cttb_para.rf_para.cw = ppara->cw;
|
||||
cttb_para.rf_para.rf = ppara->rf;
|
||||
cttb_para.rf_para.agc = ppara->agc;
|
||||
e2rom_save_rf(&cttb_para.rf_para);
|
||||
fpga_save_rf(&cttb_para.rf_para);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
uint32 db_to_local_power(int32 db_power)
|
||||
{
|
||||
uint16 temp;
|
||||
uint8 sign;
|
||||
uint32 value;
|
||||
int32 fpower;
|
||||
|
||||
uint32 ret_power;
|
||||
|
||||
if(db_power>0){
|
||||
sign = 0;
|
||||
temp = db_power;
|
||||
}
|
||||
else{
|
||||
sign = 1;
|
||||
temp = -db_power;
|
||||
|
||||
}
|
||||
|
||||
value = (temp/100)*20 + (temp%100)*20/100; //一单位0.05
|
||||
|
||||
if(sign)//负值 200对应0db,最大-10,最大+5 0~300
|
||||
fpower = 0-value;
|
||||
else
|
||||
fpower =(int32)value;
|
||||
|
||||
|
||||
fpower+=RF_POWER_ZERO;
|
||||
if(fpower>RF_POWER_MAX)
|
||||
fpower = RF_POWER_MAX;
|
||||
if(fpower<0)
|
||||
fpower = 0;
|
||||
|
||||
ret_power = (uint32)fpower;
|
||||
|
||||
return ret_power;
|
||||
}
|
||||
int32 g_dbg_rec_power = 0;
|
||||
static uint32 tcp_remote_write_exc_pro2(S_AUTOCAL_TCP_FRAME* pinframe,uint8* poutbuf)
|
||||
{
|
||||
S_EXC_SET_PARA2 *ppara = (S_EXC_SET_PARA2 *)pinframe->data;
|
||||
S_EXC_SET_PARA2 exc_set={0};
|
||||
int32 loc_db=0;
|
||||
int32 rec_power;
|
||||
uint32 tmp_pwr;
|
||||
|
||||
S_ATSC_PARA *pSysPara = &atsc_para;
|
||||
S_CGI_RF tmp_rf_para = {0};//S_CGI_RF_PARA_T tmp_rf_para={0};
|
||||
|
||||
//band
|
||||
/*if(ppara->band != cttb_para.wl_para.band)
|
||||
{
|
||||
|
||||
}*/
|
||||
|
||||
//freq
|
||||
if(ppara->freq_ch != pSysPara->rf_para.txfreq)//cttb_para.rf_para.txfreq
|
||||
{
|
||||
/*usr_load_default_rf_t(&tmp_rf_para);
|
||||
tmp_rf_para.txfreq = ppara->freq_ch;
|
||||
usr_save_rf_para(&tmp_rf_para);*/
|
||||
|
||||
// how to switch freq ...
|
||||
if(ppara->freq_ch>= FREQ_MIN_V1&& ppara->freq_ch <= FREQ_6M_MAX_U){
|
||||
/*http_load_rf(&tmp_rf_para);
|
||||
tmp_rf_para.txfreq = ppara->freq_ch;
|
||||
http_write_rf(&tmp_rf_para);*/
|
||||
|
||||
usr_http_write_freq(ppara->freq_ch);
|
||||
}
|
||||
}
|
||||
|
||||
if(ppara->rf != pSysPara->rf_para.rf && ppara->fwd_power != 0xf0f0f0f0)//cttb_para.rf_para.rf
|
||||
{
|
||||
if(ppara->rf==0||ppara->rf==1){
|
||||
/*usr_load_default_rf_t(&tmp_rf_para);
|
||||
tmp_rf_para.rf = ppara->rf;
|
||||
usr_save_rf_para(&tmp_rf_para);*/
|
||||
|
||||
// how to switch rf ...
|
||||
http_load_rf(&tmp_rf_para);
|
||||
tmp_rf_para.rf = ppara->rf;
|
||||
http_write_rf(&tmp_rf_para);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
loc_db = conv_exc_power_to_db(pSysPara->rf_para.power);//cttb_para.rf_para.power
|
||||
rec_power = (int32)ppara->fwd_power;
|
||||
|
||||
g_dbg_rec_power = (int32)ppara->fwd_power;
|
||||
|
||||
//fwd_power
|
||||
if(rec_power != loc_db && rec_power != 0xf0f0f0f0)
|
||||
{
|
||||
if(rec_power>=-25*100 && rec_power <= 10*100){
|
||||
|
||||
/*usr_load_default_rf_t(&tmp_rf_para);
|
||||
tmp_rf_para.power = db_to_local_power(rec_power);
|
||||
if(tmp_rf_para.power<220)
|
||||
usr_save_rf_para(&tmp_rf_para);*/
|
||||
|
||||
// how to set pwr ...
|
||||
http_load_rf(&tmp_rf_para);
|
||||
if(rec_power>0){
|
||||
tmp_rf_para.power[0] = 0;
|
||||
tmp_pwr = rec_power;
|
||||
}
|
||||
else{
|
||||
tmp_rf_para.power[0] = 1;
|
||||
tmp_pwr = -rec_power;
|
||||
}
|
||||
tmp_rf_para.power[1] = (uint8)(tmp_pwr/100);
|
||||
tmp_rf_para.power[2] = (uint8)((tmp_pwr%100)/5);
|
||||
http_write_rf(&tmp_rf_para);
|
||||
}
|
||||
}
|
||||
|
||||
//adpc
|
||||
if(pSysPara->system_para.adpc != ppara->adpc && ppara->adpc!= 0xf0f0f0f0){ //cttb_para.system_para.adpc
|
||||
udp_trigger_adpc(ppara->adpc);
|
||||
}
|
||||
|
||||
if(ppara->adpc == 0){
|
||||
remote_set_dpd_clr();
|
||||
}
|
||||
|
||||
return tcp_frame_ret_ok_pro2(pinframe,(S_AUTOCAL_TCP_FRAME*)poutbuf,ERR_NO_ERR,DEV_EXCITER_ID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static uint32 tcp_remote_process(uint8 *precbuf,uint32 len)
|
||||
{
|
||||
uint32 send_len = 0;
|
||||
uint32 ret;
|
||||
S_AUTOCAL_TCP_FRAME *pframe;
|
||||
|
||||
pframe = tcp_frame_checkout_pro(precbuf,len,&ret);
|
||||
|
||||
if((ret!=TCP_AUTOCAL_ERR_NONE)||(pframe==NULL))
|
||||
{
|
||||
send_len = tcp_frame_ret_err_pro2(pframe,(S_AUTOCAL_TCP_FRAME*)tcp_output_buf,ret,DEV_EXCITER_ID);
|
||||
//send_len = tcp_frame_ret_err_client_pro(pframe,(S_AUTOCAL_TCP_FRAME*)tcp_output_buf,ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(pframe->cmd_type&0xfff)
|
||||
{
|
||||
case CMD_TYPE_READ:
|
||||
memset(tcp_output_buf,0,sizeof(tcp_output_buf));
|
||||
send_len = tcp_remote_read_exc_pro2(pframe,tcp_output_buf);
|
||||
break;
|
||||
case CMD_TYPE_SET:
|
||||
memset(tcp_output_buf,0,sizeof(tcp_output_buf));
|
||||
send_len = tcp_remote_write_exc_pro2(pframe,tcp_output_buf);
|
||||
break;
|
||||
default:
|
||||
send_len = tcp_frame_ret_err_pro2(pframe,(S_AUTOCAL_TCP_FRAME*)tcp_output_buf,TCP_AUTOCAL_ERR_CMD_TYPE,DEV_PA_ID);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return send_len;
|
||||
}
|
||||
|
||||
/*
|
||||
void auto_udp_task(void * pvParameters)
|
||||
{
|
||||
struct sockaddr_in server_addr;
|
||||
int sock_pa_fd;
|
||||
int err;
|
||||
int length;
|
||||
struct sockaddr from;
|
||||
socklen_t fromlen;
|
||||
|
||||
task_set_ignore_chk(AUTO_UDP_TASK_ID);
|
||||
|
||||
printf("%s init start...\n",__FUNCTION__);
|
||||
|
||||
sock_pa_fd = lwip_socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if(sock_pa_fd == -1)
|
||||
{
|
||||
printf("failed to create udp sock_fd!\n");
|
||||
sock_pa_fd = sock_pa_fd;
|
||||
}
|
||||
|
||||
memset(&server_addr, 0, sizeof(server_addr));
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_addr.s_addr =htonl(INADDR_ANY);
|
||||
server_addr.sin_port = htons(EXC_UDP_PORT);
|
||||
|
||||
err = lwip_bind(sock_pa_fd, (struct sockaddr *)&server_addr, sizeof(server_addr));
|
||||
if(err < 0)
|
||||
{
|
||||
printf("failed to bind sock_fd!\n");
|
||||
}
|
||||
|
||||
while(1)
|
||||
{ //阻塞型
|
||||
memset(tcp_input_buf, 0, sizeof(tcp_input_buf));
|
||||
|
||||
length = lwip_recvfrom(sock_pa_fd,tcp_input_buf,TCP_AUTOCAL_REMOTE_MAX_REC_LEN, 0,&from,&fromlen);
|
||||
if(length)
|
||||
{
|
||||
memset(tcp_output_buf,0,sizeof(tcp_output_buf));
|
||||
length = tcp_remote_process(tcp_input_buf,length);
|
||||
lwip_sendto(sock_pa_fd, tcp_output_buf,length, 0,&from,fromlen);//length
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
void * auto_adj_thr(void * args)
|
||||
{
|
||||
int udo_sock_fd = 0;
|
||||
int ret = 0;
|
||||
struct sockaddr_in serverAddr;
|
||||
struct sockaddr from;
|
||||
socklen_t fromlen;
|
||||
int port;
|
||||
int recvlen = 0;
|
||||
int length;
|
||||
|
||||
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.] auto_adj_thr Start.\n");
|
||||
|
||||
/* creat udp socket */
|
||||
udo_sock_fd = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if(udo_sock_fd == -1){
|
||||
log_printf(LOG_ERR,I_NOUSED," tco_sock_fd socket fail.\n");
|
||||
return ((void*)NULL);
|
||||
}
|
||||
|
||||
memset(&serverAddr, 0, sizeof(serverAddr));
|
||||
serverAddr.sin_family = PF_INET;
|
||||
serverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
serverAddr.sin_port = htons(EXC_UDP_PORT);
|
||||
|
||||
if(bind(udo_sock_fd,(struct sockaddr*)&serverAddr, sizeof(serverAddr)) < 0)
|
||||
{
|
||||
log_printf(LOG_DEBUG,I_NOUSED," bind 0.0.0.0:%d failed\n",port);
|
||||
close(udo_sock_fd);
|
||||
return ((void*)NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_printf(LOG_DEBUG,I_NOUSED," bind 0.0.0.0:%d ok\n",port);
|
||||
}
|
||||
|
||||
|
||||
while(1) {
|
||||
memset(tcp_input_buf, 0, sizeof(tcp_input_buf));
|
||||
// block
|
||||
recvlen = recvfrom(udo_sock_fd, tcp_input_buf, TCP_AUTOCAL_REMOTE_MAX_REC_LEN, 0, &from, &fromlen);
|
||||
if(recvlen) {
|
||||
//printf("recv_len=%d\n",recvlen);
|
||||
//printf(" rx_buff %02X %02X %02X \n", tcp_input_buf[0], tcp_input_buf[1], tcp_input_buf[2]);
|
||||
memset(tcp_output_buf,0,sizeof(tcp_output_buf));
|
||||
length = tcp_remote_process(tcp_input_buf,recvlen);
|
||||
if(length) {
|
||||
sendto(udo_sock_fd, tcp_output_buf, length, 0, &from, fromlen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user