2353 lines
76 KiB
C
Executable File
2353 lines
76 KiB
C
Executable File
/**
|
|
******************************************************************************
|
|
* @file name : iuart_user.c
|
|
* @author :
|
|
* @version :
|
|
* @date :
|
|
* @brief : uart for atsc
|
|
******************************************************************************
|
|
* @attention
|
|
//USE_GPS
|
|
//
|
|
******************************************************************************
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <pthread.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <termios.h>
|
|
#include <errno.h>
|
|
#include <getopt.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <arpa/inet.h>
|
|
#include <sched.h>
|
|
#include <time.h>
|
|
|
|
|
|
#include "../inc/type.h"
|
|
#include "../inc/delay.h"
|
|
#include "../inc/lcd_task.h"
|
|
#include "../inc/isys_config.h"
|
|
#include "../inc/i2c_drv.h"
|
|
#include "../inc/dpd_proc.h"
|
|
#include "../inc/iuart_user.h"
|
|
#include "../inc/eeprom.h"
|
|
#include "../inc/gps.h"
|
|
#include "../inc/main.h"
|
|
#include "../inc/msg.h"
|
|
#include "../inc/iweb_task.h"
|
|
#include "../inc/general_api.h"
|
|
#include "../inc/isys_com.h"
|
|
#include "../inc/dac38j82.h"
|
|
#include "../inc/os_task.h"
|
|
#include "../inc/fpga.h"
|
|
#include "../inc/upgrade.h"
|
|
#include "../inc/http_get.h"
|
|
#include "../adrv9009/adrv9009_config.h"
|
|
|
|
|
|
|
|
|
|
extern uint32 internal_set_base_delay(uint32 delay);
|
|
|
|
#define UART_RCV_BUF_LEN 1024
|
|
#define RS485_FILENAME "/dev/ttymxc1"
|
|
|
|
char uart_recv_buff[UART_RCV_BUF_LEN] = {0};
|
|
char cmd_buff[UART_RCV_BUF_LEN] = {0};
|
|
int uart_ttymxc_fd = 0; // tty1
|
|
pthread_mutex_t mutex_rs485;
|
|
int rs485_de_wr = 1; // wr 1 ,rd 0
|
|
|
|
#if 1
|
|
pthread_mutex_t mutex_gps_rs232;
|
|
#define GPS_RS232_FILENAME "/dev/ttymxc3"
|
|
int gps_uart_ttymxc_fd = 0;
|
|
#endif
|
|
|
|
#define RS232_FILENAME "/dev/ttymxc2"
|
|
|
|
char rs232_uart_recv_buff[UART_RCV_BUF_LEN] = {0};
|
|
char rs232_cmd_buff[UART_RCV_BUF_LEN] = {0};
|
|
int rs232_uart_ttymxc_fd = 0; // tty1
|
|
pthread_mutex_t mutex_rs232;
|
|
|
|
|
|
extern uint8 g_remote_dpd_ctrl;
|
|
extern uint32 adpc_source_udp ;
|
|
extern uint32 adpc_source_web;
|
|
extern uint32 standard;
|
|
extern uint32 auto_update;
|
|
|
|
//-----------------------------------
|
|
|
|
|
|
extern S_DRYLOOP dryloop_status;
|
|
|
|
extern uint32 auto_update;
|
|
extern uint32 Net_write_RF(uint8 param);
|
|
|
|
extern void set_menu_init(void);
|
|
extern void enter_menu(uint32 index);
|
|
void enter_update_lcd(void);
|
|
extern uint8 agc_value[];
|
|
extern uint8 off_rf;
|
|
|
|
char std_w[5]={0};
|
|
char std_r[5]={0};
|
|
|
|
static uint8 uart_outbuf[100] = {0};
|
|
|
|
|
|
uint32 uart_init_set_result_frame(uint8 *pin,uint8 *pout,uint32 err)
|
|
{
|
|
pout[0] = pin[1]|0x80;
|
|
pout[1] = 0x07;
|
|
pout[2] = pin[0];
|
|
pout[3] = pin[3];
|
|
pout[4] = (uint8)err;
|
|
pout[5] = get_check_sum(pout,5);
|
|
pout[6] = 0x96;
|
|
return 7;
|
|
}
|
|
|
|
void agc_auto_switch(void)
|
|
{
|
|
if(atsc_para.rf_para.agc && atsc_para.wh_para.pac != 1)
|
|
{
|
|
uint8 para_middle[64] = {0,};
|
|
S_WH_PARA *ppara = (S_WH_PARA *)para_middle;
|
|
|
|
memcpy(para_middle,&atsc_para.wh_para,sizeof(atsc_para.wh_para));
|
|
|
|
ppara->pac = 1;
|
|
|
|
e2rom_save_wh(ppara);
|
|
fpga_save_wh(ppara);
|
|
memcpy(&atsc_para.wh_para,ppara,sizeof(atsc_para.wh_para));
|
|
}
|
|
}
|
|
|
|
|
|
#define PA_CONN_DELAY 10
|
|
static uint32 pa_conn_status = 0;
|
|
static uint32 pa_conn_cnt = 0;
|
|
|
|
void pa_conn_chk(void)
|
|
{
|
|
if ( pa_conn_cnt )
|
|
{
|
|
pa_conn_cnt --;
|
|
pa_conn_status = 1;
|
|
agc_auto_switch();
|
|
}
|
|
else
|
|
{
|
|
pa_conn_status = 0;
|
|
}
|
|
}
|
|
uint32 pa_conn_sta(void)
|
|
{
|
|
return pa_conn_status;
|
|
}
|
|
static void pa_conn_refresh(void)
|
|
{
|
|
pa_conn_cnt = PA_CONN_DELAY;
|
|
}
|
|
|
|
//************************************************************************/
|
|
|
|
typedef struct{
|
|
uint16 pa_link_cnt;
|
|
uint16 pa_link_err;
|
|
}S_UART_DEV_LINK;
|
|
|
|
#if USE_UART_DEV_LINK
|
|
S_UART_DEV_LINK uart_dev_link;
|
|
#endif
|
|
|
|
void uart_remote(MSG *pmsg)
|
|
{
|
|
uint32 len = 0;
|
|
uint32 set_result = 0;
|
|
uint8 *pinbuf;
|
|
uint32 port;
|
|
|
|
if(!pmsg->wPara)
|
|
{
|
|
return;
|
|
}
|
|
if(!pmsg->lPara)
|
|
{
|
|
return;
|
|
}
|
|
port = pmsg->rPara;
|
|
|
|
//log_printf(LOG_DEBUG,I_NOUSED,"uart_recv:%s\n",(uint8 *)pmsg->lPara);
|
|
if((port!=UART_USER_232_COM)&&(port!=UART_USER_485_COM))
|
|
{
|
|
return;
|
|
}
|
|
|
|
pinbuf = (uint8 *)pmsg->lPara;
|
|
|
|
if(memcmp(std_r,pinbuf,3)==0) //头部检查
|
|
{
|
|
if(get_check_sum(pinbuf,4)==pinbuf[4])//查询命令
|
|
{
|
|
len = protocol_read(pinbuf,uart_outbuf);//回复
|
|
|
|
#if USE_UART_DEV_LINK
|
|
uart_dev_link.pa_link_cnt = 0;
|
|
uart_dev_link.pa_link_err = 0;
|
|
#endif
|
|
}
|
|
}
|
|
if(memcmp(std_w,pinbuf,3)==0)
|
|
{
|
|
if(get_check_sum(pinbuf,8)==pinbuf[8])//设置命令
|
|
{
|
|
set_result = protocol_write(pinbuf,uart_outbuf);//配置本地参数
|
|
}
|
|
else
|
|
set_result = UART_PARA_SET_ERR_SUM;
|
|
len = uart_init_set_result_frame(pinbuf,uart_outbuf,set_result);
|
|
}
|
|
if(len)
|
|
{
|
|
rs485_send_string(uart_outbuf,len);//发送N字节
|
|
rs232_send_string(uart_outbuf,len);//发送N字节
|
|
}
|
|
}
|
|
|
|
uint32 protocol_read(uint8 *pbufin,uint8 *pbufout)
|
|
{
|
|
uint32 i;
|
|
int tmp_imd;
|
|
int add_imd = 0;
|
|
|
|
uint32 count = 0;
|
|
//#if TEMPREATURE_DEGREE==0
|
|
int32 ltemp = 0;
|
|
uint32 ultemp = 0;
|
|
//#endif
|
|
|
|
uint32 temp =0;
|
|
|
|
switch(pbufin[3])
|
|
{
|
|
case 0x31:
|
|
pbufout[0] = 0X76;
|
|
pbufout[1] = 0X2A;
|
|
pbufout[2] = atsc_para.config_para.id;
|
|
pbufout[3] = 0x31;
|
|
|
|
for(i=4;i<40;i++) //inbuf1[4] ~ inbuf1[39]
|
|
{
|
|
pbufout[i] = 0XFF;
|
|
}
|
|
|
|
pbufout[4] = atsc_para.rf_para.txfreq;
|
|
pbufout[5] = atsc_para.rf_para.rxfreq;
|
|
|
|
pbufout[6] = atsc_para.system_para.ctrl;
|
|
pbufout[7] = atsc_para.system_para.input;
|
|
pbufout[8] = atsc_para.system_para.adpc;
|
|
|
|
if(off_rf)
|
|
pbufout[10] = 1 | off_rf;
|
|
else
|
|
pbufout[10] = off_rf;
|
|
|
|
pbufout[11] = fpga_byte_read(0x1,0x25);
|
|
pbufout[12] = fpga_byte_read(0x1,0x23) & 0X03 ; //high 8 bit
|
|
pbufout[13] = fpga_byte_read(0x1,0x24); //low 8 bit
|
|
|
|
//#if TEMPREATURE_DEGREE==0
|
|
if(get_temp_unit()==0){
|
|
ultemp = (pbufout[12]<<8)|pbufout[13];
|
|
ultemp = ultemp&0x3ff;
|
|
if(ultemp&0x200) //-
|
|
{
|
|
ultemp = 1024-ultemp;
|
|
ltemp = ultemp/4*100+ultemp%4*25;
|
|
ltemp = -ltemp;
|
|
ltemp = degree2fah(ltemp);
|
|
}
|
|
else
|
|
{
|
|
ultemp &=0x1ff;
|
|
ltemp = ultemp/4*100+ultemp%4*25;
|
|
ltemp = degree2fah(ltemp);
|
|
}
|
|
pbufout[12] = ltemp/100;
|
|
pbufout[13] = ltemp%100;
|
|
}
|
|
//#endif
|
|
|
|
pbufout[14]= atsc_para.config_para.bps;
|
|
pbufout[15]= atsc_para.rf_para.rf;
|
|
|
|
if(atsc_para.system_para.net == 0)
|
|
{
|
|
pbufout[16] = atsc_para.network_para.delay>>16;
|
|
pbufout[17] = atsc_para.network_para.delay>>8;
|
|
pbufout[18] = atsc_para.network_para.delay;
|
|
}
|
|
|
|
pbufout[19] = atsc_para.rf_para.power>>8;
|
|
pbufout[20] = atsc_para.rf_para.power;
|
|
|
|
pbufout[21] = atsc_para.system_para.adpc_err;
|
|
pbufout[22] = atsc_para.rf_para.hz>>16;
|
|
pbufout[23] = atsc_para.rf_para.hz>>8;
|
|
pbufout[24] = atsc_para.rf_para.hz;
|
|
|
|
pbufout[25] = atsc_para.rf_para.cw;
|
|
|
|
if(atsc_para.system_para.net == 0)
|
|
{
|
|
pbufout[26] = atsc_para.network_para.txid>>8;
|
|
pbufout[27] = atsc_para.network_para.txid;
|
|
pbufout[28] = atsc_para.network_para.netid>>8;
|
|
pbufout[29] = atsc_para.network_para.netid;
|
|
}
|
|
|
|
pbufout[30] = atsc_para.rf_para.agc?1:0;
|
|
|
|
if(atsc_para.system_para.net==0)
|
|
{
|
|
pbufout[31] = atsc_para.network_para.bratio;
|
|
}
|
|
|
|
if(get_menu_index()>=SYS_LCD) //非LOG屏,立即刷新
|
|
update_log_para();
|
|
|
|
pbufout[9] =(atsc_para.log_para.asi_input<<4)|atsc_para.log_para.input_ok_flag;
|
|
|
|
pbufout[32] = 0x14; //硬件版本
|
|
|
|
pbufout[35] = atsc_para.log_para.rsnr;
|
|
//pbufout[36] = atsc_para.log_para.tsnr;
|
|
if(atsc_para.wd_para.sa >= 0)
|
|
pbufout[36] = atsc_para.log_para.tsnr+atsc_para.wd_para.sa;
|
|
else
|
|
pbufout[36] = atsc_para.log_para.tsnr-(u8)(atsc_para.wd_para.sa*-1);
|
|
//pbufout[37] = atsc_para.log_para.l_imd;
|
|
if(atsc_para.wd_para.sb >= 0)
|
|
pbufout[37] = (atsc_para.log_para.l_imd+atsc_para.wd_para.sb)+(add_imd*2);
|
|
else{
|
|
tmp_imd = atsc_para.log_para.l_imd - (int)(-1*atsc_para.wd_para.sb);
|
|
if(tmp_imd<0)
|
|
pbufout[37] = 0;
|
|
else{
|
|
int8 tmpdata = -1*atsc_para.wd_para.sb;
|
|
pbufout[37] = (atsc_para.log_para.l_imd+(add_imd*2)-(u8)(tmpdata));
|
|
}
|
|
}
|
|
//pbufout[38] = atsc_para.log_para.u_imd;
|
|
if(atsc_para.wd_para.sc >= 0)
|
|
pbufout[38] = (atsc_para.log_para.u_imd+atsc_para.wd_para.sc)+(add_imd*2);
|
|
else{
|
|
tmp_imd = atsc_para.log_para.u_imd - (int)(-1*atsc_para.wd_para.sc);
|
|
if(tmp_imd<0)
|
|
pbufout[38] = 0;
|
|
else
|
|
pbufout[38] = (atsc_para.log_para.u_imd-(u8)(-1*atsc_para.wd_para.sc))+(add_imd*2);
|
|
}
|
|
pbufout[39] = atsc_para.log_para.gps;
|
|
pbufout[40] = get_check_sum(pbufout,40);
|
|
pbufout[41] = 0X96;
|
|
count = 42;
|
|
break;
|
|
case 0x32:
|
|
pbufout[0] = 0x76;
|
|
pbufout[1] = 0x23;
|
|
pbufout[2] = atsc_para.config_para.id;
|
|
pbufout[3] = 0x32;
|
|
|
|
for(i=4;i<40;i++) //inbuf1[4] ~ inbuf1[39]
|
|
{
|
|
pbufout[i] = 0XFF;
|
|
}
|
|
if(atsc_para.log_para.mode)
|
|
{
|
|
pbufout[4]=atsc_para.mode_para.sync;
|
|
pbufout[5]=atsc_para.mode_para.zp1f;
|
|
pbufout[6]=atsc_para.mode_para.tcp_c;
|
|
pbufout[7]=(atsc_para.mode_para.pid_det&0x1fff)>>8;
|
|
pbufout[8]=atsc_para.mode_para.pid_det;
|
|
}
|
|
pbufout[9] =atsc_para.log_para.syserr;
|
|
//pbufout[10]=0;
|
|
|
|
|
|
pbufout[11]=atsc_para.log_para.mode;
|
|
if(atsc_para.system_para.mode == 2)
|
|
pbufout[11] |= 1<<1;
|
|
|
|
|
|
pbufout[12]=atsc_para.system_para.net;
|
|
if(get_menu_index()>=SYS_LCD) //非LOG屏,立即刷新
|
|
update_log_para();
|
|
if((atsc_para.system_para.gps)&&(atsc_para.log_para.use_gps)) //INT
|
|
{
|
|
#if USE_GPS
|
|
GPGSA_T *gps_gsa = gps_get_sa();
|
|
#endif
|
|
S_SYS_TIME time;
|
|
|
|
get_sys_time(&time);
|
|
|
|
pbufout[13] = time.year>>8;
|
|
pbufout[14] = time.year;
|
|
pbufout[15] = time.month;
|
|
pbufout[16] = time.date;
|
|
pbufout[17] = time.hour;
|
|
pbufout[18] = time.min;
|
|
pbufout[19] = time.sec;
|
|
#if USE_GPS
|
|
pbufout[20] = gps_gsa->sv;
|
|
pbufout[21] = atsc_para.log_para.gps_status;
|
|
pbufout[22] = atsc_para.log_para.gps_freq[0];
|
|
pbufout[23] = atsc_para.log_para.gps_freq[1];
|
|
#endif
|
|
}
|
|
#if USE_GPS
|
|
pbufout[25] = atsc_para.system_para.gps;
|
|
#endif
|
|
if(atsc_para.log_para.ts_rate&1)
|
|
pbufout[26] = 1;
|
|
else if(atsc_para.log_para.ts_under)
|
|
pbufout[26] = 2;
|
|
else
|
|
pbufout[26] = 0;
|
|
|
|
pbufout[27]=atsc_para.log_para.ts_rate/1000000;
|
|
i = atsc_para.log_para.ts_rate%1000000;
|
|
pbufout[28]= i>>16;
|
|
pbufout[29]= i>>8;
|
|
pbufout[30]= i;
|
|
|
|
pbufout[31]= atsc_para.log_para.gps_1pps;
|
|
|
|
pbufout[33]= get_check_sum(pbufout,33);
|
|
pbufout[34] = 0X96;
|
|
count = 35;//
|
|
break;
|
|
case 0x33:
|
|
pbufout[0]=0x76;
|
|
pbufout[1]=0x26;
|
|
pbufout[2]=atsc_para.config_para.id;
|
|
pbufout[3] = 0x33;
|
|
|
|
for(i=4;i<40;i++) //inbuf1[4] ~ inbuf1[39]
|
|
{
|
|
pbufout[i] = 0XFF ;
|
|
}
|
|
|
|
pbufout[4] =(atsc_para.ad_para.pcr&0X07); //ad1
|
|
pbufout[5] =atsc_para.ad_para.slow_up;
|
|
pbufout[6] =atsc_para.ad_para.slow_down;
|
|
pbufout[7] =atsc_para.ad3_para.cw;
|
|
#if USE_GPS
|
|
|
|
#endif
|
|
|
|
pbufout[9] =atsc_para.ad2_para.m_ts; //ad2
|
|
pbufout[10]=atsc_para.ad2_para.m_10m;
|
|
pbufout[11]=atsc_para.ad2_para.m_1pps;
|
|
pbufout[12]=atsc_para.ad2_para.m_dly_hh;
|
|
pbufout[13]=atsc_para.ad2_para.m_dly_mm;
|
|
pbufout[14]=atsc_para.ad2_para.m_dly_ss;
|
|
|
|
#if USE_DRY_LOOP
|
|
pbufout[15]=atsc_para.ad3_para.rc_cmd; //ad3
|
|
#endif
|
|
|
|
pbufout[16]=atsc_para.ad3_para.fwd_cal;
|
|
|
|
//pbufout[17]=atsc_para.ad3_para.cor;
|
|
|
|
pbufout[18]=atsc_para.ad4_para.pdt&0x0F; //ad4
|
|
//pbufout[19]=atsc_para.ad4_para.cfr&0x0F;
|
|
pbufout[20]=atsc_para.system_para.adpc;
|
|
|
|
pbufout[21]=atsc_para.ad5_para.time; //ad5即wk
|
|
pbufout[22]=atsc_para.ad5_para.a_snr;
|
|
pbufout[23]=atsc_para.ad5_para.a_imd;
|
|
pbufout[24]=atsc_para.ad5_para.r_snr;
|
|
pbufout[25]=atsc_para.ad5_para.r_imd;
|
|
pbufout[26]=atsc_para.ad5_para.dpd;
|
|
|
|
#if !AW_ATSC_5X
|
|
#if ERR_TO_LCM
|
|
update_latch_para();
|
|
pbufout[27]=atsc_para.latch_para.u1;
|
|
pbufout[28]=atsc_para.latch_para.u2;
|
|
pbufout[29]=atsc_para.latch_para.rf;
|
|
pbufout[30]=atsc_para.latch_para.gps;
|
|
pbufout[31]=atsc_para.latch_para.ts;
|
|
pbufout[32]=atsc_para.latch_para.sys;
|
|
pbufout[33]=atsc_para.latch_para.m_1pps;
|
|
pbufout[34]=atsc_para.latch_para.sfn;
|
|
#endif
|
|
pbufout[35]= atsc_para.rf_para.tx;
|
|
#endif
|
|
pbufout[36]= get_check_sum(pbufout,36);
|
|
pbufout[37] = 0X96;
|
|
count = 38;
|
|
break;
|
|
case 0x34:
|
|
pbufout[0] = 0x76;
|
|
pbufout[1] = 18;
|
|
pbufout[2] = atsc_para.config_para.id;
|
|
pbufout[3] = 0x34;
|
|
|
|
pbufout[4] = 0x94;
|
|
pbufout[5] = 0x40;
|
|
pbufout[6] = 0xa2;
|
|
pbufout[7] = atsc_para.wk_para.mac[0];
|
|
pbufout[8] = atsc_para.wk_para.mac[1];
|
|
pbufout[9] = atsc_para.wk_para.mac[2];
|
|
|
|
temp=(atsc_para.sn_para.sn>>32);
|
|
pbufout[10] = 0xff & (temp>>8);
|
|
pbufout[11] = 0xff & (temp);
|
|
temp=atsc_para.sn_para.sn&0xffffffff;
|
|
pbufout[12] = 0xff & (temp>>24);
|
|
pbufout[13] = 0xff & (temp>>16);
|
|
pbufout[14] = 0xff & (temp>>8);
|
|
pbufout[15] = 0xff & (temp);
|
|
pbufout[16]= get_check_sum(pbufout,16);
|
|
pbufout[17] = 0X96 ;
|
|
count = 18;
|
|
break;
|
|
|
|
|
|
#if ATSC_USA_AMP
|
|
case 0x60:
|
|
pa_conn_refresh();
|
|
pbufout[0] = 0x76; //激励器代号
|
|
pbufout[2] = atsc_para.config_para.id;
|
|
pbufout[3] = 0x60;//命令
|
|
|
|
for(i=4;i<30;i++) //inbuf1[4] ~ inbuf1[39]
|
|
{
|
|
pbufout[i] = 0XFF ;
|
|
}
|
|
|
|
pbufout[4] = 0x00;// ATSC
|
|
pbufout[5] = atsc_para.rf_para.txfreq;//频点
|
|
pbufout[6] = 0x0c;//6M
|
|
#if USE_NEW_DIO_MODE
|
|
pbufout[7] =atsc_para.ad3_para.mptv;
|
|
if(atsc_para.ad3_para.mptv==1)
|
|
{
|
|
pbufout[8] = atsc_para.mptv.dio_tx;
|
|
pbufout[9] = atsc_para.mptv.power_diff;
|
|
if((atsc_para.system_para.ctrl==CTRL_REMOTE)&&(atsc_para.ad3_para.rc_cmd==0))
|
|
{
|
|
pbufout[10] = 1;
|
|
}
|
|
else
|
|
{
|
|
pbufout[10] = 0;
|
|
}
|
|
atsc_para.mptv.power_diff = 0;
|
|
}
|
|
#endif
|
|
//pbufout[7] = atsc_para.pa_config_para.ip[3];
|
|
//pbufout[8] = atsc_para.pa_config_para.ip[2];
|
|
//pbufout[9] = atsc_para.pa_config_para.ip[1];
|
|
//pbufout[10]= atsc_para.pa_config_para.ip[0];
|
|
|
|
//pbufout[11] =atsc_para.pa_config_para.mask[3];
|
|
//pbufout[12] =atsc_para.pa_config_para.mask[2];
|
|
//pbufout[13] =atsc_para.pa_config_para.mask[1];
|
|
//pbufout[14] =atsc_para.pa_config_para.mask[0];
|
|
|
|
//pbufout[15] =atsc_para.pa_config_para.gateway[3];
|
|
//pbufout[16] =atsc_para.pa_config_para.gateway[2];
|
|
//pbufout[17] =atsc_para.pa_config_para.gateway[1];
|
|
//pbufout[18] =atsc_para.pa_config_para.gateway[0];
|
|
|
|
//pbufout[19] =atsc_para.log_para.tsnr;
|
|
if(atsc_para.wd_para.sa >= 0)
|
|
pbufout[19] = atsc_para.log_para.tsnr+atsc_para.wd_para.sa;
|
|
else
|
|
pbufout[19] = atsc_para.log_para.tsnr-(u8)(atsc_para.wd_para.sa*-1);
|
|
//pbufout[20] =atsc_para.log_para.l_imd;
|
|
add_imd = 11;
|
|
if(atsc_para.wd_para.sb >= 0)
|
|
pbufout[20] = atsc_para.log_para.l_imd+atsc_para.wd_para.sb+add_imd*2;
|
|
else{
|
|
tmp_imd = atsc_para.log_para.l_imd - (int)(-1*atsc_para.wd_para.sb);
|
|
if(tmp_imd<0)
|
|
pbufout[20] = 0;
|
|
else{
|
|
int8 tmpdata = -1*atsc_para.wd_para.sb;
|
|
pbufout[20] = atsc_para.log_para.l_imd-(u8)(tmpdata)+add_imd*2;
|
|
}
|
|
}
|
|
//pbufout[21] =atsc_para.log_para.u_imd;
|
|
if(atsc_para.wd_para.sc >= 0)
|
|
pbufout[21] = atsc_para.log_para.u_imd+atsc_para.wd_para.sc+add_imd*2;
|
|
else{
|
|
tmp_imd = atsc_para.log_para.u_imd - (int)(-1*atsc_para.wd_para.sc);
|
|
if(tmp_imd<0)
|
|
pbufout[21] = 0;
|
|
else
|
|
pbufout[21] = atsc_para.log_para.u_imd-(u8)(-1*atsc_para.wd_para.sc)+add_imd*2;
|
|
}
|
|
pbufout[22] =atsc_para.rf_para.power;
|
|
pbufout[23] =atsc_para.rf_para.power>>8;
|
|
|
|
pbufout[1]=26; //必须放在校验和执行前
|
|
pbufout[24] = get_check_sum(pbufout,24);
|
|
pbufout[25] = 0x96;
|
|
count = 26;
|
|
|
|
atsc_para.pac_flag = 1;
|
|
break;
|
|
#endif
|
|
}
|
|
|
|
return count;
|
|
}
|
|
|
|
void rf_power_set_new(uint16 new_power)
|
|
{
|
|
if(new_power>=atsc_para.rf_para.power)
|
|
{ //增加
|
|
log_printf(LOG_DEBUG,I_NOUSED,"new_power=%d, oldpower=%d\n",new_power,atsc_para.rf_para.power);
|
|
if(atsc_para.rf_para.db+ (new_power-atsc_para.rf_para.power)<RF_POWER_DB_MAX)
|
|
atsc_para.rf_para.db =atsc_para.rf_para.db+ (new_power-atsc_para.rf_para.power);
|
|
else
|
|
{
|
|
if(atsc_para.rf_para.db < RF_POWER_DB_MAX)
|
|
{
|
|
new_power = RF_POWER_DB_MAX-atsc_para.rf_para.db+atsc_para.rf_para.power;
|
|
}
|
|
else
|
|
{
|
|
new_power = atsc_para.rf_para.power;
|
|
}
|
|
atsc_para.rf_para.db = RF_POWER_DB_MAX;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(atsc_para.rf_para.db>(atsc_para.rf_para.power-new_power))
|
|
atsc_para.rf_para.db = atsc_para.rf_para.db-(atsc_para.rf_para.power-new_power);
|
|
else
|
|
{
|
|
atsc_para.rf_para.db = 0;
|
|
new_power = 0;
|
|
}
|
|
}
|
|
if(new_power!=atsc_para.rf_para.power){
|
|
turn_off_rf_agc_state(E_CHG_TX_POWER);
|
|
}
|
|
atsc_para.rf_para.power = new_power;
|
|
fpga_save_we(&atsc_para.we_para);
|
|
e2rom_save_power(&atsc_para.rf_para);
|
|
/*if(atsc_para.rf_para.agc)
|
|
{
|
|
fpga_save_agc_vol();
|
|
}*/
|
|
}
|
|
uint32 protocol_write(uint8 *pbufin,uint8 *pbufout)
|
|
{
|
|
uint32 UI_temp = 0;
|
|
uint32 result = UART_PARA_SET_ERR_OK;
|
|
#if ATSC_USA_AMP
|
|
uint16 temp=0;
|
|
int8 power_fine = 0;
|
|
#endif
|
|
uint16 mode_temp = 0;
|
|
|
|
#if USE_CTRL_MODE
|
|
#if ATSC_USA_AMP
|
|
if((pbufin[3] >= 0xa0) && (pbufin[3] <= 0xbf))
|
|
{
|
|
pa_conn_refresh(); //功放
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
if(atsc_para.system_para.ctrl==CTRL_LOCAL)
|
|
{
|
|
result = UART_PARA_SET_ERR_LOCAL;
|
|
return result;
|
|
}
|
|
}
|
|
#endif
|
|
switch(pbufin[3])
|
|
{
|
|
case 0x30: //Control
|
|
if( (pbufin[4] <=1)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.system_para.ctrl = pbufin[4];
|
|
|
|
if(atsc_para.system_para.ctrl == CTRL_REMOTE)
|
|
fpga_byte_write(0x01,0x27,1);
|
|
else
|
|
fpga_byte_write(0x01,0x27,0);
|
|
|
|
c256_bytewrite(EEPROM_CTRL_ADDR,atsc_para.system_para.ctrl);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x31: //ID
|
|
if((0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
atsc_para.config_para.id = std_w[0] = std_r[0] = pbufin[4];
|
|
c256_bytewrite(EEPROM_ID_ADDR,atsc_para.config_para.id);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x32: //TUNER TS EAS
|
|
if((pbufin[4]<ASI_INPUT_END)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
uint8 data;
|
|
|
|
if((pbufin[4]==ASI_INPUT_EAS)&&(atsc_para.sn_para.eas_key_valid==0))
|
|
{
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
}
|
|
else
|
|
{
|
|
atsc_para.system_para.input = pbufin[4];
|
|
data = ((pbufin[4]+1)&3)<<2;
|
|
fpga_byte_write(0x01,0x50,data);
|
|
c256_bytewrite(EEPROM_SYS_INPUT,pbufin[4]);
|
|
}
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x33:
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
|
|
case 0x34: //ADPC
|
|
if((pbufin[4]<=ADPC_UPDATE3)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]) ) // need to open whlie release
|
|
{
|
|
switch(pbufin[4])
|
|
{
|
|
case ADPC_OFF :
|
|
if(atsc_para.system_para.adpc==ADPC_HOLD){
|
|
dpd_set_clr();
|
|
fpga_byte_write(5,FPGA_ADDR_DPD_CTRL1, DPD_CTRL1_ALL_BYPS);
|
|
}
|
|
g_remote_dpd_ctrl=1;
|
|
adpc_source_udp=0;
|
|
adpc_source_web=0;
|
|
atsc_set_force_stop_adpc(TRUE);
|
|
atsc_para.system_para.adpc = ADPC_OFF;
|
|
atsc_para.system_para.adpc_err = ADPC_STATUS_OK; //清错误标志位
|
|
delay_us(200);
|
|
//fpga_byte_write(0x5,0x03,7);
|
|
//fpga_byte_write(0x5,0x01,0x0);
|
|
break;
|
|
case ADPC_HOLD:
|
|
g_remote_dpd_ctrl = 1;
|
|
adpc_source_udp = 0;
|
|
adpc_source_web = 0;
|
|
if(atsc_para.system_para.adpc==ADPC_OFF){
|
|
if(c256_byteread(EEPROM_DPD_FLASH_VALID)){
|
|
dpd_curve_proc(E_LOAD_TO_FPGA);
|
|
}
|
|
else{
|
|
lcd_write_string(LINE_1,0," DPD DATA IN FLASH Error! ");
|
|
lcd_write_string(LINE_2,0," ");
|
|
lcd_write_cache();
|
|
delay_ms(2000);
|
|
}
|
|
}
|
|
atsc_para.system_para.adpc = ADPC_HOLD;
|
|
atsc_para.system_para.adpc_err = ADPC_STATUS_OK; //清错误标志位
|
|
//fpga_byte_write(0x5,0x03,0x00);
|
|
light_on();
|
|
|
|
//adpc_load_data(1,ADPC_HOLD);
|
|
//dpd_curve_proc(E_LOAD_TO_FPGA);
|
|
|
|
set_menu_init();
|
|
break;
|
|
case ADPC_UPDATE1 :
|
|
g_remote_dpd_ctrl = 1;
|
|
adpc_source_udp = 0;
|
|
adpc_source_web = 1;
|
|
atsc_para.system_para.adpc = ADPC_UPDATE1;
|
|
atsc_para.system_para.adpc_err = ADPC_STATUS_OK; //开始update1时清错误标志位
|
|
if(atsc_para.system_para.adpc==ADPC_OFF)
|
|
{
|
|
atsc_para.ad5_para.use_dpd = 1; // 由OFF->UPDATE 强制使用NEW模式
|
|
}
|
|
else
|
|
{
|
|
atsc_para.ad5_para.use_dpd = atsc_para.ad5_para.dpd;
|
|
}
|
|
//fpga_write_adpc(cttb_para.system_para.adpc);
|
|
//h-anno
|
|
|
|
atsc_para.system_para.adpc_step = 0;
|
|
auto_update = TRUE;
|
|
adpc_source_udp = 0;
|
|
adpc_source_web = 1;
|
|
enter_update_lcd();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
c256_bytewrite(EEPROM_DPD_ADDR,atsc_para.system_para.adpc);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x35: //RST
|
|
if((1==pbufin[4])&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
uint8 txfreqbak= atsc_para.rf_para.txfreq;
|
|
uint8 rxfreqbak= atsc_para.rf_para.rxfreq;
|
|
e2rom_load_default_param(1);
|
|
freq_nochange(txfreqbak,rxfreqbak);
|
|
fpga_save_all_para(FALSE);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x36: //freq
|
|
if((pbufin[4]>=FREQ_MIN_V1)&&(pbufin[4]<=FREQ_MAX_U)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
int txfreq_changed = (atsc_para.rf_para.txfreq != pbufin[4])? 1 : 0;
|
|
atsc_para.rf_para.txfreq = pbufin[4];
|
|
atsc_para.we_para.ch = pbufin[4];
|
|
|
|
fpga_save_we(&atsc_para.we_para);
|
|
c256_bytewrite(EEPROM_CHANNEL_ADDR,atsc_para.rf_para.txfreq);
|
|
#if BAK_PARA_CHECK
|
|
c256_bytewrite2(BAK_EEPROM_CHANNEL_ADDR,atsc_para.rf_para.txfreq);
|
|
#endif
|
|
if(txfreq_changed){
|
|
printf("checked freq change to :%d\n",atsc_para.rf_para.txfreq);
|
|
#if USE_FREQ_CHANGE_RESET_PWR
|
|
usr_set_exc_pwr(-25*100);
|
|
usleep(4000000); // delay 4s case Slow boot
|
|
#endif
|
|
}
|
|
chang_freq(1, txfreq_changed);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x37:
|
|
if( (pbufin[4]>=FREQ_MIN_V1)&&(pbufin[4]<=FREQ_MAX_U)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
#if USE_TUNER
|
|
if(pbufin[4]!=atsc_para.rf_para.rxfreq)
|
|
{
|
|
tuner_init(pbufin[4]);
|
|
}
|
|
#endif
|
|
atsc_para.rf_para.rxfreq = pbufin[4];
|
|
atsc_para.we_para.ch = atsc_para.rf_para.txfreq;
|
|
fpga_save_we(&atsc_para.we_para);
|
|
c256_bytewrite(EEPROM_RXCHANNEL_ADDR,atsc_para.rf_para.rxfreq);
|
|
#if BAK_PARA_CHECK
|
|
c256_bytewrite2(BAK_EEPROM_RXCHANNEL_ADDR,atsc_para.rf_para.rxfreq);
|
|
#endif
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x38: //Hz
|
|
if((0xf0==pbufin[7]))
|
|
{
|
|
//协议更改: byte1 正负 0正 1负 byte2,byte3 数据 0-50000
|
|
UI_temp = (pbufin[5]<<8)|pbufin[6]; //数据 0-50000
|
|
if( UI_temp>RF_MAX_HZ)
|
|
{
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
}
|
|
else
|
|
{
|
|
atsc_para.rf_para.hz = UI_temp;
|
|
if(pbufin[4]) //- 高3byte置1
|
|
atsc_para.rf_para.hz |= 0x10000;
|
|
|
|
c256_bytewrite(EEPROM_HZ_UIH_ADDR,atsc_para.rf_para.hz>>16); //+ -
|
|
c256_bytewrite(EEPROM_HZ_UIM_ADDR,atsc_para.rf_para.hz>>8); //Hz display high 8 bit
|
|
c256_bytewrite(EEPROM_HZ_UIL_ADDR,atsc_para.rf_para.hz); //Hz display low 8 bit
|
|
|
|
fpga_byte_write(0x1,0x4c,atsc_para.rf_para.hz>>16); //+ -
|
|
fpga_byte_write(0x1,0x4d,atsc_para.rf_para.hz>>8);
|
|
fpga_byte_write(0x1,0x4e,atsc_para.rf_para.hz);
|
|
}
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x39: //Power
|
|
if( (0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
#if USA_ATSC_5X
|
|
if((dryloop_status.rf!=INVALID_DATA) && (atsc_para.ad3_para.rc_cmd==0))
|
|
{
|
|
result = UART_PARA_SET_ERR_DRYLOOP;
|
|
break;
|
|
}
|
|
#else
|
|
#if USE_NEW_DIO_MODE
|
|
if(atsc_para.ad3_para.mptv==1) //MPTV下,不能通过串口改功率
|
|
{
|
|
result = UART_PARA_SET_ERR_DRYLOOP;
|
|
break;
|
|
}
|
|
else //LPTV可改. 不考虑dryloop
|
|
{
|
|
|
|
}
|
|
#else
|
|
if((dryloop_status.rf!=INVALID_DATA) && (atsc_para.ad3_para.rc_cmd==0))
|
|
{
|
|
result = UART_PARA_SET_ERR_DRYLOOP;
|
|
break;
|
|
}
|
|
#endif
|
|
#endif
|
|
UI_temp = pbufin[4];
|
|
UI_temp = (UI_temp<<8)|pbufin[5];
|
|
if(atsc_para.wj_para.p_c)
|
|
{
|
|
if(UI_temp>RF_POWER_P_C_ON)
|
|
UI_temp = RF_POWER_P_C_ON;
|
|
}
|
|
else
|
|
{
|
|
if(UI_temp>RF_POWER_MAX)
|
|
UI_temp = RF_POWER_MAX;
|
|
}
|
|
rf_power_set_new(UI_temp);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
|
|
/* case 0x3A: //CW
|
|
if( (pbufin[4]<2)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
atsc_para.rf_para.cw = pbufin[4] ;
|
|
FPGA_bytewrite(0x0 ,0x0);
|
|
FPGA_bytewrite(0xfe,atsc_para.rf_para.cw<<7); //CW:ON/OFF
|
|
c256_bytewrite(EEPROM_PARA_CW_ADDR,atsc_para.rf_para.cw); //CW
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break; */
|
|
case 0x3B: //TXID
|
|
if((0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
/* UI_temp = pbufin[4] ;
|
|
UI_temp=(UI_temp<<8)|pbufin[5];
|
|
atsc_para.network_para.txid =UI_temp;
|
|
|
|
FPGA_bytewrite(0x0 ,0x5);
|
|
FPGA_bytewrite(0xa,UI_temp>>8);
|
|
FPGA_bytewrite(0xb,UI_temp);
|
|
c256_bytewrite(EEPROM_NET_TXID_ADDR,UI_temp>>8);
|
|
c256_bytewrite(EEPROM_NET_TXID_ADDR+1,UI_temp);*/
|
|
}
|
|
break;
|
|
case 0x3C: //NETID
|
|
if((0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
// save_Netid =Netid
|
|
/* UI_temp = pbufin[4] ;
|
|
UI_temp=(UI_temp<<8)|pbufin[5];
|
|
atsc_para.network_para.netid = UI_temp;
|
|
FPGA_bytewrite(0x0 ,0x5);
|
|
FPGA_bytewrite(0x8,UI_temp>>8);
|
|
FPGA_bytewrite(0x9,UI_temp);
|
|
c256_bytewrite(EEPROM_NET_NETID_ADDR,UI_temp>>8);
|
|
c256_bytewrite(EEPROM_NET_NETID_ADDR+1,UI_temp);*/
|
|
}
|
|
break;
|
|
case 0x3D: //DELAY
|
|
if((0xf0==pbufin[7]))
|
|
{
|
|
UI_temp = pbufin[4] ;
|
|
UI_temp = (UI_temp<<8) | pbufin[5] ;
|
|
UI_temp = (UI_temp<<8) | pbufin[6] ;
|
|
if(UI_temp>NET_MAX_DELAY)
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
else
|
|
{
|
|
atsc_para.network_para.delay =UI_temp;
|
|
|
|
c256_bytewrite(EEPROM_NET_DELAY_ADDR, (UI_temp>>16)&0x00ff);
|
|
c256_bytewrite(EEPROM_NET_DELAY_ADDR+1,(UI_temp>>8)&0x00ff);
|
|
c256_bytewrite(EEPROM_NET_DELAY_ADDR+2,UI_temp&0x00ff);
|
|
|
|
fpga_byte_write(0x01,0x3f,(UI_temp>>16)&0x00ff);
|
|
fpga_byte_write(0x01,0x40,(UI_temp>>8)&0x00ff);
|
|
fpga_byte_write(0x01,0x41,UI_temp&0x00ff);
|
|
|
|
}
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x3E: //bps
|
|
if( (pbufin[4]<3)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
atsc_para.config_para.bps = pbufin[4];
|
|
c256_bytewrite(EEPROM_BPS_ADDR,atsc_para.config_para.bps);
|
|
// oneshu add @20220617 for change bps.
|
|
MSG bps_msg;
|
|
memset(&bps_msg, 0, sizeof(MSG));
|
|
bps_msg.type = MSG_UART_RE_INIT;
|
|
msg_send_to_uart(&bps_msg);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0X3F: //RF
|
|
if( (pbufin[4]<2)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
#if 1//_USE_RVL_
|
|
result = Net_write_RF(pbufin[4]);
|
|
#endif//_USE_RVL_
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0X40: //set Custom AGC control
|
|
if(atsc_para.wf_para.agc)
|
|
{
|
|
if( (pbufin[4]<2)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
if(atsc_para.rf_para.agc!=pbufin[4])
|
|
{
|
|
/*atsc_para.rf_para.agc = pbufin[4];
|
|
if(atsc_para.ad3_para.cor==0)
|
|
c256_bytewrite(EEPROM_AGC_ADDR,atsc_para.rf_para.agc);
|
|
else
|
|
c256_bytewrite2(E2_AGC_ADDR,atsc_para.rf_para.agc);
|
|
if(atsc_para.rf_para.agc)
|
|
{
|
|
fpga_save_agc_vol();
|
|
}
|
|
fpga_byte_write(0x1,0x4A,agc_value[atsc_para.rf_para.agc]);*/
|
|
|
|
log_printf(LOG_INFO, I_USER_CFG, "uart agc=%d\n",pbufin[4]);
|
|
|
|
if(pbufin[4]==0){
|
|
set_sys_rf_agc(0);
|
|
printf(">> cfg set rf agc off\n");
|
|
}
|
|
else{
|
|
printf(">> cfg trigger rf agc on proc\n");
|
|
trigger_rf_agc_proc(1);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_AGC_ON;
|
|
break;
|
|
/*case 0x41:
|
|
if((0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
atsc_para.network_para.bratio = pbufin[4] ;
|
|
fpga_byte_write(0x0 ,0x5);
|
|
fpga_byte_write(0x7,atsc_para.network_para.bratio);
|
|
c256_bytewrite(EEPROM_NET_BRATIO_ADDR,atsc_para.network_para.bratio);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
*/
|
|
case 0x42: //SYNC
|
|
if( (pbufin[4]<2)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
mode_temp = fpga_byte_read(0x1,55) & 2 ;
|
|
if(mode_temp)
|
|
{
|
|
atsc_para.mode_para.sync=pbufin[4];
|
|
c256_bytewrite(EEPROM_MODE_SYNC,pbufin[4]);
|
|
fpga_byte_write(0x3,0x5,pbufin[4]);
|
|
}
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x43: //ZP1F
|
|
if( (pbufin[4]<2)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
mode_temp = fpga_byte_read(0x1,55)&2;
|
|
|
|
if((mode_temp)&&(atsc_para.system_para.net==0))
|
|
{
|
|
atsc_para.mode_para.zp1f=pbufin[4];
|
|
c256_bytewrite(EEPROM_MODE_ZP1F,pbufin[4]);
|
|
fpga_byte_write(0x3,0x4,pbufin[4]);
|
|
}
|
|
else
|
|
{
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
}
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x44: //TCP_C
|
|
if( (pbufin[4]<2)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
mode_temp = fpga_byte_read(0x1,55) & 2;
|
|
if((mode_temp)&&(atsc_para.system_para.net==0))
|
|
{
|
|
atsc_para.mode_para.tcp_c = pbufin[4];
|
|
c256_bytewrite(EEPROM_MODE_TCP_C,pbufin[4]);
|
|
fpga_byte_write(0x3,0xb,pbufin[4]);
|
|
}
|
|
else
|
|
{
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
}
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
/*
|
|
case 0x45: //PID
|
|
if( (0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
|
|
unsigned long temp;
|
|
|
|
temp=(pbufin[4]<<8)|pbufin[5];
|
|
if(temp>0x1fff)
|
|
temp = 0x1fff;
|
|
atsc_para.mode_para.pid =temp;
|
|
c256_bytewrite(EEPROM_PID_H_ADDR,temp>>8);
|
|
c256_bytewrite(EEPROM_PID_L_ADDR,temp);
|
|
FPGA_bytewrite(0x0 ,0x3);
|
|
FPGA_bytewrite(0x2,temp>>8);
|
|
FPGA_bytewrite(0x3,temp);
|
|
}
|
|
break;*/
|
|
/*
|
|
case 0x46: //FUNCTION
|
|
if( (pbufin[4]<3)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
#if 0
|
|
save_fpga_pid(pbufin[4]);
|
|
if(pbufin[4]==1) //start;
|
|
{
|
|
detect_id();
|
|
}
|
|
else
|
|
{
|
|
if(pbufin[4]==2)//clear
|
|
{
|
|
atsc_para.mode_para.pid_det = 0;
|
|
c256_bytewrite(EEPROM_PIDDET_H_ADDR,0);
|
|
c256_bytewrite(EEPROM_PIDDET_L_ADDR,0);
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
break;*/
|
|
case 0x47:
|
|
if((pbufin[4]<3)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.system_para.mode=pbufin[4];
|
|
c256_bytewrite(EEPROM_MODE_ADDR,atsc_para.system_para.mode);
|
|
fpga_byte_write(0x3,0x01,atsc_para.system_para.mode);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x48:
|
|
if( (pbufin[4]<2)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
//atsc_para.system_para.net=pbufin[4];
|
|
//c256_bytewrite(EEPROM_NET_ADDR,atsc_para.system_para.net);
|
|
//fpga_byte_write(0x1,0x02,atsc_para.system_para.net);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x49:
|
|
if( (pbufin[4]<=2)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.system_para.gps=pbufin[4];
|
|
c256_bytewrite(EEPROM_GPS_ADDR,atsc_para.system_para.gps);
|
|
fpga_byte_write(0x01,0x08,atsc_para.system_para.gps);//0x05->0x08
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x50:
|
|
if( (pbufin[4]<3)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]) )
|
|
{
|
|
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
// 高级菜单
|
|
case 0x60: //pcr
|
|
if( (pbufin[4]<8) &&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.ad_para.pcr= pbufin[4]&0x07;
|
|
c256_bytewrite(EEPROM_PCR_ADDR,atsc_para.ad_para.pcr);
|
|
fpga_byte_write(0x1,0x51,atsc_para.ad_para.pcr);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x61://slow_up
|
|
if( (pbufin[4]<2) && (0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
uint8 data;
|
|
|
|
atsc_para.ad_para.slow_up= pbufin[4]&0x01;
|
|
c256_bytewrite(EEPROM_SLOW_UP_ADDR, atsc_para.ad_para.slow_up);
|
|
data = atsc_para.ad_para.slow_down?1<<0:0;
|
|
data |= atsc_para.ad_para.slow_up?1<<1:0;
|
|
fpga_byte_write(0x1,0x25,data);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x62: //slow_down
|
|
if( (pbufin[4]<2) && (0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
uint8 data;
|
|
|
|
atsc_para.ad_para.slow_down= pbufin[4]&0x01;
|
|
c256_bytewrite(EEPROM_SLOW_DOWN_ADDR,atsc_para.ad_para.slow_down);
|
|
data = atsc_para.ad_para.slow_up?1<<1:0;
|
|
data |= atsc_para.ad_para.slow_down?1<<0:0;
|
|
fpga_byte_write(0x1,0x25,data);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x63: //cw
|
|
if((pbufin[4]<2) && (0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
int cw_changed = (atsc_para.ad3_para.cw == pbufin[4]) ? 0 : 1;
|
|
atsc_para.ad3_para.cw = pbufin[4]&0x01;
|
|
c256_bytewrite(EEPROM_PARA_CW_ADDR,atsc_para.ad3_para.cw); //CW
|
|
fpga_save_ad3(&atsc_para.ad3_para);
|
|
|
|
chang_cw(cw_changed);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x64: //gps_v
|
|
if( (pbufin[4]<=0x0c) && (pbufin[4]>=5) && (0xf0==pbufin[5]) && (0xf0==pbufin[6]) && (0xf0==pbufin[7]) )
|
|
{
|
|
;
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x65: //M_ts
|
|
if((pbufin[4]<2) && (0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.ad2_para.m_ts= pbufin[4]&0x01;
|
|
|
|
e2rom_save_ad2(&atsc_para.ad2_para);
|
|
fpga_save_ad2(&atsc_para.ad2_para);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x66: // m_10m
|
|
if((pbufin[4]<2) && (0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.ad2_para.m_10m= pbufin[4]&0x01;
|
|
|
|
e2rom_save_ad2(&atsc_para.ad2_para);
|
|
fpga_save_ad2(&atsc_para.ad2_para);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x67: //m_1pps
|
|
if((pbufin[4]<2) && (0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.ad2_para.m_1pps= pbufin[4]&0x01;
|
|
|
|
e2rom_save_ad2(&atsc_para.ad2_para);
|
|
fpga_save_ad2(&atsc_para.ad2_para);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x68: //m_dly_hh mm ss
|
|
if((pbufin[5]<=59)&&(pbufin[6]<=59)&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.ad2_para.m_dly_hh = pbufin[4];
|
|
atsc_para.ad2_para.m_dly_mm = pbufin[5];
|
|
atsc_para.ad2_para.m_dly_ss = pbufin[6];
|
|
|
|
e2rom_save_ad2(&atsc_para.ad2_para);
|
|
fpga_save_ad2(&atsc_para.ad2_para);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
|
|
case 0x69: //RC_CMD
|
|
if((pbufin[4]<2) && (0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
|
|
atsc_para.ad3_para.rc_cmd= pbufin[4]&0x01;
|
|
c256_bytewrite(EEPROM_AD3_RC_CMD,atsc_para.ad3_para.rc_cmd);
|
|
fpga_save_ad3(&atsc_para.ad3_para);
|
|
}
|
|
else
|
|
{
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
}
|
|
break;
|
|
case 0x6a: //FWD_CAL
|
|
if( (pbufin[4]<2) && (0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
|
|
atsc_para.ad3_para.fwd_cal= pbufin[4]&0x01;
|
|
e2rom_save_ad3(&atsc_para.ad3_para);
|
|
fpga_save_ad3(&atsc_para.ad3_para);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
#if USA_ATSC_5X
|
|
case 0x6b: //COR
|
|
if((pbufin[4]<2) && (0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
if(atsc_para.ad3_para.cor!=(pbufin[4]&0x01))
|
|
{
|
|
atsc_para.ad3_para.cor = pbufin[4]&0x01;
|
|
c256_bytewrite(EEPROM_AD3_TYPE,atsc_para.ad3_para.cor);
|
|
save_new_cor(atsc_para.ad3_para.cor);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
}
|
|
break;
|
|
#endif
|
|
|
|
case 0x6c: //pdt
|
|
if((pbufin[4]<0x10) &&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.ad4_para.pdt = (atsc_para.ad4_para.pdt&0xf0)|(pbufin[4]&0x0f);
|
|
c256_bytewrite(EEPROM_WF_ADDR+OFFSET_OF_STRUCT(S_WF_PARA,pdt),atsc_para.ad4_para.pdt);
|
|
atsc_para.wf_para.pdt = atsc_para.ad4_para.pdt;
|
|
fpga_byte_write(0x5,0x32,atsc_para.ad4_para.pdt);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x6d: //cfr
|
|
if((pbufin[4]<0x10) &&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
//atsc_para.ad4_para.cfr= (atsc_para.ad4_para.cfr&0xf0)|(pbufin[4]&0x0f);
|
|
/*c256_bytewrite(EEPROM_WB_ADDR+OFFSET_OF_STRUCT(S_WB_PARA,cfr),atsc_para.ad4_para.cfr);
|
|
atsc_para.wb_para.cfr = atsc_para.ad4_para.cfr;
|
|
fpga_byte_write(0x0,0x48,atsc_para.ad4_para.cfr);*/
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x6e: //adpc
|
|
if((pbufin[4]<=ADPC_UPDATE3)&&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]) ) // need to open whlie release
|
|
{
|
|
switch(pbufin[4])
|
|
{
|
|
case ADPC_OFF :
|
|
if(atsc_para.system_para.adpc==ADPC_HOLD){
|
|
dpd_set_clr();
|
|
fpga_byte_write(5,FPGA_ADDR_DPD_CTRL1, DPD_CTRL1_ALL_BYPS);
|
|
}
|
|
g_remote_dpd_ctrl=1;
|
|
adpc_source_udp=0;
|
|
adpc_source_web=0;
|
|
atsc_set_force_stop_adpc(TRUE);
|
|
atsc_para.system_para.adpc = ADPC_OFF;
|
|
atsc_para.system_para.adpc_err = ADPC_STATUS_OK; //清错误标志位
|
|
delay_us(200);
|
|
//fpga_byte_write(0x5,0x03,7);
|
|
//fpga_byte_write(0x5,0x01,0x0);
|
|
break;
|
|
case ADPC_HOLD:
|
|
g_remote_dpd_ctrl = 1;
|
|
adpc_source_udp = 0;
|
|
adpc_source_web = 0;
|
|
if(atsc_para.system_para.adpc==ADPC_OFF){
|
|
if(c256_byteread(EEPROM_DPD_FLASH_VALID)){
|
|
dpd_curve_proc(E_LOAD_TO_FPGA);
|
|
}
|
|
else{
|
|
lcd_write_string(LINE_1,0," DPD DATA IN FLASH Error! ");
|
|
lcd_write_string(LINE_2,0," ");
|
|
lcd_write_cache();
|
|
delay_ms(2000);
|
|
}
|
|
}
|
|
atsc_para.system_para.adpc = ADPC_HOLD;
|
|
atsc_para.system_para.adpc_err = ADPC_STATUS_OK; //清错误标志位
|
|
//fpga_byte_write(0x5,0x03,0x00);
|
|
light_on();
|
|
|
|
//adpc_load_data(1,ADPC_HOLD);
|
|
//dpd_curve_proc(E_LOAD_TO_FPGA);
|
|
|
|
set_menu_init();
|
|
break;
|
|
case ADPC_UPDATE1 :
|
|
if(g_ca_value!=1){
|
|
break;
|
|
}
|
|
g_remote_dpd_ctrl = 1;
|
|
adpc_source_udp = 0;
|
|
adpc_source_web = 1;
|
|
atsc_para.system_para.adpc = ADPC_UPDATE1;
|
|
atsc_para.system_para.adpc_err = ADPC_STATUS_OK; //开始update1时清错误标志位
|
|
if(atsc_para.system_para.adpc==ADPC_OFF)
|
|
{
|
|
atsc_para.ad5_para.use_dpd = 1; // 由OFF->UPDATE 强制使用NEW模式
|
|
}
|
|
else
|
|
{
|
|
atsc_para.ad5_para.use_dpd = atsc_para.ad5_para.dpd;
|
|
}
|
|
//fpga_write_adpc(cttb_para.system_para.adpc);
|
|
//h-anno
|
|
|
|
atsc_para.system_para.adpc_step = 0;
|
|
auto_update = TRUE;
|
|
adpc_source_udp = 0;
|
|
adpc_source_web = 1;
|
|
enter_update_lcd();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
c256_bytewrite(EEPROM_DPD_ADDR,atsc_para.system_para.adpc);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x6f: //time
|
|
if((pbufin[4]<=10) &&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.ad5_para.time = pbufin[4] & 0x0f ;
|
|
c256_bytewrite(EEPROM_AD5_TIME_ADDR,atsc_para.ad5_para.time);
|
|
atsc_para.ad5_para.c_t = atsc_para.ad5_para.time;
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x70: //a_snr
|
|
if((pbufin[4]<=99) &&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.ad5_para.a_snr= pbufin[4];
|
|
e2rom_save_ad5(&atsc_para.ad5_para);
|
|
c256_bytewrite(EEPROM_AD5_TSNR_ADDR,atsc_para.ad5_para.a_snr);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x71: //a_imd
|
|
if((pbufin[4]<=99) && (0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.ad5_para.a_imd= pbufin[4] ;
|
|
c256_bytewrite(EEPROM_AD5_IMD_ADDR,atsc_para.ad5_para.a_imd);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x72: //r_snr
|
|
if( (pbufin[4]<=99) && (0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.ad5_para.r_snr= pbufin[4] ;
|
|
c256_bytewrite(EEPROM_AD5_RSNR_ADDR,atsc_para.ad5_para.r_snr);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x73: //r_imd
|
|
if((pbufin[4]<=99) &&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.ad5_para.r_imd= pbufin[4];
|
|
c256_bytewrite(EEPROM_AD5_RIMD_ADDR,atsc_para.ad5_para.r_imd);
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
case 0x74: //dpd
|
|
if((pbufin[4]<=2) &&(0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
//uint8 data;
|
|
//data = pbufin[4] ;
|
|
//atsc_para.ad5_para.dpd = pbufin[4] ;
|
|
if(pbufin[4] == 0) //当由DPD变为0时,清除本地ADPC数据
|
|
{
|
|
show_wait_info(" ");
|
|
erase_adpc_data();
|
|
//data = atsc_para.ad5_para.dpd; // use data
|
|
}
|
|
else
|
|
{
|
|
atsc_para.ad5_para.dpd = pbufin[4];
|
|
c256_bytewrite(EEPROM_AD5_DPD_ADDR,atsc_para.ad5_para.dpd);
|
|
atsc_para.ad5_para.use_dpd =atsc_para.ad5_para.dpd;
|
|
}
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
#if USA_ATSC_5X
|
|
// RESET LATCH 屏
|
|
#if ERR_TO_LCM
|
|
case 0x75:
|
|
if( (pbufin[4] <=1 ) && (0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
atsc_para.latch_para.reset= pbufin[4];
|
|
if(atsc_para.latch_para.reset)
|
|
{
|
|
memset(&atsc_para.latch_para,0,sizeof(atsc_para.latch_para));
|
|
atsc_para.rf_para.ssref = atsc_para.latch_para.u1;
|
|
if(get_menu_index() == ADV_LCD+7) //被复位后,其他数据被清0显示,U1,U2被刷新的还是中间变量,所以重新进一下该屏.
|
|
enter_menu(ADV_LCD+7);
|
|
}
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
#endif
|
|
|
|
#if USE_DRY_LOOP
|
|
case 0x76:
|
|
if( (pbufin[4] <=1 ) && (0xf0==pbufin[5])&&(0xf0==pbufin[6])&&(0xf0==pbufin[7]))
|
|
{
|
|
if(atsc_para.wh_para.func)
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
else
|
|
{
|
|
#if USE_DRYLOOP_I2C
|
|
if((atsc_para.rf_para.tx==0)&&(pbufin[4]==1)) //OFF->ON //要执行某些动作
|
|
{
|
|
dryloop_write(DRYLOOP_I2C_RF_LED,1);
|
|
show_wait_info_with_sec(atsc_para.wj_para.rf_dly);
|
|
atsc_para.rf_para.rf = 1;
|
|
fpga_set_rf_output(1);
|
|
c256_bytewrite(EEPROM_RF_ADDR,atsc_para.rf_para.rf);
|
|
off_rf = 0;
|
|
//clrbit(off_rf,2);
|
|
}
|
|
else if((atsc_para.rf_para.tx==1)&&(pbufin[4]==0)) //ON->OFF
|
|
{
|
|
atsc_para.rf_para.rf = 0;
|
|
fpga_set_rf_output(0);
|
|
show_wait_info_with_sec(atsc_para.wj_para.rf_dly);
|
|
c256_bytewrite(EEPROM_RF_ADDR,atsc_para.rf_para.rf);
|
|
dryloop_write(DRYLOOP_I2C_RF_LED,0);
|
|
atsc_para.latch_para.rf = 1;
|
|
setbit(off_rf,_KEY_TX);
|
|
}
|
|
atsc_para.rf_para.tx = pbufin[4];
|
|
#else
|
|
if((atsc_para.rf_para.tx==0)&&(pbufin[4]==1)) //OFF->ON //要执行某些动作
|
|
{
|
|
//dryloop_write(DRYLOOP_I2C_RF_LED,1);
|
|
dryloop_amp_on(TRUE);
|
|
show_wait_info_with_sec(atsc_para.wj_para.rf_dly);
|
|
atsc_para.rf_para.rf = 1;
|
|
off_rf = 0;
|
|
fpga_set_rf_output(1);
|
|
c256_bytewrite(EEPROM_RF_ADDR,atsc_para.rf_para.rf);
|
|
}
|
|
else if((atsc_para.rf_para.tx==1)&&(pbufin[4]==0)) //ON->OFF
|
|
{
|
|
atsc_para.rf_para.rf = 0;
|
|
fpga_set_rf_output(0);
|
|
show_wait_info_with_sec(atsc_para.wj_para.rf_dly);
|
|
dryloop_amp_on(FALSE);
|
|
atsc_para.latch_para.rf = 1;
|
|
setbit(off_rf,_KEY_TX);
|
|
c256_bytewrite(EEPROM_RF_ADDR,atsc_para.rf_para.rf);
|
|
}
|
|
atsc_para.rf_para.tx = pbufin[4];
|
|
#endif
|
|
c256_bytewrite(EEPROM_RF_TX,atsc_para.rf_para.tx);
|
|
}
|
|
}
|
|
else
|
|
result = UART_PARA_SET_ERR_INVALID;
|
|
break;
|
|
#endif
|
|
#endif
|
|
|
|
|
|
//////////////////////// 功放代码 已预留空间 0xA0 ~ 0xBF ////////////////////////
|
|
|
|
#if ATSC_USA_AMP
|
|
case 0xa0: //9v电压
|
|
atsc_para.pac_flag = 1;
|
|
memcpy(&atsc_para.avr_pa_para.vol_9v, &pbufin[4],sizeof(atsc_para.avr_pa_para.vol_9v));
|
|
break;
|
|
|
|
case 0xa1: //50v电压
|
|
atsc_para.pac_flag = 1;
|
|
atsc_para.avr_pa_para.tick_cnt++;
|
|
memcpy(&atsc_para.avr_pa_para.vol_50v, &pbufin[4],sizeof(atsc_para.avr_pa_para.vol_50v));
|
|
break;
|
|
|
|
case 0xa2: //50v电流
|
|
atsc_para.pac_flag = 1;
|
|
memcpy(&atsc_para.avr_pa_para.cur_50v ,&pbufin[4],sizeof(atsc_para.avr_pa_para.cur_50v));
|
|
break;
|
|
case 0xa3: //栅极电压
|
|
atsc_para.pac_flag = 1;
|
|
memcpy(&atsc_para.avr_pa_para.gv_881,&pbufin[4],sizeof(atsc_para.avr_pa_para.gv_881));
|
|
break;
|
|
case 0xa4: //发射功率
|
|
atsc_para.pac_flag = 1;
|
|
memcpy(&atsc_para.avr_pa_para.pa_fwd,&pbufin[4],sizeof(atsc_para.avr_pa_para.pa_fwd));
|
|
break;
|
|
case 0xa5: //反射功率
|
|
atsc_para.pac_flag = 1;
|
|
memcpy(&atsc_para.avr_pa_para.pa_reflect,&pbufin[4],sizeof(atsc_para.avr_pa_para.pa_reflect));
|
|
break;
|
|
case 0xa6: //驻波比
|
|
atsc_para.pac_flag = 1;
|
|
memcpy(&atsc_para.avr_pa_para.swr,&pbufin[4],sizeof(atsc_para.avr_pa_para.swr));
|
|
break;
|
|
case 0xa7: //功放温度
|
|
atsc_para.pac_flag = 1;
|
|
memcpy(&atsc_para.avr_pa_para.temp_pa,&pbufin[4],sizeof(atsc_para.avr_pa_para.temp_pa));
|
|
break;
|
|
case 0xa8: //反射功率异常信号
|
|
atsc_para.pac_flag = 1;
|
|
atsc_para.avr_pa_para.signal_reflect= pbufin[4]?1:0;
|
|
break;
|
|
case 0xa9: //发射功率异常信号
|
|
atsc_para.pac_flag = 1;
|
|
atsc_para.avr_pa_para.signal_fwd = pbufin[4]?1:0;
|
|
break;
|
|
case 0xaa: //温度异常信号
|
|
atsc_para.pac_flag = 1;
|
|
atsc_para.avr_pa_para.signal_temp= pbufin[4]?1:0;
|
|
break;
|
|
case 0xab:
|
|
//50V电流2 200M才有
|
|
atsc_para.pac_flag = 1;
|
|
memcpy(&atsc_para.avr_pa_para.cur_50V_2,&pbufin[4],sizeof(atsc_para.avr_pa_para.cur_50V_2));
|
|
break;
|
|
case 0xac: //AMP功率等级 加一处理 /1:100M /2:200M /3:400M
|
|
atsc_para.pac_flag = 1;
|
|
atsc_para.avr_pa_para.pac_lev= pbufin[4]+1;
|
|
break;
|
|
case 0xad: //发射功率发送给FPGA 实现AGC 同50V电压
|
|
atsc_para.pac_flag = 1;
|
|
temp = ( pbufin[4] | ( (pbufin[5]&0x0f)<<8) ) << 4;
|
|
fpga_byte_write(0x1,0x81,temp>>8 );
|
|
fpga_byte_write(0x1,0x82,temp&0xff);
|
|
temp = 0;
|
|
break;
|
|
case 0xae:
|
|
atsc_para.pac_flag =1;
|
|
atsc_para.pa_config_para.ip[3] = pbufin[4];
|
|
atsc_para.pa_config_para.ip[2] = pbufin[5];
|
|
atsc_para.pa_config_para.ip[1] = pbufin[6];
|
|
atsc_para.pa_config_para.ip[0] = pbufin[7];
|
|
break;
|
|
case 0xaf:
|
|
atsc_para.pac_flag =1;
|
|
atsc_para.pa_config_para.mask[3] = pbufin[4];
|
|
atsc_para.pa_config_para.mask[2] = pbufin[5];
|
|
atsc_para.pa_config_para.mask[1] = pbufin[6];
|
|
atsc_para.pa_config_para.mask[0] = pbufin[7];
|
|
break;
|
|
case 0xb0:
|
|
atsc_para.pac_flag =1;
|
|
atsc_para.pa_config_para.gateway[3] = pbufin[4];
|
|
atsc_para.pa_config_para.gateway[2] = pbufin[5];
|
|
atsc_para.pa_config_para.gateway[1] = pbufin[6];
|
|
atsc_para.pa_config_para.gateway[0] = pbufin[7];
|
|
break;
|
|
case 0xb1:
|
|
memcpy(&atsc_para.avr_pa_para.cur_50v_3,&pbufin[4],sizeof(atsc_para.avr_pa_para.cur_50v_3));
|
|
break;
|
|
case 0xb2:
|
|
memcpy(&atsc_para.avr_pa_para.cur_50v_4,&pbufin[4],sizeof(atsc_para.avr_pa_para.cur_50v_4));
|
|
break;
|
|
case 0xb3:
|
|
memcpy(&atsc_para.avr_pa_para.pa_in,&pbufin[4],sizeof(atsc_para.avr_pa_para.pa_in));
|
|
break;
|
|
case 0xb4:
|
|
memcpy(&atsc_para.avr_pa_para.vol_12v,&pbufin[4],sizeof(atsc_para.avr_pa_para.vol_12v));
|
|
break;
|
|
case 0xb5: //配置agc使能 缓启动过程中暂停agc,否则正常配置agc
|
|
/*if(pbufin[4]==1)
|
|
{
|
|
fpga_byte_write(0x1,0x4A,agc_value[atsc_para.rf_para.agc]|(1<<5));//agc bit 5 发1 表示暂停agc,发0,开始
|
|
}
|
|
else if(pbufin[4]==0)
|
|
{
|
|
fpga_byte_write(0x1,0x4A,agc_value[atsc_para.rf_para.agc]|(0<<5));
|
|
}*/
|
|
break;
|
|
case 0xb6: //功率微调
|
|
power_fine = (int8)pbufin[4];
|
|
if(power_fine==0)
|
|
break;
|
|
if(abs(power_fine)>5)
|
|
break;
|
|
if(power_fine>0)
|
|
{ //增加
|
|
if(atsc_para.wj_para.p_c)
|
|
{
|
|
if((atsc_para.rf_para.power+power_fine< RF_POWER_P_C_ON)&&(atsc_para.rf_para.db+power_fine<RF_POWER_DB_MAX))
|
|
{
|
|
atsc_para.rf_para.power+=power_fine;
|
|
atsc_para.rf_para.db+=power_fine;
|
|
turn_off_rf_agc_state(E_CHG_TX_FREQ);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if((atsc_para.rf_para.power+power_fine< RF_POWER_MAX)&&(atsc_para.rf_para.db+power_fine<RF_POWER_DB_MAX))
|
|
{
|
|
atsc_para.rf_para.power+=power_fine;
|
|
atsc_para.rf_para.db+=power_fine;
|
|
turn_off_rf_agc_state(E_CHG_TX_FREQ);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if((atsc_para.rf_para.power-abs(power_fine)>0)&&(atsc_para.rf_para.db-abs(power_fine)>0))
|
|
{
|
|
atsc_para.rf_para.power-=abs(power_fine);
|
|
atsc_para.rf_para.db-=abs(power_fine);
|
|
turn_off_rf_agc_state(E_CHG_TX_FREQ);
|
|
}
|
|
}
|
|
fpga_save_we(&atsc_para.we_para);
|
|
e2rom_save_power(&atsc_para.rf_para);
|
|
/*if(atsc_para.rf_para.agc)
|
|
{
|
|
fpga_save_agc_vol();
|
|
}*/
|
|
break;
|
|
#if USE_NEW_DIO_MODE
|
|
case CMMB_CONFIG_STEP_ALARM: //0xb7
|
|
atsc_para.mptv.alarm = pbufin[4];
|
|
atsc_para.mptv.tx_crm_is_dio= pbufin[5];
|
|
atsc_para.mptv.tx_open = pbufin[6];
|
|
break;
|
|
#endif
|
|
|
|
case CMMB_CONFIG_EXC_RESET: //0xb8
|
|
if(pbufin[4]==0x5a&&pbufin[5]==0x5a&&pbufin[6]==0xa5&&pbufin[7]==0xa5)
|
|
{
|
|
//set_exc_reset();
|
|
}
|
|
break;
|
|
#endif
|
|
default:
|
|
result = UART_PARA_SET_ERR_UNKNOW_CMD;
|
|
break;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
static const uint16 uart_bps[4] = {9600,19200,38400,38400};
|
|
|
|
/*static void uart_hw_init(void)
|
|
{
|
|
uint8 bps = atsc_para.config_para.bps;
|
|
|
|
#if !USE_DEBUG_UART
|
|
uart_com_init(UART_USER_232_COM,uart_bps[bps&3],PARITY_NO,INT_ON);
|
|
#endif
|
|
uart_com_init(UART_USER_485_COM,uart_bps[bps&3],PARITY_NO,INT_ON);
|
|
}*/
|
|
|
|
|
|
|
|
static void info_init_ok(void)
|
|
{/*
|
|
#if !USE_DEBUG_UART
|
|
uart_send_string(UART_USER_232_COM," Initialize OK ",strlen(" Initialize OK "));
|
|
#endif
|
|
uart_send_string(UART_USER_485_COM," Initialize OK ",strlen(" Initialize OK "));
|
|
*/
|
|
}
|
|
|
|
/*void uart_task(void * pvParameters)
|
|
{
|
|
MSG *pmsg = NULL;
|
|
uint32 sec_cnt;
|
|
(void)pvParameters;
|
|
//uart_hw_init();
|
|
config_time_msg(MSG_SEC);
|
|
|
|
task_is_ok();
|
|
info_init_ok();
|
|
|
|
while((pmsg = get_msg(OS_WAIT_FOREVER))!=NULL)
|
|
{
|
|
switch(pmsg->type)
|
|
{
|
|
case MSG_RS232:
|
|
uart_Remote(pmsg);
|
|
break;
|
|
case MSG_SEC:
|
|
pa_conn_chk();
|
|
task_is_ok();
|
|
|
|
#if USE_UART_DEV_LINK
|
|
sec_cnt++;
|
|
if(sec_cnt>=40){
|
|
sec_cnt = 40;
|
|
|
|
if(uart_dev_link.pa_link_cnt<=20){
|
|
uart_dev_link.pa_link_cnt++;
|
|
}
|
|
else{
|
|
uart_dev_link.pa_link_err = 1;
|
|
if(atsc_para.config_para.pa_link_ctrl_rf==1){//使能开关
|
|
if(atsc_para.rf_para.rf==1)
|
|
Net_write_RF(0);
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
|
|
break;
|
|
case MSG_UART_RE_INIT:
|
|
uart_hw_init();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
if(MSG_NEED_TO_FREE(pmsg))
|
|
free_msg(pmsg);
|
|
}
|
|
}*/
|
|
|
|
|
|
#if 1
|
|
|
|
|
|
int speed_arr[] = {
|
|
B921600, B460800, B230400, B115200, B57600, B38400, B19200,
|
|
B9600, B4800, B2400, B1200, B300,
|
|
};
|
|
|
|
int name_arr[] = {
|
|
921600, 460800, 230400, 115200, 57600, 38400, 19200,
|
|
9600, 4800, 2400, 1200, 300,
|
|
};
|
|
|
|
void set_speed(int fd, int speed)
|
|
{
|
|
int i;
|
|
int status;
|
|
struct termios Opt;
|
|
tcgetattr(fd, &Opt);
|
|
|
|
for ( i= 0; i < sizeof(speed_arr) / sizeof(int); i++) {
|
|
if (speed == name_arr[i]) {
|
|
tcflush(fd, TCIOFLUSH);
|
|
cfsetispeed(&Opt, speed_arr[i]);
|
|
cfsetospeed(&Opt, speed_arr[i]);
|
|
status = tcsetattr(fd, TCSANOW, &Opt);
|
|
if (status != 0)
|
|
perror("tcsetattr fd1");
|
|
return;
|
|
}
|
|
tcflush(fd,TCIOFLUSH);
|
|
}
|
|
|
|
if (i == 12){
|
|
log_printf(LOG_DEBUG,I_NOUSED,"\tSorry, please set the correct baud rate!\n\n");
|
|
}
|
|
}
|
|
/*
|
|
*@brief 设置串口数据位,停止位和效验位
|
|
*@param fd 类型 int 打开的串口文件句柄*
|
|
*@param databits 类型 int 数据位 取值 为 7 或者8*
|
|
*@param stopbits 类型 int 停止位 取值为 1 或者2*
|
|
*@param parity 类型 int 效验类型 取值为N,E,O,,S
|
|
*/
|
|
int set_Parity(int fd,int databits,int stopbits,int parity)
|
|
{
|
|
struct termios options;
|
|
if ( tcgetattr( fd,&options) != 0) {
|
|
perror("SetupSerial 1");
|
|
return(FALSE);
|
|
}
|
|
options.c_cflag &= ~CSIZE ;
|
|
switch (databits) /*设置数据位数*/ {
|
|
case 7:
|
|
options.c_cflag |= CS7;
|
|
break;
|
|
case 8:
|
|
options.c_cflag |= CS8;
|
|
break;
|
|
default:
|
|
fprintf(stderr,"Unsupported data size\n");
|
|
return (FALSE);
|
|
}
|
|
|
|
switch (parity) {
|
|
case 'n':
|
|
case 'N':
|
|
options.c_cflag &= ~PARENB; /* Clear parity enable */
|
|
options.c_iflag &= ~INPCK; /* Enable parity checking */
|
|
break;
|
|
case 'o':
|
|
case 'O':
|
|
options.c_cflag |= (PARODD | PARENB); /* 设置为奇效验*/
|
|
options.c_iflag |= INPCK; /* Disnable parity checking */
|
|
break;
|
|
case 'e':
|
|
case 'E':
|
|
options.c_cflag |= PARENB; /* Enable parity */
|
|
options.c_cflag &= ~PARODD; /* 转换为偶效验*/
|
|
options.c_iflag |= INPCK; /* Disnable parity checking */
|
|
break;
|
|
case 'S':
|
|
case 's': /*as no parity*/
|
|
options.c_cflag &= ~PARENB;
|
|
options.c_cflag &= ~CSTOPB;
|
|
break;
|
|
default:
|
|
fprintf(stderr,"Unsupported parity\n");
|
|
return (FALSE);
|
|
}
|
|
/* 设置停止位*/
|
|
switch (stopbits) {
|
|
case 1:
|
|
options.c_cflag &= ~CSTOPB;
|
|
break;
|
|
case 2:
|
|
options.c_cflag |= CSTOPB;
|
|
break;
|
|
default:
|
|
fprintf(stderr,"Unsupported stop bits\n");
|
|
return (FALSE);
|
|
}
|
|
/* Set input parity option */
|
|
if (parity != 'n')
|
|
options.c_iflag |= INPCK;
|
|
|
|
options.c_cc[VTIME] = 1; //(百毫秒) 150 = 15 seconds
|
|
options.c_cc[VMIN] = 50; // 最小(读)字节数
|
|
|
|
options.c_lflag &= ~(ECHO | ICANON |ECHOE|ISIG);//[one add @20220307]
|
|
|
|
options.c_cflag |= CLOCAL|CREAD;
|
|
|
|
options.c_oflag &= ~(ONLCR | OCRNL |OPOST); //[one add @20220222]
|
|
options.c_iflag &= ~(IXON | IXOFF | IXANY |BRKINT|ICRNL|INPCK|ISTRIP); // [one add @20220222]
|
|
|
|
tcflush(fd,TCIFLUSH); /* Update the options and do it NOW */
|
|
if (tcsetattr(fd,TCSANOW,&options) != 0) {
|
|
perror("SetupSerial 3");
|
|
return (FALSE);
|
|
}
|
|
return (TRUE);
|
|
}
|
|
|
|
int OpenDev(char *Dev)
|
|
{
|
|
int fd = open( Dev, O_RDWR | O_NOCTTY | O_NDELAY); //
|
|
if (-1 == fd) { /*设置数据位数*/
|
|
perror("Can't Open Serial Port");
|
|
return -1;
|
|
} else
|
|
return fd;
|
|
}
|
|
|
|
uint32 rs485_init(uint32 baud,int databits,int stopbits,int parity)
|
|
{
|
|
set_gpio_export(RS485_GPIO_NUM_DE);
|
|
set_gpio_io_direct(RS485_GPIO_NUM_DE, E_IO_OUT);
|
|
// system("echo 5 > /sys/class/gpio/export");
|
|
// system("echo out > /sys/class/gpio/gpio5/direction");
|
|
|
|
|
|
pthread_mutex_init(&mutex_rs485, NULL);
|
|
|
|
uart_ttymxc_fd = OpenDev(RS485_FILENAME);
|
|
|
|
// set fd to nonblock , Improve the read/write speed serial port
|
|
fcntl(uart_ttymxc_fd, F_SETFL, 0|O_NONBLOCK);
|
|
|
|
if (uart_ttymxc_fd > 0) {
|
|
set_speed(uart_ttymxc_fd, baud);
|
|
} else {
|
|
fprintf(stderr, "Error opening %s: %s\n", RS485_FILENAME, strerror(errno));
|
|
return (1);
|
|
}
|
|
|
|
if (set_Parity(uart_ttymxc_fd, databits, stopbits, parity)== FALSE) {
|
|
fprintf(stderr, "Set Parity Error\n");
|
|
close(uart_ttymxc_fd);
|
|
return (1);
|
|
}
|
|
log_printf(LOG_DEBUG,I_NOUSED,"rs485 init success.\n");
|
|
}
|
|
|
|
uint32 rs232_init(uint32 baud,int databits,int stopbits,int parity)
|
|
{
|
|
pthread_mutex_init(&mutex_rs232, NULL);
|
|
|
|
rs232_uart_ttymxc_fd = OpenDev(RS232_FILENAME);
|
|
|
|
// set fd to nonblock , Improve the read/write speed serial port
|
|
fcntl(rs232_uart_ttymxc_fd, F_SETFL, 0|O_NONBLOCK);
|
|
|
|
if (rs232_uart_ttymxc_fd > 0) {
|
|
set_speed(rs232_uart_ttymxc_fd, baud);
|
|
} else {
|
|
fprintf(stderr, "Error opening %s: %s\n", RS232_FILENAME, strerror(errno));
|
|
return (1);
|
|
}
|
|
|
|
if (set_Parity(rs232_uart_ttymxc_fd, databits, stopbits, parity)== FALSE) {
|
|
fprintf(stderr, "Set Parity Error\n");
|
|
close(rs232_uart_ttymxc_fd);
|
|
return (1);
|
|
}
|
|
log_printf(LOG_DEBUG,I_NOUSED,"rs232 init success.\n");
|
|
}
|
|
|
|
|
|
#if 1
|
|
int gps_rs232_init(uint32 baud,int databits,int stopbits,int parity)
|
|
{
|
|
pthread_mutex_init(&mutex_gps_rs232, NULL);
|
|
|
|
gps_uart_ttymxc_fd = OpenDev(GPS_RS232_FILENAME);
|
|
|
|
// set fd to nonblock , Improve the read/write speed serial port
|
|
fcntl(gps_uart_ttymxc_fd, F_SETFL, 0|O_NONBLOCK);
|
|
|
|
if (gps_uart_ttymxc_fd > 0) {
|
|
set_speed(gps_uart_ttymxc_fd, baud);
|
|
} else {
|
|
fprintf(stderr, "Error opening %s: %s\n", GPS_RS232_FILENAME, strerror(errno));
|
|
return (-1);
|
|
}
|
|
|
|
if (set_Parity(gps_uart_ttymxc_fd, databits, stopbits, parity)== FALSE) {
|
|
fprintf(stderr, "Set Parity Error\n");
|
|
close(gps_uart_ttymxc_fd);
|
|
return (-1);
|
|
}
|
|
log_printf(LOG_DEBUG,I_NOUSED,"gps rs232 init success.\n");
|
|
|
|
return 0;
|
|
}
|
|
|
|
int gps_uart_hw_init(void)
|
|
{
|
|
int ret=0;
|
|
uint16 bps=9600;
|
|
//uint16 uart_bps[4] = {9600,19200,38400,38400};
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"init gps-uart hw baud=%d\n",bps);
|
|
|
|
ret = gps_rs232_init(bps, 8, 1, 'N');
|
|
return ret;
|
|
}
|
|
|
|
|
|
int gps_rs232_send_string(const uint8 *pbuf,uint32 len)
|
|
{
|
|
int ret = 0;
|
|
|
|
if(len <= 0)
|
|
return 0;
|
|
|
|
ret = write(gps_uart_ttymxc_fd, pbuf, len);
|
|
setvbuf(stdout,(char*) pbuf, _IONBF, 0);
|
|
fflush(stdout);
|
|
system("sync");
|
|
|
|
if(ret < 0 )
|
|
log_printf(LOG_ERR,I_NOUSED,"ret=%d, len=%d\n", ret, len);
|
|
|
|
setvbuf(stdout,(char*) pbuf, _IONBF, 0);
|
|
fflush(stdout);
|
|
system("sync");
|
|
|
|
}
|
|
int gps_rs232_read_string(uint8 *pbuf,uint32 len)
|
|
{
|
|
int nread = 0;
|
|
|
|
nread = read(gps_uart_ttymxc_fd, pbuf, (size_t)len);
|
|
return nread;
|
|
}
|
|
|
|
#endif
|
|
|
|
int rs485_send_string(const uint8 *pbuf,uint32 len)
|
|
{
|
|
int ret = 0;
|
|
|
|
if(len <= 0)
|
|
return -1;
|
|
|
|
rs485_de_wr = 1;
|
|
|
|
ret = set_gpio_value(RS485_GPIO_NUM_DE, E_IO_H);
|
|
//system("echo 1 > /sys/class/gpio/gpio5/value"); // DE set wr
|
|
if(ret!=0){
|
|
return -1;
|
|
}
|
|
|
|
ret = write(uart_ttymxc_fd, pbuf, len);
|
|
setvbuf(stdout,(char*) pbuf, _IONBF, 0);
|
|
fflush(stdout);
|
|
system("sync");
|
|
|
|
if(ret < 0 )
|
|
log_printf(LOG_ERR,I_NOUSED,"ret=%d, len=%d\n", ret, len);
|
|
|
|
setvbuf(stdout,(char*) pbuf, _IONBF, 0);
|
|
fflush(stdout);
|
|
system("sync");
|
|
|
|
//system("echo 0 > /sys/class/gpio/gpio5/value"); // DE set rd
|
|
ret = set_gpio_value(RS485_GPIO_NUM_DE, E_IO_L);
|
|
|
|
rs485_de_wr = 0;
|
|
|
|
return ret;
|
|
}
|
|
|
|
int rs232_send_string(const uint8 *pbuf,uint32 len)
|
|
{
|
|
int ret = 0;
|
|
|
|
if(len <= 0)
|
|
return 0;
|
|
|
|
ret = write(rs232_uart_ttymxc_fd, pbuf, len);
|
|
setvbuf(stdout,(char*) pbuf, _IONBF, 0);
|
|
fflush(stdout);
|
|
system("sync");
|
|
|
|
if(ret < 0 )
|
|
log_printf(LOG_ERR,I_NOUSED,"ret=%d, len=%d\n", ret, len);
|
|
|
|
setvbuf(stdout,(char*) pbuf, _IONBF, 0);
|
|
fflush(stdout);
|
|
system("sync");
|
|
|
|
}
|
|
|
|
|
|
int rs485_read_string(uint8 *pbuf,uint32 len)
|
|
{
|
|
if(rs485_de_wr)
|
|
return 0;
|
|
|
|
int nread = 0;
|
|
|
|
//pthread_mutex_lock(&mutex_rs485);
|
|
nread = read(uart_ttymxc_fd, pbuf, (size_t)len);
|
|
|
|
//pthread_mutex_unlock(&mutex_rs485);
|
|
|
|
return nread;
|
|
}
|
|
|
|
int rs232_read_string(uint8 *pbuf,uint32 len)
|
|
{
|
|
int nread = 0;
|
|
|
|
//pthread_mutex_lock(&mutex_rs485);
|
|
nread = read(rs232_uart_ttymxc_fd, pbuf, (size_t)len);
|
|
|
|
//pthread_mutex_unlock(&mutex_rs485);
|
|
|
|
return nread;
|
|
}
|
|
|
|
|
|
void uart_hw_init(void)
|
|
{
|
|
uint8 bps;
|
|
uint16 uart_bps[4] = {9600,19200,38400,38400};
|
|
|
|
|
|
bps = atsc_para.config_para.bps;
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"init uart485 hw baud=%d\n",uart_bps[bps&3]);
|
|
|
|
rs485_init(uart_bps[bps&3], 8, 1, 'N');
|
|
}
|
|
|
|
void rs232_uart_hw_init(void)
|
|
{
|
|
uint8 bps;
|
|
uint16 uart_bps[4] = {9600,19200,38400,38400};
|
|
|
|
|
|
bps = atsc_para.config_para.bps;
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"init uart485 hw baud=%d\n",uart_bps[bps&3]);
|
|
|
|
rs232_init(uart_bps[bps&3], 8, 1, 'N');
|
|
}
|
|
|
|
void uart_hw_deinit(void)
|
|
{
|
|
close(uart_ttymxc_fd);
|
|
set_gpio_unexport(RS485_GPIO_NUM_DE);
|
|
}
|
|
|
|
|
|
void dev_pa_link_sec_check(void)
|
|
{
|
|
static uint16 sec_cnt=0;
|
|
|
|
pa_conn_chk();
|
|
|
|
#if USE_UART_DEV_LINK
|
|
sec_cnt++;
|
|
if(sec_cnt>=40){
|
|
sec_cnt = 40;
|
|
|
|
if(uart_dev_link.pa_link_cnt<=20){
|
|
uart_dev_link.pa_link_cnt++;
|
|
}
|
|
else{
|
|
uart_dev_link.pa_link_err = 1;
|
|
if(atsc_para.config_para.pa_link_ctrl_rf==1){//使能开关
|
|
if(atsc_para.rf_para.rf==1)
|
|
Net_write_RF(0);
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
#endif
|
|
//---------------------------------------------
|
|
|
|
void * uart_thr(void * args)
|
|
{
|
|
int nread;
|
|
MSG msg;
|
|
int ret;
|
|
rs485_de_wr = 0;// 0:read
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.] uart_thr Start.\n");
|
|
while(1) {
|
|
|
|
if(get_upgrade_flg()){
|
|
usleep(1000000);
|
|
continue;
|
|
}
|
|
//O_NONBLOCK
|
|
nread = rs485_read_string(uart_recv_buff, sizeof(uart_recv_buff));
|
|
if (nread > 0) {
|
|
memset(cmd_buff, 0 ,sizeof(cmd_buff));
|
|
memcpy(cmd_buff, uart_recv_buff, nread);
|
|
msg.type = MSG_RS232;
|
|
msg.need_free = MSG_NO_NEED_FREE; // lpara no need free
|
|
msg.lPara = (uint32)&cmd_buff;
|
|
msg.wPara = nread;
|
|
msg.rPara = UART_USER_485_COM;
|
|
ret=msg_send_to_uart(&msg);
|
|
if(ret<0){
|
|
log_printf(LOG_ERR,I_NOUSED,"485 recv then msgsnd failed\n");
|
|
usleep(200*1000);
|
|
}
|
|
}
|
|
|
|
//O_NONBLOCK
|
|
nread = rs232_read_string(rs232_uart_recv_buff, sizeof(rs232_uart_recv_buff));
|
|
if (nread > 0) {
|
|
memset(rs232_cmd_buff, 0 ,sizeof(rs232_cmd_buff));
|
|
memcpy(rs232_cmd_buff, rs232_uart_recv_buff, nread);
|
|
msg.type = MSG_RS232;
|
|
msg.need_free = MSG_NO_NEED_FREE; // lpara no need free
|
|
msg.lPara = (uint32)&rs232_cmd_buff;
|
|
msg.wPara = nread;
|
|
msg.rPara = UART_USER_232_COM;
|
|
ret=msg_send_to_uart(&msg);
|
|
if(ret<0){
|
|
log_printf(LOG_DEBUG,I_NOUSED,"232 recv then msgsnd failed\n");
|
|
usleep(200*1000);
|
|
}
|
|
}
|
|
|
|
usleep(5000);// wait 5ms
|
|
}
|
|
}
|
|
|
|
int creat_uart_thread(void)
|
|
{
|
|
int ret = -1;
|
|
pthread_t uart_thr_id;
|
|
|
|
log_printf(LOG_DEBUG,I_NOUSED,"[.thr.]->-\n");
|
|
uart_hw_init();
|
|
|
|
rs232_uart_hw_init();
|
|
|
|
ret = pthread_create(&uart_thr_id, NULL, (void *)uart_thr, NULL);
|
|
if(ret != 0) {
|
|
log_printf(LOG_ERR,I_NOUSED," creat thread err.\n");
|
|
return -1;
|
|
}
|
|
else{
|
|
log_printf(LOG_DEBUG,I_NOUSED," Ok . creat thread succeed.\n");
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|