eps_dissector.lua 6.4 KB

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