uhf_dissector.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. function UHF_DISSECTOR(buffer, pinfo, tree, HM_TM_dissector, offset, tm_len,data3)
  2. -- UHF_DISSECTOR(buffer, pinfo, tree, TC_TM_PROTOCOL, offset, tm_len,data3)
  3. -- Define ProtoFields for each element of the structure (like in your original example)
  4. local f_cnt_hk_str = ProtoField.uint8("TC_TM_PROTOCOL.cnt_hk_str", "cnt_hk_str", base.DEC)
  5. local f_timestamp = ProtoField.uint32("TC_TM_PROTOCOL.timestamp1", "timestamp", base.DEC)
  6. local f_uptime = ProtoField.uint32("TC_TM_PROTOCOL.uptime", "Uptime", base.DEC)
  7. local f_uarto_rx_count = ProtoField.uint32("TC_TM_PROTOCOL.uarto_rx_count", "UART0 RX Count", base.DEC)
  8. local f_uart1_rx_count = ProtoField.uint32("TC_TM_PROTOCOL.uart1_rx_count", "UART1 RX Count", base.DEC)
  9. local f_rx_mode = ProtoField.uint8("TC_TM_PROTOCOL.rx_mode", "RX Mode", base.DEC)
  10. local f_tx_mode = ProtoField.uint8("TC_TM_PROTOCOL.tx_mode", "TX Mode", base.DEC)
  11. local f_adc = ProtoField.uint16("TC_TM_PROTOCOL.adc", "ADC", base.DEC) -- array of int16_t[10]
  12. local f_last_rssi = ProtoField.uint8("TC_TM_PROTOCOL.last_rssi", "Last RSSI", base.DEC)
  13. local f_last_lqi = ProtoField.uint8("TC_TM_PROTOCOL.last_lqi", "Last LQI", base.DEC)
  14. local f_last_freqest = ProtoField.uint8("TC_TM_PROTOCOL.last_freqest", "Last Frequency Estimate", base.DEC)
  15. local f_pkt_sent = ProtoField.uint32("TC_TM_PROTOCOL.Pkt_sent", "Packets Sent", base.DEC)
  16. local f_cs_count = ProtoField.uint32("TC_TM_PROTOCOL.cs_count", "CS Count", base.DEC)
  17. local f_pkt_good = ProtoField.uint32("TC_TM_PROTOCOL.Pkt_good", "Packets Good", base.DEC)
  18. local f_pkt_rejected_checksum = ProtoField.uint32("TC_TM_PROTOCOL.Pkt_rejected_checksum", "Packets Rejected (Checksum)", base.DEC)
  19. local f_pkt_rejected_reserved = ProtoField.uint32("TC_TM_PROTOCOL.Pkt_rejected_reserved", "Packets Rejected (Reserved)", base.DEC)
  20. local f_pkt_rejected_other = ProtoField.uint32("TC_TM_PROTOCOL.Pkt_rejected_other", "Packets Rejected (Other)", base.DEC)
  21. local f_reserved0 = ProtoField.uint32("TC_TM_PROTOCOL.reserved0", "Reserved0", base.DEC)
  22. -- local f_reserved1 = ProtoField.uint32("TC_TM_PROTOCOL.reserved1", "Reserved1", base.DEC) -- Uncomment if needed
  23. local f_customo = ProtoField.uint32("TC_TM_PROTOCOL.customo", "Custom 0", base.DEC)
  24. local f_custom1 = ProtoField.uint32("TC_TM_PROTOCOL.custom1", "Custom 1", base.DEC)
  25. -- Add the fields to the protocol
  26. HM_TM_dissector.fields = {
  27. f_timestamp,
  28. f_cnt_hk_str,
  29. f_uptime,
  30. f_uarto_rx_count,
  31. f_uart1_rx_count,
  32. f_rx_mode,
  33. f_tx_mode,
  34. f_adc,
  35. f_last_rssi,
  36. f_last_lqi,
  37. f_last_freqest,
  38. f_pkt_sent,
  39. f_cs_count,
  40. f_pkt_good,
  41. f_pkt_rejected_checksum,
  42. f_pkt_rejected_reserved,
  43. f_pkt_rejected_other,
  44. f_reserved0,
  45. -- f_reserved1, -- Uncomment if you want to include reserved1
  46. f_customo,
  47. f_custom1
  48. }
  49. local subtree = tree:add(TC_TM_PROTOCOL, buffer(), "UHF")
  50. -- For your dissection function (within a loop structure)
  51. for i = 0, data3 - 1 do
  52. --offset = offset + 8
  53. local subtree1 = subtree:add(TC_TM_PROTOCOL, buffer(), "Instance "..i)
  54. --local a = buffer(offset, 1):le_uint()
  55. --subtree1:add(f_cnt_hk_str, a)
  56. --offset = offset + 1
  57. local b = buffer(offset, 4):le_uint()
  58. subtree1:add(f_timestamp, b)
  59. offset = offset + 8
  60. --b = buffer(offset, 4):le_uint()
  61. --subtree1:add(f_timestamp, b)
  62. --offset = offset + 4
  63. -- dissect uptime
  64. local uptime = buffer(offset, 4):le_uint()
  65. subtree1:add(f_uptime, uptime)
  66. offset = offset + 4
  67. -- dissect uarto_rx_count
  68. local uarto_rx_count = buffer(offset, 4):le_uint()
  69. subtree1:add(f_uarto_rx_count, uarto_rx_count)
  70. offset = offset + 4
  71. -- dissect uart1_rx_count
  72. local uart1_rx_count = buffer(offset, 4):le_uint()
  73. subtree1:add(f_uart1_rx_count, uart1_rx_count)
  74. offset = offset + 4
  75. -- dissect rx_mode
  76. local rx_mode = buffer(offset, 1):le_uint()
  77. subtree1:add(f_rx_mode, rx_mode)
  78. offset = offset + 1
  79. -- dissect tx_mode
  80. local tx_mode = buffer(offset, 1):le_uint()
  81. subtree1:add(f_tx_mode, tx_mode)
  82. offset = offset + 1
  83. -- dissect adc (array of int16, loop through based on 10 elements)
  84. for j = 1, 10 do
  85. local adc_value = buffer(offset, 2):le_int()
  86. subtree1:add(f_adc, adc_value)
  87. offset = offset + 2
  88. end
  89. -- dissect last_rssi
  90. local last_rssi = buffer(offset, 1):le_int()
  91. subtree1:add(f_last_rssi, last_rssi)
  92. offset = offset + 1
  93. -- dissect last_lqi
  94. local last_lqi = buffer(offset, 1):le_uint()
  95. subtree1:add(f_last_lqi, last_lqi)
  96. offset = offset + 1
  97. -- dissect last_freqest
  98. local last_freqest = buffer(offset, 1):le_int()
  99. subtree1:add(f_last_freqest, last_freqest)
  100. offset = offset + 1
  101. -- dissect Pkt_sent
  102. local pkt_sent = buffer(offset, 4):le_uint()
  103. subtree1:add(f_pkt_sent, pkt_sent)
  104. offset = offset + 4
  105. -- dissect cs_count
  106. local cs_count = buffer(offset, 4):le_uint()
  107. subtree1:add(f_cs_count, cs_count)
  108. offset = offset + 4
  109. -- dissect Pkt_good
  110. local pkt_good = buffer(offset, 4):le_uint()
  111. subtree1:add(f_pkt_good, pkt_good)
  112. offset = offset + 4
  113. -- dissect Pkt_rejected_checksum
  114. local pkt_rejected_checksum = buffer(offset, 4):le_uint()
  115. subtree1:add(f_pkt_rejected_checksum, pkt_rejected_checksum)
  116. offset = offset + 4
  117. -- dissect Pkt_rejected_reserved
  118. local pkt_rejected_reserved = buffer(offset, 4):le_uint()
  119. subtree1:add(f_pkt_rejected_reserved, pkt_rejected_reserved)
  120. offset = offset + 4
  121. -- dissect Pkt_rejected_other
  122. local pkt_rejected_other = buffer(offset, 4):le_uint()
  123. subtree1:add(f_pkt_rejected_other, pkt_rejected_other)
  124. offset = offset + 4
  125. -- dissect reserved0
  126. local reserved0 = buffer(offset, 4):le_uint()
  127. subtree1:add(f_reserved0, reserved0)
  128. offset = offset + 9
  129. -- dissect customo
  130. --local customo = buffer(offset, 4):le_uint()
  131. --subtree1:add(f_customo, customo)
  132. --offset = offset + 4
  133. -- dissect custom1
  134. --local custom1 = buffer(offset, 4):le_uint()
  135. --subtree1:add(f_custom1, custom1)
  136. --offset = offset + 4
  137. -- (continue for any other fields you want to dissect, e.g., reserved1 if needed)
  138. end
  139. end