eps_dissector.lua 6.8 KB

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