本文是對于IEC62056協議族,即DLMS協議族的中文說明手冊。本文并沒有包含DLMS協議族的全部,但解釋了在應用中可能出現的大多數情況。本文的目的是為電能量數據采集終端提供與使用DLMS協議族的電能表通訊的協議說明。
?????? 本文參考文獻如下:
?????? (1)DLMS User Association , COSEM Identification System andInterface Objects , Third Edition
?????? (2)IEC62056 -53 Electricitymetering - Data exchange for meter reading, tariff and load ????????????????????????????????????????????????? ?????control -Part 53:?COSEM applicationlayer
?????? (3)IEC62056 -46Electricity metering - Data exchange for meter reading, tariff and load ?????????????????????????????????????????????????? ???????? control -Part 46:?Data link layerusing HDLC protocol
?????? (4)IEC62056 -42?Electricity metering - Data exchange for meter reading, tariff and load ????????????????????????????????????????????????? ???????? control -Part 42:?Physical layer?servicesand procedures for ??????????????????????????????????????????????????????????????????? connection-orientedasynchronous data exchange
?????? (5)IEC62056 -61 Electricity metering - Data exchange for meter reading, tariff and load ????????????????????????????????????????????????? ???????? control -Part 61: Object identificationsystem (OBIS)
?????? (6)Amber Management logical device-FR:AMBER/FW TECH_SPEC ??????????????????????????????????????????????????????????????????????????????? ???????? MANAGEMENT_LOGICAL_DEVICE
?????????(7)Amber Electricity Logical Device -?FR:AMBER/FWTECH_SPEC ???????????????????????????????????????????????????????????????????????????????? ???????? ELECTRICITY_LOGICAL_DEVICE
???? (8)A Layman's Guide to a Subset of ASN.1, BER, and DER-
?????????????????????????????????? AnRSA Laboratories Technical Note
?????????????????????????????????? Burton S. KaliskiJr.Revised November 1, 1993
?????? (9)IEC61334采用配線載波的配電自動化,譯文匯編。
一、本文的結構
?????? 由于DLMS協議族的復雜性,必然導致本文篇幅較長,涉及的內容比較多。這里有必要把本文的內容,做一個綜述,并解釋各部分之間的相互關系。
?????? 一、DLMS協儀模型:從整體上介紹DLMS協議。
?????? 二、DLMS物理層協議:講述DLMS物理層在整個協議族中的作用。
?????? 三、DLMS鏈路層協議:講述HDLC鏈路層協議在整個協議族中的作用。
?????? 四、DLMS應用層協議:講述DLMS應用層協議在整個協議族中的作用。這一部分又???????????????? 包括如下幾部分內容。
????????????? (一、)ASN.1語法:這個語法是用來描述DLMS應用層協議幀的組成的。
????????????? (二、)BER編碼與AXDR編碼:這兩種編碼是用來實現ASN.1語法的。
????????????? (三、)AARQ與AARE數據幀:這是兩個特殊的數據幀,它用來構筑DLMS協??????????????????????????????? 議中的client端與server端的應用層連接。
????????????? (四、)數據請求過程描述:介紹請求數據時所用的的數據幀。
?????? 五、請求數據實例:這里提供了幾個請求數據的實際范例的數據包文。
1、? 請求電量
2、? 請求瞬時量(電壓、電流、功率)
3、? 請求負荷曲線
4、? 請求時間
一、DLMS協儀模型
下圖從整體上描述了DLMS協儀模型。
協儀共分為3層,物理層,鏈路層,應用層。層與層之間使用指定的服務通訊。
通訊的雙方采用Client—Server結構,數據請求端(采集器)為Client,數據提供端(電表)為Server.
通訊過程描述:
(一)?? 建立物理層連接
??? 物理層位于通訊模型的最底層。DLMS規約可以建立在多種物理層之上,物理 層的做用主要是對底層通訊硬件的操做(如對PSTN?MODEM的初始化,打開,?? 關閉。)
(二)?? 建立鏈路層連接
???????????????????? 物理層連接建立之后,數據通訊的第一步是建立鏈路層的連接,鏈路層主要負?????? ?? ? 責數據傳輸的可靠性,包括以下幾個方面,地址校驗,幀長校驗,數據的CRC校??????????????? 驗。長數據幀的拆包組包。同時向應用層提供鏈路傳輸的服務。
(三)?? 建立應用層連接
????????????? 鏈路層連接建立之后,在DLMS協儀中還要建立應用層連接,才可進行數據通訊。
?????? 這個應用層連接建立過程被稱為Negotioation。
????????????? 這個過程是為數據通訊提供一些配置參數。應用層連接請求由Client端發起,Client????? 端發aarq幀,Server端響應aare幀
(四)?? 進行數據通訊
?????? 當連接建立起后,就可進行數據通訊了。Client端發送數據請求幀Server端以數據響應。Client在請求不同的數據時,要使用特定數據的獨有的class id和OBIS,用以標識不同類型的數據。
(五)?? 數據通訊結束,釋放鏈路,解除連接。
?????? 數據通訊結束后,發鏈路結束幀,結束一次通訊過程。一次數據通訊結束后,可以通過發鏈路結束幀,來結束一次通訊過程。也可以,不發任何數據幀,依靠server端的超時掛斷機制,來結束一次通訊過程。一般應使用前者。
(六)?? 解除物理層連接
關閉物理端口(如掛斷Modem)。從物理上結束一次通訊。
二、DLMS物理層協議
?????? 物理層協議位于DLMS協議族的最底層,負責數據通訊的物理傳輸。DLMS可以工作于多種不同的物理介質上(PSTN,網絡,串行通道等)。
?????? 物理層的功能是接受鏈路層數據,發送到物理介質上,傳送到通信的對端。或是接收通信的對端傳送來得數據,再傳送到鏈路層,供更高層的協議處理數據。
?????? DLMS物理層協議,主要規定了物理層應實現的服務,如:打開端口,初始化端口,收發數據,關閉端口等。在通常的嵌入式系統中(如電能量采集裝置),物理層對應于系統的底層驅動部分。這部分一般不被通訊規約控制。因此,在不影響通訊協議功能實現的前提下,本文將不具體討論物理層服務。
三、DLMS鏈路層協議
?????? 物理層之上即為鏈路層,鏈路層是物理層與應用層通信的通道。DLMS鏈路層使用的是HDLC高速鏈路控制協議。
??????
鏈路層的構成:
?????? 鏈路層由兩個子層構成,即LLC子層,和MAC子層。
?????? (一) 、LLC子層(邏輯鏈路控制子層)
?????? 這一層的功能是將MAC子層的數據轉發到應用層,或將應用層的數據轉發到MAC子層。LLC子層只是作轉發而不對數據做出處理。其存在的重要性在于向應用層提供鏈路傳輸的服務(從鏈路層接收或發送數據)。
?????? 具體到數據通訊時,對于client端應用層發送的數據,要加上LLC幀頭(0xe6 , 0xe6, 0x00),server端應用層發送的數據,要加上LLC幀頭 (?0xe6 ?, ?0xe7 ,?0x00)。
?????? 由于LLC子層鏈路傳輸服務的具體實現,可以不受DLMS協議的限制,由應用程序實現。故本文不具體說明LLC子層的各種服務。
?????? (二)、MAC子層(媒體訪問控制子層)
?????? MAC子層在鏈路層中負責數據傳輸的可靠性,包括地址檢查,數據的CRC校驗,長數據幀的打包拆包等。這些工作對于數據通訊都是必不可少的,MAC子層功能的說明將是以下的重點。
1??HDLC幀格式
(1)不包含應用層數據信息
0x7e | 幀類型與幀長 | 目的地址域 | 源地址域 | 控制域 | 數據幀校驗 | 0x7e |
兩個0x7e是HDLC數據幀固定的幀頭與幀尾,兩個0x7e之間是鏈用戶數據。
(2)?包含應用層數據信息
0x7e | 幀類型與幀長 | 目的地址域 | 源地址域 | 控制域 | 幀頭校驗 | LLC幀頭 | 用戶數據信息 | 數據幀校驗 | 0x7e |
與不包含應用層數據信息的數據幀相比這里多了3項:
幀頭校驗:為增強通訊的可靠性,對幀頭的數據也加上CRC校驗。幀頭包括如下??
字段:幀類型與幀長、目的地址域、源地址域、和控制域
LLC幀頭:用戶數據信息前要加0xe6 , 0xe6, 0x00或0xe6 , 0xe7, 0x00。
用戶數據信息:應用層處理的數據。
注:出于數據完整性的考慮,用戶數據信息的最大長度,默認為128字節。如果想要更多的字節,可以在SNRM數據幀中協議。
2??幀類型字段與‘S’位
幀類型與幀長字段,共兩個字節。內容如下:
FrameType :用于指出當前數據幀的類型。HDLC有多種數據幀類型,DLMS使?用Frame Type 3。FrameType恒為A(1010)。
?????? S:(segmentation Bit)這個字段只有一位,它用于說明數據幀是否被分割。在長數據幀傳輸時要使用到這一位。長數據幀的傳輸將在后面解釋。
?????? FrameLength Sub-field :這個字段用于說明當前數據幀的長度,(以字節為單位,不包括兩個0x7e)
3??????????地址解析
?????? 地址域分為兩部分。目的地址域和源地址域。對于client端,目的地址為server的地址,源地址為client的地址。對于server端正好相反。
(1)擴展編址技術
?????? HDLC使用擴展編址技術,即某一個地址字節的最低位如為0,則表明該地址域沒有結束,仍有后續字節是該地址域的一部分。若某一地址字節最低位為1,則說明該地址域已經結束,沒有后續字節。
(2)地址結構
?????? ?????? Client端的地址永遠是一個字節,由于擴展編址技術的使用,最低位置1,所以client?????? 端的地址只能有128個。
?????? Server端為了實現一個物理地址對應多個邏輯地址,將地址分成了兩部分upper HDLCAddress?用于表述邏輯地址,lower HDLC address用于表述物理地址。Upper?address總是應當有的,lower address在確認不需要的情況下,可以不出現。(sl7000 電表這兩部分地址都是需要的)。
?????? Server端的地址在使用擴展編址技術時,也并非是可以無限長(雖然在理論上可以,但在實踐上是有上限的)。Server端的地址結構可以使用如下方式:
?????? Onebyte: only the upper HDLC address is present.
?????? 一字節:只出現HDLC高位一字節地址。??????
?????? 兩字節:只出現HDLC高位一字節地址,和HDLC低位一字節地址。??????
?????? 四字節:只出現HDLC高位兩字節地址,和HDLC低位兩字節地址
???????? 對于SL7000電表,經測試只有四字節sever地址結構可用。
(3)特殊地址
?????? 有一些地址被HDLC定為保留地址。這其中比較重要的是廣播地址。??????
?????? 對于SL7000電能表,實踐中可行的地址結構是client端一字節,server端4字節。對于DLMS協議族是可以使用上述地址結構中的任一種,并且支持特殊地址。
4??????????幀控制字
?????? 幀控制字字段主要負責,通訊中的幀計數,以及特殊數據幀的標識。
?????? 幀控制字字段結構如下:
?????? 對應項的解釋如下:
?????? RRR:為接收幀計數。
?????? SSS:為發送幀計數。
????????????? ?注:對幀計數的解釋,
????????????? ?????? 在鏈路層連接建立之后,第一次請求數據時(在client端,包括發送AARQ)???????????????? RRR置為0,SSS置為0。Server端收到這一幀數據后,返回數據響應RRR為1,????????? ?????? SSS為0。Client再次請求數據時RRR加1,SSS加1。Server端收到這一幀數據后,????????????? 返回數據響應RRR加1(成為2),SSS加1。如此反復直到client得到所有的數據??????????????? 為止。整個數據傳輸過程以I數據幀請求和響應。這里要說明的是在請求數據結束?? ????????????? 后還要再發送RR幀,收到確認后。才可以再發送DISC幀結束鏈路。其中Client端??????????????? 的RR幀中的幀計數位RRR只需將client的幀計數位RRR加1得到。
????????????? 下圖描述了幀計數位的變化過程:
P/F:poll/final bit。
?????? ?Poll bit :由client發送,置1時表示server端回應,置0時表示不允許回應。
?????? ?final bit:由server發送,置1時表示一次數據幀的發送結束,置0時表示還未???????????????????????? 發送完。final bit只有在通訊窗口(window size)大于1的情況下才有意?????????????? 義。在window size = 1時,由server端返回的數據幀中的這一位總是???????????????????? 置1。(關于window size將會在“建立鏈路層連接”時解釋)
?????????????
幾種不同的數據幀分別應用在不同的場合,下圖列出了幾種請求和響應的對應的情況。
????????????????????
?????? I????? :信息傳輸幀
RR?? :準備接收數據幀(用來表示準備接收下一幀數據)
RNR:接收沒有準備好(receive not ready)。相當于別的通訊協議中的忙幀。
SNRM:設置正常相應數據幀。用于建立鏈路層連接。
UA:對SNRM和DISC的響應幀。
DISC:結束鏈路幀。
DM:對DISC的響應幀。(Disconnected?mode)
UI:可以用于保持鏈路,這個數據幀的發送,對于鏈路的控制沒有任何影響。
FRMR:拒絕接收幀(Frame reject),由于不確定的某種原因拒絕接收到的數據幀。
5??????????長數據幀的傳輸
?????? 在很多情況下,數據不能在一次請求和一次響應中,就能夠結束數據傳輸的過程(受限于用戶數據字節不超過128字節)。這時就有必要啟動長數據幀鏈路控制流程。
?????? 注:請求負荷曲線時一定是使用長數據幀。
?????? 當使用長數據幀時,必須把長數據幀分割成短數據幀。然后把這些短數據幀依次發送出去,在接收端將這些短數據幀依次處理。這樣就實現了一個較大的數據包,完整的傳送到接收端。
?????? 在數據幀被分割時,幀類型與幀長字段中的‘S’位,將被置1。當接收端檢測到這一位被置位后,就知道數據幀已被分割,此時要做出對分割數據幀的相應處理。
?????? 下圖介紹了長數據幀的收發過程:
client端通過發送RR數據幀來請求被分割的數據幀的其他部分。
6??????????數據幀校驗
?????? HDLC使用16位CRC校驗。使用的多項式是:
?????? 具體的實現程序,可參照英文參考文獻IEC62056 - 46的附錄A。
(三)、鏈路層連接的建立,與斷開
?????? (1)建立連接
?????? 鏈路層在開始工作之前,要建立鏈路層連接(Association)。這一步驟是通過client端發送SNRM數據幀,server端響應UA數據幀表示已建立連接,server端響應DM數據幀表示鏈路斷開,連接沒有建立。
UA數據幀常含有鏈路參數的配置信息。鏈路參數是指2個控制數據傳輸的參數。
WINDOW_SIZE parameter;???????? 這個參數描述通訊時,通訊的雙方一次發送數據幀的數目。?????????????????????????????????? ????????????? HDLC允許一次發送多幀數據。
MAXIMUM_INFORMATION_FIELD_LENGTHparameter . 最大信息域長度,這個參數用于描????????????????????????????????????? ?????? 述一個鏈路數據幀中用戶數據的長度。
?????? 這兩個參數的默認值如下
default WINDOW_SIZE = 1;
defaultMAXIMUM_INFORMATION_FIELD_LENGTH = 128(BYTEs)
具體在數據幀中有如下4個參數:
transmit maximum information field length
receive maximum information field length
transmit window size
receive window size
注:這里沒有給出數據幀的具體格式,而是用舉例來說明如何組幀。這種做法可能給讀者帶來不便。但在DLMS的規約原文中就是用這種辦法,故這里仍這樣做。
以下舉例說明如何建立連接:
//SNRM
S: 7e a021 00 22 00 23 03 93 0b 14 81 80 12 05 01 80 06 01 80 07 04 00 00 00 01 08 0400 00 00 07 65 5e 7e
解釋:
7e
a0 21????? 幀類型與幀長
00 22 0023??? 目的地址
03 ???????? 源地址
93?????????? 控制字
0b 14 ??? 幀頭校驗
81 80 ??SNRM 標識
12 ???????? group lenth.
05Hparameter identifier (maximum information field length transmit)
????????????? 01H parameter length (1 octet)
????????????? 80H parameter value(128 bytes)
06Hparameter identifier (maximum information field length receive)
????????????? 01H parameter length (1 octet)
????????????? 80H parameter value? (128 bytes)
07Hparameter identifier (window size, transmit)
????????????? 04H parameter length (4 octets)
????????????? 00H parameter value? (high byte of value)
????????????? 00H parameter value
????????????? 00H parameter value
?????? ?????? 01Hparameter value? (low byte of value)
08Hparameter identifier (window size, receive)
????????????? 04H parameter length (4 octets)
????????????? 00H parameter value? (high byte of value)
????????????? 00H parameter value
????????????? 00H parameter value
????????????? 07H parameter value? (low byte of value)
65 5e????? 數據幀校驗(CRC校驗)
7e
在SNRM數據幀中的用戶信息可以不出現,表示client接收server端的已配置數據。
//UA
R: 7E A021 03 00 22 00 23 73 28 F0 81 80 12 05 01 80 06 01 80 07 04 00 00 00 01 08 0400 00 00 01 53 3B 7E
解釋:
7E//Flag
?????? 0xA0 21//(type=a :frame type 3 , s=0 :end of frame , len=021 : 33 bytes)
?????? 03//source address
?????? 00 22
?????? 00 23 //destination address
?????? 73 //control UA
?????? 28 F0 //hcs
?????? 81 80 12 05 01 80 06 01 80 07 04 00 00 0001 08 04 00 00 00 01
?????? //information field
?????? //parameter negotiation
?????? //81
?????? //80
?????? //12
?????? //05? 0180?????????????????????????? :maximuminformation field length? transmit (128BYTEs)
?????? //06? 0180?????????????????????????? :maximuminformation field length? receive? (128 BYTEs)
?????? //07? 0400 00 00 01????????????? :window size,transmit (1)
?????? //08? 0400 00 00 01????????????? :window size,receive? (1)
?????? 53 3B//fcs
?????? 7E
?????? (2)斷開連接
?????? 斷開連接由于不用參數設置,所以比建立連接要簡單。Client端發送DISC數據幀,Server端響應UA或DM表示斷開連接。UA表示接到DISC后斷開連接。DM表示在接到DISC之前已處于斷開狀態。
一下仍給出具體的通訊實例:
S: 7e a0 0a 00 22 00 23 03 53 06 c7 7e
解釋:
7e a0 0a 00 22 00 23 03
53 // 幀類型Disc
06 c7 7e
R: 7E A0 0A 03 00 22 00 23 1F 43 4C 7E
解釋:
7E A0 0A 03 00 22 00 23
1F//幀類型DM
43 4C 7E
(四)、關于鏈路層的透明數據傳輸
0x7e | 幀類型與幀長 | 目的地址域 | 源地址域 | 控制域 | 幀頭校驗 | LLC幀頭 | 用戶數據信息 | 數據幀校驗 | 0x7e |
?????? HDLC是一種透明數據傳輸的鏈路層協議。用戶數據信息與鏈路層沒有任何關系。在DLMS的協議模型中,鏈路層負責數據傳輸的可靠性,應用層處理用戶數據信息。鏈路層為應用層數據的傳輸提供透明通道。
四、DLMS應用層協議
?????? 理解DLMS應用層協議,需要首先建立以下幾個概念:
?????? ASN.1語法,BER編碼,AXDR編碼。
??? ASN.1語法是用來描述應用層數據幀的。DLMS協議不同于其他一些簡單通訊協議的地方就在于此。他不是用一些表格,及一些固定的幀格式來描述的,而是用一種抽象語法語言來描述。這樣做的好處是,極大的提高了協議的抽象性和通用性,有利于程序移植。
?????? BER編碼和AXDR編碼是用來實現ASN.1語法的。為了實現ASN.1的抽象性和通用性,這個語法要用特殊的編碼來描述。這就引入了BER編碼和AXDR編碼。
?????? 以下分別解釋這幾項。
(一)ASN.1語法
?????? 一個用ASN.1語法描述的數據幀,看上去應該是下面的樣子:
?????? Name ?::= ?[tag]? ??????IMPLICIT/ EXPLICIT ????????Data type
?????? {
?????? null-data ????????? [0]?IMPLICIT NULL,
?????? item1????? ?????? [1]?IMPLICIT/ EXPLICIT??? Data type? A1 OPTIONAL
?????? item2????? ?????? [2]?IMPLICIT/ EXPLICIT?????Data type ?A2 OPTIONAL
?????? item3???????????? [3] Data type????????????
?????? …
?????? }
?????? 下面解釋這個語法描述。
Name? ? -??? 是這個數據幀的名字。
Tag???????? -??? tag包含兩部分classtype 和一個數字
???????????????????? Class type有以下四種:
???????????????????? ?????? 1)Universal? 表明name定義的數據幀在所有的DLMS應用中的含義是唯一的。
???????????????????? ?????? 2)Application 表明name定義的數據幀的含義同具體的應用有關。
???????????????????? ?????? 3)Private?表明name定義的數據幀只在某一廠家的自定義范圍之內。
???????????????????? ?????? 4)Context-specific 表明name定義的數據幀同上下文數據項的含義有關。??????????????????????????? 這種類型的數據,在不同的結構中可能有不同的含義。
???????????????????? Tag中的數字,是作為這個數據幀的標號存在的,它做為該數據幀的句柄出現?????????????? 在應用數據單元中。
IMPLICIT/ EXPLICIT -?????當前數據幀(稱為子數據幀)可能派生于某一數據幀(稱為父數?????????????????????????????????? ?????? 據幀),這個字段用來描述子數據幀同父數據幀的關系。
? ? ? ? ?IMPLICIT? :???? 改變了父數據幀的Tag。
? ? ? ? ? EXPLICIT :?? 不改變父數據幀的Tag。
? ? ? ? ? 不注明IMPLICIT的項即為EXPLICIT。
Data type -???? 描述數據幀的數據類型。數據類型分為簡單型和復合型。多數數據類型可以從?????????????? 名字看出其類型。以下列出了幾種,完整的數據類型集合請參見附錄。
???Type???????????????????? Tag number???? Tag number
???????????????????????????? (decimal)????? (hexadecimal)
??? INTEGER????????????????? 2????????????? 02
??? BIT STRING?????????????? 3????????????? 03
??? OCTET STRING???????????? 4????????????? 04
??? NULL???????????????????? 5????????????? 05
??? OBJECT IDENTIFIER??????? 6????????????? 06
??? SEQUENCE and SEQUENCE OF 16???????????? 10
??? SET and SET OF?????????? 17???????????? 11
??? PrintableString????????? 19???????????? 13
??? T61String??????????????? 20???????????? 14
??? IA5String??????????????? 22???????????? 16
??? UTCTime????????????????? 23???????????? 17
“{}”-??????? 大括號中的內容,即為數據幀中的數據項。每一數據項后的數字序號,即為該???????????????????? 數據項的標識(tag)。每一數據項可以是對另一數據幀的復合。即一個數據?????????????????????? 幀通常是對其它數據幀的一種組合。
OPTIONAL - 這個關鍵字描述的數據項,在用戶認為需要的場合可以省略。
比較重要的兩種復合類型SEQUENCE和CHOICE 下面舉例解釋:
?????? 1)SEQUENCE : 數據幀中的內容是順序排列的。下面以舉例說明SEQUENCE類型。
????????????? Get-Request-Normal ::=?SEQUENCE
????????????? {
????????????? invoke-id-and-priority?????????? Invoke-Id-And-Priority,
????????????? cosem-attribute-descriptor?? Cosem-Attribute-Descriptor,
????????????? access-selection-parameters Selective-Access-DescriptorOPTIONAL
????????????? }
?????? 這是一個在請求數據時常用的數據幀。SEQUENCE表明數據幀的內容是順序排列的。
?????? 2)CHOICE :即選則類型,它表明當前數據幀是從幾個數據幀中選擇一種做為當前數???????????????? 據幀的類型。下面以舉例說明CHOICE類型。
?????? ?????? GET-Request ::=?CHOICE
????????????? {
?????????????????? get-request-normal? ?????? [1]?IMPLICIT?Get-Request-Normal,
?????????????????? get-request-next ?????????????? [2]IMPLICIT?Get-Request-Next,
?????????????????? get-request-with-list?????????? [3]?IMPLICIT?Get-Request-With-List
????????????? }
?????? GET-Request數據幀只能填入三個選擇項之一。
?????? 以上簡單介紹了ASN.1語法,由這一語法描述的各種數據幀,將在附錄中全部給出。這些各種各樣的數據幀,將構成DLMS協議中Client同Server應用層交互時使用的語言。
?????? 讀者如對ASN.1語法有不解之處,可參閱本文的英文參考文獻【7】
(二)BER編碼與AXDR編碼
?????? ASN.1只是一種語法,要把它寫入數據幀中,就要把它轉換為一個個數據字節。這就要一種(實際是兩種)編碼來實現這種語法。于是就引入了BER編碼與AXDR編碼。
?????? 在DLMS中用ASN.1描述的DLMS協議,用BER編碼實現;用ASN.1描述的XDLMS協議用AXDR編碼實現。
?????? 注:DLMS中只有AARQ與AARE數據幀的部分內容是使用DLMS協議的。絕大多數的應用層數據通訊使用XDLMS。這里無意對DLMS和XDLMS做出劃分和解釋,具體的解釋可參見英文參考文獻【2】。這里只需知道這兩種協議使用不同的編碼。
1 BER
編碼的詳細語法參見附錄。
通常的BER編碼采用如下結構,其中數據內容部分可以嵌套另一BER編碼結構:
數據標識 | 數據長度 | 數據內容 |
數據長度,和數據內容從名字即可知道內容。
這里有必要解釋一下數據標識的構成:
一個BER數據標識和一個BER數據長度構成一個16位的位串:
bit15????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? bit0
datatype classes(bit15、14) | Data type(bit13) | data length(bit12-bit0) |
1)datatype classes 字段:這一字段用于對ASN.1語法中的class type編碼
???? Universal??? (00)
???? Application? (01)
???? Context-specific? (10)
???? Private ?????????? (11)
2)Datatype字段:用于描述數據內容的結構
???? Primitive ???????? (0)???? 簡單類型
???? Constructed ?????? (1)????? 復合類型(數組或結構)
3)datalength字段:用于描述數據內容的長度(以字節為單位)。
下面以接收到的AARE數據幀為例:
AARE數據幀的語法描述:
AARE-apdu ::= [APPLICATION1] IMPLICIT SEQUENCE
――[APPLICATION 1] == [ 61H ] = [ 97 ]
{
protocol-version?????????????????????????? [0] IMPLICIT BITSTRING {version1 (0) } DEFAULT{version1},
application-context-name ??????? ?[1]Application-context-name,
result????????????????????????????????????????????? [2] Association-result,
result-source-diagnostic ????????? ?[3] Associate-source-diagnostic,
responding-AP-title???????????????????? [4] AP-title?OPTIONAL,
responding-AE-qualifier ????????? ?[5] AE-qualifier?OPTIONAL,
responding-AP-invocation-id??? [6] AP-invocation-identifier?OPTIONAL,
responding-AE-invocation-id??? [7] AE-invocation-identifier?OPTIONAL,
-- The following field shall not be presentif only the kernel is used.
responder-acse-requirements? [8] IMPLICIT ACSE-requirements?OPTIONAL,
-- The following field shall only be presentif the authentication functional unit is selected.
mechanism-name????????????????????? ?????? ?[9] IMPLICITmechanism-name?OPTIONAL,
-- The following field shall only be presentif the authentication functional unit is selected.
responding-authentication-value??? ?[10] EXPLICIT authentication-value?OPTIONAL,
implementation-information????????????? [29] IMPLICIT implementation-dataOPTIONAL,
user-information?????????????????????????????????? [30]IMPLICIT association-information?OPTIONAL
}
AARE數據幀的BER編碼和AXDR編碼實現:
61 //AARE tag
42 //AARE len
A1 //tag of COSEM_Application_Context_Name
?09?????????????????????? ?//數據長度
?06????//(OBJECTIDENTIFIER, Universal)OBJECT IDENTIFIER是一種????????????????????????????????????? ????//ASN.1數據類型.
? 07???????????????????????? //數據長度
?6085 74 05 08 01 01 //數據內容
//以下的數據幀可以用同樣的方法一一解釋
A2 //Tag of Association-result,
03 02 01 00
A3 //Tag of Associate-source-diagnostic
05 A1 03 02 0100
88 //IMPLICIT ACSE-requirements OPTIONA
02 07 80
89 //IMPLICIT mechanism-name OPTIONAL
07 60 85 74 0508 02 01
AA //EXPLICIT authentication-value OPTIONAL
0A 80 08 41 4243 44 45 46 47 48
BE
04 // encoding the choice for user-information (OCTET?STRING,Universal)
0E // encoding of the length of the OCTET STRING’s value field (14 octets)
??? /*以下內容為XDLMS用AXDR描述*/
08 //encoding the tag (explicit tag) of the DLMS PDU CHOICE(InitiateResponse)
00 // usage flag for the proposed-quality-of-service component(FALSE, not present)
06 //negotiated-dlms-version-number
5F 1F // encoding the [APPLICATION 31] tag (ASN.1 explicit tag)
04 // encoding the length of the 'contents' field in octet (4)
00 // encoding of the number of unused bits in the final octet ofthe bitstring
00 08 1D// encoding of the fixed length BITSTRING value????????????????? ??
21 34 // the A-XDR encoding of an Unsigned16 is its value
? 0007 // the A-XDR encoding of an Unsigned16 is its value . 00 07 == LN??
2? A-XDR:
?????? 這種編碼是對unix的XDR(外部數據標識法)編碼的擴展。參見IEC61334采用配線載波的配電自動化,譯文匯編,下冊,第六部分。本文參考文獻【9】
3???? 兩種編碼的比較:
?????? A-XDR編碼,與BER編碼的區別可從下例看出。
?????? 對兩數進行編碼,其值分別為0x1234,0x5678
1) 用BER編碼
30 | 08 | 02 | 02 | 12 | 34 | 34 | 02 | 56 | 78 |
序列標識
序列長度
A的標識(整型)
A的字長
A的數值
B的標識(整型)
B的字長
B的數值
??????
2) 用AXDR編碼
1 | 12 | 34 | 56 | 78 |
序列標識
A的數值
B的數值
這里給出一個AXDR編碼的實例:
注:這里的語法仍是ASN.1但將采用不同的編碼。
ASN.1語法描述:(這一數據幀是AARQ數據幀的一部分)
xDLMS-Initiate.request ::=?SEQUENCE
{
dedicated-key OCTET STRINGOPTIONAL,
response-allowed?BOOLEANDEFAULT TRUE,
proposed-quality-of-service[0] IMPLICIT Integer8?OPTIONAL,
proposed-dlms-version-numberUnsigned8,
proposed-conformanceConformance,
client-max-receive-pdu-sizeUnsigned16
}
AXDR編碼:
01--------------------------------------------------------dlmspuu標識
00 ----------------------------------//usageflag for the dedicated-key component (FALSE, not present)
00--------------- //usage flag for theresponse-allowed component (FALSE, default value conveyed)
00-------------- //usage flag for theproposed-quality-of-service component (FALSE, not present)
06-------------- //the A-XDR encoding of anUnsigned8 is its value
5f ---------- //encoding the [APPLICATION31] tag (ASN.1 explicit tag)
?04---------- //encoding the length of the'contents' field in octet (4)
?????? 00-----//encoding of the number of unused bits in the final octet of the BITSTRING
?????? ?00 00 10------- // encoding of the fixedlength bitstring value.(LN/SN)
00 80 // client-max-receive-pdu-size(128 bytes)
(三)AARQ與AARE數據幀
?????? 有了基本的語法和編碼的概念后,下面就開始討論具體的DLMS應用層協議。在前面的DLMS協議模型中已經說明,在進行應用層數據通訊之前,要建立鏈路層連接和應用層連接。鏈路層連接已經在鏈路層協議中解釋過,下面講如何建立應用層連接。
?????? 應用層連接的建立是通過client端發送AARQ數據幀,server端響應AARE數據幀來實現的。這兩個數據幀主要是配置應用層數據通訊的參數。
?????? 關于AARQ,AARE:
在標準的面向連接的應用層服務控制(ACSE)中,為了同服務的使用者進行交互,ACSE提供了很多功能單元。在COSEM中只使用了其中的兩個:the?kernel?and theauthentication functional units.
(一) AARQ , AARE數據幀的具體描述(ASN.1語法描述):
AARQ-apdu ::= [APPLICATION0] IMPLICIT SEQUENCE
{
protocol-version ???????????????????????? [0] IMPLICIT BIT STRING{version1 (0) } DEFAULT{version1},
application-context-name? ? ? ? ? [1] Application-context-name,
called-AP-title????????????????????????????[2] AP-title?OPTIONAL,
called-AE-qualifier????????????????????? [3] AE-qualifier?OPTIONAL,
called-AP-invocation-id????????????? [4] AP-invocation-identifier?OPTIONAL,
called-AE-invocation-id ??????????? [5] AE-invocation-identifier?OPTIONAL,
calling-AP-title????????????????????????????? [6] AP-title?OPTIONAL,
calling-AE-qualifier ?????????????????? [7] AE-qualifier?OPTIONAL,
calling-AP-invocation-id ?????????? [8] AP-invocation-identifier?OPTIONAL,
calling-AE-invocation-id???????????? [9] AE-invocation-identifier?OPTIONAL,
.?Thefollowing field shall not be present if only the kernel is used.
. sender-acse-requirements ??? [10]IMPLICIT ACSE-requirements?OPTIONAL,
-- The following field shall only be presentif the authentication functional unit is selected.
mechanism-name ??????????????????? [11] IMPLICIT mechanism-nameOPTIONAL,
-- The following field shall only be presentif the authentication functional unit is selected.
calling-authentication-value????? [12] EXPLICIT authentication-value?OPTIONAL,
implementation-information?? [29] IMPLICIT implementation-data?OPTIONAL,
user-information ??????????????????????? [30] IMPLICITassociation-information?OPTIONAL
}
AARE-apdu ::= [APPLICATION1] IMPLICIT SEQUENCE
{
protocol-version?????????????????????????? [0] IMPLICIT BITSTRING {version1 (0) } DEFAULT{version1},
application-context-name ??????? ?[1]Application-context-name,
result????????????????????????????????????????????? [2] Association-result,
result-source-diagnostic ????????? ?[3] Associate-source-diagnostic,
responding-AP-title???????????????????? [4] AP-title?OPTIONAL,
responding-AE-qualifier ????????? ?[5] AE-qualifier?OPTIONAL,
responding-AP-invocation-id??? [6] AP-invocation-identifier?OPTIONAL,
responding-AE-invocation-id??? [7] AE-invocation-identifier?OPTIONAL,
-- The following field shall not be presentif only the kernel is used.
responder-acse-requirements? [8] IMPLICIT ACSE-requirements?OPTIONAL,
-- The following field shall only be presentif the authentication functional unit is selected.
mechanism-name????????????????????? ?????? ?[9] IMPLICITmechanism-name?OPTIONAL,
-- The following field shall only be presentif the authentication functional unit is selected.
responding-authentication-value??? ?[10] EXPLICIT authentication-value?OPTIONAL,
implementation-information????????????? [29] IMPLICIT implementation-dataOPTIONAL,
user-information?????????????????????????????????? [30]IMPLICIT association-information?OPTIONAL
}
被標記為OPTIONAL的項,在組成數據幀時都是可以被省略的。但有如下幾個例外:
(1)??? user-information攜帶著XDLMS信息(XDLMS將在稍后解釋),是永遠不能被省略的。
(2)??????如Server端聲明了身份校驗(要求提供密碼登陸),則AARQ中的sender-acse-requirements,mechanism-name,calling-authentication-value,AARE中的responder-acse-requirement,mechanism-name ,responding-authentication-value 都是不能被省略的。如果省略這些項,則請求數據將被拒絕。
(二)AARQ , AARE數據幀中各項的解釋:
1???? AARQ
?protocol-version: 即 ACSE protocol-version. 使用默認值在數據幀中不出現。
application-contex-name:這項是必須項,對于目前的使用情況這個值是唯一的。(0x60 0x85 ??? 0x74 0x050x08 0x01 0x01,具體含義不解釋了,可參見IEC62056-53?的7.3.7.1)
sender and responder acse requirements:?指明是否使用ACSE authentication功能(請求數據等),?????? 使用BER位串編碼,只使用BIT0位。該位置位時表明使用authentication功能
?????? 例:
?????? 8a // the tag for the acse-requirements field component ([10],IMPLICIT, Context-specific )
?????? 02 //Len
?????? //the sender-acse-requirements component (ACSE-requirements::= BIT STRING)
?????? 07 //the number of unused bits in the last byte of the BITSTRING
?????? 80 //encoding of the authentication functional unit (0)。最高位置1其余的為unused bits。
mechanism-name:用于指明使用何種Authentication。共有4種。
calling and authentication value:?指出Authentication的值(即密碼)。
user-information:?內容即為xDLMS-Initiate.requestPDU,xDLMS-Initiate.request的內容如??????????? 下。
?????? xDLMS-Initiate.request :: =?SEQUENCE
?????? {
?????? dedicated-key OCTET STRING?OPTIONAL,
?????? response-allowed?BOOLEAN DEFAULT TRUE,
?????? proposed-quality-of-service [0] IMPLICIT Integer8?OPTIONAL,
?????? proposed-dlms-version-number Unsigned8,
?????? proposed-conformance Conformance,
?????? client-max-receive-pdu-size Unsigned16
?????? }
下面分別解釋xDLMS-Initiate.request的各項內容:
dedicated-key :指出數據是否被加密(ciphering)。通常不用。
response-allowed :是否允許回應。通常允許。
proposed-quality-of-service:通常不用。
proposed-dlms-version-number:目前是6
proposed-conformance :這是主體部分,主要描述需要server端提供的XDLMS服務類型和種類。
它是一個24位的位串,如上圖所示,每一位都代表一種服務,具體解釋如下:
Attibute_0 referencingwith SET is not supported (Bit_08)
Priority Management issupported (Bit_09)
Attibute_0 referencingwith GET is supported (Bit_10)
Block Transfer with theGET service is supported (Bit_11)
Block Transfer with theSET service is supported (Bit_12)
Block Transfer with theACTION service is supported (Bit_13)
Multiple references aresupported (Bit_14)
?All LNservices (GET, SET, ACTION,EVENT NOTIFICATION) are supported (Bit_19, 20, 22,23)
Selective Access featureis supported (Bit_21)
這里提供的多種服務,對于采集器抄表來說,對于采集器最重要的服務是GET service,即讀取數據的功能。通常這個24位的位串被定義為0x00,0x00,0x10即可。即只使用LN services的GET service。
client-max-receive-pdu-size:client端接受數據的最大限制。設為0x0000 表明使用默認設置,則應用層數據單元最長為128字節。
例:以下為接受到的一個最長數據單元
R:
7E A8 8C 03 00 22 00 23 BA88 4D ?? //HDLC 幀頭
00 00 00 02 02 0F 00 16 1E02 03 09 06 01 01 3E 08 00 FF 06 00 00 00 00 02 02 0F 00 16 1E
02 03 09 06 01 01 02 08 00FF 06 00 4B 09 74 02 02 0F 00 16 1E 02 03 09 06 01 01 17 08 00 FF 06 00 00 7E72 02 02 0F 00 16 20 02 03 09 06 01 01 2B 08 00 FF 06 00 00 01 2C 02 02 0F 0016 20 02 03 09 06 01 01 3F 08 00 FF 06 00 00 00 00 02 02 0F 00 16 20 02 03 0906 01 01 03 08 00 FF 06 00 00 7F ?????????????????? //應用層數據單元128字節
2A EA 7E????????????????????????????????????????? //HDLC幀尾
(IMPORTANT?For compliance with existing implementations, encoding ofthe [Application 31] tag on one byte (5F)
instead of two bytes (5F1F) is accepted when the 3-layer, connection-oriented, HDLC based profile isused.)
2??????????AARE
?protocol-version: 即 ACSE protocol-version. 使用默認值在數據幀中不出現。
result:?Server端對于Client端的連接請求回復的結果
result-source-diagnostics:?Server端拒絕Client端的連接請求,在這里給出原因。
application-context-name:?同AARQ
responding authentication value:?同AARQ
user-information:?內容即為xDLMS-Initiate.responsePDU,xDLMS-Initiate.response的內容????????? 如下。
???????? xDLMS-Initiate.response :: = SEQUENCE
???????? {
???????? negotiated-quality-of-service ????????????????????????????? [0] IMPLICIT Integer8 OPTIONAL,
???????? negotiated-dlms-version-number Unsigned8,
???????? negotiated-conformance Conformance,
???????? server-max-receive-pdu-size Unsigned16,
???????? vaa-name ObjectName
???????? }
下面分別解釋xDLMS-Initiate. response的各項內容:
negotiated-quality-of-service: 對應于xDLMS-Initiate.request的proposed-quality-of-service, 通???????????????????????????????? ????????????? 常不用。
negotiated-dlms-version-number:對應于xDLMS-Initiate.request 的
??????????????????????????? ????????????? ??proposed-dlms-version-number,目前是6
negotiated-conformance :這里是server端對client端請求的XDLMS服務的回應。如果允許client??????????????????????????????? ????????????? 端的請求,就對相應的位置1。位串的模式與???????????????????????????????????????????????????????????????? xDLMS-Initiate.request 的conformance相同
server-max-receive-pdu-size: server端可以接收的應用數據單元的最大限制。對于采集器而??????????????????????????????????? ????????????? 言,通常不會向server端發送很長的數據幀。
vaa-name : 目前此項沒有什么用處,server端只是回應一默認值0x0007。
3 其它項
?????? AARQ,AARE數據幀中其它標為OPTIONAL的項,可以在數據幀中不出現,如果一旦在client端出現,而server端沒有相應的處理,則server端只會把這些項略過,不作處理,而不會影響連接的建立。
4 實例
? 這里給出一AARQ、AARE通訊實例。
//aarq
S: 7e a047 00 22 00 23 03 10 d0 5e e6 e6 00 60 36 a1 09 06 07 60 85 74 05 08 01 01 8a02 07 80 8b 07 60 85 74 05 08 02 01 ac 0a 80 08 41 42 43 44 45 46 47 48 be 1004 0e 01 00 00 00 06 5f 1f 04 00 00 08 1d 00 00 9a 7a 7e
解釋:
{
?????? 7e
?????? a0 47 //
?????? 00 22 00 23 //
?????? 03
?????? 10
?????? d0 5e
?????? e6 e6 00 //LLC
?????? {
????????????? 60 // AARQ tag
????????????? 36 // length
????????????? //???? Theapplication-context-name must be in.???
????????????? a1 //tag for theapplication-context-name component
????????????? 09 //the length of the taggedcomponent value field
06 // data type choice forapplication-context-name (OBJECT IDENTIFIER,
Universal)
???????????????????? 07 // Len
???????????????????? 60 85 74 05 08 01 01//(context_id = 1 ; means LN referncing);
//COMMENT by DL :?The most important part of thisapplication-context-name //is that it chooses LN referencing or SN referencing.
????????????????????
????????????? //encoding the sender-acse-requirementsfield component (tagged component, [10]
8a //encoding the tag for theacse-requirements field component
([10], IMPLICIT,Context-specific )
????????????? 02?//Len
???????????????????? //thesender-acse-requirements component (ACSE-requirements ::= BIT STRING)
???????????????????? 07 //the number of unusedbits in the last byte of the BIT STRING
???????????????????? 80 //encoding of theauthentication functional unit (0)
?????????????
???????????????????? //encoding themechanism-name component (tagged component [11])
????????????? 8b?//the tag for the mechanism-name component ([11], IMPLICIT,Context-specific)
????????????? 07?//the length of the tagged component's value field
???????????????????? 60 85 74 05 08 02 01 //thevalue of the Object Identifier
????????????? ac?//the tag for the mechanism-name component ([12], Context-specific)
????????????? 0a?//Len
????????????? 80 //the choice forAuthentication-information (charstring [0] IMPLICIT GraphicString)
???????????????????? 08 //Len
???????????????????? 41 42 43 44 45 46 47 48
????????????? /* User information can't beignored. */
????????????? be?//user information(x-DLMS context)
????????????? 10?//Len (according to bytes)
????????????? {
???????????????????? 04 //data type choice foruser-information (OCTET STRING, Universal)
???????????????????? 0e //Len = 14 bytes
01 00 00 00 06 5f 1f 04 00 00 08 1d 00 00
//the octet sequence of the xDLMS-Initiate.requestPDU.
???????????????????? /*
?????????????????????????????????? xDLMS-Initiate.request:: = SEQUENCE
?????????????????????????????????? {
?????????????????????????????????? dedicated-key?????????????????????????????????? OCTETSTRING OPTIONAL,
?????????????????????????????????? response-allowed?????????????????????? BOOLEAN DEFAULTTRUE,
?????????????????????????????????? proposed-quality-of-service????????? [0] IMPLICIT Integer8 OPTIONAL,
?????????????????????????????????? proposed-dlms-version-number?? Unsigned8,
?????????????????????????????????? proposed-conformance?????????????? Conformance,
?????????????????????????????????? client-max-receive-pdu-size Unsigned16
?????????????????????????????????? }
?????????????????????????????????? Theclient-max-receive-pdu-size is 1200D = 0x4B0.
???????????????????? */
???????????????????? /*
???????????????????? 01 //the tag (explicit tag)of the DLMS PDU CHOICE
???????????????????? //--dedicated-key
???????????????????? 00 //usage flag for thededicated-key component (FALSE, not present)
??????????????????????????? //--response-allowed
00 //usage flag for the response-allowedcomponent (FALSE, default value conveyed)
??????????????????????????? //--proposed-quality-of-service
00 //usage flag for theproposed-quality-of-service component (FALSE, not present)
??????????????????????????? //--proposed-quality-of-service
???????????????????? 06 //the A-XDR encoding ofan Unsigned8 is its value
??????????????????????????? //--proposed-conformance
???????????????????? 5f 1f //encoding the[APPLICATION 31] tag (ASN.1 explicit tag)
???????????????????? ?? 04 //encoding the length of the 'contents'field in octet (4)
00 //encoding of the number ofunused bits in the final octet of the BITSTRING
???????????????????? ?? 00 08 1d // encoding of the fixed lengthbitstring value.(LN/SN)
??????????????????????????? //--client-max-receive-pdu-size
??????????????????????????? 00 00 //the A-XDRencoding of an Unsigned16 is its value.
??????????????????????????? */
????????????? }
?????? }
?????? 9a 7a
?????? 7e
}
//aare
R: 7E A053 03 00 22 00 23 30 40 A6 E6 E7 00 61 42 A1 09 06 07 60 85 74 05 08 01 01 A203 02 01 00 A3 05 A1 03 02 01
?????? ??00 88 02 07 80 89 07 60 85 74 05 08 02 01 AA 0A 80 08 41 42 43 44 45 4647 48 BE 10 04 0E 08 00 06 5F 1F 04
?????? ??00 00 08 1D 21 34 00 07 72 A4 7E
{
?????? 7E
?????? A0 53
?????? 03
?????? 00 22 00 23
?????? 30
?????? 40 A6
?????? E6 E7 00
?????? 61 //AARE tag
?????? 42 //AARE len
????????????? {
????????????? A1//COSEM_Application_Context_Name
????????????? 09?
???????????????????? 06 //type = Objectidentifier
???????????????????? 07 //length = 07
??????????????????????????? 60 85 74 05 08 01 01
????????????? A2 //Tag of Association-result,
????????????? 03 //Len of Association-result,
???????????????????? 02 //type = structure
???????????????????? 01 //length = 1
???????????????????? 00 //
????????????? /*
????????????? Association-result ::= INTEGER
????????????? {
???????????????????? accepted (0),
???????????????????? rejected-permanent (1),
???????????????????? rejected-transient (2)
????????????? }
????????????? encoding the result component(tagged component [2])
????????????? A2 // encoding the tag &length for the result component ([2], Context-specific )
????????????? ??03 // encoding of the length of the tagged component?ˉs value field
????????????? -- encoding the result-component(INTEGER)
????????????? ???? 02 // encoding the choice for result(INTEGER, Universal)
????????????? ??????? 01 // encoding of the length of theresult?ˉs value field (1 octets)
????????????? ?????????? 00 // encoding of the value of theResult (0, accepted)
????????????? */
????????????? A3 //Tag ofAssociate-source-diagnostic,
????????????? 05 //Len ofAssociate-source-diagnostic
????????????? ?????? A1
????????????? ?????? 03
????????????? ?????? 0201 00
????????????? /*
????????????? Associate-source-diagnostic ::=CHOICE
????????????? {
???????????????????? acse-service-user????????????????? [1] INTEGER
???????????????????? {
??????????????????????????? null (0),
??????????????????????????? no-reason-given (1),
??????????????????????????? application-context-name-not-supported(2),
??????????????????????????? authentication-mechanism-name-not-recognised(11),
??????????????????????????? authentication-mechanism-name-required(12),
??????????????????????????? authentication-failure(13),
??????????????????????????? authentication-required(14)
???????????????????? },
???????????????????? acse-service-provider??????????? [2] INTEGER
???????????????????? {
??????????????????????????? null (0),
??????????????????????????? no-reason-given (1),
??????????????????????????? no-common-acse-version(2)
???????????????????? }
????????????? }
????????????? -- encoding theresult-source-diagnostic (tagged component [3])
A3 //encoding the tag for the result-source-diagnostic component ([3],Context-specific )
05 //encoding of the length of the tagged component?ˉs value field
A1 //encoding the tag for the acse-service-user CHOICE (1)
03 //encoding of the length of the tagged component's value field
--encoding the result-source-diagnostics component (INTEGER)
02 //encoding the choice for result-source-diagnostics (INTEGER, Universal)
01 //encoding of the length of the value field (1 octets)
00 //encoding of the value: 0, no diagnostics provided.
????????????? */
????????????? //Contents below can be ignored.
????????????? 88 //IMPLICIT ACSE-requirementsOPTIONAL
????????????? 02
???????????????????? 07
???????????????????? 80
????????????? 89 //IMPLICIT mechanism-nameOPTIONAL
????????????? 07
???????????????????? 60 85 74 05 08 02 01
????????????????????
????????????? AA //EXPLICIT authentication-valueOPTIONAL
????????????? 0A
???????????????????? 80
???????????????????? 08
???????????????????? 41 42 43 44 45 46 47 48
?????????????
????????????? //User information must be exist.
????????????? /*
????????????? xDLMS-Initiate.response :: =SEQUENCE
????????????? {
????????????? negotiated-quality-of-service???????????????????????????? [0] IMPLICITInteger8 OPTIONAL,
????????????? negotiated-dlms-version-number?????????????????????????????? Unsigned8,
????????????? negotiated-conformance?????????????????????????????????????????? Conformance,
????????????? server-max-receive-pdu-size???????????????????????????????????? Unsigned16,
????????????? vaa-name??????????????????????????????????????????????????????????????? ObjectName
????????????? }
????????????? */
????????????? BE //User information (x-DLMScontext)
????????????? 10
???????????????????? {
???????????????????? 04 // encoding the choicefor user-information (OCTET STRING, Universal)
???????????????????? 0E // encoding of thelength of the OCTET STRING?ˉs value field (14 octets)
???????????????????? ?? //-- A-XDR encoding thexDLMS-Initiate.response PDU
???????????????????? ?? 08 //encoding the tag (explicit tag) of theDLMS PDU CHOICE (InitiateResponse)
???????????????????? ?? //-- encoding the negotiated-quality-of-servicecomponent (OPTIONAL, not present)
???????????????????? ?? 00 // usage flag for theproposed-quality-of-service component (FALSE, not present)
???????????????????? ?? //-- encoding of thenegotiated-dlms-version-number component (Unsigned8, value=6)
???????????????????? ?? 06 //negotiated-dlms-version-number
???????????????????? ?? //-- encoding the conformance block[APPLICATION 31] IMPLICIT BITSTRING (SIZE(24))
???????????????????? ?? 5F 1F // encoding the [APPLICATION 31] tag(ASN.1 explicit tag)
???????????????????? ????? 04 // encoding the length of the'contents' field in octet (4)
??????????????????????????? ??? 00 // encoding of the number of unused bitsin the final octet of the bitstring
?????????????????????????????????? // encodingof the fixed length BITSTRING value
?????????????????????????????????? 00 08 1D
??????????????????????????? //-- encoding theserver-max-receive-pdu-size component (Unsigned16, value=0x01F4)
???????????????????? ?? 21 34 // the A-XDR encoding of an Unsigned16is its value
???????????????????? ?? //-- encoding the VAA-Name component(Unsigned16, value=0x0007 for LN and FA 00 for SN)
???????????????????? ?? 00 07 // the A-XDR encoding of an Unsigned16is its value . 00 07 == LN??????????????? ???
???????????????????? }
????????????? }
?????? 72 A4
?????? 7E
(四)必要的數據請求幀,和響應幀
?????? 在應用層連接建立之后,client就可以向server請求數據了。這里只介紹兩個基本的數據通訊幀。
所有的DLMS應用數據幀都是COSEMpdu的一部分下面首先列出COSEMpdu。
COSEMpdu ::=?CHOICE?{
-- standardized DLMS PDUs used in COSEM
-- DLMS PDUs (no encryption selected30)
initiateRequest ????????????????????????? [1]?IMPLICIT?InitiateRequest,
readRequest ???????????????????????????? [5]?IMPLICIT?ReadRequest,
writeRequest ????????????????????? [6]?IMPLICIT?WriteRequest,
initiateResponse ?????????????????????? [8]?IMPLICIT?InitiateResponse,
readResponse ????????????????????????? [12]?IMPLICIT?ReadResponse,
writeResponse ????????????????????????? [13]?IMPLICIT?WriteResponse,
confirmedServiceError ????????????? [14] ConfirmedServiceError,
unconfirmedWriteRequest ???????? [22]?IMPLICIT?UnconfirmedWriteRequest,
informationReportRequest ???????? [24]?IMPLICIT?InformationReportRequest,
-- the two ACSE APDUs
aarq AARQ-apdu
aare AARE-apdu,
-- APDUs used for data communication servicesusing LN referencing
get-request ?????????????????????????????? [192]?IMPLICIT?GET-Request,
set-request ?????????????????????????????? [193]?IMPLICIT?SET-Request,
event-notification-request????????? [194]?IMPLICIT?EVENT-NOTIFICATION-Request,
action-request ?????????????????????????? [195]?IMPLICIT?ACTION-Request,
get-response ??????????????????????????? [196]?IMPLICIT?GET-Response,
set-response ??????????????????????????? [197]?IMPLICIT?SET-Response,
action-response ??????????????????????? [199]?IMPLICIT?ACTION-Response,
-- global ciphered pdus
glo-get-request ???????????????????????? [200]?IMPLICITOCTET STRING,
glo-set-request ???????????????????????? [201]?IMPLICITOCTET STRING,
glo-event-notification-request??? [202]?IMPLICIT OCTET STRING,
glo-action-request ???????????????????? [203]?IMPLICITOCTET STRING,
glo-get-response ????????????????????? [204]?IMPLICITOCTET STRING,
glo-set-response ?????????????????????? [205]?IMPLICITOCTET STRING,
glo-action-response ????????????????? [207]?IMPLICITOCTET STRING,
-- dedicated ciphered pdus
ded-get-request ??????????????????????? [208]?IMPLICITOCTET STRING,
ded-set-request ??????????????????????? [209]?IMPLICITOCTET STRING,
ded-event-notification-request?? [210]?IMPLICIT OCTET STRING,
ded-actionRequest ??????????????????? [211]?IMPLICITOCTET STRING,
ded-get-response ???????????????????? [212]?IMPLICITOCTET STRING,
ded-set-response ????????????????????? [213]?IMPLICITOCTET STRING,
ded-action-response ???????????????? [215]?IMPLICITOCTET STRING
}
這里要說明一下OBIS:
在數據請求幀中,必須有Cosem-Attribute-Descriptor項:
Cosem-Attribute-Descriptor ::= SEQUENCE
{
class-id Cosem-Class-Id,
instance-id Cosem-Object-Instance-Id,
attribute-id Cosem-Object-Attribute-Id
}
其中的class-id ?attribute-id由本文參考文獻【1】定義。
Cosem-Object-Instance-Id由本文參考文獻【5】定義。
由參考文獻【5】定義的內容即OBIS。它是由COSEM定義的一系列編碼,共6個字節長。他的作用就是為每一種數據類型提供一個唯一的編碼。有關OBIS的具體內容請參閱參考文獻【5】。
1)??? 數據請求幀
GET-Request ::= CHOICE
{
get-request-normal??????? [1] IMPLICIT Get-Request-Normal,
get-request-next??????????? [2] IMPLICIT Get-Request-Next,
get-request-with-list?????? [3] IMPLICIT Get-Request-With-List
}
Get-Request-Normal ::= SEQUENCE
{
invoke-id-and-priority???????????????? Invoke-Id-And-Priority,
cosem-attribute-descriptor??????????? Cosem-Attribute-Descriptor,
access-selection-parameters?????????? Selective-Access-Descriptor OPTIONAL
}
Cosem-Attribute-Descriptor ::= SEQUENCE
{
class-id Cosem-Class-Id,
instance-id Cosem-Object-Instance-Id,
attribute-id Cosem-Object-Attribute-Id
}
Cosem-Object-Instance-Id ::= OCTET STRING(SIZE(6))
Cosem-Object-Attribute-Id ::= Integer8
以請求反向有功為例:
S: 7e a0 1c 00 22 00 23 03 54 bd 5e e6 e6 00c0 01 81 00 03 01 01 02 08 00 ff 02 00 9f 36 7e?
解釋:
7e a0 1c 00 22 00 23 03 54 bd 5e e6 e6 00 //Hdlchead
c0 // get-request ?????????????????????????????? Cosemapdu[192]
01 //Request Nomal
81 // invoke-id(000 0001) and priority(1)
00 // Get-Data-Result = data
03//Class id
01 01 02 08 00 ff //反向總有功 OBIS
02 00 //反向總有功的第二屬性,值域。
9f 36 7e //HDLC Tail
2)??? 數據響應幀
?????? GET-Response ::= CHOICE
?????? {
?????? get-response-normal ???????????????? [1]IMPLICIT?Get-Response-Normal,
?????? get-response-with-datablock????????????? [2]IMPLICIT?Get-Response-With-Datablock,
?????? get-response-with-list ??????????????? [3]IMPLICIT?Get-Response-With-List
?????? }
?????? Get-Response-Normal ::=?SEQUENCE
?????? {
?????? invoke-id-and-priority ??????????????? Invoke-Id-And-Priority,
?????? result ??????????????????????????????????????? Get-Data-Result
?????? }
?????? Get-Data-Result ::=?CHOICE
?????? {
?????? data [0] Data,
?????? data-access-result [1]?IMPLICIT?Data-Access-Result
?????? }
?????? Data ::= CHOICE
?????? {
?????? null-data?????????????????????? [0]IMPLICIT NULL,
???????array??????????????????????????? [1]IMPLICIT SEQUENCE OF Data,
?????? structure????????????????????? [2]IMPLICIT SEQUENCE OF Data,
?????? boolean?????????????????????? [3]IMPLICIT BOOLEAN,
?????? bit-string????????????????????? [4]IMPLICIT BIT STRING,
?????? double-long???????????????? [5]IMPLICIT Integer32,
?????? double-long-unsigned?? [6]IMPLICIT Unsigned32,
?????? floating-point?????????????? [7]IMPLICIT OCTET STRING(SIZE(4))33,
?????? octet-string????????????????? [9]IMPLICIT OCTET STRING,
?????? visible-string??????????????? [10]IMPLICIT VisibleString,
?????? time???????????????????????????? [11]IMPLICIT GeneralizedTime,
?????? bcd???????????????????????????? [13]IMPLICIT Integer8,
?????? integer???????????????????????? [15]IMPLICIT Integer8,
?????? long???????????????????????????? [16]IMPLICIT Integer16,
?????? unsigned????????????????????? [17]IMPLICIT Unsigned8,
?????? long-unsigned???????????????????? [18]IMPLICIT Unsigned16,
?????? compact-array????????????? [19]IMPLICIT SEQUENCE
?????? {
?????? contents-description ?? [0]TypeDescription,
?????? array-contents????????????? [1]IMPLICIT OCTET STRING
?????? }
?????? long64??????????????????????????????? [20]IMPLICIT Integer64,
?????? long64-unsigned????????????????? [21]IMPLICIT Unsigned64,
?????? enum????????????????????????????????? [22]IMPLICIT ENUMERATED,
?????? float32??????????????????????????????? [23]IMPLICIT OCTET STRING (SIZE(4)),
?????? float64??????????????????????????????? [24]IMPLICIT OCTET STRING (SIZE(8)),
?????? don’t-care?????????????????????????? [255]IMPLICIT NULL
?????? }
?????? Data-Access-Result ::= ENUMERATED
?????? {
?????? success????????????????????????????? (0),
?????? hardware-fault????????????? (1),
?????? temporary-failure???????????????? (2),
?????? read-write-denied???????????????? (3),
?????? object-undefined???????????????? (4),
?????? object-class-inconsistent???? (9),
?????? object-unavailable?????????????? (11),
?????? type-unmatched????????????????? (12),
?????? scope-of-access-violated??? (13),
?????? data-block-unavailable???????? (14),
?????? long-get-aborted???????????????? (15),
?????? no-long-get-in-progress?????? (16),
?????? long-set-aborted????????????????? (17),
?????? no-long-set-in-progress??????? (18),
?????? other-reason??????????????????????? (250)
?????? }
以響應“請求反向有功”為例:
R: 7E A0 18 03 00 22 00 23 74 E4 13 E6 E7 00C4 01 81 00 06 00 35 7B 18 CD E8 7E
解釋:
7E A0 18 03 00 22 00 23 74 E4 13 E6 E700? //Hdlc head
C4 01 //Response Normal
81 // invoke-id(000 0001) and priority(1)
00 //by data
06 //數據長度
00 35 7B 18 //反向有功值
CD E8 7E//HDLC Tail
五、對于接收到的數據幀的拆解
?????? 接收到的請求數據都是按照AXDR編碼的。接收到的數據幀的數據結構,在參考文獻【7】中都有詳細解釋。
?????? 以下給出數據幀解析的實例:
例:Load_profile
//hdlclink
//SNRM
S: 7e a021 00 22 00 23 03 93 0b 14 81 80 12 05 01 80 06 01 80 07 04 00 00 00 01 08 0400 00 00 07 65 5e 7e
//UA
R: 7E A021 03 00 22 00 23 73 28 F0 81 80 12 05 01 80 06 01 80 07 04 00 00 00 01 08 0400 00 00 01 53 3B 7E
//aarq
S: 7e a047 00 22 00 23 03 10 d0 5e e6 e6 00 60 36 a1 09 06 07 60 85 74 05 08 01 01 8a02 07 80 8b 07 60 85 74 05 08 02 01 ac 0a 80 08 41 42 43 44 45 46 47 48 be 1004 0e 01 00 00 00 06 5f 1f 04 00 00 08 1d 00 00 9a 7a 7e
//aare
R: 7E A053 03 00 22 00 23 30 40 A6 E6 E7 00 61 42 A1 09 06 07 60 85 74 05 08 01 01 A203 02 01 00 A3 05 A1 03 02 01 00 88 02 07 80 89 07 60 85 74 05 08 02 01 AA 0A80 08 41 42 43 44 45 46 47 48 BE 10 04 0E 08 00 06 5F 1F 04 00 00 08 1D 21 3400 07 72 A4 7E
//
S: 7e a00a 00 22 00 23 03 31 12 87 7e
R: 7E A00A 03 00 22 00 23 31 3F 84 7E
S: 7e a00a 00 22 00 23 03 31 12 87 7e
R: 7E A00A 03 00 22 00 23 31 3F 84 7E
//requestdata
S: 7e a01c 00 22 00 23 03 32 8d 58 e6 e6 00 c0 01 81?
?? 00 07 0000 63 80 01 ff?? 02 00
?? 44 58 7e
R: 7E A04F 03 00 22 00 23 52 07 E2 E6 E7 00 C4 01 81 00
?? 01 01 //1 array
?? 02 06 //6 strures
?? 09 06 01 01 01 1B 00 FF //1
?? 02 02 0F 03 16 1B????????? //2
?? 09 06 01 01 02 1B 00 FF //3
?? 02 02 0F 03 16 1B????????? //4
?? 09 0C 07 D3 05 08 FF FF FF FF FF FF FF FF???? //5
?? 09 0C 07 D3 05 17 FF FF FF FF FF FF FF FF???? //6
?? F6 CE 7E?
??
S: 7e a00a 00 22 00 23 03 51 14 e4 7e
R: 7E A00A 03 00 22 00 23 51 39 E7 7E
S: 7e a01c 00 22 00 23 03 54 bd 5e e6 e6 00 c0 01 81 00 07
?? ff ff 62 85 02 ff
?? 02 00
?? 7a 23 7e
R: 7E A88C 03 00 22 00 23 74 FA 62 E6 E7 00 C4 01 81 00
?? 01 //arry
??? 01 //total 1 array
?? 02 //structure
??? 34 //total 52 structure
?? 02 03 //3 structure
????????????? 09 06???????????? 01 01 15 08 00 FF???????? //octetstring , 6 bytes long ,obiscode(01 01 15 08 00 FF)
????????????? 06????????????????? 0000 00 00???????????????????????? //Unsigned32(0x06),data (00 00 00 00)
????????????? 02 02????? //scal and unit.02 typ=strcture, 02 num = 2 strctures. ???????
???????????????????? 0F 00????? // scal :êy?YààDíInteger8(0x0f),êy?Y?úèYdata (0x00)?? //??62056μ?pdf
???????????????????? 16 1E????? // unit :ENUMERATED(0x16) , data(0x1e =wh)
?????????????????????????????????? //unit:enum.Thiscan be founded in Blue book 3rd edition.
?? //attention (By DL): according to XDR ,whena datatype(Such as octet string,array ,stucture)
?? //can't express the data length ,a datalength byte should exist.On the other hand ,when the length can be expressed by
?? //the data type(such asInteger8,Unsigned32,and ENUMERATED),the length byte arnn't exist.
?? //?ù?YBER±à????
?? 02 03
????????????? 09 06 01 01 29 08 00 FF????????????? 06 00 00 00 00 02 02???? 0F 00 16 1E
?? 02 03
????????????? 09 06 01 01 3D 08 00 FF???????????? 06 00 00 00 00 02 02???? 0F 00 16 1E
?? 02 03
????????????? 09 06 01 01 01 08 00 FF????????????? 06 00 00 00 00 02 02???? 0F 00 16 1E
?? 02 03
????????????? 09 06 01 01 16 08 00 FF????????????? 06 00 2E 6E FE 02 02?? 0F 00 16 1E
?? 02 03
????????????? 09 06 01 01 2A 08 00 FF???????????? 06 00
?? 9E 5D 7E
S: 7e a00a 00 22 00 23 03 71 16 c5 7e
R: 7E A88C 03 00 22 00 23 76 E8 41
?????????????????????????????????????????????????????????????? ? 00 00 00 02 02?? 0F 00 16 1E????????? 02 03
?? 09 06 0101 3E 08 00 FF 06 00 00 00 00 02 02???? 0F 00 16 1E????????? 0203
?? 09 06 0101 02 08 00 FF? 06 00 2E 6E FE 02 02?? 0F 00 16 1E????????? 0203
?? 09 06 0101 17 08 00 FF? 06 00 00 00 00 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 2B 08 00 FF 06 00 00 00 82 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 3F 08 00 FF 06 00 00 00 00 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 03 08 00 FF? 06 00 00 00
?? CB 00 7E
S: 7e a00a 00 22 00 23 03 91 18 22 7e
R: 7E A88C 03 00 22 00 23 78 96 A8
????????????????????????????????????????????????????????????????????? ??? 82 02 02? 0F00 16 20?????????? 02 03
?? 09 06 0101 18 08 00 FF? 06 00 03 C2 EE 02 02?? 0F 00 16 20?????????? 0203
?? 09 06 0101 2C 08 00 FF 06 00 00 00 82 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 40 08 00 FF? 06 00 00 00 00 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 04 08 00 FF? 06 00 03 C3 70 02 02??? 0F 00 16 20?????????? 0203
?? 09 06 0101 19 08 00 FF? 06 00 00 00 00 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 2D 08 00 FF 06 00 00 00 50 02
?? 88 CB7E
S: 7e a00a 00 22 00 23 03 b1 1a 03 7e
R: 7E A88C 03 00 22 00 23 7A 84 8B
??????????????????????????????????????????????????????????????????????????????????? ? 02?????? 0F00 16 20?????????? 02 03
?? 09 06 0101 41 08 00 FF? 06 00 00 00 00 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 05 08 00 FF? 06 00 00 00 50 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 1A 08 00 FF 06 00 00 00 00 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 2E 08 00 FF 06 00 00 00 32 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 42 08 00 FF? 06 00 00 00 00 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 06 08 00 FF? 06 00 00 00 32 02 02???? 0F
?? B9 E0 7E
S: 7e a00a 00 22 00 23 03 d1 1c 60 7e
R: 7E A88C 03 00 22 00 23 7C B2 EE
????????????????????????????????????????????????????????????????????????????????????????????????? ?? 00 16 20????????? 0203
?? 09 06 0101 1B 08 00 FF 06 00 03 C2 EE 02 02?? 0F 00 16 20?????????? 0203
?? 09 06 0101 2F 08 00 FF 06 00 00 00 64 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 43 08 00 FF? 06 00 00 00 00 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 07 08 00 FF? 06 00 03 C3 52 02 02??? 0F 00 16 20?????????? 0203
?? 09 06 0101 1C 08 00 FF 06 00 00 00 00 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 30 08 00 FF? 06 00 00 00 1E 02 02??? 0F 00 16
?? A8 C8 7E
S: 7e a00a 00 22 00 23 03 f1 1e 41 7e
R: 7E A88C 03 00 22 00 23 7E A0 CD
??????????????????????????????????????????????????????????????????????????????????????????????????????????????? ?20???????? 0203
?? 09 06 0101 44 08 00 FF? 06 00 00 00 00 02 02???? 0F 00 16 20?????????? 0203
?? 09 06 0101 08 08 00 FF? 06 00 00 00 1E 02 02??? 0F 00 16 20?????????? 0203
?? 09 06 0101 1D 08 00 FF 06 00 00 00 00 02 02???? 0F 00 16 1F?????????? 0203
?? 09 06 0101 31 08 00 FF? 06 00 00 02 62 02 02???? 0F 00 16 1F?????????? 0203
?? 09 06 0101 45 08 00 FF? 06 00 00 00 00 02 02???? 0F 00 16 1F?????????? 0203
?? 09 06 0101 09 08 00 FF? 06 00 00 02 62 02 02???? 0F 00 16 1F?????????? 02
?? 5B 0C 7E
S: 7e a00a 00 22 00 23 03 11 10 a6 7e
R: 7E A88C 03 00 22 00 23 70 DE 24
?? 03
?? 09 06 01 01 1E 08 00 FF 06 00 2E 8D B2 02 020F 00 16 1F 02 03
?? 09 06 01 01 32 08 00 FF 06 00 00 00 00 02 020F 00 16 1F 02 03
?? 09 06 01 01 46 08 00 FF 06 00 00 00 00 02 020F 00 16 1F 02 03
?? 09 06 01 01 0A 08 00 FF 06 00 2E 8D B2 02 020F 00 16 1F 02 03
?? 09 06 FF 02 FF 08 00 FF 06 00 00 00 00 02 020F 00 16 FF 02 03
?? 09 06 FF 03 FF 08 00 FF 06 00 00 00 00 02 020F 00 16 FF 02 03
?? 09
?? 1C EB 7E
S: 7e a00a 00 22 00 23 03 31 12 87 7e
R: 7E A88C 03 00 22 00 23 72 CC 07
?????? ?06 FF 04 FF 08 00 FF 06 00 00 00 00 02 02 0F 00 16 FF 02 03
?? 09 06 FF 05 FF 08 00 FF 06 00 00 00 00 02 020F 00 16 FF 02 03
?? 09 06 FF 02 FF 08 00 FF 06 00 00 00 00 02 020F 00 16 FF 02 03
?? 09 06 FF 03 FF 08 00 FF 06 00 00 00 00 02 020F 00 16 FF 02 03
?? 09 06 FF 04 FF 08 00 FF 06 00 00 00 00 02 020F 00 16 FF 02 03
?? 09 06 FF 05 FF 08 00 FF 06 00 00 00 00 02 020F 00 16 FF 02 03
?? 09 06 FF
?? 29 95 7E
S: 7e a00a 00 22 00 23 03 51 14 e4 7e
R: 7E A05B 03 00 22 00 23 74 8C 7C 06 FF 08 00
??????????????????????? FF 06 00 00 00 00 02 020F 00 16 FF 02 03
?? 09 06 FF 07 FF 08 00 FF 06 00 00 00 00 02 020F 00 16 FF 02 03
?? 09 06 FF 08 FF 08 00 FF 06 00 00 00 00 02 020F 00 16 FF 02 03
?? 09 06 FF 09 FF 08 00 FF 06 00 00 00 00 02 020F 00 16 FF
?? 0B 2E 7E
S: 7e a00a 00 22 00 23 03 71 16 c5 7e
R: 7E A00A 03 00 22 00 23 71 3B C6 7E
S: 7e a00a 00 22 00 23 03 71 16 c5 7e
R: 7E A00A 03 00 22 00 23 71 3B C6 7E
S: 7e a00a 00 22 00 23 03 71 16 c5 7e
R: 7E A00A 03 00 22 00 23 71 3B C6 7E
S: 7e a00a 00 22 00 23 03 71 16 c5 7e
R: 7E A00A 03 00 22 00 23 71 3B C6 7E
S: 7e a00a 00 22 00 23 03 71 16 c5 7e
R: 7E A00A 03 00 22 00 23 71 3B C6 7E
S: 7e a00a 00 22 00 23 03 71 16 c5 7e
R: 7E A00A 03 00 22 00 23 71 3B C6 7E
//disclink
S: 7e a00a 00 22 00 23 03 53 06 c7 7e
R: 7E A00A 03 00 22 00 23 1F 43 4C 7E
六、請求數據實例
?????? 這里給出幾個數據通訊的實例,供程序員編程時參考。
1、??? 請求電量
請求正向有功總電量,及分費率電量。
S:7E A0 0A 00 22 0023 03 93 0A 01 7E
R:7E A0 21 03 00 2200 23 73 28 F0 81 80 12 05 01 80 06 01 80 07 04 00 00 00 01 08 04 00 00 00 0153 3B 7E
S:7E A0 46 00 22 0023 03 10 05 C1 E6 E6 00 60 35 A1 09 06 07 60 85 74 05 08 01 01 8A 02 07 80 8B07 60 85 74 05 08 02 01 AC 0A 80 08 41 42 43 44 45 46 47 48 BE 10 04 0E 01 0000 00 06 5F 04 00 00 00 14 00 00 BD BF 7E
R:7E A0 52 03 00 2200 23 30 95 39 E6 E7 00 61 41 A1 09 06 07 60 85 74 05 08 01 01 A2 03 02 01 00A3 05 A1 03 02 01 00 88 02 07 80 89 07 60 85 74 05 08 02 01 AA 0A 80 08 41 4243 44 45 46 47 48 BE 0F 04 0D 08 00 06 5F 04 00 00 00 14 21 34 00 07 14 53 7E
S:7E A0 1B 00 22 0023 03 32 95 9F E6 E6 00 C0 01 81 00 03 01 01 01 08 00 FF 02 0C F6 7E
R:7E A0 18 03 00 2200 23 52 D0 57 E6 E7 00 C4 01 81 00 06 00 06 1B 98 5A 60 7E
S:7E A0 1B 00 22 0023 03 54 A5 99 E6 E6 00 C0 01 81 00 04 01 01 01 08 01 FF 02 DE 30 7E
R:7E A0 18 03 00 2200 23 74 E4 13 E6 E7 00 C4 01 81 00 06 00 01 C7 14 A0 54 7E
S:7E A0 1B 00 22 0023 03 76 B5 9B E6 E6 00 C0 01 81 00 04 01 01 01 08 02 FF 02 BA DF 7E
R:7E A0 18 03 00 2200 23 96 F8 D7 E6 E7 00 C4 01 81 00 06 00 03 17 5E 7D 53 7E
S:7E A0 1B 00 22 0023 03 98 C5 95 E6 E6 00 C0 01 81 00 04 01 01 01 08 03 FF 02 66 85 7E
R:7E A0 18 03 00 2200 23 B8 84 1F E6 E7 00 C4 01 81 00 06 00 01 3D 26 49 C7 7E
S:7E A0 1B 00 22 0023 03 BA D5 97 E6 E6 00 C0 01 81 00 04 01 01 01 08 04 FF 02 63 09 7E
R:7E A0 18 03 00 2200 23 DA 90 5F E6 E7 00 C4 01 81 00 06 00 00 00 00 7B DF 7E
S:7E A0 0A 00 22 0023 03 D1 1C 60 7E
R:7E A0 0A 03 00 2200 23 D1 31 63 7E
S:7E A0 0A 00 22 0023 03 53 06 C7 7E
R:7E A0 0A 03 00 2200 23 73 29 E5 7E
2、請求瞬時量(電壓、電流、功率)
S:7E A0 0A 00 22 0023 03 93 0A 01 7E
R:7E A0 21 03 00 2200 23 73 28 F0 81 80 12 05 01 80 06 01 80 07 04 00 00 00 01 08 04 00 00 00 0153 3B 7E
S:7E A0 46 00 22 0023 03 10 05 C1 E6 E6 00 60 35 A1 09 06 07 60 85 74 05 08 01 01 8A 02 07 80 8B07 60 85 74 05 08 02 01 AC 0A 80 08 41 42 43 44 45 46 47 48 BE 10 04 0E 01 0000 00 06 5F 04 00 00 00 14 00 00 BD BF 7E
R:7E A0 52 03 00 2200 23 30 95 39 E6 E7 00 61 41 A1 09 06 07 60 85 74 05 08 01 01 A2 03 02 01 00A3 05 A1 03 02 01 00 88 02 07 80 89 07 60 85 74 05 08 02 01 AA 0A 80 08 41 4243 44 45 46 47 48 BE 0F 04 0D 08 00 06 5F 04 00 00 00 14 21 34 00 07 14 53 7E
S:7E A0 1B 00 22 0023 03 32 95 9F E6 E6 00 C0 01 81 00 03 01 01 1F 07 00 FF 02 0D 91 7E
R:7E A0 16 03 00 2200 23 52 F1 D1 E6 E7 00 C4 01 81 00 12 00 02 33 53 7E
S:7E A0 1B 00 22 0023 03 54 A5 99 E6 E6 00 C0 01 81 00 03 01 01 33 07 00 FF 02 AC 86 7E
R:7E A0 16 03 00 2200 23 74 C5 95 E6 E7 00 C4 01 81 00 12 00 02 33 53 7E
S:7E A0 1B 00 22 0023 03 76 B5 9B E6 E6 00 C0 01 81 00 03 01 01 47 07 00 FF 02 4F BE 7E
R:7E A0 16 03 00 2200 23 96 D9 51 E6 E7 00 C4 01 81 00 12 00 02 33 53 7E
S:7E A0 1B 00 22 0023 03 98 C5 95 E6 E6 00 C0 01 81 00 03 01 01 20 07 00 FF 02 20 2F 7E
R:7E A0 16 03 00 2200 23 B8 A5 99 E6 E7 00 C4 01 81 00 12 00 01 A8 61 7E
S:7E A0 1B 00 22 0023 03 BA D5 97 E6 E6 00 C0 01 81 00 03 01 01 34 07 00 FF 02 70 B6 7E
R:7E A0 16 03 00 2200 23 DA B1 D9 E6 E7 00 C4 01 81 00 12 00 01 A8 61 7E
S:7E A0 1B 00 22 0023 03 DC E5 91 E6 E6 00 C0 01 81 00 03 01 01 48 07 00 FF 02 B3 D4 7E
R:7E A0 16 03 00 2200 23 FC 85 9D E6 E7 00 C4 01 81 00 12 00 01 A8 61 7E
S:7E A0 0A 00 22 0023 03 F1 1E 41 7E
R:7E A0 0A 03 00 2200 23 F1 33 42 7E
S:7E A0 0A 00 22 0023 03 53 06 C7 7E
R:7E A0 0A 03 00 2200 23 73 29 E5 7E
3、請求負荷曲線
S:7E A0 0A 00 22 0023 03 93 0A 01 7E
R:7E A0 21 03 00 2200 23 73 28 F0 81 80 12 05 01 80 06 01 80 07 04 00 00 00 01 08 04 00 00 00 0153 3B 7E
S:7E A0 46 00 22 0023 03 10 05 C1 E6 E6 00 60 35 A1 09 06 07 60 85 74 05 08 01 01 8A 02 07 80 8B07 60 85 74 05 08 02 01 AC 0A 80 08 41 42 43 44 45 46 47 48 BE 10 04 0E 01 0000 00 06 5F 04 00 00 00 14 00 00 BD BF 7E
R:7E A0 52 03 00 2200 23 30 95 39 E6 E7 00 61 41 A1 09 06 07 60 85 74 05 08 01 01 A2 03 02 01 00A3 05 A1 03 02 01 00 88 02 07 80 89 07 60 85 74 05 08 02 01 AA 0A 80 08 41 4243 44 45 46 47 48 BE 0F 04 0D 08 00 06 5F 04 00 00 00 14 21 34 00 07 14 53 7E
S:7E A0 3C 00 22 0023 03 32 0E 3B E6 E6 00 C0 01 81 00 07 00 00 63 01 00 FF 02 01 01 02 04 00 090C 07 D3 06 09 FF FF FF FF FF FF FF FF 09 0C 07 D3 06 0A FF FF FF FF FF FF FFFF DE 82 7E
R:7E A8 8C 03 00 2200 23 52 CE 26 E6 E7 00 C4 01 81 00 01 22 02 06 02 02 09 0C 07 D3 06 09 FF 091D 0D FF FF FF FF 04 06 40 00 00 00 10 00 00 10 00 00 02 06 00 00 00 00 10 0000 10 00 00 02 06 00 00 00 00 10 00 00 10 00 00 02 06 00 00 00 00 10 00 00 1000 00 02 06 00 00 00 00 10 00 00 10 00 00 02 06 00 00 00 00 10 00 00 10 00 0002 06 00 00 00 00 10 00 00 10 00 00 02 06 00 00 00 00 10 00 00 10 00 00 02 0600 00 00 83 9E 7E
S:7E A0 0A 00 22 0023 03 51 14 E4 7E
R:7E A8 8C 03 00 2200 23 54 F8 43 00 10 00 00 10 00 00 02 06 00 00 00 00 10 00 00 10 00 00 02 0600 00 00 00 10 00 00 10 00 00 02 06 00 00 00 00 10 00 00 10 00 00 02 06 00 0000 00 10 00 00 10 00 00 02 06 00 00 00 00 10 00 00 10 00 00 02 06 00 00 00 0010 00 00 10 00 00 02 06 00 00 00 00 10 00 00 10 00 00 02 06 00 00 00 00 10 0000 10 00 00 02 06 00 00 00 00 10 00 00 10 00 00 02 06 00 00 00 00 10 00 00 10 0000 02 F9 31 7E
S:7E A0 0A 00 22 0023 03 71 16 C5 7E
R:7E A8 8C 03 00 2200 23 56 EA 60 06 00 00 00 00 10 00 00 10 00 00 02 06 00 00 00 00 10 00 00 1000 00 02 06 00 00 00 00 10 00 00 10 00 00 02 06 00 00 00 00 10 00 00 10 00 0002 06 00 00 02 02 09 0C FF FF FF FF FF 0F 08 34 FF FF FF FF 04 06 40 02 02 090C FF FF FF FF FF 0F 0E 1F FF FF FF FF 04 06 40 10 00 00 10 00 00 02 06 00 0000 00 10 00 00 10 00 00 02 06 00 00 00 00 10 00 00 10 00 00 02 06 00 00 00 0010 00 00 14 24 7E
S:7E A0 0A 00 22 0023 03 91 18 22 7E
R:7E A0 75 03 00 2200 23 58 40 72 10 00 00 02 06 00 00 00 00 10 00 00 10 00 00 02 06 00 00 00 0010 00 00 10 00 00 02 06 00 00 00 00 10 00 00 10 00 00 02 06 00 00 00 00 10 0000 10 00 00 02 06 00 00 00 00 10 00 00 10 00 00 02 06 00 00 00 00 10 00 00 1000 00 02 06 00 02 02 09 0C FF FF FF FF FF 11 23 0C FF FF FF FF 04 06 40 00 0010 00 00 10 00 00 A2 1B 7E
S:7E A0 0A 00 22 0023 03 B1 1A 03 7E
R:7E A0 0A 03 00 2200 23 51 39 E7 7E
S:7E A0 0A 00 22 0023 03 53 06 C7 7E
R:7E A0 0A 03 00 2200 23 73 29 E5 7E
4、請求時間
S:7E A0 0A 00 22 0023 03 93 0A 01 7E
R:7E A0 21 03 00 2200 23 73 28 F0 81 80 12 05 01 80 06 01 80 07 04 00 00 00 01 08 04 00 00 00 0153 3B 7E
S:7E A0 46 00 22 0023 03 10 05 C1 E6 E6 00 60 35 A1 09 06 07 60 85 74 05 08 01 01 8A 02 07 80 8B07 60 85 74 05 08 02 01 AC 0A 80 08 41 42 43 44 45 46 47 48 BE 10 04 0E 01 0000 00 06 5F 04 00 00 00 14 00 00 BD BF 7E
R:7E A0 52 03 00 2200 23 30 95 39 E6 E7 00 61 41 A1 09 06 07 60 85 74 05 08 01 01 A2 03 02 01 00A3 05 A1 03 02 01 00 88 02 07 80 89 07 60 85 74 05 08 02 01 AA 0A 80 08 41 4243 44 45 46 47 48 BE 0F 04 0D 08 00 06 5F 04 00 00 00 14 21 34 00 07 14 53 7E
S:7E A0 1B 00 22 0023 03 32 95 9F E6 E6 00 C0 01 81 00 08 00 00 01 00 00 FF 02 46 2F 7E
R:7E A0 21 03 00 2200 23 52 A3 C0 E6 E7 00 C4 01 81 00 09 0C 07 D3 06 0E 06 0E 0D 03 FF FF FF 0010 38 7E
S:7E A0 0A 00 22 0023 03 51 14 E4 7E
R:7E A0 0A 03 00 2200 23 51 39 E7 7E
S:7E A0 0A 00 22 0023 03 53 06 C7 7E
R:7E A0 0A 03 00 2200 23 73 29 E5 7E
?????? 本文到這里就結束了。徹底理解DLMS協議是一個大的系統工程。這個協議的制定,又很多地方時面向通用性的。為實現通用性,其實協議中的很多地方不必那么復雜的地方,顯得很復雜。同時這個協議又涉及到了許多別的標準,在看本文時最好同時參照本文的參考文獻,將有助于理解本文。
補充一:對于SNReferencing的解釋
???????When SN referencing is used, the attributes and methodsof each interface object are mapped to?DLMS named variables. This isdone during the design of the meter.Each named variable is identified with a?short name, which is a 16 bitunsigned integer.Attribute 1, the logical name of the object is mapped to aDLMS named variable identified by a?base name. Except in the case of afew special objects, there are no general rules defined for assigning base names.All other attributes and methods of the object are then also mapped to DLMSnamed variables. The offsets between the base name and the short nameidentifying the other attributes and methods are defined in the definition ofeach interface class. The actual values of the short names thus depend on thenumber and kind of objects instantiated and the mapping strategy used. The basenames allocated in the metering equipment can be retrieved by reading theobject_list attribute of the SN Association object. When SN referencing is used,the DLMS named variables are accessed by the standard DLMS READ and WRITE services.
???????When LN referencing is used,?attributesand methods are accessed via the logical name of the object, specifying theindex(es) of the attribute(s) and/or the method(s). Logical names are definedby OBIS. When LN referencing is used, the attributes and methods are accessedby the xDLMS GET/SET and ACTION services.
(Referencingfrom “DLMS User Association Frequently Asked Questions”)
SNReferencing 不同于LN Referencing 它使用一個整型數(WORD)即ShortName,來取代LN Referencing中的OBIS . Short Name 由廠家自定義.對于西門子D型表使用了SN . 因此只有在廠家提供SN的情況下,才可以使用SN的application-context-name 訪問表內的數據.
下面是一個SN數據請求幀的例子:
S:7E A011 03 21 32 B7 3D E6 E6 00 05 01 02 FF 08 A0 E0 7E
7E A0 1103 21 32 B7 3D E6 E6 00
05//SN application-context-name ?ReadRequest
01 02 FF08 //short name and attribute ???
A0 E0 7E
補充二:?? 目前DLMS規約中用到的CLASS ID 和OBIS? ??
數據名稱 | CLASS ID | OBIS | ATTRIBUTE |
時鐘 | 00 08 | 00 00 01 00 00 ff | 02 00 |
正想有功(總) | 00 03 | 01 01 01 08 00 ff | 02 00 |
正想有功(費率一) | 00 04 | 01 01 01 08 01 ff | 02 00 |
正想有功(費率二) | 00 04 | 01 01 01 08 02 ff | 02 00 |
正想有功(費率三) | 00 04 | 01 01 01 08 03 ff | 02 00 |
正想有功(費率四) | 00 04 | 01 01 01 08 04 ff | 02 00 |
反想有功(總) | 00 03 | 01 01 02 08 00 ff | 02 00 |
反想有功(費率一) | 00 04 | 01 01 02 08 01 ff | 02 00 |
反想有功(費率二) | 00 04 | 01 01 02 08 02 ff | 02 00 |
反想有功(費率三) | 00 04 | 01 01 02 08 03 ff | 02 00 |
反想有功(費率四) | 00 04 | 01 01 02 08 04 ff | 02 00 |
有功功率(總) | 00 03 | 01 01 01 07 00 ff | 02 00 |
無功功率(總) | 00 03 | 01 01 02 07 00 ff | 02 00 |
L1電壓 | 00 03 | 01 01 1f 07 00 ff | 02 00 |
L2電壓 | 00 03 | 01 01 33 07 00 ff | 02 00 |
L3電壓 | 00 03 | 01 01 47 07 00 ff | 02 00 |
L1電流 | 00 03 | 01 01 20 07 00 ff | 02 00 |
L2電流 | 00 03 | 01 01 34 07 00 ff | 02 00 |
L3電流 | 00 03 | 01 01 48 07 00 ff | 02 00 |
- 1.
DLMS協議族概述
-
協議族結構:DLMS協議族分為三層:物理層、鏈路層和應用層。通訊雙方采用Client-Server結構,Client為采集器,Server為電表。原文
-
通訊過程:包括建立物理層連接、鏈路層連接、應用層連接、數據通訊、數據通訊結束、解除物理層連接。原文
-
- 2.
DLMS物理層協議原文
-
物理層功能:負責數據通訊的物理傳輸,支持多種物理介質(PSTN、網絡、串行通道等)。原文
-
服務:如打開端口、初始化端口、收發數據、關閉端口等。原文
-
- 3.
DLMS鏈路層協議原文
-
HDLC協議:鏈路層使用HDLC高速鏈路控制協議,由LLC子層和MAC子層構成。原文
-
LLC子層:負責數據轉發,不處理數據。原文
-
MAC子層:負責數據傳輸的可靠性,包括地址檢查、數據CRC校驗、長數據幀的打包拆包等。原文
-
- 4.
DLMS應用層協議原文
-
ASN.1語法:用于描述應用層數據幀,具有高抽象性和通用性。原文
-
BER編碼與AXDR編碼:用于實現ASN.1語法,AARQ與AARE數據幀用于配置應用層數據通訊參數。原文
-
AARQ與AARE數據幀:AARQ用于建立應用層連接,AARE用于響應連接請求。原文
-
- 5.
數據請求與響應
-
數據請求幀:如GET-Request、SET-Request、Event-Notification-Request等。原文
-
數據響應幀:如GET-Response、SET-Response、Event-Notification-Response等。原文
-
- 6.
數據幀解析實例原文
-
請求電量:示例數據幀包括S和R的發送與接收。原文
-
請求瞬時量:示例數據幀包括S和R的發送與接收。
-
請求負荷曲線:示例數據幀包括S和R的發送與接收。
-
請求時間:示例數據幀包括S和R的發送與接收。
-
- 7.
SNReferencing與LNReferencing
-
SNReferencing:使用短名稱(ShortName)代替OBIS,由廠家自定義。原文
-
LNReferencing:通過邏輯名稱訪問對象的屬性和方法,定義在OBIS中。原文
-
- 8.
CLASS ID與OBIS
-
CLASS ID:用于標識數據類型。原文
-
OBIS:用于唯一標識數據類型,定義在COSEM中。原文
-
通過以上內容,讀者可以全面了解DLMS協議族及其在電能量數據采集終端中的應用。