项目中用到南向协议与北向协议开发记录
【摘要】 南向协议与北向协议 南向协议根据连接方式分类RS-485:连接线:4芯线,实际可能还需要额外直流电源仪表总线M-BUS:连接线:2芯线,无需额外直流电源Ethernet4GCat.1:DTU(Data Transfer Unit):串口数据与IP数据转换RTU(Remote Terminal Unit):比DTU增加采集和控制功能串口服务器:基于tcp、udp、http、mqtt、webs...
南向协议与北向协议
南向协议根据连接方式分类
- RS-485:
- 连接线:4芯线,实际可能还需要额外直流电源
- 仪表总线M-BUS:
- 连接线:2芯线,无需额外直流电源
- Ethernet
- 4GCat.1:
- DTU(Data Transfer Unit):串口数据与IP数据转换
- RTU(Remote Terminal Unit):比DTU增加采集和控制功能
- 串口服务器:基于tcp、udp、http、mqtt、websocket等传输层与应用层协议实现数据透传
- 红外无线
- Wi-SUN(Wireless Utility Networks):
- 基于IEEE 802.15.4标准,使用920MHz频段
- 家域网HAN(Home Area Network)
- 区域网FAN(Field Area Network)
ModbusRTU
- 数据帧:
- 地址域:1字节
- 功能码:1字节
- 数据域:
- 地址:2字节
- 数量:2字节
- CRC校验:2字节
DL/T645-2007
- 帧格式:
- 帧起始字符:68H
- 地址域:A0 A1 A2 A3 A4 A5
- 帧起始字符:68H
- 控制码:1字节
- 主站:
- 13H:请求读电能表通信地址
- 11H:请求读电能表数据
- 1CH:请求跳闸、合闸
- 从站:
- 91H:正常应答读电能表
- 9CH:正常应答跳闸、合闸
- 主站:
- 数据域长度:1字节
- 数据域:DI0 DI1 DI2 DI3
- 发送方:每字节+33H
- 接收方:每字节-33H
- 数据标识:
- 电能量
- 最大需量及发生时间
- 变量
- 事件记录
- 参变量
- 冻结量
- 负荷记录
- 密码、操作者代码、数据、帧序号
- 校验码:1字节,从第一个帧起始字符到校验码之前求Checksum校验和
- 结束符:16H
- 字节格式:
- 起始位:0
- 8位数据
- 偶校验位
- 停止位:1
- 数据标识中常用数据项:
- 00 00 00 00:(当前)组合有功总电能CurrentMixActiveEnergy
- 00 01 00 00:(当前)正向有功总电能CurrentForwardActiveEnergy
- 00 02 00 00:(当前)反向有功总电能CurrentReverseActiveEnergy
- 00 15 00 00:(当前)A相正向有功电能CurrentAForwardActiveEnergy
- 00 16 00 00:(当前)A相反向有功电能CurrentAReverseActiveEnergy
- 00 29 00 00:(当前)B相正向有功电能CurrentBForwardActiveEnergy
- 00 2A 00 00:(当前)B相反向有功电能CurrentBReverseActiveEnergy
- 00 3D 00 00:(当前)C相正向有功电能CurrentCForwardActiveEnergy
- 00 3E 00 00:(当前)C相反向有功电能CurrentCReverseActiveEnergy
- 01 01 00 00:(当前)正向有功总最大需量及发生时间CurrentForwardMaxEnergy,CurrentForwardMaxEnergyTime
- 01 02 00 00:(当前)反向有功总最大需量及发生时间CurrentReverseMaxEnergy,CurrentReverseMaxEnergyTime
- 01 15 00 00:(当前)A相正向有功最大需量及发生时间CurrentAForwardMaxEnergy,CurrentAForwardMaxEnergyTime
- 01 16 00 00:(当前)A相反向有功最大需量及发生时间CurrentAReverseMaxEnergy,CurrentAReverseMaxEnergyTime
- 01 29 00 00:(当前)B相正向有功最大需量及发生时间CurrentBForwardMaxEnergy,CurrentBForwardMaxEnergyTime
- 01 2A 00 00:(当前)B相反向有功最大需量及发生时间CurrentBReverseMaxEnergy,CurrentBReverseMaxEnergyTime
- 01 3D 00 00:(当前)C相正向有功最大需量及发生时间CurrentCForwardMaxEnergy,CurrentCForwardMaxEnergyTime
- 01 3E 00 00:(当前)C相反向有功最大需量及发生时间CurrentCReverseMaxEnergy,CurrentCReverseMaxEnergyTime
- 02 01 01 00:A相电压AVoltage
- 02 02 01 00:B相电压BVoltage
- 02 03 01 00:C相电压CVoltage
- 02 06 00 00:总功率因数TotalPowerFactor
- 02 06 01 00:A相功率因数APowerFactor
- 02 06 02 00:B相功率因数BPowerFactor
- 02 06 03 00:C相功率因数CPowerFactor
- 02 80 00 01:零线电流ZerolineAmpere
- 02 80 00 02:电网频率Frequency
- 02 80 00 07:表内温度MeterTemp
- 02 80 00 08:时钟电池电压BatteryVoltage
- 04 00 04 01:通讯地址
- 04 00 13 01:无线通信信号强弱
- 数据标识中常用数据块:
- 04 00 05 FF:电表运行状态字数据块
- 04 00 05 01:
- 04 00 05 02:
- 04 00 05 03:操作类
- 04 00 05 04:A相故障状态
- 04 00 05 05:B相故障状态
- 04 00 05 06:C相故障状态
- 04 00 05 07:合相故障状态
- 04 00 05 FF:电表运行状态字数据块
- 数据帧示例:
- 主站:
- 读仪表地址:FE FE FE FE 68 AA AA AA AA AA AA 68 13 00 DF 16
- 读(当前)正向有功总电能:FE FE FE FE 68 AA AA AA AA AA AA 68 11 04 33 33 34 33 AE 16
- 从站:
- 回复读仪表:FE FE FE FE 68 81 38 33 10 02 25 68 93 06 B4 6B 66 43 35 58 E1 16
- 回复读正向有功总电能:FE FE FE FE 68 81 38 33 10 02 25 68 91 08 33 33 34 33 33 33 33 33 25 16
- 主站:
CJ/T188-2004
- 帧格式:
- 帧起始符:68H
- 仪表类型:
- 地址域:A0 A1 A2 A3 A4 A5 A6
- 控制码:1字节
- 数据长度域:1字节
- 数据域:
- 校验码:1字节,从第一个帧起始符到校验码之前求Checksum校验和
- 结束符:16H
- 字节格式:
- 起始位:0
- 8位数据
- 偶校验位
- 停止位:1
- 读仪表地址:FE FE FE FE 68 AA AA AA AA AA AA AA AA 03 03 81 0A 00 49 16
代码实现
- 变量类型:
- 1Byte=8bit
- Char=2Byte
- Short=2Byte
- Int=4Byte
- long=8Byte
- 使用Netty中ByteBuf:
- 大端读写:writeInt、readInt
- 小端读写:writeIntLE、readIntLE
- 大小端转换:Short.reverseBytes、Integer.reverseBytes
- hex字符串转byte[]:ByteBufUtil.decodeHexDump
- byte[]转ASCII字符串:New String(byte[])
北向协议工作模式
- 长连接与短连接
- 平台主动与设备主动
Jetlinks官方协议
内部变量
- 上线:AcknowledgeDeviceMessage
- 下线:DisconnectDeviceMessage
- 更新标签:UpdateTagMessage
- 上报属性:ReportPropertyMessage
- 上报事件:EventMessage
- 读取属性:ReadPropertyMessage
- 修改属性:WritePropertyMessage
- 调用功能:FunctionInvokeMessage
Mqtt协议中topic
- 上线:
- /{productId}/{deviceId}/child/{childDeviceId}/online
- 下线:
- /{productId}/{deviceId}/child/{childDeviceId}/offline
- 更新标签:
- /{productId}/{deviceId}/tags
- 上报属性:
- /{productId}/{deviceId}/properties/report
- /{GateWayProductId}/{GatewayProductDeviceID}/child/{GatewaySubProductDeviceId}/properties/report
- 上报事件:
- /{productId}/{deviceId}/event/{eventId}
- /{productId}/{deviceId}/child/{childDeviceId}/event/{eventId}
- 读取属性:
- /{productId}/{deviceId}/properties/read
- /{productId}/{deviceId}/properties/read/reply
- /{productId}/{deviceId}/child/{childDeviceId}/properties/read
- /{productId}/{deviceId}/child-reply/{childDeviceId}/properties/read/reply
- 修改属性:
- /{productId}/{deviceId}/properties/write
- /{productId}/{deviceId}/properties/write/reply
- /{productId}/{deviceId}/child/{childDeviceId}/properties/write
- /{productId}/{deviceId}/child-reply/{childDeviceId}/properties/write/reply
- 调用功能:
- /{productId}/{deviceId}/function/invoke
- /{productId}/{deviceId}/function/invoke/reply
- /{productId}/{deviceId}/child/{childDeviceId}/function/invoke
- /{productId}/{deviceId}/child-reply/{childDeviceId}/function/invoke/reply
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)