DLMS电能表通讯协议心得与个人理解

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

DLMS电能表通讯协议⼼得与个⼈理解
先做下⾃我介绍,本⼈从事海外电表好⼏年了但是对DLMS协议的理解还是有所⽋缺,⼀直在不断的⾃学,公司也是把其作为核⼼秘密保护。

通过这⼏年的⾃我学习终于有对这个协议不太陌⽣,但是因为⼯作上这个已经被封装成库函数,具体的细节还是会存在不理解的。

希望可以帮助那些在海上还没有找到灯塔的帆船。

⾸先感谢DLMS电能表通讯协议的第⼀版作者,也希望我这个补充可以起到⼀块砖的作⽤,我主要是通过本地485数据帧的分析来帮助我们理解这个协议。

如果第⼀遍看不懂请多看⼏遍!
建⽴和释放应⽤连接:
为建⽴和释放应⽤连接提供的服务如下:
COSEM-OPEN
COSEM-RELEASE
COSEM-ABORT//底层连接已断开的情况下通知上层进程
对于本地通信信道,如RS485、红外等,当物理连接建⽴时,默认预连接的通道即存在,不需要额外的建⽴以及预连接管理。

举例上位机发送⼀个SNRM数据帧控制码93
具体数据:
SEND:7E A0 0A 00 02 40 01 25 93 4C B6 7E
解析:
在SNRM数据帧中的⽤户信息可以不出现,表⽰client接收server端的已配置数据"Start Flag" value="7E" length="1"
"Frame Flag" value="A00A" length="2"
"Type" value="3"
"Frame Length" value="10"
"DEST" value="00024001" length="4"
"UMAC" value="1"
"LMAC" value="4096"
"SRC" value="25" length="1"
"UMAC" value="18"
"LMAC" value="false"
"CTRL" value="93" length="1"
"HCS" value="4CB6" length="2"
"EF" value="7E" length="1"
RECEIVE:接受
7E A0 23 25 00 02 40 01 73 AF C3 81 80 14 05 02 01 2F 06 02 01 2F 07 04 00 00 00 01 08 04 00 00 00 01 75 0C 7E 解析:
控制码73 UA对SNRM的回应。

"Start Flag" value="7E" length="1"
"Frame Flag" value="A023" length="2"
"Type" value="3"
"Segmentation" value="false"
"Frame Length" value="35"
"DEST" value="25" length="1"
"UMAC" value="18"
"LMAC" value="false"
"SRC" value="00024001" length="4
"UMAC" value="1"
"LMAC" value="4096"
"CTRL" value="73" length="1"
"HCS" value="AFC3" length="2"
"INFO" value="8180140502012F0602012F070400000001080400000001" length="23" "Type" value="UA Frame" "Server WindowSize" value="1"
"Client WindowSize" value="1"
"Server MaxInfoLen" value="303"//⽤户数据信息最⼤长度
"Client MaxInfoLen" value="303"
"FCS" value="750C" length="2"
"EF" value="7E" length="1"
UA数据帧所包含的链路参数:
Window_size 通讯的双⽅⼀次发送数据帧的数⽬。

(默认值为1)
Maximun_infomation_field_length 链路数据帧中⽤户数据的最⼤长度。

(默认值为128)
/////////////////////////////////////////////////////////////////////////////////
Application Associations (AAs) 在服务器中预先设置:
应⽤环境,认证机制, xDLMS环境, 访问权限, 安全环境
为了能够访问数据,必须适当地认证客户机。

AA建⽴时,客户机和服务器之间的认证环境被商定。

这规定了各对等层所要求的认证,以及为了验证该认证所需要的安全算法。

提供了三种数据访问安全级别:
Lowest level security (no security);
Low Level Security (LLS);
High Level Security (HLS).
最低级别的安全性(⽆安全);
低级别安全(LLS的);
⾼级别安全(HLS)
下⾯我们拿LLS举例。

⾼级别的希望有⼈可以在后⾯补充。

LLS的⽬的是为了采⽤验证所提供的⼝令来允许客户机的认证。

服务器没有认证。

当通讯通道提供⾜够安全性,能防⽌窃听和消息(⼝令)重放,通常使⽤本认
证环境。

在AA建⽴过程中,客户机必须提供正确的⼝令。

如果⼝令正确,AA被
建⽴且客户端能够访问给定AA中有效访问权限内的数据。

否则,AA不会被建⽴。

具体数据:AARQ
SEND:7E A0 47 00 02 40 01 25 10 96 E9 E6 E6 00 60 36 A1 09 06 07 60 85 74 05 08 01 01 8A 02 07 80 8B 07 60 85 74 05 08 02 01 AC 0A 80 08 31 32 33 34 35 36 37 38 BE 10 04 0E 01 00 00 00 06 5F 1F 04 00 FF FF FF FF FF AD 1A 7E
⼀个BER数据标识和⼀个BER数据长度构成⼀个16位的位串:
Universal (00)
Application (01)
Context-specific (10)
Private (11)
2)Datatype字段:⽤于描述数据内容的结构
Primitive (0) 简单类型
Constructed (1) 复合类型(数组或结构)
3)data length字段:⽤于描述数据内容的长度(以字节为单位)。

