eps_get_live_param.lua 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. function eps_get_live_param_dissector(buffer, pinfo, tree, TC_TM_PROTOCOL, offset)
  2. local f_pv_cnt = ProtoField.uint8("TC_TM_PROTOCOL.pv_cnt", "PV Count", base.DEC)
  3. local f_mppt_cnt = ProtoField.uint8("TC_TM_PROTOCOL.mppt_cnt", "MPPT Count", base.DEC)
  4. local f_op_conv_cnt = ProtoField.uint8("TC_TM_PROTOCOL.op_conv_cnt", "OP Converter Count", base.DEC)
  5. local f_btry_cnt = ProtoField.uint8("TC_TM_PROTOCOL.btry_cnt", "Battery Count", base.DEC)
  6. local f_btry_temp_sns_cnt = ProtoField.uint8("TC_TM_PROTOCOL.btry_temp_sns_cnt", "Battery Temp Sensor Count", base.DEC)
  7. local f_chnl_cnt = ProtoField.uint8("TC_TM_PROTOCOL.chnl_cnt", "Channel Count", base.DEC)
  8. local f_volt_rail_cnt = ProtoField.uint8("TC_TM_PROTOCOL.volt_rail_cnt", "Voltage Rail Count", base.DEC)
  9. local f_pv_volt_rd = ProtoField.float("TC_TM_PROTOCOL.pv_volt_rd", "PV Voltage Readings", base.DEC)
  10. local f_pv_cur_rd = ProtoField.float("TC_TM_PROTOCOL.pv_cur_rd", "PV Current Readings", base.DEC)
  11. local f_mppt_volt_rd = ProtoField.float("TC_TM_PROTOCOL.mppt_volt_rd", "MPPT Voltage Readings", base.DEC)
  12. local f_mppt_cur_rd = ProtoField.float("TC_TM_PROTOCOL.mppt_cur_rd", "MPPT Current Readings", base.DEC)
  13. local f_op_conv_volt_rd = ProtoField.bytes("TC_TM_PROTOCOL.op_conv_volt_rd", "OP Converter Voltage Readings")
  14. local f_tot_btry_volt_rd = ProtoField.float("TC_TM_PROTOCOL.tot_btry_volt_rd", "Total Battery Voltage Read", base.DEC)
  15. local f_tot_btry_cur_rd = ProtoField.float("TC_TM_PROTOCOL.tot_btry_cur_rd", "Total Battery Current Read", base.DEC)
  16. local f_btry_temp_sns_rd = ProtoField.uint8("TC_TM_PROTOCOL.btry_temp_sns_rd", "Battery Temp Sensor Readings", base.DEC)
  17. local f_chnl_state = ProtoField.uint16("TC_TM_PROTOCOL.chnl_state", "Channel States", base.DEC)
  18. local f_volt_rail_cur_value = ProtoField.bytes("TC_TM_PROTOCOL.volt_rail_cur_value", "Voltage Rail Current Values")
  19. local f_chnl_ovr_cur_flg = ProtoField.bytes("TC_TM_PROTOCOL.chnl_ovr_cur_flg", "Channel Overcurrent Flags")
  20. local f_hrm_btry_mode_info = ProtoField.uint8("TC_TM_PROTOCOL.hrm_btry_mode_info", "HRM Battery Mode Info", base.DEC)
  21. local f_reserved_byte_size = ProtoField.uint8("TC_TM_PROTOCOL.f_reserved_byte_size", "Reserved Byte Size", base.DEC)
  22. local f_reserved_byte_array = ProtoField.uint8("TC_TM_PROTOCOL.f_reserved_byte_size", "Reserved Byte Array", base.DEC)
  23. TC_TM_PROTOCOL.fields = {
  24. f_pv_cnt, f_mppt_cnt, f_op_conv_cnt, f_btry_cnt, f_btry_temp_sns_cnt,
  25. f_chnl_cnt, f_volt_rail_cnt, f_pv_volt_rd, f_pv_cur_rd, f_mppt_volt_rd,
  26. f_mppt_cur_rd, f_op_conv_volt_rd, f_tot_btry_volt_rd, f_tot_btry_cur_rd,
  27. f_btry_temp_sns_rd, f_chnl_state, f_volt_rail_cur_value,
  28. f_chnl_ovr_cur_flg, f_hrm_btry_mode_info
  29. }
  30. local subtree = tree:add(TC_TM_PROTOCOL, buffer(), "EPS GET LIVE PARAM")
  31. local pv_cnt = buffer(offset, 1):le_uint()
  32. subtree:add(f_pv_cnt, buffer(offset, 1):le_uint())
  33. offset = offset + 1
  34. local mppt_cnt = buffer(offset, 1):le_uint()
  35. subtree:add(f_mppt_cnt, buffer(offset, 1):le_uint())
  36. offset = offset + 1
  37. local op_conv_cnt = buffer(offset, 1):le_uint()
  38. subtree:add(f_op_conv_cnt, buffer(offset, 1):le_uint())
  39. offset = offset + 1
  40. local btry_cnt = buffer(offset, 1):le_uint()
  41. subtree:add(f_btry_cnt, buffer(offset, 1):le_uint())
  42. offset = offset + 1
  43. local btry_temp_sns_cnt = buffer(offset, 1):le_uint()
  44. subtree:add(f_btry_temp_sns_cnt, buffer(offset, 1):le_uint())
  45. offset = offset + 1
  46. local chnl_cnt = buffer(offset, 1):le_uint()
  47. subtree:add(f_chnl_cnt, buffer(offset, 1):le_uint())
  48. offset = offset + 1
  49. local volt_rail_cnt = buffer(offset, 1):le_uint()
  50. subtree:add(f_volt_rail_cnt, buffer(offset, 1):le_uint())
  51. offset = offset + 1
  52. local count = 0 -- Initialize the sum to 0
  53. local value
  54. for i = 0, pv_cnt - 1 do
  55. value = buffer(offset, 2):le_uint() -- Parse as little-endian uint16
  56. value = value/10;
  57. subtree:add(f_pv_volt_rd, value):set_text(string.format("PV Volt %d ----> %0.1f V", i, value))
  58. offset = offset + 2 -- Move the offset forward by 2 bytes
  59. end
  60. for i = 0, pv_cnt - 1 do
  61. value = buffer(offset, 2):le_uint()
  62. value = value / 100
  63. subtree:add(f_pv_cur_rd, value):set_text(string.format("PV Current %d ----> %0.2f A", i, value))
  64. offset = offset + 2
  65. end
  66. for i = 0, mppt_cnt - 1 do
  67. value = buffer(offset, 2):le_uint()
  68. value = value / 10
  69. subtree:add(f_mppt_volt_rd, value):set_text(string.format("MPPT Volt %d ----> %0.1f V", i, value))
  70. offset = offset + 2
  71. end
  72. for i = 0, mppt_cnt - 1 do
  73. value = buffer(offset, 2):le_uint()
  74. value = value / 100
  75. subtree:add(f_mppt_cur_rd, value):set_text(string.format("MPPT Current %d ----> %0.2f A", i, value))
  76. offset = offset + 2
  77. end
  78. for i = 0, op_conv_cnt - 1 do
  79. value = buffer(offset, 2):le_uint()
  80. value = value / 10
  81. subtree:add(f_op_conv_volt_rd, value):set_text(string.format("OP Convertor Volt %d ----> %0.1f V", i, value))
  82. offset = offset + 2
  83. end
  84. local tot_btry_volt = buffer(offset, 2):le_uint()
  85. tot_btry_volt = tot_btry_volt / 10
  86. subtree:add(f_tot_btry_volt_rd, tot_btry_volt):set_text(string.format("Total Battery Voltage Read ---- %0.1f V", tot_btry_volt))
  87. offset = offset + 2
  88. local tot_btry_curr = buffer(offset, 2):le_uint()
  89. tot_btry_curr = tot_btry_curr / 100
  90. subtree:add(f_tot_btry_cur_rd, tot_btry_curr):set_text(string.format("Total Battery Curr Read ---- %0.2f V", tot_btry_curr))
  91. offset = offset + 2
  92. for i = 0, btry_temp_sns_cnt - 1 do
  93. value = buffer(offset, 1):le_uint()
  94. subtree:add(f_btry_temp_sns_rd, value):set_text(string.format("Battery Temp Sensor %d ----> %d degC", i, value))
  95. offset = offset + 1
  96. end
  97. count = math.ceil(chnl_cnt / 8)
  98. local chnl_state = buffer(offset, count):le_uint()
  99. for i = 0, chnl_cnt - 1 do
  100. data = (chnl_state >> i) & 1
  101. if data == 1 then
  102. subtree:add(f_chnl_state, data):set_text(string.format("Channel %d ----> ON", i)) -- Adjust size as needed
  103. else
  104. subtree:add(f_chnl_state, data):set_text(string.format("Channel %d ----> OFF", i))
  105. end
  106. end
  107. offset = offset + count
  108. for i = 0, volt_rail_cnt - 1 do
  109. value = buffer(offset, 2):le_uint()
  110. value = value / 100
  111. subtree:add(f_volt_rail_cur_value, value):set_text(string.format("Volt Rail current Values %d ----> %0.2f V", i, value))
  112. offset = offset + 2
  113. end
  114. count = math.ceil(volt_rail_cnt / 8)
  115. local over_flow = buffer(offset, count):le_uint()
  116. for i = 0, volt_rail_cnt - 1 do
  117. data = (over_flow >> i) & 1
  118. if data == 1 then
  119. subtree:add(f_chnl_ovr_cur_flg, data):set_text(string.format("Over Current Flag %d ----> SET", i)) -- Adjust size as needed
  120. else
  121. subtree:add(f_chnl_ovr_cur_flg, data):set_text(string.format("Over Current Flag %d ----> CLR", i))
  122. end
  123. end
  124. offset = offset + count
  125. local btry_mode = buffer(offset, 1):le_uint()
  126. local data = btry_mode & 0x0f
  127. if data == 0 then
  128. subtree:add(f_hrm_btry_mode_info,data):set_text(string.format("EPS MODE ----> OFF"))
  129. elseif data == 1 then
  130. subtree:add(f_hrm_btry_mode_info, data):set_text(string.format("EPS MODE ----> CRITICAL"))
  131. elseif data == 2 then
  132. subtree:add(f_hrm_btry_mode_info, data):set_text(string.format("EPS MODE ----> SAFE"))
  133. elseif data == 3 then
  134. subtree:add(f_hrm_btry_mode_info, data):set_text(string.format("EPS MODE ----> NORMAL"))
  135. elseif data == 4 then
  136. subtree:add(f_hrm_btry_mode_info, data):set_text(string.format("EPS MODE ----> FULL"))
  137. end
  138. data = (btry_mode >> 4) & 1
  139. if data == 1 then
  140. subtree:add(f_hrm_btry_mode_info, data):set_text(string.format("Bttery Charge Status ----> Charging"))
  141. else
  142. subtree:add(f_hrm_btry_mode_info, data):set_text(string.format("Bttery Charge Status ----> Not Charging"))
  143. end
  144. data = (btry_mode >> 5) & 3
  145. if data == 3 then
  146. subtree:add(f_hrm_btry_mode_info, data):set_text(string.format("HRM Release Status ----> Both Left and Right opened"))
  147. elseif data == 2 then
  148. subtree:add(f_hrm_btry_mode_info, data):set_text(string.format("HRM Release Status ----> Left opened and Right Not opened"))
  149. elseif data == 1 then
  150. subtree:add(f_hrm_btry_mode_info, data):set_text(string.format("HRM Release Status ----> Right opened and Left Not opened"))
  151. elseif data == 0 then
  152. subtree:add(f_hrm_btry_mode_info, data):set_text(string.format("HRM Release Status ----> Both Left and Right Not opened"))
  153. end
  154. offset = offset + 1
  155. --subtree:add(f_reserved_byte_size, buffer(offset, 1):le_uint())
  156. --offset = offset + 1
  157. --subtree:add(reserved_byte_array, buffer(offset, 1):le_uint())
  158. --offset = offset + 1
  159. end