分析BACnet协议栈2.doc

分析BACnet协议栈2.doc

ID:49505835

大小:58.00 KB

页数:6页

时间:2020-03-02

分析BACnet协议栈2.doc_第1页
分析BACnet协议栈2.doc_第2页
分析BACnet协议栈2.doc_第3页
分析BACnet协议栈2.doc_第4页
分析BACnet协议栈2.doc_第5页
资源描述:

《分析BACnet协议栈2.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、mstpscap.c这个文件主要实现从串口上抓取MS/TP协议上的packet功能。测试时的格式为:mstsnap[serial][baud][network]默认参数是串口/dev/ttyUSBO.波特率赴38400,ethO:#include#include#inelude#include#ineluderOSspecificinclude*/#include“net.

2、h"#include"timer.h”rlocalincludes7#include”bytes.h”#includeHrs485.hM#include"crc.h"#include"mstp.h”#include”dlmslp.h”#includeMmstptext.hw#include"bacint.h"/"@filelinux/mstpsnap.cExampleapplicationtestingBACnetMS/TPonLinux.*/#ifndefmax#definemax(a,b)({(a)

3、>(b))?(a):(b))#definemin(a,b)(((a)<(b))?(a):(b))#endifrlocalportdata-sharedwithRS-485*/staticvolatilestructmstp_port_struct_tMSTP_Port;/*buffersneededbymstpportstruct*/staticuint8JRxBuffer[MAX_MPDU];staticuint8JTxBuffer[MAX_MPDU];staticuint16_tTimer_Sile

4、nce(void){uint32jdelta_time=0;deltajime=timer_milliseconds仃IMERSILENCE);if(deltajime>OxFFFF){deltajime=OxFFFF;}return(uint16J)deltajime;}staticvoidTimer_Silence_Reset(void){timer_reset仃IMER一SILENCE);rfunctionsusedbytheMS/TPstatemachinetoputorgetdata7uint

5、16JMSTP_Put_Receive(volatilestructmstp_port_struct」*mstp_port){(void)mstp_port;return0;}/*fortheMS/TPstatemachinetouseforgettingdatatosend*/rReturn:amountofPDUdata7uint16_tMSTP_Get_Send(volatilestructmstp_port_struct_t*mstp_port,unsignedtimeout){/*millis

6、econdstowaitforapacket*/(void)mstp__port;(void)timeout;return0;}uint16JMSTP_Get_Reply(volatilestructmstp_port_struct_t*mstp^port,unsignedtimeout){/*millisecondstowaitforapacket7(void)mstp_port;(void)timeout;return0;}staticintnetwork」nit(constchar*name,in

7、tprotocol){rchecktoseeifwearebeingrunasroot*/if(getuid()!=0){〃函数返回•个调用程序的宾实川户ID.般来说,这个函数祁於会调用成功的。getuid=0农示root用fprintffstderr,'RequiresrootprivelegesAn");return-1;}intsockfd=socket(PF_PACKET,SOCK_RAWthtons(protocol));//得到原始的IP包,htons得到网络字冲序(人瑤模式)网络上统使用大

8、瑞模式传输if(sockfd==-1){perror(HUnabletocreatesocket'*);returnsockfd;}structifreqifr;〃获取IP地址和MAC地址memset(&ifr,0,sizeof(ifr));stmcpy(ifr.ifr_name,name,strlen(name));if(ioctl(sockfd,SIOCGIFINDEX,&ifr)==-1){//获取并打印网冃也址perror(uUna

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。