被标记为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 都是不能被省略的。

如果省略这些项,则请求数据将被拒绝。

////
7E
A0 47
00 02
40 01
25
10
96 E9
E6 E6 00
60 //AARQ
36//LEN
A1 //tar
09 //len
06 //Context_name 数据类型
07 len
//应⽤语境名按照OBJECT IDENTIFIER ASN.1规定,COSEM采⽤下列对象标识码值来标识应⽤语境名:
60 85 74 05 08 01 01
8A // the tag for the acse-requirements field component ([10], IMPLICIT,Context-specific ) 02//len
07 //the number of unused bits in the last byte of the BIT STRING//此处不太理解下⾯有7个bit位没有,在哪⾥规定这么个⽤法
80 //⾼位是BIT0encoding of the authentication functional
8B //mechanism-name:⽤于指明使⽤何种Authentication。

共有4种。

07 //len
60 85 74 05 08 02 01 //
具体内容为
AC//the tag for the mechanism-name component ([12], Context-specific)
0A//Len
80 ///the choice for Authentication-information (charstring [0] IMPLICIT GraphicString)
08 //len
31 32 33 34 35 36 37 38//密码
BE //user information(x-DLMS context)
10 //Len (according to bytes)
04//
0E
01 //the tag (explicit tag) of the DLMS PDU CHOICE
//--dedicated-key
00 //usage flag for the dedicated-key component (FALSE, not present)
//--response-allowed
00 //usage flag for the response-allowed component (FALSE, default value conveyed)
//--proposed-quality-of-service
00 //usage flag for the proposed-quality-of-service component (FALSE, not present)
//--proposed-quality-of-service
06 //the A-XDR encoding of an Unsigned8 is its value
5F 1F //不理解明明下⾯有写⽤5f
ASN.1语法描述:(这⼀数据帧是AARQ数据帧的⼀部分)
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
}
AXDR编码:
01--------------------------------------------------------dlms puu标识
00 ----------------------------------//usage flag for the dedicated-key component (FALSE, not present) 00--------------- //usage flag for the response-allowed component (FALSE, default value conveyed) 00-------------- //usage flag for the proposed-quality-of-service component (FALSE, not present) 06-------------- //the A-XDR encoding of an Unsigned8 is its value
5f ----------//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 of the BITSTRING
00 00 10------- // encoding of the fixed length bitstring value.(LN/SN)
00 80 //client-max-receive-pdu-size(128 bytes)
*/
04 //encoding the length of the 'contents' field inoctet (4)
00 //encoding of the number of unused bits in the final octet of the BITSTRING
FF FF FF //24bit
FF FF//client-max-receive-pdu-size整个帧长
AD 1A//cs
7E
//aare地址变动了⼀下
R:7E A0 37 25 03 30 0D 1F E6 E7 00 61 29 A1 09 06 07 60 85 74 05 08 01 01 A2 03 02 01 00 A3 05 A1 03 02 01 00 BE 10 04 0E 08 00 06 5F 1F 04 00 00 1A 1D 02 00 00 07 D6 FD 7E
AARE数据帧的语法描述:
AARE-apdu ::= [APPLICATION 1] IMPLICIT SEQUENCE
――[APPLICATION 1] == [ 61H ] = [ 97 ]
{
protocol-version [0] IMPLICIT BIT STRING {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 present if only the kernel is used.
responder-acse-requirements [8] IMPLICIT ACSE-requirements OPTIONAL,
-- The following field shall only be present if the authentication functional unit is selected. mechanism-name [9] IMPLICIT mechanism-name OPTIONAL,
-- The following field shall only be present if the authentication functional unit is selected. responding-authentication-value [10] EXPLICIT authentication-value OPTIONAL, implementation-information [29] IMPLICIT implementation-data OPTIONAL, user-information [30] IMPLICIT association-information OPTIONAL
}
解析:
7E A0 37 25 03 30 0D 1F E6 E7 00
61 //taraare
29 //len
A1 //[1] Application-context-name,
09//len
06 //数据类型
07 //len
60 85 74 05 08 01 01
A2 //tar[2] Association-result,
03 //len
02 //type = structure
01
00
/*( 2)响应结果部分:⽤来描述服务器对客户机请求建⽴连接的结果:接受
连接请求或拒绝连接请求
Association-result ::= INTEGER
{
accepted (0),
rejected-permanent (1),
rejected-transient (2)
}
*/
A3 //tar[3] Associate-source-diagnostic,Server端拒绝Client端的连接请求,在这⾥给出原因05 //len
A1 //
03 02 01 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 the result-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.
*/
/*我们公司把88 02 07 80
89 07 60 05 08 02 01
AA 0A 80 08 31 32 33 ………
查找了下绿⽪书发现是可以省略的对于成功的LLS密码等级
*/
BE//taruser information (x-DLMS context)下⾯就是服务器的返回描述服务器⽀持的通信环境10 04 0E 08 00 06 5F 1F
04 00 00 1A 1D
02 00
00 07
D6 FD 7E
后⾯还有对每⼀类的实例讲解分析有兴趣的可以加我微信150********,我会把⼤家拉到⼀个群⾥讨论。

相关文档
最新文档