eps_dissector.lua 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. for i=1,data3 do
  34. --offset = offset+8
  35. local subtree = tree:add(TC_TM_PROTOCOL, buffer(), "Power System Data")
  36. subtree:add(f_tim,buffer(offset,4):le_uint())
  37. offset = offset+8
  38. -- dissect pv_cnt
  39. local pv_cnt = buffer(offset, 1):le_uint()
  40. subtree:add(f_pv_cnt, pv_cnt)
  41. offset = offset + 1
  42. -- dissect mppt_cnt
  43. local mppt_cnt = buffer(offset, 1):le_uint()
  44. subtree:add(f_mppt_cnt, mppt_cnt)
  45. offset = offset + 1
  46. -- dissect op_conv_cnt
  47. local op_conv_cnt = buffer(offset, 1):le_uint()
  48. subtree:add(f_op_conv_cnt, op_conv_cnt)
  49. offset = offset + 1
  50. -- dissect btry_cnt
  51. local btry_cnt = buffer(offset, 1):le_uint()
  52. subtree:add(f_btry_cnt, btry_cnt)
  53. offset = offset + 1
  54. -- dissect btry_temp_sns_cnt
  55. local btry_temp_sns_cnt = buffer(offset, 1):le_uint()
  56. subtree:add(f_btry_temp_sns_cnt, btry_temp_sns_cnt)
  57. offset = offset + 1
  58. -- dissect chnl_cnt
  59. local chnl_cnt = buffer(offset, 1):le_uint()
  60. subtree:add(f_chnl_cnt, chnl_cnt)
  61. offset = offset + 1
  62. -- dissect volt_rail_cnt
  63. local volt_rail_cnt = buffer(offset, 1):le_uint()
  64. subtree:add(f_volt_rail_cnt, volt_rail_cnt)
  65. offset = offset + 1
  66. ------------------------------------------------------------------------------------------------------------
  67. for i=1, pv_cnt do
  68. -- dissect pv_volt_rd
  69. --local pv_volt = string.unpack("<d", buffer(offset, 2):le_uint())
  70. local pv_volt = buffer(offset, 2):le_uint()
  71. subtree:add(f_pv_volt_rd, pv_volt)
  72. offset = offset + 2
  73. end
  74. for i=1, pv_cnt do
  75. -- dissect pv_cur_rd
  76. local pv_cur = buffer(offset, 2):le_uint()
  77. subtree:add(f_pv_cur_rd, pv_cur)
  78. offset = offset + 2
  79. end
  80. --for i=1, mppt_cnt do
  81. -- dissect mppt_volt_rd
  82. local mppt_volt = buffer(offset, 2):le_uint()
  83. subtree:add(f_mppt_volt_rd, mppt_volt)
  84. offset = offset + 2
  85. --end
  86. --for i=1, mppt_cnt do
  87. -- dissect mppt_cur_rd
  88. local mppt_cur = buffer(offset, 2):le_uint()
  89. subtree:add(f_mppt_cur_rd, mppt_cur)
  90. offset = offset + 2
  91. --end
  92. for i=1 ,op_conv_cnt do
  93. -- dissect op_conv_volt_rd (array of uint16, loop through based on op_conv_cnt)
  94. local op_conv_volt = buffer(offset, 2):le_uint()
  95. subtree:add(f_op_conv_volt_rd, op_conv_volt)
  96. offset = offset + 2
  97. end
  98. -- dissect tot_btry_volt_rd
  99. local tot_btry_volt_rd = buffer(offset, 2):le_uint()
  100. subtree:add(f_tot_btry_volt_rd, tot_btry_volt_rd)
  101. offset = offset + 2
  102. -- dissect tot_btry_cur_rd
  103. local tot_btry_cur_rd = buffer(offset, 2):le_uint()
  104. subtree:add(f_tot_btry_cur_rd, tot_btry_cur_rd)
  105. offset = offset + 2
  106. for i=1, btry_temp_sns_cnt do
  107. -- dissect btry_temp_sns_rd (array of uint8, loop through based on btry_temp_sns_cnt)
  108. local btry_temp = buffer(offset, 1):le_uint()
  109. subtree:add(f_btry_temp_sns_rd, btry_temp)
  110. offset = offset + 1
  111. end
  112. for i=1, chnl_cnt do
  113. -- dissect chnl_state (array of uint8, loop through based on chnl_cnt)
  114. local chnl_state_value = buffer(offset, 1):le_uint()
  115. subtree:add(f_chnl_state, chnl_state_value)
  116. offset = offset + 1
  117. end
  118. for i=1, volt_rail_cnt do
  119. -- volt_rail_cur_value
  120. local volt_rail_value = buffer(offset, 2):le_uint()
  121. subtree:add(f_volt_rail_cur_value, volt_rail_value)
  122. offset = offset + 1
  123. end
  124. for i=1,volt_rail_cnt do
  125. -- dissect chnl_ovr_cur_flg (array of uint8, loop through based on chnl_cnt)
  126. local chnl_ovr_cur_flg_value = buffer(offset, 1):le_uint()
  127. subtree:add(f_chnl_ovr_cur_flg, chnl_ovr_cur_flg_value)
  128. offset = offset + 1
  129. end
  130. -- dissect hrm_btry_mode_info
  131. local hrm_btry_mode_info = buffer(offset, 1):le_uint()
  132. subtree:add(f_hrm_btry_mode_info, hrm_btry_mode_info)
  133. offset = offset + 1
  134. for i=1 ,36 do
  135. subtree:add(eps_hardware_data,buffer(offset,1):le_uint())
  136. offset=offset+1
  137. end
  138. end
  139. end