GB/T 32960 协议网关

协议介绍

emqx-gbt32960 做为 emqx 的接入网关,按照其功能逻辑和整个系统的关系,将整个消息交换的过程可以分成三个部分:终端侧,平台侧和其它侧:

  1. |<-- Terminal -->|<----------- Broker Side ---------->|<--- Others --->|
  2. |<- Side ->| |<-- Side -->|
  3. +---+ PUB +-----------+
  4. | D | INCOMING +-------------+ PUB +---------+ -->| subscriber|
  5. | E |----------->| |----------->| |--/ +-----------+
  6. | V | |emqx-gbt32960| | EMQX |
  7. | I |<-----------| |<-----------| |<-- +-----------+
  8. | C | OUTGOING +-------------+ PUB +---------+ \--| publisher |
  9. | E | PUB +-----------+
  10. +---+
  1. 终端侧:通过 GB/T 32960 协议进行交换数据,实现不同类型的数据的上报,或者发送下行的消息到终端。
  2. 平台侧:emqx-gbt32960 将报文解码后执行 注册/鉴权、或将数据报文 PUBLISH 到特定的主题上;代理订阅下行主题,将下行的 PUBLISH 消息转化为 GB/T 32960 协议的报文结构,下发到终端。
  3. 其它侧,可以对 2 中出现的上行的 PUBLISH 消息的主题进行订阅,以接收上行消息。或对发布消息到具体的下行的主题,以发送数据到终端侧。

创建模块

打开 EMQX DashboardGB/T32960 网关 - 图1 (opens new window),点击左侧的 “模块” 选项卡,选择添加:

image-20200927213049265

选择 GB/T 32960 协议接入网关:

image-20200927213049265

配置相关基础参数:

image-20200927213049265

添加监听端口:

image-20200927213049265

配置监听参数:

image-20200927213049265

点击确认到配置参数页面:

image-20200927213049265

点击添加后,模块添加完成: image-20200927213049265

配置参数

配置项说明
允许最大报文长度最大处理的单个GB/T32960协议报文大小
重传间隔时间消息重传间隔时间
最大重传次数最大的消息重传次数
消息队列长度最大的消息缓存队列长度

约定:

  • Payload 采用 Json 格式进行组装
  • Json Key 采用大驼峰格式命名

数据上报流程

数据流向: Terminal -> emqx_gbt32960 -> EMQX

车辆登入

Topic: gbt32960/${vin}/upstream/vlogin

  1. {
  2. "Cmd": 1,
  3. "Encrypt": 1,
  4. "Vin": "1G1BL52P7TR115520",
  5. "Data": {
  6. "ICCID": "12345678901234567890",
  7. "Id": "C",
  8. "Length": 1,
  9. "Num": 1,
  10. "Seq": 1,
  11. "Time": {
  12. "Day": 29,
  13. "Hour": 12,
  14. "Minute": 19,
  15. "Month": 12,
  16. "Second": 20,
  17. "Year": 12
  18. }
  19. }
  20. }

车辆登出

Topic: gbt32960/${vin}/upstream/vlogout

  1. {
  2. "Cmd": 4,
  3. "Encrypt": 1,
  4. "Vin": "1G1BL52P7TR115520",
  5. "Data": {
  6. "Seq": 1,
  7. "Time": {
  8. "Day": 1,
  9. "Hour": 2,
  10. "Minute": 59,
  11. "Month": 1,
  12. "Second": 0,
  13. "Year": 16
  14. }
  15. }
  16. }

信息上报

Topic: gbt32960/${vin}/upstream/info

不同信息类型上报,格式上只有 Infos 里面的对象属性不同,通过 Type 进行区分 Infos 为数组,代表车载终端每次报文可以上报多个信息

整车数据

  1. {
  2. "Cmd": 2,
  3. "Encrypt": 1,
  4. "Vin": "1G1BL52P7TR115520",
  5. "Data": {
  6. "Infos": [
  7. {
  8. "AcceleratorPedal": 90,
  9. "BrakePedal": 0,
  10. "Charging": 1,
  11. "Current": 15000,
  12. "DC": 1,
  13. "Gear": 5,
  14. "Mileage": 999999,
  15. "Mode": 1,
  16. "Resistance": 6000,
  17. "SOC": 50,
  18. "Speed": 2000,
  19. "Status": 1,
  20. "Type": "Vehicle",
  21. "Voltage": 5000
  22. }
  23. ],
  24. "Time": {
  25. "Day": 1,
  26. "Hour": 2,
  27. "Minute": 59,
  28. "Month": 1,
  29. "Second": 0,
  30. "Year": 16
  31. }
  32. }
  33. }

