希望高手帮帮忙~~~~
以下是我接受—解析—发送部分源码
static err_t TCP_SER_Receive(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
tTCPSessionData *pState;
pState=&g_sTCPSession;
unsigned char ProtID[2]={0x00,0x00};
unsigned short regLen;
unsigned short regLen_tmp; // ether_cmd register calculate tmp.
unsigned char eth_send_data[256]; //ethernet send byte ptr.
unsigned short uslen; //send byte length.
unsigned short usaddr,byte_addr=0; //inqire byte frist address.
unsigned char byte_len,ucCunt;
if((err == ERR_OK) && (p != NULL))
{
/* Inform TCP that we have taken the data. */
tcp_recved(pcb,p->tot_len);
eth_cmd= (unsigned char*)p->payload;
if((*(eth_cmd+2)==ProtID[0])&&(*(eth_cmd+3)==ProtID[1]))
{
if((*(eth_cmd+6)==s_psComData->ucMeterAddr)&&((*(eth_cmd+7)==0x03)||(*(eth_cmd+7)==0x04)))
{
regLen=((unsigned short)s_psComData->ucREGnumH)|s_psComData->ucREGnumL; //计算表里面的寄存器数目
usaddr = (unsigned short)*(eth_cmd+8)|(*(eth_cmd+9));
uslen = (unsigned short)*(eth_cmd+10)|(*(eth_cmd+11));
regLen_tmp = usaddr+uslen; // 计算命令帧中的寄存器数
//判断寄存器是不是越界,因为表内寄存器有限
if((regLen_tmp8)&0xFF);
eth_send_data[5] = (unsigned char)((byte_len+3)&0xFF);
eth_send_data[6] = s_psComData->ucMeterAddr;
eth_send_data[7] = *(eth_cmd+7);
eth_send_data[8] = byte_len;
for(ucCunt=0;ucCuntucData[byte_addr+ucCunt];
lCount=byte_len+9;
if(tcp_sndbuf(tpcb) < lCount)
{
lCount = tcp_sndbuf(tpcb);
}
// Write the local buffer into the TCP buffer
tcp_write(tpcb,eth_send_data,(byte_len+9),0);
pbuf_free(p); // 释放缓冲区数据
}