/* demo for support "use com0" function on TCP port 9999. 1.先測試一個封包一個命令。 */ #include "module1.h" typedef struct { int skt; int slot; char *cmd; void (*fun)(pCOMPORT com); } SLOT_DCON_CMD, *pSLOT_DCON_CMD; int Add87kCmd_1(int slot,int skt,char *cmd,void (*fun)(pCOMPORT)); extern int SlotNo; extern pSLOT_DCON_CMD CurCom0Cmd; int CurSlot=0; char CurDio[100]={0}; void DoCom0Reply(pCOMPORT com) { com->Buf[com->Size]=0; TcpPrint(CurCom0Cmd->skt,1,"%s\r",com->Buf); } /* -------------------------------------------------------------------------------- int VcomCmd7000(TCPREADDATA *p); -------------------------------------------------------------------------------- VCOM3001 or later will call this function for port 9999. when socket from TCP PORT 9999 will call this function. user can get the following message: p->ReadUartChar : the buffer store the command data. p->Length : the command data length. p->Socket : the socket number that receive the command, that is when the user function want return message to the client, just use the socket to send data. use: VcomSendSocket(p->Socket,pdata,datalength); */ int VcomCmd7000(TCPREADDATA *p) { char *cmd; int slot; cmd=p->ReadUartChar; cmd[p->Length]=0; if(*cmd=='/'){ //command if(!strncmp("slot",cmd+1,4)){ slot=atoi(cmd+5); if(slot>=0 && slot < SlotNo){ CurSlot=slot; ChangeToSlot(slot); TcpPrint(p->Socket,1,"Change to slot %d\r\n",slot); } else { TcpPrint(p->Socket,1,"CAN NOT Change to slot %d\r\n",slot); } } } else { // the command to 87K module if(cmd[p->Length-1]=='\r') cmd[p->Length-1]=0; //TcpPrint(p->Socket,1,"[%s]",cmd); Add87kCmd_1(CurSlot,p->Socket,cmd,DoCom0Reply); } }