驱动电机数据

  1. {
  2. "Cmd": 2,
  3. "Encrypt": 1,
  4. "Vin": "1G1BL52P7TR115520",
  5. "Data": {
  6. "Infos": [
  7. {
  8. "Motors": [
  9. {
  10. "CtrlTemp": 125,
  11. "DCBusCurrent": 31203,
  12. "InputVoltage": 30012,
  13. "MotorTemp": 125,
  14. "No": 1,
  15. "Rotating": 30000,
  16. "Status": 1,
  17. "Torque": 25000
  18. },
  19. {
  20. "CtrlTemp": 125,
  21. "DCBusCurrent": 30200,
  22. "InputVoltage": 32000,
  23. "MotorTemp": 145,
  24. "No": 2,
  25. "Rotating": 30200,
  26. "Status": 1,
  27. "Torque": 25300
  28. }
  29. ],
  30. "Number": 2,
  31. "Type": "DriveMotor"
  32. }
  33. ],
  34. "Time": {
  35. "Day": 1,
  36. "Hour": 2,
  37. "Minute": 59,
  38. "Month": 1,
  39. "Second": 0,
  40. "Year": 16
  41. }
  42. }
  43. }

燃料电池数据

  1. {
  2. "Cmd": 2,
  3. "Encrypt": 1,
  4. "Vin": "1G1BL52P7TR115520",
  5. "Data": {
  6. "Infos": [
  7. {
  8. "CellCurrent": 12000,
  9. "CellVoltage": 10000,
  10. "DCStatus": 1,
  11. "FuelConsumption": 45000,
  12. "H_ConcSensorCode": 11,
  13. "H_MaxConc": 35000,
  14. "H_MaxPress": 500,
  15. "H_MaxTemp": 12500,
  16. "H_PressSensorCode": 12,
  17. "H_TempProbeCode": 10,
  18. "ProbeNum": 2,
  19. "ProbeTemps": [120, 121],
  20. "Type": "FuelCell"
  21. }
  22. ],
  23. "Time": {
  24. "Day": 1,
  25. "Hour": 2,
  26. "Minute": 59,
  27. "Month": 1,
  28. "Second": 0,
  29. "Year": 16
  30. }
  31. }
  32. }

发动机数据

  1. {
  2. "Cmd": 2,
  3. "Encrypt": 1,
  4. "Vin": "1G1BL52P7TR115520",
  5. "Data": {
  6. "Infos": [
  7. {
  8. "CrankshaftSpeed": 2000,
  9. "FuelConsumption": 200,
  10. "Status": 1,
  11. "Type": "Engine"
  12. }
  13. ],
  14. "Time": {
  15. "Day": 1,
  16. "Hour": 22,
  17. "Minute": 59,
  18. "Month": 10,
  19. "Second": 0,
  20. "Year": 16
  21. }
  22. }
  23. }

车辆位置数据

  1. {
  2. "Cmd": 2,
  3. "Encrypt": 1,
  4. "Vin": "1G1BL52P7TR115520",
  5. "Data": {
  6. "Infos": [
  7. {
  8. "Latitude": 100,
  9. "Longitude": 10,
  10. "Status": 0,
  11. "Type": "Location"
  12. }
  13. ],
  14. "Time": {
  15. "Day": 1,
  16. "Hour": 22,
  17. "Minute": 59,
  18. "Month": 10,
  19. "Second": 0,
  20. "Year": 16
  21. }
  22. }
  23. }

极值数据

  1. {
  2. "Cmd": 2,
  3. "Encrypt": 1,
  4. "Vin": "1G1BL52P7TR115520",
  5. "Data": {
  6. "Infos": [
  7. {
  8. "MaxBatteryVoltage": 7500,
  9. "MaxTemp": 120,
  10. "MaxTempProbeNo": 12,
  11. "MaxTempSubsysNo": 14,
  12. "MaxVoltageBatteryCode": 10,
  13. "MaxVoltageBatterySubsysNo": 12,
  14. "MinBatteryVoltage": 2000,
  15. "MinTemp": 40,
  16. "MinTempProbeNo": 13,
  17. "MinTempSubsysNo": 15,
  18. "MinVoltageBatteryCode": 11,
  19. "MinVoltageBatterySubsysNo": 13,
  20. "Type": "Extreme"
  21. }
  22. ],
  23. "Time": {
  24. "Day": 30,
  25. "Hour": 12,
  26. "Minute": 22,
  27. "Month": 5,
  28. "Second": 59,
  29. "Year": 17
  30. }
  31. }
  32. }

报警数据

  1. {
  2. "Cmd": 2,
  3. "Encrypt": 1,
  4. "Vin": "1G1BL52P7TR115520",
  5. "Data": {
  6. "Infos": [
  7. {
  8. "FaultChargeableDeviceNum": 1,
  9. "FaultChargeableDeviceList": ["00C8"],
  10. "FaultDriveMotorNum": 0,
  11. "FaultDriveMotorList": [],
  12. "FaultEngineNum": 1,
  13. "FaultEngineList": ["006F"],
  14. "FaultOthersNum": 0,
  15. "FaultOthersList": [],
  16. "GeneralAlarmFlag": 3,
  17. "MaxAlarmLevel": 1,
  18. "Type": "Alarm"
  19. }
  20. ],
  21. "Time": {
  22. "Day": 20,
  23. "Hour": 22,
  24. "Minute": 23,
  25. "Month": 12,
  26. "Second": 59,
  27. "Year": 17
  28. }
  29. }
  30. }

