发表于:2004-04-09 17:04:00
楼主
我是一个学生,目前正在做一个LonWorks网络列车监控系统,系统的基本原理是车厢上的微机将检测到的数据通过lon网传输到主站上显示,本设计要解决RS232与lon网络通讯问题,由于要传输的数据比较多(一次七个字节)故采用网络报文传输,同时由于成本问题决定自己开发网关,用单片机解决RS232与lon网络通讯问题。可实际的传输速度达不到列车上的一些要求,想问一下问题可能处在什么地方,可有好的解决方案?谢谢。
具体程序如下:
#pragma enable_io_pullups
#pragma app_buf_out_priority_count 0
#pragma net_buf_out_priority_count 0
#pragma receive_trans_count 15
#pragma num_domain_entries 1
#pragma num_addr_table_entries 3
#include <netmgmt.h>
#include <msg_addr.h>
#include <status.h>
#define NODE_ID 2
#define BUF_SIZE 60
IO_0 input byte data_in;
IO_0 output byte data_out;
IO_8 output bit data_wr;
IO_9 output bit data_rd;
IO_10 input bit request_flag;
unsigned short send_flag;
unsigned short Receive_buf[BUF_SIZE];
unsigned short Receive_head=0;
unsigned short Receive_tail=0;
unsigned short Send_buf[BUF_SIZE];
unsigned short Send_head=0;
unsigned short Send_tail=0;
unsigned short Temp1_buf[BUF_SIZE];
unsigned short Temp1_total;
unsigned short Temp2_buf[BUF_SIZE];
unsigned short Temp2_total;
msg_tag bind_info (nonbind) TAG_OUT;
priority when(msg_arrives)
{ for(int i=0;i<msg_in.len;i++)
{ Receive_buf[Receive_tail]=msg_in.data[i];
Receive_tail++;
Receive_tail%=BUF_SIZE;
}
}
priority when(io_in(request_flag)==0)
{ unsigned short data_temp;
io_set_direction(data_in);
io_out(data_rd,0);
data_temp=io_in(data_in);
io_out(data_rd,1);
if(send_flag==1) send_flag=0;
else
{ Send_buf[Send_tail]=data_temp;
io_out(data_wr,1);
Send_tail++;
Send_tail%=BUF_SIZE;
io_out(data_wr,0);
}
}
when(1)
{ if(Receive_head != Receive_tail && send_flag==0)
{ io_set_direction(data_out);
io_out(data_out,Receive_buf[Receive_head]);
send_flag=1;
io_out(data_wr,1);
Receive_head++;
Receive_head%=BUF_SIZE;
io_out(data_wr,0);
}
if(Send_head != Send_tail)
{ Temp1_total=0;
while(Send_head != Send_tail)
{ Temp1_buf[Temp1_total]=Send_buf[Send_head];
Temp1_total++;
Send_head++;
Send_head%=BUF_SIZE;
}
msg_out.tag=TAG_OUT;
msg_out.code=0;
memcpy(msg_out.data,Temp1_buf,Temp1_total);
msg_out.dest_addr.bcast.type=BROADCAST;
msg_out.dest_addr.bcast.domain=0;
msg_out.dest_addr.bcast.subnet=0;
msg_out.dest_addr.bcast.backlog=0;
msg_out.dest_addr.bcast.rpt_timer=8;
msg_out.dest_addr.bcast.retry=3;
msg_out.dest_addr.bcast.tx_timer=6;
msg_out.service=UNACKD;
msg_send();
}
}
when(reset)
{
io_out(data_wr,0);
io_out(data_rd,1);
io_set_direction(data_out);
io_out(data_out,0x03);
}
when(power_up)
{
domain_struct my_domain;
my_domain=*(access_domain(0));
my_domain.len=0;
my_domain.subnet=1;
my_domain.node=NODE_ID;
memset(my_domain.key,0xff,6);
update_domain(&my_domain,0);
}