1、BACnet通讯1、概述、系统实现基于BACnet(又称BIP)网络进行通讯。BCnet虚拟链路层(BVLL)提供了BCnet网络层与某指定得通讯子系统得接口,本文指定了Cnet虚拟链路控制(BC)要求支持得定向与广播信息。本实现关于BCnet协议定义主要可分为三层:B/I网络虚拟层,BCnet网络层与BACnt应用层。B/IP提供了P/IP一样得通讯结构,采用UDP得通讯方式。本文接下来将对此三层结构进行详细得讲解。其文本协议得大致格式如下:BACnet/PBACnet网络层ACnt 应用层BVLC TypBVLC FnctionLenhNDUAPDUNDU:ACt网络层数据结构,下文进行详
2、细得讲解APDU:BACnet应用层数据结构,下文进行详细得讲解2、BACnetI、BVL Type:81,代表BACtIP网络BVC Funtion:指定报文得类型,何种作用;本应用使用得报文类型分为两种:0A:点对点通讯0B:广播通信Length:指定报文得长度,包括BVC ye、VC Fncton以及本身在内NPD:根据不同情况,报文长短不同,见下文得解析。APDU:根据PD不同以及不同得请求,报文不同,见下文得解析。3、BAe NPU结构、版本信息1 ByteVerion控制字1 eCnrol目标网络号2BytDNET目标网络长度1 BtDLEN目标地址可变长度DAR原网络号2 Byt
3、eNT原网络长度1 BteN原地址可变T路由数目1 teHop ount消息类型1 BeMsage Tpe卖方ID2 yteVenor I应用层信息可变APD版本信息:默认01控制字:I:1表示MessagTyp存在,为0时Message pe不存在 IT6:保留,为0 BIT5:表示DNET LEN Hop Coun存在,当DL为0时表明广播网络DR不存在;0表示DNETDLEN DADR Hop Count不存在 BIT4:保留,为0BIT3:1表示SNE LEN存在,当SLEN为时表明无效SR不存在;0表示SNET SEN SDR Hop Count不存在 BIT2:1表示为一个需确认得
4、请求数据单元,一复杂CK数据单元或一网络层信息非eply得;表示除去上述情形得数据单元B、0:网络优先级11 =Liefety mesage10 Criical ipent mese01= Urt message00= ormalmea目标网络号:FFFF得时候表示广播目标长度: 表示DR得长度目标地址:目标网络地址原网络号: 同目标网络号原网络长度:表示AR得长度原地址: 原网络得MC地址路由数目:数据需要经过得路由个数,当不存在DNET得时候,需设置为FF消息类型:X00: Wo-Is-Route-ToNewokX1: I-Am-RoterTo-NetworX02:ColdB-Rotero
5、Netwok0: RejetMesa-oetwrkX0: Ruter-usy-To-NetwoX05: RuterailableoNetworX06: ItilizeoiTableX07: Initialie-Rutig-TlAc8: Estalish-onncin-To-NtworkX9: Disconnet-Connecti-To-etoX to 7F: eservefor se by AHRAEX80 to XF: Avaiablefor veor ropretary messes卖方I:当控制字得BI7为1并且消息类型为80 o XFF:得时候,才会存在本次开发没有用到,不再解释本次应
6、用中控制字只用到0x20与x04两种,前者为广播查询设备,后者微点对对取设备数据或属性。4、BACetADU结构:(应用层协议数据单元)BACe网络层数据主要分为一下几种:BACnetPDU::= CHICE onfimrees-PD BACnt-Confirme-Rqest-D,nconfirmd-reqest-PDU 1 BACnet-Unconfrmed-Rqest-DU,ipleACPD 2 BACneSimpeAKPDU,xACK-PU 3 BAnt-peACK-PDU,segmntAck-DU 4 Cnt-SegntACK-PDU,error-PDU 5 ACnt-Err-DU,e
7、ect-PU ACnt-RejePU,abotDU 7 ACne-Abort-PU对于本次应用,主要用到了BACne-Cnfir-Requs-PDU(需确认得请求协议数据单元)ACet-UnonirmeReque-U(无需确认得请求协议数据单元)BACnetlxAK-PDU(复杂得ACK命令)BACne-Erro-PDU(报错得协议数据单元)对于上述几种数据得分类主要根据pd pe(下文进行讲解)进行判定。4、1、BACtConfrmed-equePDU得结构:BACnt-Confirmd-RequetPDU ::SEQUEpdu-typ 0 signd (、1),- 0 for his PD
8、U tyesementedssage BOLAN,or-folls BOOLAN,segmeed-repose-acceped3OAN,rserved4 Usigned (0、3), - ust e et o zrm-sgmens-aceped 5 Usine (0、7), - s per 20.1.2、4max-APDUlength-accepte6 Unsigned (、15), - asr 0.1.2、5invokeID7 Unsined (0、25),equece-mber ngned (0、255) OPTIONL, -oly i sgmend msroposedinow-s 9 U
9、nsigne(、127) OPIONAL, - onlf metd msgervechoce 0 BACneConmedericeChce,ericerequ1 BCnt-Conimedervice-ReusOPTIONALIT7BTBT4BT3BIT2BIT1ITPDUTYPESGMOA00Max egsMax RespnveIDSequce Nm(only rese b SEG=1)Propsed Wnow Size(oyres by SG=)eic hioSrvice ReqesUTy 0 (BCnet-CnfimedSrvie-eqest-PDU)SEG0(Unsgened euest
10、)1 (Sente equet)R0(No Mor Segmens Fllow)1 (More egment Follw)SA (Segmntesoe nt cepted)(Segntd Responecpted)Maegs (、7) (Number ofreonse segmes acpted p 2.1.、)MRes(0、5) (Sizeof MaimumAUaccted per 20.1.2、5)Invoke ID (0、255)Sequence Number(0、55) On prsent iG =1Proposed Wiow Sie (、127)Only resenif SE= er
11、vic CiceAnetonirmedServeChoiceSevice ReqesVarable EcodingSEG:指出当前得数据单元就是否为完整得还就是为一部分分段信息MO:指出就是否还有更多得分段信息S: 为1时指出将收到一个复杂得回应(plex ac)MaxSegs :指出设备将要接收到多少分段信息B000 spciiednume of smensaceted、B001 seges accpted、B10 4 segments ccepted、018 gments accepted、B100 16 sgmentaccepted、B01 32 egment acepd、B1 4 se
12、gmnts ccepted、111 rear tan6segms acepted、xsp:指出将收到得(PDU)最大长度B000 UpnmumMssaeSiz (0 octts)B001Up o 12 octetsB0010 Upto 06 octets (fits in LoTalkame)B001 Up to 80 ctt (fi nANET frame)B01p o 24 cesB10 Up o 147 ocets(fitsinan IO880-frame)Ink I:调用者IDSei Chice:此处表明次报文得作用,详见ACetConrdSrvceChoSerc Rees:根据BAC
13、neConfireSerchoice不同而结构不同,详见BAet-Cnired-SriceReqestBAnetnfrmeSerceChoce:= 枚举类型 - lar an Event ServiesaknowldgeAa(),cnfiredCOVNotcation (),ofedEvntNotficatio (),tArSmmary (3),gtnrollmenSuary (4),getEventInformon (29),ubsribeCO(5),bcibeCVropt (28),lifeSaetyOperation (7),- ServiesatocedFe (),atomiWrite
14、ie (7),- Object Acess SrvcesddListElemen (8),moeLstlmnt(9),creaeOject(10),deletOect (),eaProety (12),readropertyCndoal (1),eadPpertyull (14),readnge(26),witePrpety (15),wieroertyMlile (16),。上述标记为红色得表示本次应用中所用到得,所以只对这些进行讲解。可以根据BACetofirmedServeChie找到相对应得Rqest或者Ak得数据得结构ACnt-Cid-Service-Requst := CHE/对应
15、上面得hoice-Alarm andEvnt rcsacknowlgeAlarm0 AcknedgeAa-Request,onfirmdCONotificaion1ConfimdVotifcain-Rques,confiedEntNotiiatin ofiedvntfiaio-Reuest,- gelaSumary conv no raetretEnromentSummr 4 GeEnolntmmry-Ruest,getEtIformtin 2 GeEvnIormation-eqes,usribeCOV 5SubscribeCV-Reqest,subcribeOVPropert 28 Subs
16、cribCPrrty-Reuest,aftpetio 27feSaftypertion-Ree,- eicesamicReadFie 6Atomcead,atomicWrieil Aomirt,- bect Acces ServiceaddListElmn8 AddLisEleent-Reuet,revisElemnt 9 RemoeLstElement-qest,reatebjct10 CreteObjec-Requ,deeteObje 1eletbjec-Reuest,readProperty12 Rarope-Reet,rerpertyConditionl 3ReadPropertyCo
17、nna-equest,rearoertyutiple14 eadPopertMultiple-Rquest,readang 2 RadRane-Request,teProery 15 WriePrperty-Rquest,writePoprtMultple16WritePpertyMltipe-equest,。上述标记为红色得既就是针对BACnetonfirmedericeCoice所用到得数据结构。ReaPoperty-Rqst:= SEUCE /读数据请求与读数据回答obectIdntfier BACnetOetIdenfier,prertyIdntfie BCnePrertyIentii
18、e,ppertArrayIdx 2 nsign OPTIONAL -usedol wit aray daaypeReadPropetMulple-Reuest := SEQUENCiOfReaAccesspecs SEUENCE OF dcesSpefitionReadessSpeciaton:= SEUNC objectIdentfir 0 ACntOectdentifir,lOfProprtyRferenc 1 EUENCE OF CntPropertyReferncBACneropetyRefn :=SQCE roperentfirCnetPropertIdntiie,proertyra
19、yIde 1 UnsigneOPONAL -use nly wit araydatatye-ifomitt wih an array tentire arayirefrencedBACetPropertyIdentier := EUERATEacepted-des (175),ced-trniions (0),ack-requied (1),acton (2),actin-txt (),actvext(4),atie-vt-sesions(5),active-co-subsciptions (2),djust-lue (176),lm-vau (6),a-vlues(7),all (8),al
20、-wts-sucesful (9),au-segment-imeut (0),apu-timeout (11),applicatio-softwre-ersn (12),firmware-revision(),achiv (3),ttmptedsamples (124),lit-ofgroupebers (53),ls-of-ojc-proert-reerenc (54),lst-f-sessionkys(5),oc-date(56),al-tim(57),lcaon (58),aitenace-eqird (58),manuae-varial-rfrc (60),maa-sveddress-
21、bindig(170),aximum-outpu (61),axium-vale (35),mxim-valu-timetap(149),max-apulegth-acpted (2),max-in-fmes (63),ma-master (64),a-res-vlue(65),max-segmets-acepe (6),mebeo (),mimum-off-tme (66),inimum-n-tm (7),miimum-utput(68),evntate (6),modelname(7),numbr-of-APDU-etres (73),jetdnifier (75),obect-list
22、(6),object-nae (77),ject-rer-eeree(78),ojct-ype(79),oprato-xected(61),opional (0),otofsevice(81),utput-uts(82),- e eent-arameters (83),polary (84),pescale (5),pesen-value (85),riorty (6),puls-rate (186),piority-aray (7),prorty-for-wrting(88),prtol-ojec-tpes-supportd (96),protocolevision (9),prooco-s
23、ervcesupported (97),otool-versin (98),eliality (10),relnqsh-deult (104),scheduledefaul (174),egnttion-suppored(17),ste-text(110),status-fags (11),stotime (143),stop-henfll (144),stem-stat(11),tracngvalue (164),uits (117),variaevale (151),venr-ietif (20),vendrname (1),- see atabase-reviion (155),上述标记
24、为红色者既就是本次应用所用到得属性对象BCetOjetIdentifier得编码分为两个部分:ObjetyeIstnce Nbr占用了10B占用了2BiObjecTye得表格如下:BACetOjectTypesSupporte :BIT STRNG- accmulaor(23),analog-ipt (0),n-output (),anog-valu (2),- aerging (18),inar-input (),bin-ouput (4),binary-value(5),candar(6),man (7),devie (),eent-enrllmet (9),fle (10),ru (11
25、),loop (12),muti-sateinput (13),mlti-state-utput (4),- muli-stat-alue (19),notfcatio-ca (15),prgrm (16),设备对象所具备得所有属性及其数据结构如下:DCE:= SEQUENCEojec-ideifie 5 BCnetObecIntifie,ojct-m 77 CaracterSri,objec-tp 79 BCnObjectTpe,ssem-satus112 BACnetDeiceStaus,vendo-name121Chacetring,vedoridentifier 120 nsine16
26、,odlnae 70haracttrng,firmwae-evisin CacteSring,applaon-soaeveion 12 ChracerSng,ocat 58Charaterting OINL,ecrption28 artrtring OPTIONA,ol-ven 98Unine,prtoco-revisin139Unsign,procl-servicesuportd 7 BACntSrveSprted,protool-obc-types-sppo 96BACetObjecTypsSuppoed,bjectlist 6 SEQUENCOFBACnetbjctIetife, - c
27、cesed s a AnetRYmxAD-lengh-prted 62Ugd,segmentaion-suported07 CntSgmentai,tclases-upted 12 UENCE OF BACneVTClss OPTIONL,activ-v-sessons 5SEQECE F BnetSesion PIONL,locatime 57 Tim PTIAL,lldate 56 DateOPTIONAL,uc-offt11 INTEER IONL,daliht-avin-sttus 24BOOLENOPIAL,ap-ent-timeout 0 Usigned,pd-tmo11 Unig
28、ned,numerof-ADU-retre73 Unsigd,lis-o-sson-kys 5 SEQUE OF BACntSsoney OONA,ti-synchonizinrecpents 16 EQUNCE OF BnetRecipien TIONAL, - reqire fo time trmaxmaer 64 Ungned(1、27) OPTNL, - qire for /TP aster, se 12、1mx-inf-fams63 nignd TONA, - reuied for S/T maser, se 12、11devcaddess-biin 3SEQECE BAnetAdd
29、essBidig,dataaervision 155 Unsiged,confgraonfils15 EQENCE OF BCetObjecIdetifer,lat-resto-time 15BCtTmStap,acu-ailure-ieou 153 Unsiged16,actv-cov-subscriptins 12 SEQUENC OFBACetCOVSbscrition,maxsemnts-acceptd 167 Unsned,sla-prox-enabl 172EQENCEF BOOLAN OTIONL,auto-lave-discoe 69 SEQUNCE OBOOLEANOPION
30、AL,sveaddrss-bnig71SEQUE FBCnetAddresBindng OTIONA,maual-slav-adress-bding 170 SEUENCEO BACneAddessBiig OPTION,ro 168haracerStigOPTIONA上述标记为红色者既就是本次应用用到得设备属性对象ALOG-NUT::= SEQUENC ojecidentifier 75 BACnetObctIenfier,objct-ame 77CharcteSring,bjec-type 79 BCneOeTy,presen-vaue 5 EL,descrition28harcteSti
31、gOPTIONA,device-te 3 ChrcerString OPTIOAL,statusflags 111 BACnetSauslgs,entstate 36 BCetEventStae,reabilit 13 CetRliability OPTIONA,out-osev 81BOLA,uat-itrval11 Unigned OPTIONAL,uis 117 CetEgieergUnis,min-prs-vaue 69 REAL OTIONAL,maxpres-vale65REAL OPTONA,reoion 106AOPTIONAL,ccrm 22 RA OTIL,tme-del
32、13 UsgedOPTIONAL,notificatin-class 17 nsigneOPIONAL,ighlit45 REOPTI,lo-lmi 59 REAL OTION,eaband25REA OPTIOAL,lmitable 5 BCnetLinabe OPTIONAL,event-enble 35 BACnetEvetasiinBits PTIONA,ack-trnsitions 0 ACnetventransitinBit PTIOL,notfy-ype 72 AntNfyT OPTNA,vent-ime-samps 130SEQUENCE OFBCetTimeta OPTIOAL,-aceseda a BACntARRYpro 1 CharactSting OTIONAANALOGOTPUT ::=ENC object-identfe 75BAntOectdtiier,objetne7 CharactrStrg,object-type BACnetObjectyp,pesent-vlu85 RE,scripton28 CharactrtrPTIOL,dice-e CrctetingOTIN,status-flgs 1BAnetStatuslag,eet-st 3