BACnet通讯
1、概述.
系统实现基于BACnet/IP(又称B/IP)网络进行通讯。BACnet虚拟链路层(BVLL)提供了BACnet网络层和某指定的通讯子系统的接口,本文指定了BACnet虚拟链路控制(BVLC)要求支持的定向和广播信息。本实现关于BACnet协议定义主要可分为三层:B/IP网络虚拟层,BACnet网络层和BACnet应用层。B/IP提供了TCP/IP一样的通讯结构,采用UDP的通讯方式。本文接下来将对此三层结构进行详细的讲解。
其文本协议的大致格式如下: BACnet/IP BVLC Type BVLC Function Length BACnet网络层 NPDU BACnet 应用层 APDU NPDU:BACnet网络层数据结构,下文进行详细的讲解 APDU:BACnet应用层数据结构,下文进行详细的讲解
2、BACnet/IP.
BVLC Type: 0x81,代表BACnet/IP网络
BVLC Function: 指定报文的类型,何种作用;本应用使用的报文类型分为两种: 0A:点对点通讯
0B:广播通信 Length: NPDU: APDU:
指定报文的长度,包括BVLC Type、BVLC Function以及本身在内根据不同情况,报文长短不同,见下文的解析。
根据NPDU不同以及不同的请求,报文不同,见下文的解析。
3、BACnet NPDU结构.
版本信息 控制字 目标网络号 目标网络长度 目标地址 原网络号 原网络长度 原地址 路由数目 消息类型 卖方ID 应用层信息 版本信息 控制字
1 Byte 1 Byte 2 Bytes 1 Byte 可变长度 2 Bytes 1 Byte 可变 1 Byte 1 Byte 2 Bytes 可变 Version Control DNET DLEN DADR SNET SLEN SNET Hop Count Message Type Vendor ID APDU :默认0x01 :BIT7:1表示Message Type存在,为0时Message Type不存在
BIT6:保留,为0
BIT5:1表示DNET DLEN Hop Count存在,当DLEN为0时表明广播网络
DADR不存在;0表示DNET DLEN DADR Hop Count不存在
BIT4:保留,为0
BIT3:1表示SNET SLEN存在,当SLEN为0时表明无效SADR不存在;
0表示SNET SLEN SADR Hop Count不存在
BIT2:1表示为一个需确认的请求数据单元,一复杂ACK数据单元或一网络层
信息非reply的;0表示除去上述情形的数据单元
BIT1、0:网络优先级
11 = Life Safety message
10 = Critical Equipment message 01 = Urgent message 00 = Normal message
目标网络号:FFFF的时候表示广播 目标长度: 表示DADR的长度 目标地址: 目标网络MAC地址 原网络号: 同目标网络号 原网络长度:表示SADR的长度 原地址: 原网络的MAC地址 路由数目: 消息类型:
数据需要经过的路由个数,当不存在DNET的时候,需设置为FF
X'00': Who-Is-Router-To-Network X'01': I-Am-Router-To-Network
X'02': I-Could-Be-Router-To-Network X'03': Reject-Message-To-Network X'04': Router-Busy-To-Network X'05': Router-Available-To-Network X'06': Initialize-Routing-Table X'07': Initialize-Routing-Table-Ack
X'08': Establish-Connection-To-Network X'09': Disconnect-Connection-To-Network X'0A' to X'7F': Reserved for use by ASHRAE
X'80' to X'FF': Available for vendor proprietary messages
当控制字的BIT7为1并且消息类型为X'80' to X'FF':的时候,才会存在 本次开发没有用到,不再解释
卖方ID:
本次应用中控制字只用到0x20和0x04两种,前者为广播查询设备,后者微点对对取设备数据或属性。
4、BACnet APDU结构:(应用层协议数据单元)
BACnet网络层数据主要分为一下几种: BACnetPDU ::= CHOICE {
confirmed-request-PDU [0] BACnet-Confirmed-Request-PDU,
unconfirmed-request-PDU simpleACK-PDU complexACK-PDU segmentAck-PDU error-PDU reject-PDU abort-PDU [1] BACnet-Unconfirmed-Request-PDU,
[2] BACnet-SimpleACK-PDU, [3] BACnet-ComplexACK-PDU, [4] BACnet-SegmentACK-PDU, [5] BACnet-Error-PDU, [6] BACnet-Reject-PDU, [7] BACnet-Abort-PDU
}
对于本次应用,主要用到了
BACnet-Confirmed-Request-PDU(需确认的请求协议数据单元) BACnet-Unconfirmed-Request-PDU(无需确认的请求协议数据单元) BACnet-ComplexACK-PDU(复杂的ACK命令) BACnet-Error-PDU(报错的协议数据单元)
对于上述几种数据的分类主要根据pdu type(下文进行讲解)进行判定。
4.1. BACnet-Confirmed-Request-PDU的结构:
BACnet-Confirmed-Request-PDU ::= SEQUENCE {
pdu-type [0] Unsigned (0..15), -- 0 for this PDU type segmented-message [1] BOOLEAN, more-follows [2] BOOLEAN, segmented-response-accepted [3] BOOLEAN, reserved [4] Unsigned (0..3), -- must be set to zero max-segments-accepted [5] Unsigned (0..7), -- as per 20.1.2.4 max-APDU-length-accepted [6] Unsigned (0..15), -- as per 20.1.2.5 invokeID [7] Unsigned (0..255), sequence-number [8] Unsigned (0..255) OPTIONAL, -- only if segmented msg proposed-window-size [9] Unsigned (1..127) OPTIONAL, -- only if segmented msg service-choice [10] BACnetConfirmedServiceChoice, service-request [11] BACnet-Confirmed-Service-Request OPTIONAL } BIT7 0 BIT6 BIT5 Max Segs Invoke ID Sequence Number(only present by SEG==1) Proposed Window Size(only present by SEG==1) BIT4 BIT3 SEG BIT2 MOR BIT1 SA BIT0 0 PDU TYPE Max Resp Service Chioce Service Request…… PDU Type SEG
0 0 1
(BACnet-Confirmed-Service-Request-PDU) (Unsegmented Request) (Segmented Request)
MOR
0 (No More Segments Follow) 1 (More Segments Follow)
SA 0 (Segmented Response not accepted)
1 (Segmented Response accepted)
Max Segs (0..7) (Number of response segments accepted per 20.1.2.4) Max Resp (0..15) (Size of Maximum APDU accepted per 20.1.2.5) Invoke ID (0..255) Sequence Number (0..255) Only present if SEG = 1 Proposed Window Size (1..127) Only present if SEG = 1 Service Choice BACnetConfirmedServiceChoice Service Request Variable Encoding
SEG:指出当前的数据单元是否为完整的还是为一部分分段信息 MOR:指出是否还有更多的分段信息
SA: 为1时指出将收到一个复杂的回应(complex ack) Max Segs :指出设备将要接收到多少分段信息 B'000' Unspecified number of segments accepted.
B'001' 2 segments accepted. B'010' 4 segments accepted. B'011' 8 segments accepted. B'100' 16 segments accepted. B'101' 32 segments accepted. B'110' 64 segments accepted.
B'111' Greater than 64 segments accepted.
Max Resp:指出将收到的(APDU)最大长度 B'0000' Up to MinimumMessageSize (50 octets)
B'0001' Up to 128 octets
B'0010' Up to 206 octets (fits in a LonTalk frame) B'0011' Up to 480 octets (fits in an ARCNET frame) B'0100' Up to 1024 octets
B'0101' Up to 1476 octets (fits in an ISO 8802-3 frame)
Invoke ID:调用者ID
Service Chioce:此处表明次报文的作用,详见BACnetConfirmedServiceChoice Service Request:根据BACnetConfirmedServiceChoice不同而结构不同,详见
BACnet-Confirmed-Service-Request
BACnetConfirmedServiceChoice ::= 枚举类型 {
-- Alarm and Event Services
acknowledgeAlarm (0), confirmedCOVNotification (1), confirmedEventNotification (2), getAlarmSummary (3), getEnrollmentSummary (4),
getEventInformation (29), subscribeCOV (5), subscribeCOVProperty (28), lifeSafetyOperation (27),
-- File Access Services
atomicReadFile (6), atomicWriteFile (7),
-- Object Access Services
addListElement (8), removeListElement (9), createObject (10), deleteObject (11), readProperty (12), readPropertyConditional (13), readPropertyMultiple (14), readRange (26), writeProperty (15), writePropertyMultiple (16), 。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
}
上述标记为红色的表示本次应用中所用到的,所以只对这些进行讲解。
可以根据BACnetConfirmedServiceChoice找到相对应的Request或者Ack的数据的结构 BACnet-Confirmed-Service-Request ::= CHOICE //对应上面的Choice {
-- Alarm and Event Services
acknowledgeAlarm [0] AcknowledgeAlarm-Request, confirmedCOVNotification [1] ConfirmedCOVNotification-Request, confirmedEventNotification [2] ConfirmedEventNotification-Request,
-- getAlarmSummary conveys no parameters
getEnrollmentSummary [4] GetEnrollmentSummary-Request, getEventInformation [29] GetEventInformation-Request, subscribeCOV [5] SubscribeCOV-Request, subscribeCOVProperty [28] SubscribeCOVProperty-Request, lifeSafetyOperation [27] LifeSafetyOperation-Request,
-- File Access Services
atomicReadFile [6] AtomicReadFile-Request, atomicWriteFile [7] AtomicWriteFile-Request,
-- Object Access Services
addListElement [8] AddListElement-Request,
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库BACnet通讯分析在线全文阅读。
相关推荐: