资源简介
slip.c 代码
代码片段和文件信息
#include “testlib3.h“
#ifdef MODULE_SLIP
#define THIS_MODULE “SLIP“
const int SERV_PORT = 60180; //5555;
#define MAX_MESG_SIZE 1024
#define TTY_SLIP_NUM 10
#define DISPLAY_LINE 4
#define CMD “baudrate:“
static int clientcnt = 0;
static int leavedclientcnt = 0;
char tty[64];
char speed[64];
char localIp[64];
char peerIp[64];
char peerNetIp[64];
char ttyNames[TTY_SLIP_NUM][64];
char speeds[TTY_SLIP_NUM][64];
char localIps[TTY_SLIP_NUM][64];
char peerIps[TTY_SLIP_NUM][64];
void slip_server();
void printd(char *fmt int size) {
int i = 0;
for(i = 0; i < size; i ++)
printf(“DEBUG: line-%d %02x“ __LINE__ fmt[i]);
}
void setting_SLIP() {
const char *ttys[] = {“/dev/ttyAMA2“ “/dev/ttyAMA3“ “/dev/ttydev“ “/dev/ttyhost“};
int sel = 0;
clearline_p(0 -1);
printline_p(0 LEFT_P “KEY1 - Client“);
printline_p(1 LEFT_P “KEY2 - Server“);
printline_p(2 LEFT_P “please enter:(other key exit)“);
sel = getkey_p();
if(sel == KEY1_P) {
clearline_p(0 -1);
printline_p(0 LEFT_P “KEY1 - /dev/ttyAMA2“);
printline_p(1 LEFT_P “KEY2 - /dev/ttyAMA3“);
printline_p(2 LEFT_P “KEY3 - /dev/ttydev“);
printline_p(3 LEFT_P “KEY4 - /dev/ttyhost“);
printline_p(4 LEFT_P “please enter:(other key exit)“);
switch(getkey_p()) {
case KEY1_P:
strcpy(tty ttys[0]);
break;
case KEY2_P:
strcpy(tty ttys[1]);
break;
case KEY3_P:
strcpy(tty ttys[2]);
break;
case KEY4_P:
strcpy(tty ttys[3]);
break;
default:
return;
}
do {
GET_STR_VALUE(“Baudrate:“ speed “115200“);
GET_STR_VALUE(“localIp:“ localIp “192.168.0.1“);
GET_STR_VALUE(“peerIp:“ peerIp “192.168.0.2“);
GET_STR_VALUE(“peerNetIp:“ peerNetIp “192.168.0.2“);
}while(0);
}
else if(sel == KEY2_P) {
slip_server();
}
}
int send_baudrate_sync(const char *baudrate) {
int sockfd iRet;
struct sockaddr_in servaddr;
char sendbuff[128];
char recvbuff[128];
int i len;
unsigned char lrc = 0xff;
bzero(&servaddr sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(SERV_PORT);
inet_aton(peerIp &servaddr.sin_addr);
sockfd = socket(AF_INET SOCK_STREAM 0);
ASSERT(sockfd > 0 “socket error=%d %s“ errno strerror(errno));
if(sockfd < 0){
return -1;
}
iRet = connect(sockfd (struct sockaddr*) &servaddr sizeof(servaddr));
ASSERT(iRet == 0 “connect error=%d %s“ errno strerror(errno));
if ( iRet < 0)
{
return -1;
}
memset(sendbuff 0 sizeof sendbuff);
sendbuff[0] = 0x02;
strcpy(sendbuff+1 CMD);
strcpy(sendbuff+1+strlen(CMD) baudrate);
sendbuff[0+1+strlen(CMD)+strlen(baudrate)] = 0x03;
for(i = 0; i < strlen(sendbuff); i++)
{
lrc ^= sendbuff[i];
}
sendbuff[strlen(sendbuff)] = lrc;
if(lrc == 0) {
iRet = send(sockfd sendbuff strlen(sendbuff)+1 0);
ASSERT(iRet == strlen(sendbuff) “send error errno=%d %s“ errno strerror(errno));
}
else {
- 上一篇:应用服务器直接上传视频文件到抖英开放平台
- 下一篇:11种数字模拟混合信号调制识别
评论
共有 条评论