📄 connector_app.c
字号:
udp_send(udp_demo_soch,UDP_DEMO_RMTHOST_IP,UDP_DEMO_RMTHOST_PRT,net_buf+UDP_APP_OFFSET,NETWORK_TX_BUFFER_SIZE-UDP_APP_OFFSET,datalen);
OldSwitchValue = temp;
}
//============================================================
//============================================================
void get_led_state(void){
UINT16 i, datalen;
datalen=14;
//LED1
i = 0; net_buf[UDP_APP_OFFSET+i]='c';
i = 1; net_buf[UDP_APP_OFFSET+i]='o';
i = 2; net_buf[UDP_APP_OFFSET+i]='m';
i = 3; net_buf[UDP_APP_OFFSET+i]='m';
i = 4; net_buf[UDP_APP_OFFSET+i]='R';
i = 5; net_buf[UDP_APP_OFFSET+i]='C';
i = 6; net_buf[UDP_APP_OFFSET+i]='V';
i = 7; net_buf[UDP_APP_OFFSET+i]='@';
i = 8; net_buf[UDP_APP_OFFSET+i]='e';
i = 9; net_buf[UDP_APP_OFFSET+i]='q';
i = 10; net_buf[UDP_APP_OFFSET+i]='@';
if (PTG_PTG0 == 0) {
i = 11; net_buf[UDP_APP_OFFSET+i]='l';
i = 12; net_buf[UDP_APP_OFFSET+i]='1';
i = 13; net_buf[UDP_APP_OFFSET+i]='n';
udp_send(udp_demo_soch,UDP_DEMO_RMTHOST_IP,UDP_DEMO_RMTHOST_PRT,net_buf+UDP_APP_OFFSET,NETWORK_TX_BUFFER_SIZE-UDP_APP_OFFSET,datalen);
#if (GAMEMODE)
i = 0; net_buf[UDP_APP_OFFSET+i]='c';
i = 1; net_buf[UDP_APP_OFFSET+i]='o';
i = 2; net_buf[UDP_APP_OFFSET+i]='m';
i = 3; net_buf[UDP_APP_OFFSET+i]='m';
i = 4; net_buf[UDP_APP_OFFSET+i]='C';
i = 5; net_buf[UDP_APP_OFFSET+i]='o';
i = 6; net_buf[UDP_APP_OFFSET+i]='n';
i = 7; net_buf[UDP_APP_OFFSET+i]='n';
i = 8; net_buf[UDP_APP_OFFSET+i]='e';
i = 9; net_buf[UDP_APP_OFFSET+i]='c';
i = 10; net_buf[UDP_APP_OFFSET+i]='t';
i = 11; net_buf[UDP_APP_OFFSET+i]='@';
i = 12; net_buf[UDP_APP_OFFSET+i]='e';
i = 13; net_buf[UDP_APP_OFFSET+i]='q';
i = 14; net_buf[UDP_APP_OFFSET+i]='@';
i = 15; net_buf[UDP_APP_OFFSET+i]='t';
i = 16; net_buf[UDP_APP_OFFSET+i]='r';
i = 17; net_buf[UDP_APP_OFFSET+i]='u';
i = 18; net_buf[UDP_APP_OFFSET+i]='e';
udp_send(udp_demo_soch,UDP_DEMO_RMTHOST_IP,UDP_DEMO_RMTHOST_PRT,net_buf+UDP_APP_OFFSET,NETWORK_TX_BUFFER_SIZE-UDP_APP_OFFSET,i+1);
#endif //(GAMEMODE)
}
else {
i = 11; net_buf[UDP_APP_OFFSET+i]='l';
i = 12; net_buf[UDP_APP_OFFSET+i]='1';
i = 13; net_buf[UDP_APP_OFFSET+i]='f';
udp_send(udp_demo_soch,UDP_DEMO_RMTHOST_IP,UDP_DEMO_RMTHOST_PRT,net_buf+UDP_APP_OFFSET,NETWORK_TX_BUFFER_SIZE-UDP_APP_OFFSET,datalen);
}
//LED2
i = 0; net_buf[UDP_APP_OFFSET+i]='c';
i = 1; net_buf[UDP_APP_OFFSET+i]='o';
i = 2; net_buf[UDP_APP_OFFSET+i]='m';
i = 3; net_buf[UDP_APP_OFFSET+i]='m';
i = 4; net_buf[UDP_APP_OFFSET+i]='R';
i = 5; net_buf[UDP_APP_OFFSET+i]='C';
i = 6; net_buf[UDP_APP_OFFSET+i]='V';
i = 7; net_buf[UDP_APP_OFFSET+i]='@';
i = 8; net_buf[UDP_APP_OFFSET+i]='e';
i = 9; net_buf[UDP_APP_OFFSET+i]='q';
i = 10; net_buf[UDP_APP_OFFSET+i]='@';
i = 11; net_buf[UDP_APP_OFFSET+i]='l';
i = 12; net_buf[UDP_APP_OFFSET+i]='2';
if (PTG_PTG1 == 0) {
i = 13; net_buf[UDP_APP_OFFSET+i]='n';
udp_send(udp_demo_soch,UDP_DEMO_RMTHOST_IP,UDP_DEMO_RMTHOST_PRT,net_buf+UDP_APP_OFFSET,NETWORK_TX_BUFFER_SIZE-UDP_APP_OFFSET,datalen);
}
else {
i = 13; net_buf[UDP_APP_OFFSET+i]='f';
udp_send(udp_demo_soch,UDP_DEMO_RMTHOST_IP,UDP_DEMO_RMTHOST_PRT,net_buf+UDP_APP_OFFSET,NETWORK_TX_BUFFER_SIZE-UDP_APP_OFFSET,datalen);
}
}
//============================================================
/* Initialize resources needed for the UDP socket application */
//============================================================
void udp_demo_init(void){
DEBUGOUT("Initializing UDP demo client\r\n");
/* Get socket:
* 0 - for now not type of service implemented in UDP
* udp_echo_eventlistener - pointer to listener function
* UDP_OPT_SEND_CS|UDP_OPT_CHECK_CS - checksum options. Calculate
* checksum for outgoing packets and check checksum for
* received packets.
*/
udp_demo_soch=udp_getsocket(0 , udp_demo_eventlistener , UDP_OPT_SEND_CS | UDP_OPT_CHECK_CS);
if(udp_demo_soch == -1){
DEBUGOUT("No free UDP sockets!! \r\n");
RESET_SYSTEM();
}
/* open socket for receiving/sending of the data on defined UDP_DEMO_RMTHOST_PRT*/
udp_open(udp_demo_soch,UDP_DEMO_PORT);
/* for now no data sending */
udp_demo_senddata=0;
}
//============================================================
/* UDP Demo app main loop that is periodically invoked from the
* main loop (see main_demo.c)
*/
//============================================================
void udp_demo_run(void){
udp_demo_send();
get_a2d(0);
#if (~GAMEMODE & 1)
check_switch();
#endif //(~GAMEMODE & 1)
}
//============================================================
/*
* Event listener invoked when TCP/IP stack receives UDP datagram for
* a given socket. Parameters:
* - cbhandle - handle of the socket this packet is intended for. Check it
* just to be sure, but in general case not needed
* - event - event that is notified. For UDP, only UDP_EVENT_DATA
* - UDP_DEMO_RMTHOST_IP - IP address of remote host who sent the UDP datagram
* - UDP_DEMO_RMTHOST_PRT - UDP_DEMO_RMTHOST_PRT number of remote host who sent the UDP datagram
* - buffindex - buffer index in RTL8019AS allowing you to read
* received data more than once from Ethernet controller by
* invoking NETWORK_RECEIVE_INITIALIZE(buffindex) and then start
* reading the bytes all over again
*/
//============================================================
INT32 udp_demo_eventlistener (INT8 cbhandle, UINT8 event, UINT32 ipaddr, UINT16 port, UINT16 buffindex, UINT16 datalen) {
UINT16 i;
if(cbhandle!=udp_demo_soch){
DEBUGOUT("Not my handle!!!!");
return (-1);
}
switch(event){
case UDP_EVENT_DATA:
/* read data to transmit buffer and send response*/
if(datalen>(NETWORK_TX_BUFFER_SIZE-UDP_APP_OFFSET))
datalen=NETWORK_TX_BUFFER_SIZE-UDP_APP_OFFSET;
if (datalen <= 3 ) {
ETH_DEBUGOUT("Command proper size\n");
RECEIVE_NETWORK_BUF(net_buf+UDP_APP_OFFSET,datalen);
//LEDs
if (net_buf[UDP_APP_OFFSET+0] == 'l') {
if (net_buf[UDP_APP_OFFSET+1] == '1') {
if (net_buf[UDP_APP_OFFSET+2] == 'n') {
PTG_PTG0 = 0;
#if !(GAMEMODE)
OldSwitchValue=255;
OldPot=1050;
#endif
get_led_state();
}
else if (net_buf[UDP_APP_OFFSET+2] == 'f') {
PTG_PTG0 = 1;
}
}
else if (net_buf[UDP_APP_OFFSET+1] == '2') {
if (net_buf[UDP_APP_OFFSET+2] == 'n') {
PTG_PTG1 = 0;
}
else if (net_buf[UDP_APP_OFFSET+2] == 'f') {
PTG_PTG1 = 1;
}
}
}
}
else {
//Command to big
}
break;
default:
/* should never get here */
DEBUGOUT("Unknown UDP event :-(");
break;
}
return 0;
}
//============================================================
/* internal function invoked to send UDP message to, in this case,
* some predefined host.
*/
//============================================================
INT16 udp_demo_send (void) {
UINT8 NewB1;
UINT16 i, datalen;
datalen = 13;
i = 0; net_buf[UDP_APP_OFFSET+i]='c';
i = 1; net_buf[UDP_APP_OFFSET+i]='o';
i = 2; net_buf[UDP_APP_OFFSET+i]='m';
i = 3; net_buf[UDP_APP_OFFSET+i]='m';
i = 4; net_buf[UDP_APP_OFFSET+i]='R';
i = 5; net_buf[UDP_APP_OFFSET+i]='B';
i = 6; net_buf[UDP_APP_OFFSET+i]='1';
i = 7; net_buf[UDP_APP_OFFSET+i]='@';
i = 8; net_buf[UDP_APP_OFFSET+i]='e';
i = 9; net_buf[UDP_APP_OFFSET+i]='q';
i = 10; net_buf[UDP_APP_OFFSET+i]='@';
NewB1 = PORTE_BIT0;
if (NewB1 != OldB1) {
i = 11; net_buf[UDP_APP_OFFSET+i]='b';
i = 12; net_buf[UDP_APP_OFFSET+i]='1';
OldB1 = NewB1;
if (NewB1 == 0) udp_send(udp_demo_soch,UDP_DEMO_RMTHOST_IP,UDP_DEMO_RMTHOST_PRT,net_buf+UDP_APP_OFFSET,NETWORK_TX_BUFFER_SIZE-UDP_APP_OFFSET,datalen);
}
}
//============================================================
//============================================================
void porth_isr_handler(void) {
UINT8 NewB2;
UINT16 i, datalen;
NewB2 = PTH_PTH4;
if (NewB2 != OldB2) {
datalen = 13;
i = 0; net_buf[UDP_APP_OFFSET+i]='c';
i = 1; net_buf[UDP_APP_OFFSET+i]='o';
i = 2; net_buf[UDP_APP_OFFSET+i]='m';
i = 3; net_buf[UDP_APP_OFFSET+i]='m';
i = 4; net_buf[UDP_APP_OFFSET+i]='R';
i = 5; net_buf[UDP_APP_OFFSET+i]='B';
i = 6; net_buf[UDP_APP_OFFSET+i]='2';
i = 7; net_buf[UDP_APP_OFFSET+i]='@';
i = 8; net_buf[UDP_APP_OFFSET+i]='e';
i = 9; net_buf[UDP_APP_OFFSET+i]='q';
i = 10; net_buf[UDP_APP_OFFSET+i]='@';
if (NewB2 == 0) {
PPSH_PPSH4 = 1;
i = 11; net_buf[UDP_APP_OFFSET+i]='b';
i = 12; net_buf[UDP_APP_OFFSET+i]='n';
udp_send(udp_demo_soch,UDP_DEMO_RMTHOST_IP,UDP_DEMO_RMTHOST_PRT,net_buf+UDP_APP_OFFSET,NETWORK_TX_BUFFER_SIZE-UDP_APP_OFFSET,datalen);
PIFH = PIFH_PIFH4_MASK; //Clear Intrrupt
}
else if (NewB2 == 1) {
PPSH_PPSH4 = 0;
i = 11; net_buf[UDP_APP_OFFSET+i]='b';
i = 12; net_buf[UDP_APP_OFFSET+i]='f';
udp_send(udp_demo_soch,UDP_DEMO_RMTHOST_IP,UDP_DEMO_RMTHOST_PRT,net_buf+UDP_APP_OFFSET,NETWORK_TX_BUFFER_SIZE-UDP_APP_OFFSET,datalen);
PIFH = PIFH_PIFH4_MASK; //Clear Intrrupt
}
OldB2 = NewB2;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -