eps_dissector.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. -- Define the dissector function
  2. function dissect_power_system_data(buffer, pinfo, tree,HM_TM_dissector, offset, len,data3)
  3. -- Define ProtoFields for each field in the structure
  4. local f_pv_cnt = ProtoField.uint8("PowerSystemData.pv_cnt", "PV Count", base.DES)
  5. local f_mppt_cnt = ProtoField.uint8("PowerSystemData.mppt_cnt", "MPPT Count", base.DES)
  6. local f_op_conv_cnt = ProtoField.uint8("PowerSystemData.op_conv_cnt", "Operating Converter Count", base.DES)
  7. local f_btry_cnt = ProtoField.uint8("PowerSystemData.btry_cnt", "Battery Count", base.DES)
  8. local f_btry_temp_sns_cnt = ProtoField.uint8("PowerSystemData.btry_temp_sns_cnt", "Battery Temperature Sensor Count", base.DES)
  9. local f_chnl_cnt = ProtoField.uint8("PowerSystemData.chnl_cnt", "Channel Count", base.DES)
  10. local f_volt_rail_cnt = ProtoField.uint8("PowerSystemData.volt_rail_cnt", "Voltage Rail Count", base.DES)
  11. local f_tot_btry_volt_rd = ProtoField.uint16("PowerSystemData.tot_btry_volt_rd", "Total Battery Voltage", base.DES)
  12. local f_tot_btry_cur_rd = ProtoField.uint16("PowerSystemData.tot_btry_cur_rd", "Total Battery Current", base.DES)
  13. local f_hrm_btry_mode_info = ProtoField.uint8("PowerSystemData.hrm_btry_mode_info", "Harmonic Battery Mode Info", base.DES)
  14. -- Fields for arrays (treated as ProtoFields with array index)
  15. local f_pv_volt_rd = ProtoField.uint16("PowerSystemData.pv_volt_rd", "PV Voltage Reading", base.DES)
  16. local f_pv_cur_rd = ProtoField.uint16("PowerSystemData.pv_cur_rd", "PV Current Reading", base.DES)
  17. local f_mppt_volt_rd = ProtoField.uint16("PowerSystemData.mppt_volt_rd", "MPPT Voltage Reading", base.DES)
  18. local f_mppt_cur_rd = ProtoField.uint16("PowerSystemData.mppt_cur_rd", "MPPT Current Reading", base.DES)
  19. local f_op_conv_volt_rd = ProtoField.uint16("PowerSystemData.op_conv_volt_rd", "Operating Converter Voltage", base.DES)
  20. local f_btry_temp_sns_rd = ProtoField.uint8("PowerSystemData.btry_temp_sns_rd", "Battery Temperature Sensor Readings", base.DES)
  21. local f_chnl_state = ProtoField.uint8("PowerSystemData.chnl_state", "Channel State", base.DES)
  22. local f_volt_rail_cur_value = ProtoField.uint8("PowerSystemData.volt_rail_cur_value", "Voltage Rail Current Value", base.DES)
  23. local f_chnl_ovr_cur_flg = ProtoField.uint8("PowerSystemData.chnl_ovr_cur_flg", "Channel Over Current Flag", base.DES)
  24. -- Add the fields to the protocol
  25. HM_TM_dissector.fields = { f_pv_cnt, f_mppt_cnt, f_op_conv_cnt, f_btry_cnt, f_btry_temp_sns_cnt, f_chnl_cnt,
  26. f_volt_rail_cnt, f_tot_btry_volt_rd, f_tot_btry_cur_rd, f_hrm_btry_mode_info,
  27. f_pv_volt_rd, f_pv_cur_rd, f_mppt_volt_rd, f_mppt_cur_rd, f_op_conv_volt_rd,
  28. f_btry_temp_sns_rd, f_chnl_state, f_volt_rail_cur_value, f_chnl_ovr_cur_flg
  29. }
  30. for i=1,data3 do
  31. offset = offset+8
  32. local subtree = tree:add(TC_TM_PROTOCOL, buffer(), "Power System Data")
  33. -- dissect pv_cnt
  34. local pv_cnt = buffer(offset, 1):le_uint()
  35. subtree:add(f_pv_cnt, pv_cnt)
  36. offset = offset + 1
  37. -- dissect mppt_cnt
  38. local mppt_cnt = buffer(offset, 1):le_uint()
  39. subtree:add(f_mppt_cnt, mppt_cnt)
  40. offset = offset + 1
  41. -- dissect op_conv_cnt
  42. local op_conv_cnt = buffer(offset, 1):le_uint()
  43. subtree:add(f_op_conv_cnt, op_conv_cnt)
  44. offset = offset + 1
  45. -- dissect btry_cnt
  46. local btry_cnt = buffer(offset, 1):le_uint()
  47. subtree:add(f_btry_cnt, btry_cnt)
  48. offset = offset + 1
  49. -- dissect btry_temp_sns_cnt
  50. local btry_temp_sns_cnt = buffer(offset, 1):le_uint()
  51. subtree:add(f_btry_temp_sns_cnt, btry_temp_sns_cnt)
  52. offset = offset + 1
  53. -- dissect chnl_cnt
  54. local chnl_cnt = buffer(offset, 1):le_uint()
  55. subtree:add(f_chnl_cnt, chnl_cnt)
  56. offset = offset + 1
  57. -- dissect volt_rail_cnt
  58. local volt_rail_cnt = buffer(offset, 1):le_uint()
  59. subtree:add(f_volt_rail_cnt, volt_rail_cnt)
  60. offset = offset + 1
  61. ------------------------------------------------------------------------------------------------------------
  62. for i=1, pv_cnt do
  63. -- dissect pv_volt_rd
  64. --local pv_volt = string.unpack("<d", buffer(offset, 2):le_uint())
  65. local pv_volt = buffer(offset, 2):le_uint()
  66. subtree:add(f_pv_volt_rd, pv_volt)
  67. offset = offset + 2
  68. end
  69. for i=1, pv_cnt do
  70. -- dissect pv_cur_rd
  71. local pv_cur = buffer(offset, 2):le_uint()
  72. subtree:add(f_pv_cur_rd, pv_cur)
  73. offset = offset + 2
  74. end
  75. --for i=1, mppt_cnt do
  76. -- dissect mppt_volt_rd
  77. local mppt_volt = buffer(offset, 2):le_uint()
  78. subtree:add(f_mppt_volt_rd, mppt_volt)
  79. offset = offset + 2
  80. --end
  81. --for i=1, mppt_cnt do
  82. -- dissect mppt_cur_rd
  83. local mppt_cur = buffer(offset, 2):le_uint()
  84. subtree:add(f_mppt_cur_rd, mppt_cur)
  85. offset = offset + 2
  86. --end
  87. for i=1 ,op_conv_cnt do
  88. -- dissect op_conv_volt_rd (array of uint16, loop through based on op_conv_cnt)
  89. local op_conv_volt = buffer(offset, 2):le_uint()
  90. subtree:add(f_op_conv_volt_rd, op_conv_volt)
  91. offset = offset + 2
  92. end
  93. -- dissect tot_btry_volt_rd
  94. local tot_btry_volt_rd = buffer(offset, 2):le_uint()
  95. subtree:add(f_tot_btry_volt_rd, tot_btry_volt_rd)
  96. offset = offset + 2
  97. -- dissect tot_btry_cur_rd
  98. local tot_btry_cur_rd = buffer(offset, 2):le_uint()
  99. subtree:add(f_tot_btry_cur_rd, tot_btry_cur_rd)
  100. offset = offset + 2
  101. for i=1, btry_temp_sns_cnt do
  102. -- dissect btry_temp_sns_rd (array of uint8, loop through based on btry_temp_sns_cnt)
  103. local btry_temp = buffer(offset, 1):le_uint()
  104. subtree:add(f_btry_temp_sns_rd, btry_temp)
  105. offset = offset + 1
  106. end
  107. for i=1, chnl_cnt do
  108. -- dissect chnl_state (array of uint8, loop through based on chnl_cnt)
  109. local chnl_state_value = buffer(offset, 1):le_uint()
  110. subtree:add(f_chnl_state, chnl_state_value)
  111. offset = offset + 1
  112. end
  113. for i=1, volt_rail_cnt do
  114. -- volt_rail_cur_value
  115. local volt_rail_value = buffer(offset, 2):le_uint()
  116. subtree:add(f_volt_rail_cur_value, volt_rail_value)
  117. offset = offset + 1
  118. end
  119. for i=1,volt_rail_cnt do
  120. -- dissect chnl_ovr_cur_flg (array of uint8, loop through based on chnl_cnt)
  121. local chnl_ovr_cur_flg_value = buffer(offset, 1):le_uint()
  122. subtree:add(f_chnl_ovr_cur_flg, chnl_ovr_cur_flg_value)
  123. offset = offset + 1
  124. end
  125. -- dissect hrm_btry_mode_info
  126. local hrm_btry_mode_info = buffer(offset, 1):le_uint()
  127. subtree:add(f_hrm_btry_mode_info, hrm_btry_mode_info)
  128. offset = offset + 1
  129. end
  130. end