可充电储能装置电压数据

  1. {
  2. "Cmd": 2,
  3. "Encrypt": 1,
  4. "Vin": "1G1BL52P7TR115520",
  5. "Data": {
  6. "Infos": [
  7. {
  8. "Number": 2,
  9. "SubSystems": [
  10. {
  11. "CellsTotal": 2,
  12. "CellsVoltage": [5000],
  13. "ChargeableCurrent": 10000,
  14. "ChargeableSubsysNo": 1,
  15. "ChargeableVoltage": 5000,
  16. "FrameCellsCount": 1,
  17. "FrameCellsIndex": 0
  18. },
  19. {
  20. "CellsTotal": 2,
  21. "CellsVoltage": [5001],
  22. "ChargeableCurrent": 10001,
  23. "ChargeableSubsysNo": 2,
  24. "ChargeableVoltage": 5001,
  25. "FrameCellsCount": 1,
  26. "FrameCellsIndex": 1
  27. }
  28. ],
  29. "Type": "ChargeableVoltage"
  30. }
  31. ],
  32. "Time": {
  33. "Day": 1,
  34. "Hour": 22,
  35. "Minute": 59,
  36. "Month": 10,
  37. "Second": 0,
  38. "Year": 16
  39. }
  40. }
  41. }

可充电储能装置温度数据

  1. {
  2. "Cmd": 2,
  3. "Encrypt": 1,
  4. "Vin": "1G1BL52P7TR115520",
  5. "Data": {
  6. "Infos": [
  7. {
  8. "Number": 2,
  9. "SubSystems": [
  10. {
  11. "ChargeableSubsysNo": 1,
  12. "ProbeNum": 10,
  13. "ProbesTemp": [0, 0, 0, 0, 0, 0, 0, 0, 19, 136]
  14. },
  15. {
  16. "ChargeableSubsysNo": 2,
  17. "ProbeNum": 1,
  18. "ProbesTemp": [100]
  19. }
  20. ],
  21. "Type": "ChargeableTemp"
  22. }
  23. ],
  24. "Time": {
  25. "Day": 1,
  26. "Hour": 22,
  27. "Minute": 59,
  28. "Month": 10,
  29. "Second": 0,
  30. "Year": 16
  31. }
  32. }
  33. }

数据补发

Topic: gbt32960/${vin}/upstream/reinfo

数据格式: 略 (与实时数据上报相同)

数据下发流程

请求数据流向: EMQX -> emqx_gbt32960 -> Terminal

应答数据流向: Terminal -> emqx_gbt32960 -> EMQX

下行主题: gbt32960/${vin}/dnstream 上行应答主题: gbt32960/${vin}/upstream/response

参数查询

Req:

  1. {
  2. "Action": "Query",
  3. "Total": 2,
  4. "Ids": ["0x01", "0x02"]
  5. }

Response:

  1. {
  2. "Cmd": 128,
  3. "Encrypt": 1,
  4. "Vin": "1G1BL52P7TR115520",
  5. "Data": {
  6. "Total": 2,
  7. "Params": [
  8. {"0x01": 6000},
  9. {"0x02": 10}
  10. ],
  11. "Time": {
  12. "Day": 2,
  13. "Hour": 11,
  14. "Minute": 12,
  15. "Month": 2,
  16. "Second": 12,
  17. "Year": 17
  18. }
  19. }
  20. }

参数设置

Req:

  1. {
  2. "Action": "Setting",
  3. "Total": 2,
  4. "Params": [{"0x01": 5000},
  5. {"0x02": 200}]
  6. }

Response:

  1. // fixme? 终端是按照这种方式返回?
  2. {
  3. "Cmd": 129,
  4. "Encrypt": 1,
  5. "Vin": "1G1BL52P7TR115520",
  6. "Data": {
  7. "Total": 2,
  8. "Params": [
  9. {"0x01": 5000},
  10. {"0x02": 200}
  11. ],
  12. "Time": {
  13. "Day": 2,
  14. "Hour": 11,
  15. "Minute": 12,
  16. "Month": 2,
  17. "Second": 12,
  18. "Year": 17
  19. }
  20. }
  21. }

终端控制

命令的不同, 参数不同; 无参数时为空

远程升级: Req:

  1. {
  2. "Action": "Control",
  3. "Command": "0x01",
  4. "Param": {
  5. "DialingName": "hz203",
  6. "Username": "user001",
  7. "Password": "password01",
  8. "Ip": "192.168.199.1",
  9. "Port": 8080,
  10. "ManufacturerId": "BMWA",
  11. "HardwareVer": "1.0.0",
  12. "SoftwareVer": "1.0.0",
  13. "UpgradeUrl": "ftp://emqtt.io/ftp/server",
  14. "Timeout": 10
  15. }
  16. }

车载终端关机:

  1. {
  2. "Action": "Control",
  3. "Command": "0x02"
  4. }

车载终端报警:

  1. {
  2. "Action": "Control",
  3. "Command": "0x06",
  4. "Param": {"Level": 0, "Message": "alarm message"}
  5. }