📄 net.c
字号:
unsigned char t1;
t1=0;
checksum=0;
for(i=2;i<5;i++)
{
t1=net_Rxout+i;
checksum = checksum+ net_rx_buf[t1];
}
checksum=~checksum+1;
t1=net_Rxout+5;
if( net_rx_buf[t1]==checksum )
{
net_send_cmd(1,5);
t1=net_Rxout+4;
temperature_h[0]=net_rx_buf[t1];
write_eeprom(S1_TEMP_ADDR_H,temperature_h[0]);
}
net_Rxout += 6;
net_Rxout &= DATA_LEN;
}
//---------------------------------------------------------
// NAME: net_set_sound()
// ENTRY: void
// RETURN: void
// FUNCTION:根据数据信息分析设置声音
// MODIFY: 2004.2.3
//---------------------------------------------------------
void net_set_sound(void)
{
unsigned char i,checksum;
unsigned char t1;
unsigned char temp;
t1=0;
checksum=0;
for(i=2;i<6;i++)
{
t1=net_Rxout+i;
checksum = checksum+ net_rx_buf[t1];
}
checksum=~checksum+1;
t1=net_Rxout+6;
if( net_rx_buf[t1]==checksum )
{
net_send_cmd(1,5);
t1=net_Rxout+4;
if(net_rx_buf[t1]==1)
{
t1=net_Rxout+5;
if(net_rx_buf[t1])
temp=1;
else
temp=0;
for(i=0;i<4;i++)
{
sound_swtich[i]=temp;
write_eeprom(0x005A +i,temp);
}
}
else
{
t1=net_Rxout+5;
sound_type_saved=net_rx_buf[t1];
write_eeprom(0x0052,sound_type_saved); //sound type
}
}
net_Rxout += 7;
net_Rxout &= DATA_LEN;
}
//---------------------------------------------------------
// NAME: net_set_clock()
// ENTRY: void
// RETURN: void
// FUNCTION:根据数据信息分析设置时钟
// MODIFY: 2004.2.3
//---------------------------------------------------------
void net_set_clock(void)
{
unsigned char i,checksum;
unsigned char t1;
t1=0;
checksum=0;
for(i=2;i<7;i++)
{
t1=net_Rxout+i;
checksum = checksum+ net_rx_buf[t1];
}
checksum=~checksum+1;
t1=net_Rxout+7;
if( net_rx_buf[t1]==checksum )
{
net_send_cmd(1,5);
t1=net_Rxout+4;
time[2]= net_rx_buf[t1];
time[1]= net_rx_buf[t1+1];
time[0]= net_rx_buf[t1+2];
set_time(time[0],time[1],time[2]);
set_date(time[3],time[4],time[5],time[6]);
}
net_Rxout += 11;
net_Rxout &= DATA_LEN;
}
//---------------------------------------------------------
// NAME: net_set_password()
// ENTRY: void
// RETURN: void
// FUNCTION:根据数据信息分析设置密码
// MODIFY: 2004.2.3
//---------------------------------------------------------
void net_set_password(void)
{
unsigned char i,checksum;
unsigned char t1;
t1=0;
checksum=0;
for(i=2;i<10;i++)
{
t1=net_Rxout+i;
checksum = checksum+ net_rx_buf[t1];
}
checksum=~checksum+1;
t1=net_Rxout+10;
if( net_rx_buf[t1]==checksum )
{
net_send_cmd(1,5);
for(i=0;i<6;i++)
{
t1=net_Rxout+4+i;
menu_password[i]=net_rx_buf[t1];
write_eeprom(PASSWORD_ADD+i,menu_password[i]);
}
}
net_Rxout += 11;
net_Rxout &= DATA_LEN;
}
//---------------------------------------------------------
// NAME: net_password_check()
// ENTRY: void
// RETURN: void
// FUNCTION:以太网登陆密码校验
// MODIFY: 2004.2.3
//---------------------------------------------------------
void net_password_check(void)
{
unsigned char i,checksum;
unsigned char t1;
t1=0;
checksum=0;
for(i=2;i<10;i++)
{
t1=net_Rxout+i;
checksum = checksum+ net_rx_buf[t1];
}
checksum=~checksum+1;
t1=net_Rxout+10;
if( net_rx_buf[t1]==checksum )
{
net_password_ok=1;
for(i=0;i<6;i++)
{
t1=net_Rxout+4+i;
if(net_password[i]!=net_rx_buf[t1])
net_password_ok=0;
}
if(net_password_ok)
net_send_cmd(1,5);
else
password_check_count++;
if(password_check_count>=3) //password check more than 3 times
{
W3100A_close(); //terminate the connection
password_check_count=0;
have_connect=0;
}
}
net_Rxout += 11;
net_Rxout &= DATA_LEN;
}
//---------------------------------------------------------
// NAME: client_control_power()
// ENTRY: void
// RETURN: void
// FUNCTION:远程控制电源
// MODIFY: 2004.2.3
//---------------------------------------------------------
void client_control_power(void)
{
unsigned char i,checksum;
unsigned char temp,temp1,len;
temp=0;len=0;temp1=0;
checksum=0;
for(i=2;i<5;i++)
{
temp=net_Rxout+i;
checksum = checksum+ net_rx_buf[temp];
}
checksum=~checksum+1;
temp=net_Rxout+5;
if( net_rx_buf[temp]==checksum )
{
temp=net_Rxout+4;
temp1=net_Rxout+2;
len=net_rx_buf[temp1]+3;
if(net_rx_buf[temp]&&(!power_on))
{
server_power_on();//start_server();
}
else
{
if((!net_rx_buf[temp])&&power_on)
com_send_cmd(2,len); //send to the uart
}
}
net_Rxout+=len;
net_Rxout &= DATA_LEN;
}
//---------------------------------------------------------
// NAME: net_client_receive_to_face()
// ENTRY: void
// RETURN: void
// FUNCTION:远程网管控制MCU控制板本地设置
// MODIFY: 2004.2.3
//---------------------------------------------------------
void net_client_receive_to_face(void)
{
unsigned char len,comm;
unsigned char temp;
temp=0;
if( net_Rxin>net_Rxout )
{
len = net_Rxin-net_Rxout;
}
else len = 256-(net_Rxout-net_Rxin);
temp=net_Rxout+3;
comm=net_rx_buf[temp];
switch( comm )
{
case 1:
if(len<9) return;
net_set_qam();
break;
case 2: //set the temperature
if(len<6) return;
net_set_temperature();
break;
case 3: //set the sound
if(len<7) return;
net_set_sound();
break;
/*
case 3: //set the Ethernet
if( len<6 ) return;
net_set_enet();
break;
case 4: //set the uart
if( len<6 ) return;
break;
*/
case 6: //set the clock
if( len<8 ) return;
net_set_clock();
break;
case 7: //set the password
if( len<11 ) return;
net_set_password();
break;
case 8: //client loading password check
if( len<11 ) return;
net_password_check();
break;
/*
case 8: //net is closed by the client
if( len<6 ) return;
net_close();
break;
*/
case 9: //remote control power on/off
if( len<6 ) return;
client_control_power();
break;
case 10:
rst_pc();
break;
default:
net_Rxout++; net_Rxout &= 255;
break;
}
}
//---------------------------------------------------------
// NAME: net_client_receive_to_server()
// ENTRY: void
// RETURN: void
// FUNCTION:远程网管与服务器的信息交换
// MODIFY: 2004.2.3
//---------------------------------------------------------
void net_client_receive_to_server(void)
{
unsigned char checksum;
unsigned char len,i;
unsigned char temp;
temp=0;
checksum=0;
if( net_Rxin>net_Rxout )
{
len = net_Rxin-net_Rxout;
}
else len = 256-(net_Rxout-net_Rxin);
for(i=0;i<(len-3);i++) //count checksum
{
temp=net_Rxout+2+i;
checksum = checksum+ net_rx_buf[temp];
}
checksum=~checksum+1;
temp=net_Rxout+len-1;
if( net_rx_buf[temp]==checksum ) //commpare checksum
{
//net_send_cmd(1,5); //ack to the net//no ack needed
com_send_cmd(2,len); //send to the uart
net_Rxout+=len;
net_Rxout &= DATA_LEN;
}
}
//---------------------------------------------------------
// NAME: net_client_receive()
// ENTRY: void
// RETURN: void
// FUNCTION:分析处理远程网管信息
// MODIFY: 2004.2.3
//---------------------------------------------------------
void net_client_receive( void )
{
unsigned char comm;
unsigned char checksum;
unsigned char len;
unsigned char temp;
temp=0;
WDR();
net_receive_data_operation();
if( net_Rxin==net_Rxout )
return;
if( net_Rxin>net_Rxout )
{
len = net_Rxin-net_Rxout;
}
else len = 256-(net_Rxout-net_Rxin);
if( len<5) return; //receive data is enough?
while( len>0 ) //search the start char of the information
{
if( net_rx_buf[net_Rxout]==0X47 ) break;
net_Rxout++;
net_Rxout &= 255;
len--;
}
if( len<5 ) return; //receive data is enough?
if(!net_password_ok) //check the ethernet passwor
{
if(len<11) return;
comm = net_rx_buf[net_Rxout+1]; //read the command uchar
if(comm==0xaa)
net_password_check();
return;
}
temp=net_Rxout+1;
comm = net_rx_buf[temp]; //read the command uchar
checksum = 0;
if(comm==0xaa)
{
if( len<6) return;
net_client_receive_to_face();
}
else if(comm==0x55)
{
if( len<5) return;
net_client_receive_to_server();
}
}
//---------------------------------------------------------
// NAME: net_client_transmit()
// ENTRY: void
// RETURN: void
// FUNCTION:向远程网管发送数据信息
// MODIFY: 2004.2.3
//---------------------------------------------------------
void net_client_transmit(unsigned char leng )
{
unsigned char i,num;
WDR();
if( net_Txout == net_Txin ) // judge the send array is emtpy ?
{
if( !net_tx_empty )
return; // the send data in the send array is full
num = 255; // the most send array
}
else // there is data in the send array
{
if( net_Txout<net_Txin ) // count the length of send array spare space
num=256-(net_Txin-net_Txout);
else num=(net_Txout-net_Txin);
}
if( num<5 )
return; // the space of the send array is not enough
for( i=0;i<leng;i++ )
{
net_tx_buf[net_Txin] = net_send_data[i]; // put the data to be send into the send array
++net_Txin;
net_Txin &= DATA_LEN;
}
if( net_tx_empty ) // send array have empty
{
//UDR1=net_send_data[0]; // start send data
net_transmit_data_opertion(leng);
//net_Txout++;
net_Txout+=leng;
net_Txout &= DATA_LEN;
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -