function adcs_dissector(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance, queue_id)
 
  if queue_id == 0 then
     require("adcs_dissector")
     adcs_dissector_0(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
     
  elseif queue_id == 1 then 
    require("adcs_dissector")
    adcs_dissector_1(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    
  elseif queue_id == 2 then
    require("adcs_dissector")
    adcs_dissector_2(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    
  elseif queue_id == 3 then 
    require("adcs_dissector")
    adcs_dissector_3(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    
  elseif queue_id == 4 then 
    require("adcs_dissector")
    adcs_dissector_4(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    
  elseif queue_id == 5 then 
    require("adcs_dissector")
    adcs_dissector_5(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
  
  elseif queue_id == 6 then 
    require("adcs_dissector")
    adcs_dissector_6(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    
  elseif queue_id == 7 then 
    require("adcs_dissector")
    adcs_dissector_7(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
  elseif queue_id == 8 then 
    require("adcs_dissector")
    adcs_dissector_8(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    
  elseif queue_id == 9 then 
    require("adcs_dissector")
    adcs_dissector_9(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    
  elseif queue_id == 10 then 
    require("adcs_dissector")
    adcs_dissector_10(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    
  elseif queue_id == 11 then 
    require("adcs_dissector")
    adcs_dissector_11(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    
  elseif queue_id == 12 then 
    require("adcs_dissector")
    adcs_dissector_12(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    
   elseif queue_id == 13 then 
    require("adcs_dissector")
    adcs_dissector_13(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    
    elseif queue_id == 14 then
      require("adcs_dissector")
      adcs_dissector_14(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

  elseif queue_id == 15 then
      require("adcs_dissector")
      adcs_dissector_15(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 16 then
      require("adcs_dissector")
      adcs_dissector_16(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 17 then
      require("adcs_dissector")
      adcs_dissector_17(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 18 then
      require("adcs_dissector")
      adcs_dissector_18(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 19 then
      require("adcs_dissector")
      adcs_dissector_19(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 20 then
      require("adcs_dissector")
      adcs_dissector_20(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 21 then
      require("adcs_dissector")
      adcs_dissector_21(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 22 then
      require("adcs_dissector")
      adcs_dissector_22(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 23 then
      require("adcs_dissector")
      adcs_dissector_23(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 24 then
      require("adcs_dissector")
      adcs_dissector_24(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 25 then
      require("adcs_dissector")
      adcs_dissector_25(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 26 then
      require("adcs_dissector")
      adcs_dissector_26(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 27 then
      require("adcs_dissector")
      adcs_dissector_27(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 28 then
      require("adcs_dissector")
      adcs_dissector_28(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 29 then
      require("adcs_dissector")
      adcs_dissector_29(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 30 then
      require("adcs_dissector")
      adcs_dissector_30(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 31 then
      require("adcs_dissector")
      adcs_dissector_31(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

elseif queue_id == 32 then
      require("adcs_dissector")
      adcs_dissector_32(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

  end
  
  
     
end
  
  
function adcs_dissector_0(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

  local status_field = ProtoField.uint32("adcs_protocol.status", "Status", base.DEC)
  local time_field = ProtoField.uint32("adcs_protocol.time", "Time", base.DEC)
  local nadir_3v3_current_field = ProtoField.uint32("adcs_protocol.nadir_3v3_current", "Nadir Sensor 3V3 Current", base.DEC)
  local fss_3v3_current_field = ProtoField.uint32("adcs_protocol.fss_3v3_current", "FSS 3V3 Current", base.DEC)
  local nadir_sram_current_field = ProtoField.uint32("adcs_protocol.nadir_sram_current", "Nadir SRAM Current", base.DEC)
  local fss_sram_current_field = ProtoField.uint32("adcs_protocol.fss_sram_current", "FSS SRAM Current", base.DEC)

  -- Add the fields to the protocol's 'fields' table
  adcs_protocol.fields = {
    status_field,
    time_field,
    nadir_3v3_current_field,
    fss_3v3_current_field,
    nadir_sram_current_field,
    fss_sram_current_field
    }
    
local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
    
    for i = 0,  num_of_instance - 1 do
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
    -- Dissect status
     local status = buffer(offset, 1):le_uint()
    subtree:add(status_field, status)
    offset = offset + 1

    -- Dissect time (4 bytes, little-endian)
    local time = buffer(offset, 4):le_uint()
    subtree:add(time_field, time)
    offset = offset + 4

    -- Dissect nadir 3V3 current (4 bytes, little-endian)
    local nadir_3v3_raw = buffer(offset, 2):le_uint()
    --local nadir_3v3_current = nadir_3v3_raw * 0.1  -- Apply multiplier
    subtree:add(nadir_3v3_current_field, nadir_3v3_raw)
    offset = offset + 2

    -- Dissect fss 3V3 current (4 bytes, little-endian)
    local fss_3v3_raw = buffer(offset, 2):le_uint()
    --local fss_3v3_current = fss_3v3_raw * 0.1  -- Apply multiplier
    subtree:add(fss_3v3_current_field, fss_3v3_raw)
    offset = offset + 2

    -- Dissect nadir SRAM current (4 bytes, little-endian)
    local nadir_sram_raw = buffer(offset, 2):le_uint()
    --local nadir_sram_current = nadir_sram_raw * 0.1  -- Apply multiplier
    subtree:add(nadir_sram_current_field, nadir_sram_raw)
    offset = offset + 2

    -- Dissect fss SRAM current (4 bytes, little-endian)
    local fss_sram_raw = buffer(offset, 2):le_uint()
    --local fss_sram_current = fss_sram_raw * 0.1  -- Apply multiplier
    subtree:add(fss_sram_current_field, fss_sram_raw)
    offset = offset + 2
    
  end
end

function adcs_dissector_1(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

    local f_operation_status = ProtoField.uint32("adcs_dissector.operation_status", "Operation Status", base.DEC)
    local f_epoch_time = ProtoField.uint32("adcs_dissector.epoch_time", "Epoch Time", base.DEC)
    local f_3v_current = ProtoField.float("adcs_dissector.3v_current", "Current Value (3.3V)", base.DEC)
    local f_5v_current = ProtoField.float("adcs_dissector.5v_current", "Current Value (5V)", base.DEC)
    local f_vbat_current = ProtoField.float("adcs_dissector.vbat_current", "Vbat Current Value", base.DEC)

    -- Add fields to the protocol's 'fields' table
    adcs_protocol.fields = {
    f_operation_status,
    f_epoch_time,
    f_3v_current,
    f_5v_current,
    f_vbat_current  
    }

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    for i = 0,  num_of_instance - 1 do
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
    local operation_status = buffer(offset, 1):le_uint()
    subtree:add(f_operation_status, operation_status)
    offset = offset + 1

    -- Dissect epoch time (4 bytes, little-endian)
    local epoch_time = buffer(offset, 4):le_uint()
    subtree:add(f_epoch_time, epoch_time)
    offset = offset + 4

    -- Dissect 3.3V current value (4 bytes, little-endian)
    local raw_3v_current = buffer(offset, 2):uint()
    --local formatted_3v_current = raw_3v_current * 0.1  -- Apply multiplier
    subtree:add(f_3v_current, raw_3v_current)
    offset = offset + 2

    -- Dissect 5V current value (4 bytes, little-endian)
    local raw_5v_current = buffer(offset, 2):uint()
    --local formatted_5v_current = raw_5v_current * 0.1  -- Apply multiplier
    subtree:add(f_5v_current, raw_5v_current)
    offset = offset + 2

    -- Dissect Vbat current value (4 bytes, little-endian)
    local raw_vbat_current = buffer(offset, 2):uint()
    --local formatted_vbat_current = raw_vbat_current * 0.1  -- Apply multiplier
    subtree:add(f_vbat_current, raw_vbat_current)
    offset = offset + 2
    end

end

function adcs_dissector_2(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

    local f_operation_status = ProtoField.uint32("adcs_dissector.operation_status", "Operation Status", base.DEC)
    local f_epoch_time = ProtoField.uint32("adcs_dissector.epoch_time", "Epoch Time", base.DEC)
    local f_num_reaction_wheels = ProtoField.uint32("adcs_dissector.num_reaction_wheels", "Number of Reaction Wheel", base.DEC)
    local f_rw_current_1 = ProtoField.float("adcs_dissector.rw_current_1", "Reaction Wheel Current 1 (A)", base.DEC)
    local f_rw_current_2 = ProtoField.float("adcs_dissector.rw_current_2", "Reaction Wheel Current 2 (A)", base.DEC)
    local f_rw_current_3 = ProtoField.float("adcs_dissector.rw_current_3", "Reaction Wheel Current 3 (A)", base.DEC)
    
    adcs_protocol.fields = {
    f_operation_status,
    f_epoch_time,
    f_num_reaction_wheels,
    f_rw_current_1,
    f_rw_current_2,
    f_rw_current_3
}
  local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
  
    for i = 0,  num_of_instance - 1 do
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
    local operation_status = buffer(offset, 1):le_uint()
    subtree:add(f_operation_status, operation_status)
    offset = offset + 1

    -- Dissect epoch time (4 bytes, little-endian)
    local epoch_time = buffer(offset, 4):le_uint()
    subtree:add(f_epoch_time, epoch_time)
    offset = offset + 4

    -- Dissect number of reaction wheels (4 bytes, little-endian)
    local num_reaction_wheels = buffer(offset, 1):le_uint()
    subtree:add(f_num_reaction_wheels, num_reaction_wheels)
    offset = offset + 1

    -- Dissect Reaction Wheel Current 1 (4 bytes, little-endian)
    local rw_current_1_raw = buffer(offset, 2):le_uint()
    local rw_current_1 = rw_current_1_raw * 0.1  -- Apply multiplier
    subtree:add(f_rw_current_1, rw_current_1)
    offset = offset + 2

    -- Dissect Reaction Wheel Current 2 (4 bytes, little-endian)
    local rw_current_2_raw = buffer(offset, 2):le_uint()
    local rw_current_2 = rw_current_2_raw * 0.1  -- Apply multiplier
    subtree:add(f_rw_current_2, rw_current_2)
    offset = offset + 2

    -- Dissect Reaction Wheel Current 3 (4 bytes, little-endian)
    local rw_current_3_raw = buffer(offset, 2):le_uint()
    local rw_current_3 = rw_current_3_raw * 0.1  -- Apply multiplier
    subtree:add(f_rw_current_3, rw_current_3)
    offset = offset + 2
    end
end 

function adcs_dissector_3(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

local f_operation_status = ProtoField.uint8("current_protocol.operation_status", "Operation Status", base.DEC)
local f_epoch_time = ProtoField.uint32("current_protocol.epoch_time", "Epoch Time", base.DEC)
local f_cube_star_current = ProtoField.uint16("current_protocol.cube_star_current", "Cube Star Current ", base.DEC)
local f_magnetorquer_current = ProtoField.uint16("current_protocol.magnetorquer_current", "Magnetorquer Current ", base.DEC)
local f_cube_star_mcu_temp = ProtoField.uint16("current_protocol.cube_star_mcu_temp", "Cube Star MCU Temperature ", base.DEC)


adcs_protocol.fields = { 
    f_operation_status,
    f_epoch_time,
    f_cube_star_current,
    f_magnetorquer_current,
    f_cube_star_mcu_temp }

   local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
    
    for i = 0, num_of_instance - 1 do 
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
    subtree:add(f_operation_status, buffer(offset, 1):le_uint())
    offset = offset + 1  -- Update offset

    -- Epoch Time (4 bytes, UINT)
    subtree:add(f_epoch_time, buffer(offset, 4):le_uint())
    offset = offset + 4  -- Update offset

    -- Cube Star Current (2 bytes, UINT)
    local cube_star_current = buffer(offset, 2):le_uint() * 0.1  -- Apply the scaling factor (RAWVAL * 0.1)
    subtree:add(f_cube_star_current, cube_star_current)
    offset = offset + 2  -- Update offset

    -- Magnetorquer Current (2 bytes, UINT)
    local magnetorquer_current = buffer(offset, 2):le_uint() * 0.1  -- Apply the scaling factor (RAWVAL * 0.1)
    subtree:add(f_magnetorquer_current, magnetorquer_current)
    offset = offset + 2  -- Update offset

    -- Cube Star MCU Temperature (2 bytes, UINT)
    local cube_star_mcu_temp = buffer(offset, 2):le_uint() * 0.1  -- Apply the scaling factor (RAWVAL * 0.1)
    subtree:add(f_cube_star_mcu_temp, cube_star_mcu_temp)
    offset = offset + 2  -- Update offset
    end
end

function adcs_dissector_4(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

   local f_operation_status = ProtoField.uint32("adcs_protocol.operation_status", "Operation Status", base.DEC)
   local f_epoch_time = ProtoField.uint32("adcs_protocol.epoch_time", "Epoch Time", base.DEC)
   local f_mcu_temperature = ProtoField.int16("adcs_protocol.mcu_temperature", "MCU Temperature ", base.DEC)
   local f_magnetometer_temperature = ProtoField.int16("adcs_protocol.magnetometer_temperature", "Magnetometer Temperature ", base.DEC)
   local f_redundant_magnetometer_temperature = ProtoField.int16("adcs_protocol.redundant_magnetometer_temperature", "Redundant Magnetometer Temperature ", base.DEC)

-- Add the fields to the protocol
adcs_protocol.fields = { f_operation_status, f_epoch_time, f_mcu_temperature, f_magnetometer_temperature, f_redundant_magnetometer_temperature }

   local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
    
    for i = 0, num_of_instance - 1 do
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
    subtree:add(f_operation_status, buffer(offset, 1):le_uint())  -- 1 bytes for Operation Status (UINT)
    offset = offset + 1
    
    subtree:add(f_epoch_time, buffer(offset, 4):le_uint())        -- 4 bytes for Epoch Time (UINT)
    offset = offset + 4
    
    -- Extract raw values for the temperatures (2 bytes each for INT)
    local mcu_temp = buffer(offset, 2):le_uint() * 0.01
    offset = offset + 2
    
    local magnetometer_temp = buffer(offset, 2):le_uint() * 0.01
    offset = offset + 2
    
    local redundant_magnetometer_temp = buffer(offset, 2):le_uint() * 0.01
    offset = offset + 2
    
    -- Add the temperature values to the tree with scaling applied
    subtree:add(f_mcu_temperature, mcu_temp)
    subtree:add(f_magnetometer_temperature, magnetometer_temp)
    subtree:add(f_redundant_magnetometer_temperature, redundant_magnetometer_temp)
    end
end

function adcs_dissector_5(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

  local f_operation_status = ProtoField.uint8("adcs_protocol.operation_status", "Operation Status", base.DEC)
  local f_epoch_time = ProtoField.uint32("adcs_protocol.epoch_time", "Epoch Time", base.DEC)
  local f_raw_mag_x = ProtoField.uint16("adcs_protocol.raw_mag_x", "X Rate Sensor Temperature ", base.DEC)
  local f_raw_mag_y = ProtoField.uint16("adcs_protocol.raw_mag_y", "Y Rate Sensor Temperature ", base.DEC)
  local f_raw_mag_z = ProtoField.uint16("adcs_protocol.raw_mag_z", "Z Rate Sensor Temperature ", base.DEC)

-- Add the fields to the protocol
adcs_protocol.fields = { f_operation_status, f_epoch_time, f_raw_mag_x, f_raw_mag_y, f_raw_mag_z }

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

  for i = 0, num_of_instance - 1 do
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
        -- Operation Status (1 bytes, unsigned)
        subtree:add(f_operation_status, buffer(offset, 1):le_uint())
        offset = offset + 1
        
        -- Epoch Time (4 bytes, unsigned)
        subtree:add(f_epoch_time, buffer(offset, 4):le_uint())
        offset = offset + 4

        -- Raw Magnetometer X (2 bytes, signed)
        local raw_mag_x = buffer(offset, 2):le_int()
        subtree:add(f_raw_mag_x, raw_mag_x)
        offset = offset + 2

        -- Raw Magnetometer Y (4 bytes, signed)
        local raw_mag_y = buffer(offset, 2):le_int()
        subtree:add(f_raw_mag_y, raw_mag_y)
        offset = offset + 2

        -- Raw Magnetometer Z (4 bytes, signed)
        local raw_mag_z = buffer(offset, 2):le_int()
        subtree:add(f_raw_mag_z, raw_mag_z)
        offset = offset + 2
    end
end
function adcs_dissector_6(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

local f_operation_status = ProtoField.uint8("adcs_protocol.operation_status", "Operation Status", base.HEX)
local f_epoch_time = ProtoField.uint32("adcs_protocol.epoch_time", "Epoch Time", base.DEC)
local f_attitude_estimation_mode = ProtoField.uint8("adcs_protocol.attitude_estimation_mode", "Attitude Estimation Mode", base.DEC)
local f_control_mode = ProtoField.uint8("adcs_protocol.control_mode", "Control Mode", base.DEC)
local f_adcs_run_mode = ProtoField.uint8("adcs_protocol.adcs_run_mode", "ADCS Run Mode", base.DEC)
local f_asgp4_mode = ProtoField.uint8("adcs_protocol.asgp4_mode", "ASGP4 Mode", base.DEC)

-- Define boolean fields for enabled flags
local f_cube_control_signal_enabled = ProtoField.bool("adcs_protocol.cube_control_signal_enabled", "Cube Control Signal Enabled")
local f_cube_control_motor_enabled = ProtoField.bool("adcs_protocol.cube_control_motor_enabled", "Cube Control Motor Enabled")
local f_cubesense1_enabled = ProtoField.bool("adcs_protocol.cubesense1_enabled", "Cubesense1 Enabled")
local f_cubesense2_enabled = ProtoField.bool("adcs_protocol.cubesense2_enabled", "Cubesense2 Enabled")
local f_cube_wheel1_enabled = ProtoField.bool("adcs_protocol.cube_wheel1_enabled", "Cube Wheel 1 Enabled")
local f_cube_wheel2_enabled = ProtoField.bool("adcs_protocol.cube_wheel2_enabled", "Cube Wheel 2 Enabled")
local f_cube_wheel3_enabled = ProtoField.bool("adcs_protocol.cube_wheel3_enabled", "Cube Wheel 3 Enabled")
local f_cube_star_enabled = ProtoField.bool("adcs_protocol.cube_star_enabled", "Cube Star Enabled")
local f_gps_receiver_enabled = ProtoField.bool("adcs_protocol.gps_receiver_enabled", "GPS Receiver Enabled")
local f_gps_lna_power_enabled = ProtoField.bool("adcs_protocol.gps_lna_power_enabled", "GPS LNA Power Enabled")
local f_motor_driver_enabled = ProtoField.bool("adcs_protocol.motor_driver_enabled", "Motor Driver Enabled")
local f_sun_is_above_local_horizon = ProtoField.bool("adcs_protocol.sun_is_above_local_horizon", "Sun is Above Local Horizon")

-- Communication error fields
local f_cubesense1_comm_error = ProtoField.bool("adcs_protocol.cubesense1_comm_error", "Cubesense1 Communications Error")
local f_cubesense2_comm_error = ProtoField.bool("adcs_protocol.cubesense2_comm_error", "Cubesense2 Communications Error")
local f_cubcontrol_signal_comm_error = ProtoField.bool("adcs_protocol.cubcontrol_signal_comm_error", "CubeControl Signal Communications Error")
local f_cubcontrol_motor_comm_error = ProtoField.bool("adcs_protocol.cubcontrol_motor_comm_error", "CubeControl Motor Communications Error")
local f_cubewheel1_comm_error = ProtoField.bool("adcs_protocol.cubewheel1_comm_error", "Cube Wheel 1 Communications Error")
local f_cubewheel2_comm_error = ProtoField.bool("adcs_protocol.cubewheel2_comm_error", "Cube Wheel 2 Communications Error")

local f_cubewheel3_comm_error = ProtoField.bool("adcs_protocol.cubewheel2_comm_error", "Cube Wheel 3 Communications Error")
local f_cubestar_comm_error = ProtoField.bool("adcs_protocol.cubewheel2_comm_error", "Cube star communications Error")

local f_magnetometer_range_error = ProtoField.bool("adcs_protocol.magnetometer_range_error", "Magnetometer Range Error")
local f_cam1_sram_overcurrent = ProtoField.bool("adcs_protocol.cam1_sram_overcurrent", "Cam1 SRAM Overcurrent Detected")
local f_cam1_3v3_overcurrent = ProtoField.bool("adcs_protocol.cam1_3v3_overcurrent", "Cam1 3v3 Overcurrent Detected")
local f_cam1_sensor_busy = ProtoField.bool("adcs_protocol.cam1_sensor_busy", "Cam1 Sensor Busy Error")
local f_cam1_sensor_detection_error = ProtoField.bool("adcs_protocol.cam1_sensor_detection_error", "Cam1 Sensor Detection Error")
local f_sun_sensor_range_error = ProtoField.bool("adcs_protocol.sun_sensor_range_error", "Sun Sensor Range Error")
local f_cam2_sram_overcurrent = ProtoField.bool("adcs_protocol.cam2_sram_overcurrent", "Cam2 SRAM Overcurrent Detected")
local f_cam2_3v3_overcurrent = ProtoField.bool("adcs_protocol.cam2_3v3_overcurrent", "Cam2 3v3 Overcurrent Detected")
local f_cam2_sensor_busy = ProtoField.bool("adcs_protocol.cam2_sensor_busy", "Cam2 Sensor Busy Error")
local f_cam2_sensor_detection_error = ProtoField.bool("adcs_protocol.cam2_sensor_detection_error", "Cam2 Sensor Detection Error")
local f_nadir_sensor_range_error = ProtoField.bool("adcs_protocol.nadir_sensor_range_error", "Nadir Sensor Range Error")
local f_rate_sensor_range_error = ProtoField.bool("adcs_protocol.rate_sensor_range_error", "Rate Sensor Range Error")
local f_wheel_speed_range_error = ProtoField.bool("adcs_protocol.wheel_speed_range_error", "Wheel Speed Range Error")
local f_coarse_sun_sensor_error = ProtoField.bool("adcs_protocol.coarse_sun_sensor_error", "Coarse Sun Sensor Error")
local f_star_tracker_match_error = ProtoField.bool("adcs_protocol.star_tracker_match_error", "Star Tracker Match Error")
local f_star_tracker_overcurrent = ProtoField.bool("adcs_protocol.star_tracker_overcurrent", "Star Tracker Overcurrent Detected")
local f_orbit_parameters_invalid = ProtoField.bool("adcs_protocol.orbit_parameters_invalid", "Orbit Parameters are Invalid")
local f_configuration_invalid = ProtoField.bool("adcs_protocol.configuration_invalid", "Configuration is Invalid")
local f_control_mode_change_not_allowed = ProtoField.bool("adcs_protocol.control_mode_change_not_allowed", "Control Mode Change is not allowed")
local f_estimator_change_not_allowed = ProtoField.bool("adcs_protocol.estimator_change_not_allowed", "Estimator Change is not allowed")

-- Define Magnetometer Sampling Mode field (2 bytes)
local f_magnetometer_sampling_mode = ProtoField.uint8("adcs_protocol.magnetometer_sampling_mode", "Magnetometer Sampling Mode", base.DEC)

-- Define runtime error fields
local f_cubesense1_runtime_error = ProtoField.bool("adcs_protocol.cubesense1_runtime_error", "CubeSense1 Runtime Error")
local f_cubesense2_runtime_error = ProtoField.bool("adcs_protocol.cubesense2_runtime_error", "CubeSense2 Runtime Error")
local f_cubecontrol_signal_runtime_error = ProtoField.bool("adcs_protocol.cubecontrol_signal_runtime_error", "CubeControl Signal Runtime Error")
local f_cubecontrol_motor_runtime_error = ProtoField.bool("adcs_protocol.cubecontrol_motor_runtime_error", "CubeControl Motor Runtime Error")
local f_cubewheel1_runtime_error = ProtoField.bool("adcs_protocol.cubewheel1_runtime_error", "CubeWheel1 Runtime Error")
local f_a = ProtoField.bool("adcs_protocol.cubewheel1_runtime_error", "CubeWheel1 Runtime Error")
local f_b = ProtoField.bool("adcs_protocol.cubewheel1_runtime_error", "CubeWheel1 Runtime Error")
local f_cubewheel2_runtime_error = ProtoField.bool("adcs_protocol.cubewheel2_runtime_error", "CubeWheel2 Runtime Error")
local f_cubewheel3_runtime_error = ProtoField.bool("adcs_protocol.cubewheel3_runtime_error", "CubeWheel3 Runtime Error")
local f_cubestar_runtime_error = ProtoField.bool("adcs_protocol.cubestar_runtime_error", "CubeStar Runtime Error")
local f_magnetometer_error = ProtoField.bool("adcs_protocol.magnetometer_error", "Magnetometer Error")
local f_rate_sensor_failure = ProtoField.bool("adcs_protocol.rate_sensor_failure", "Rate Sensor Failure")

-- Add all fields to the protocol
adcs_protocol.fields = {
    f_operation_status,
    f_epoch_time,
    f_attitude_estimation_mode,
    f_control_mode,
    f_adcs_run_mode,
    f_asgp4_mode,
    f_cube_control_signal_enabled,
    f_cube_control_motor_enabled,
    f_cubesense1_enabled,
    f_cubesense2_enabled,
    f_cube_wheel1_enabled,
    f_cube_wheel2_enabled,
    f_cube_wheel3_enabled,
    f_cube_star_enabled,
    f_gps_receiver_enabled,
    f_gps_lna_power_enabled,
    f_motor_driver_enabled,
    f_sun_is_above_local_horizon,
    f_cubesense1_comm_error,
    f_cubesense2_comm_error,
    f_cubcontrol_signal_comm_error,
    f_cubcontrol_motor_comm_error,
    f_cubewheel1_comm_error,
    f_cubewheel2_comm_error,
    f_cubewheel3_comm_error,
    f_cubestar_comm_error,
    f_magnetometer_range_error,
    f_cam1_sram_overcurrent,
    f_cam1_3v3_overcurrent,
    f_cam1_sensor_busy,
    f_cam1_sensor_detection_error,
    f_sun_sensor_range_error,
    f_cam2_sram_overcurrent,
    f_cam2_3v3_overcurrent,
    f_cam2_sensor_busy,
    f_cam2_sensor_detection_error,
    f_nadir_sensor_range_error,
    f_rate_sensor_range_error,
    f_wheel_speed_range_error,
    f_coarse_sun_sensor_error,
    f_star_tracker_match_error,
    f_star_tracker_overcurrent,
    f_orbit_parameters_invalid,
    f_a,
    f_b,
    f_configuration_invalid,
    f_control_mode_change_not_allowed,
    f_estimator_change_not_allowed,
    f_magnetometer_sampling_mode,
    f_cubesense1_runtime_error,
    f_cubesense2_runtime_error,
    f_cubecontrol_signal_runtime_error,
    f_cubecontrol_motor_runtime_error,
    f_cubewheel1_runtime_error,
    f_cubewheel2_runtime_error,
    f_cubewheel3_runtime_error,
    f_cubestar_runtime_error,
    f_magnetometer_error,
    f_rate_sensor_failure
}

  local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
  
  for i = 0, num_of_instance - 1 do
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
 
    subtree:add(f_operation_status, buffer(offset, 1):le_uint())
    offset = offset + 1
    subtree:add(f_epoch_time, buffer(offset, 4):le_uint())
    offset = offset + 4

    -- Parse Attitude Estimation Mode (8 bits)
    subtree:add(f_attitude_estimation_mode, buffer(offset, 1):le_uint())
    offset = offset + 1

    -- Parse Control Mode (8 bits)
    subtree:add(f_control_mode, buffer(offset, 1):le_uint())
    offset = offset + 1

    -- Parse ADCS Run Mode (2 bits / 2 bytes)
    local a=buffer(offset, 1):le_uint()
    subtree:add(f_adcs_run_mode, a & 0x03)
    --offset = offset + 2

    -- Parse ASGP4 Mode (2 bits / 2 bytes)
    subtree:add(f_asgp4_mode, (a >> 2) & 0x03)
    
    subtree:add(f_cube_control_signal_enabled, (a >> 4) & 0x01)
    
    subtree:add(f_cube_control_motor_enabled,(a >> 5) & 0x01 )
    
    subtree:add(f_cubesense1_enabled,(a >> 6) & 0x01 )
  
    subtree:add(f_cubesense2_enabled,(a >> 7) & 0x01 )
    
    offset = offset + 1
    -- Parse CubeWheel Enabled Flags
    a=buffer(offset, 1):le_uint()
    
    subtree:add(f_cube_wheel1_enabled, (a >> 0) & 0x01)
    --offset = offset + 1
    a=buffer(offset, 1):le_uint()
    subtree:add(f_cube_wheel2_enabled, (a >> 1) & 0x01)
    
    a=buffer(offset, 1):le_uint()
    subtree:add(f_cube_wheel3_enabled, (a >> 2) & 0x01)
    --offset = offset + 1
    subtree:add(f_cube_star_enabled, (a >> 3) & 0x01)
    --offset = offset + 1

    -- Parse GPS and Motor Driver enabled flags
    subtree:add(f_gps_receiver_enabled, (a >> 4) & 0x01)
    --offset = offset + 1
    -- Continue adding each field to the subtree with the appropriate offsets and bitfields

-- Define additional boolean fields for enabled flags and errors
subtree:add(f_gps_lna_power_enabled, (a >> 5) & 0x01)  -- GPS LNA Power Enabled
subtree:add(f_motor_driver_enabled, (a >> 6) & 0x01)  -- Motor Driver Enabled
subtree:add(f_sun_is_above_local_horizon, (a >> 7) & 0x01)  -- Sun is Above Local Horizon
offset = offset + 1

a = buffer(offset, 1):le_uint()
-- Communication error flags
subtree:add(f_cubesense1_comm_error, (a >> 0) & 0x01)  -- Cubesense1 Communications Error
subtree:add(f_cubesense2_comm_error, (a >> 1) & 0x01)  -- Cubesense2 Communications Error

a=buffer(offset, 1):le_uint()
subtree:add(f_cubcontrol_signal_comm_error, (a >> 2) & 0x01)  -- CubeControl Signal Communications Error


subtree:add(f_cubcontrol_motor_comm_error, (a >> 3) & 0x01)  -- CubeControl Motor Communications Error
subtree:add(f_cubewheel1_comm_error, (a >> 4) & 0x01)  -- Cube Wheel1 Communications Error
subtree:add(f_cubewheel2_comm_error, (a >> 5) & 0x01)  -- Cube Wheel2 Communications Error
subtree:add(f_cubewheel3_comm_error, (a >> 6) & 0x01)
subtree:add(f_cubestar_comm_error, (a >> 7) & 0x01)
offset = offset + 1
a=buffer(offset, 1):le_uint()

subtree:add(f_magnetometer_range_error, (a >> 0) & 0x01)  -- Magnetometer Range Error
--offset = offset + 1

-- Sensor errors
subtree:add(f_cam1_sram_overcurrent, (a >> 1) & 0x01)  -- Cam1 SRAM Overcurrent Detected

--offset = offset + 1
--offset = offset + 1
--a=buffer(offset,1):le_uint()
subtree:add(f_cam1_3v3_overcurrent, (a >> 2) & 0x01)  -- Cam1 3v3 Overcurrent Detected
subtree:add(f_cam1_sensor_busy, (a >> 3) & 0x01)  -- Cam1 Sensor Busy Error

subtree:add(f_cam1_sensor_detection_error, (a >> 4) & 0x01 )  -- Cam1 Sensor Detection Error


subtree:add(f_sun_sensor_range_error, (a >> 5) & 0x01)  -- Sun Sensor Range Error
subtree:add(f_cam2_sram_overcurrent, (a >> 6) & 0x01)  -- Cam2 SRAM Overcurrent Detected
subtree:add(f_cam2_3v3_overcurrent, (a >> 7) & 0x01)  -- Cam2 3v3 Overcurrent Detected
offset=offset+1
local data=buffer(offset, 1):le_uint()

subtree:add(f_cam2_sensor_busy, (data >> 0) & 0x01)  -- Cam2 Sensor Busy Error
--offset = offset + 1

subtree:add(f_cam2_sensor_detection_error, (data >> 1) & 0x01)  -- Cam2 Sensor Detection Error

--offset = offset + 1 
--local data = buffer(offset, 1):le_uint()
subtree:add(f_nadir_sensor_range_error, (data >> 2) & 0x01)  -- Nadir Sensor Range Error
subtree:add(f_rate_sensor_range_error, (data >> 3) & 0x01)  -- Rate Sensor Range Error

subtree:add(f_wheel_speed_range_error,(data >> 4) & 0x01)  -- Wheel Speed Range Error

-- Error flags for sensors and system issues
subtree:add(f_coarse_sun_sensor_error,(data >> 5) & 0x01)  -- Coarse Sun Sensor Error
subtree:add(f_star_tracker_match_error, (data >> 6) & 0x01)  -- Star Tracker Match Error
subtree:add(f_star_tracker_overcurrent, (data >> 7) & 0x01)  -- Star Tracker Overcurrent Detected
offset = offset + 1
 data = buffer(offset, 1):le_uint()

subtree:add(f_orbit_parameters_invalid, (data >> 0) & 0x01)  -- Orbit Parameters are Invalid
subtree:add(f_configuration_invalid,(data >> 1) & 0x01)  -- Configuration is Invalid

--offset = offset + 1
  --data = buffer(offset, 1):le_uint()
subtree:add(f_control_mode_change_not_allowed, (data >> 2) & 0x01)  -- Control Mode Change is Not Allowed
subtree:add(f_estimator_change_not_allowed, (data >> 3) & 0x01)  -- Estimator Change is Not Allowed

-- Magnetometer Sampling Mode (2 bits)

subtree:add(f_magnetometer_sampling_mode, (data >> 4) & 0x03)  -- Current Magnetometer Sampling Mode

-- Runtime error flags for sensors and systems
subtree:add(f_a, (data >> 6 ) & 0x01)  -- CubeSense1 Runtime Error
subtree:add(f_b, (data >> 7) & 0x01)  -- CubeSense2 Runtime Error
offset=offset+1
data = buffer(offset, 1):le_uint()

subtree:add(f_cubesense1_runtime_error, (data >> 0) & 0x01)  -- CubeSense1 Runtime Error
subtree:add(f_cubesense2_runtime_error, (data >> 1) & 0x01)  -- CubeSense2 Runtime Error
subtree:add(f_cubecontrol_signal_runtime_error, (data >> 2) & 0x01)  -- CubeControl Signal Runtime Error
subtree:add(f_cubecontrol_motor_runtime_error, (data >> 3) & 0x01)  -- CubeControl Motor Runtime Error
subtree:add(f_cubewheel1_runtime_error,(data >> 4) & 0x01)  -- CubeWheel1 Runtime Error
subtree:add(f_cubewheel2_runtime_error, (data >> 5) & 0x01)  -- CubeWheel2 Runtime Error
--offset = offset + 1

  --data = buffer(offset, 1):le_uint()
subtree:add(f_cubewheel3_runtime_error, (data >> 6) & 0x01)  -- CubeWheel3 Runtime Error
subtree:add(f_cubestar_runtime_error, (data >> 7) & 0x01)  -- CubeStar Runtime Error
offset=offset+1
data = buffer(offset, 1):le_uint()
-- Magnetometer and sensor errors
subtree:add(f_magnetometer_error, (data >> 0) & 0x01)  -- Magnetometer Error
subtree:add(f_rate_sensor_failure, (data >> 1) & 0x01)  -- Rate Sensor Failure

offset = offset + 1

   end 
end

function adcs_dissector_7(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

local f_operation_status = ProtoField.uint8("adcs_protocol.operation_status", "Operation Status", base.DEC)
local f_epoch_time = ProtoField.uint32("adcs_protocol.epoch_time", "Epoch Time", base.DEC)
local f_x_sun_vector = ProtoField.float("adcs_protocol.x_sun_vector", "X Sun Vector", base.DEC)
local f_y_sun_vector = ProtoField.float("adcs_protocol.y_sun_vector", "Y Sun Vector", base.DEC)
local f_z_sun_vector = ProtoField.float("adcs_protocol.z_sun_vector", "Z Sun Vector", base.DEC)

-- Register fields to the protocol
adcs_protocol.fields = { f_operation_status, f_epoch_time, f_x_sun_vector, f_y_sun_vector, f_z_sun_vector }

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
    
    for i = 0, num_of_instance - 1 do
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
    subtree:add(f_operation_status, buffer(offset, 1):le_uint())  -- 1 byte for Operation Status
    offset = offset + 1  -- Update offset

    -- Epoch Time (4 bytes, UINT)
    subtree:add(f_epoch_time, buffer(offset, 4):le_uint())  -- 4 bytes for Epoch Time
    offset = offset + 4  -- Update offset

    -- X-axis Sun Vector (2 bytes, INT) with scaling factor (RAWVAL * 0.001)
    local x_sun_vector_raw = buffer(offset, 2):le_int()  -- Read the 2-byte INT value
    local x_sun_vector = x_sun_vector_raw * 0.001  -- Apply scaling factor
    subtree:add(f_x_sun_vector, x_sun_vector)  -- Add to subtree with scaling
    offset = offset + 2  -- Update offset

    -- Y-axis Sun Vector (2 bytes, INT) with scaling factor (RAWVAL * 0.001)
    local y_sun_vector_raw = buffer(offset, 2):le_int()  -- Read the 2-byte INT value
    local y_sun_vector = y_sun_vector_raw * 0.001  -- Apply scaling factor
    subtree:add(f_y_sun_vector, y_sun_vector)  -- Add to subtree with scaling
    offset = offset + 2  -- Update offset

    -- Z-axis Sun Vector (2 bytes, INT) with scaling factor (RAWVAL * 0.001)
    local z_sun_vector_raw = buffer(offset, 2):le_int()  -- Read the 2-byte INT value
    local z_sun_vector = z_sun_vector_raw * 0.001  -- Apply scaling factor
    subtree:add(f_z_sun_vector, z_sun_vector)  -- Add to subtree with scaling
    offset = offset + 2  -- Update offset
    end
end

function adcs_dissector_8(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

local f_operation_status = ProtoField.uint8("adcs_protocol.operation_status", "Operation Status", base.DEC)
local f_epoch_time = ProtoField.uint32("adcs_protocol.epoch_time", "Epoch Time", base.DEC)
local f_css_ad_value_1 = ProtoField.uint8("myprotocol.css_ad_value_1", "Raw css 1 ", base.DEC)
local f_css_ad_value_2 = ProtoField.uint8("myprotocol.css_ad_value_2", "Raw css 2", base.DEC)
local f_css_ad_value_3 = ProtoField.uint8("myprotocol.css_ad_value_3", "Raw css 3", base.DEC)
local f_css_ad_value_4 = ProtoField.uint8("myprotocol.css_ad_value_4", "Raw css 4", base.DEC)
local f_css_ad_value_5 = ProtoField.uint8("myprotocol.css_ad_value_5", "Raw css 5", base.DEC)
local f_css_ad_value_6 = ProtoField.uint8("myprotocol.css_ad_value_6", "Raw css 6", base.DEC)
local f_css_ad_value_7 = ProtoField.uint8("myprotocol.css_ad_value_7", "Raw css 7", base.DEC)
local f_css_ad_value_8 = ProtoField.uint8("myprotocol.css_ad_value_8", "Raw css 8", base.DEC)
local f_css_ad_value_9 = ProtoField.uint8("myprotocol.css_ad_value_9", "Raw css 9", base.DEC)
local f_css_ad_value_10 = ProtoField.uint8("myprotocol.css_ad_value_10", "Raw css 10", base.DEC)



adcs_protocol.fields = { f_operation_status,
 f_epoch_time, f_css_ad_value_1,
    f_css_ad_value_2,
    f_css_ad_value_3,
    f_css_ad_value_4,
    f_css_ad_value_5,
    f_css_ad_value_6,
    f_css_ad_value_7,
    f_css_ad_value_8,
    f_css_ad_value_9,
    f_css_ad_value_10
 }

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
    
    for i = 0, num_of_instance - 1 do
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
    subtree:add(f_operation_status, buffer(offset, 1):le_uint())  -- 1 byte for Operation Status
    offset = offset + 1  -- Update offset

    -- Epoch Time (4 bytes, UINT)
    subtree:add(f_epoch_time, buffer(offset, 4):le_uint())  -- 4 bytes for Epoch Time
    offset = offset + 4  -- Update offset

    -- CSS A/D Values (10 individual uint8 fields)
    subtree:add(f_css_ad_value_1, buffer(offset, 1))
    offset = offset + 1  -- Update offset
    subtree:add(f_css_ad_value_2, buffer(offset, 1))
    offset = offset + 1  -- Update offset
    subtree:add(f_css_ad_value_3, buffer(offset, 1))
    offset = offset + 1  -- Update offset
    subtree:add(f_css_ad_value_4, buffer(offset, 1))
    offset = offset + 1  -- Update offset
    subtree:add(f_css_ad_value_5, buffer(offset, 1))
    offset = offset + 1  -- Update offset
    subtree:add(f_css_ad_value_6, buffer(offset, 1))
    offset = offset + 1  -- Update offset
    subtree:add(f_css_ad_value_7, buffer(offset, 1))
    offset = offset + 1  -- Update offset
    subtree:add(f_css_ad_value_8, buffer(offset, 1))
    offset = offset + 1  -- Update offset
    subtree:add(f_css_ad_value_9, buffer(offset, 1))
    offset = offset + 1  -- Update offset
    subtree:add(f_css_ad_value_10, buffer(offset, 1))
    offset = offset + 1
     end  
end
function adcs_dissector_9(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

-- Define the fields for the protocol
local f_operation_status = ProtoField.uint8("adcs_protocol.operation_status", "Operation Status", base.DEC)
local f_epoch_time = ProtoField.uint32("adcs_protocol.epoch_time", "Epoch Time", base.DEC)
local f_sun_x = ProtoField.float("adcs_protocol.sun_x", "FSS X axis vector ", base.DEC)
local f_sun_y = ProtoField.float("adcs_protocol.sun_y", "FSS y axis vector", base.DEC)
local f_sun_z = ProtoField.float("adcs_protocol.sun_z", "FSS z axis vector", base.DEC)

adcs_protocol.fields = {
    f_operation_status, f_epoch_time,
    f_sun_x, f_sun_y, f_sun_z }
    
local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
    
    for i = 0, num_of_instance - 1 do
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
    
    subtree:add(f_operation_status, buffer(offset, 1):le_uint())
    offset = offset + 1  -- Update offset

    -- Epoch Time (4 bytes, UINT)
    subtree:add(f_epoch_time, buffer(offset, 4):le_uint())
    offset = offset + 4  -- Update offset

    -- Sun X (2 bytes, INT, formatted as RAWVAL * 0.001)
    local raw_sun_x = buffer(offset, 2):le_int()
    local sun_x = raw_sun_x * 0.001
    subtree:add(f_sun_x, sun_x)
    offset = offset + 2  -- Update offset

    -- Sun Y (2 bytes, INT, formatted as RAWVAL * 0.001)
    local raw_sun_y = buffer(offset, 2):le_int()
    local sun_y = raw_sun_y * 0.001
    subtree:add(f_sun_y, sun_y)
    offset = offset + 2  -- Update offset

    -- Sun Z (2 bytes, INT, formatted as RAWVAL * 0.001)
    local raw_sun_z = buffer(offset, 2):le_int()
    local sun_z = raw_sun_z * 0.001
    subtree:add(f_sun_z, sun_z)
    offset = offset + 2  -- Update offs
    end
end
function adcs_dissector_10(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

local f_operation_status = ProtoField.uint8("adcs_protocol.operation_status", "Operation Status", base.DEC)
local f_epoch_time = ProtoField.uint32("adcs_protocol.epoch_time", "Epoch Time", base.DEC)
local f_fss_raw_x_angle = ProtoField.int16("adcs_protocol.fss_raw_x_angle", "FSS Raw X Angle", base.DEC)
local f_fss_raw_y_angle = ProtoField.int16("adcs_protocol.fss_raw_y_angle", "FSS Raw Y Angle", base.DEC)
local f_fss_capture_status = ProtoField.uint8("adcs_protocol.fss_capture_status", "FSS Capture Status", base.DEC)
local f_fss_detection_result = ProtoField.uint8("adcs_protocol.fss_detection_result", "FSS Detection Result", base.DEC)

-- Add the protocol fields to the protocol
adcs_protocol.fields = {
    f_operation_status,
    f_epoch_time,
    f_fss_raw_x_angle,
    f_fss_raw_y_angle,
    f_fss_capture_status,
    f_fss_detection_result
}

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
    
    for i = 0, num_of_instance - 1 do
local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
    subtree:add(f_operation_status, buffer(offset, 1):le_uint())
    offset = offset + 1  -- Update offset

    -- Epoch Time (4 bytes, UINT)
    subtree:add(f_epoch_time, buffer(offset, 4):le_uint())
    offset = offset + 4  -- Update offset

    -- FSS Raw X Angle (2 bytes, INT)
    subtree:add(f_fss_raw_x_angle, buffer(offset, 2):le_int())
    offset = offset + 2  -- Update offset

    -- FSS Raw Y Angle (2 bytes, INT)
    subtree:add(f_fss_raw_y_angle, buffer(offset, 2):le_int())
    offset = offset + 2  -- Update offset

    -- FSS Capture Status (1 byte, ENUM)
    local capture_status = buffer(offset, 1):le_uint()
    subtree:add(f_fss_capture_status, capture_status)
    --subtree:add_expert_info(PI_INFO, PI_WARN, "FSS Capture Status: " .. capture_status_enum[capture_status] or "Unknown")
    offset = offset + 1  -- Update offset

    -- FSS Detection Result (1 byte, ENUM)
    local detection_result = buffer(offset, 1):le_uint()
    subtree:add(f_fss_detection_result, detection_result)
    --subtree:add_expert_info(PI_INFO, PI_WARN, "FSS Detection Result: " .. detection_result_enum[detection_result] or "Unknown")
    offset = offset + 1  -- Update offset
   end 
end

function adcs_dissector_11(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)


local f_operation_status = ProtoField.uint8("adcs_protocol.operation_status", "Operation Status", base.DEC)
local f_epoch_time = ProtoField.uint32("adcs_protocol.epoch_time", "Epoch Time", base.DEC)
local f_x_axis_nadir_vector = ProtoField.int16("adcs_protocol.x_axis_nadir_vector", "X axis Nadir Vector ", base.DEC)
local f_y_axis_nadir_vector = ProtoField.int16("adcs_protocol.y_axis_nadir_vector", "Y axis Nadir Vector ", base.DEC)
local f_z_axis_nadir_vector = ProtoField.int16("adcs_protocol.z_axis_nadir_vector", "Z axis Nadir Vector ", base.DEC)

-- Add the protocol fields to the protocol
adcs_protocol.fields = {
    f_operation_status,
    f_epoch_time,
    f_x_axis_nadir_vector,
    f_y_axis_nadir_vector,
    f_z_axis_nadir_vector
}

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
    
    for i = 0, num_of_instance - 1 do
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
    subtree:add(f_operation_status, buffer(offset, 1):le_uint())
    offset = offset + 1  -- Update offset

    -- Epoch Time (4 bytes, UINT)
    subtree:add(f_epoch_time, buffer(offset, 4):le_uint())
    offset = offset + 4  -- Update offset

    -- X axis Nadir Vector (2 bytes, INT) *0.001 (formatted value)
    local x_axis_raw = buffer(offset, 2):le_int()
    local x_axis_nadir = x_axis_raw * 0.001  -- Apply the formatting to the raw value
    subtree:add(f_x_axis_nadir_vector, x_axis_raw)
    --subtree:add(PI_INFO, PI_WARN, string.format("X axis Nadir vector: %.3f", x_axis_nadir))
    offset = offset + 2  -- Update offset

    -- Y axis Nadir Vector (2 bytes, INT) *0.001 (formatted value)
    local y_axis_raw = buffer(offset, 2):le_int()
    local y_axis_nadir = y_axis_raw * 0.001  -- Apply the formatting to the raw value
    subtree:add(f_y_axis_nadir_vector, y_axis_raw)
    --subtree:add(PI_INFO, PI_WARN, string.format("Y axis Nadir vector: %.3f", y_axis_nadir))
    offset = offset + 2  -- Update offset

    -- Z axis Nadir Vector (2 bytes, INT) *0.001 (formatted value)
    local z_axis_raw = buffer(offset, 2):le_int()
    local z_axis_nadir = z_axis_raw * 0.001  -- Apply the formatting to the raw value
    subtree:add(f_z_axis_nadir_vector, z_axis_raw)
    --subtree:add(PI_INFO, PI_WARN, string.format("Z axis Nadir vector: %.3f", z_axis_nadir))
    offset = offset + 2  -- Update offset
    

    end
end

function adcs_dissector_12(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)


local f_operation_status = ProtoField.uint8("adcs_protocol.operation_status", "Operation Status", base.DEC)
local f_epoch_time = ProtoField.uint32("adcs_protocol.epoch_time", "Epoch Time", base.DEC)
local f_nadir_x_angle = ProtoField.int16("adcs_protocol.nadir_x_angle", "Nadir Sensor Raw X Angle", base.DEC)
local f_nadir_y_angle = ProtoField.int16("adcs_protocol.nadir_y_angle", "Nadir Sensor Raw Y Angle", base.DEC)
local f_nadir_capture_status = ProtoField.uint8("adcs_protocol.nadir_capture_status", "Nadir Sensor Capture Status", base.DEC)
local f_nadir_detection_result = ProtoField.uint8("adcs_protocol.nadir_detection_result", "Nadir Sensor Detection Result", base.DEC)

-- Add the protocol fields to the protocol
adcs_protocol.fields = {
    f_operation_status,
    f_epoch_time,
    f_nadir_x_angle,
    f_nadir_y_angle,
    f_nadir_capture_status,
    f_nadir_detection_result
}

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
    
    for i = 0, num_of_instance - 1 do
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
    subtree:add(f_operation_status, buffer(offset, 1):le_uint())
    offset = offset + 1  -- Update offset

    -- Epoch Time (4 bytes, UINT)
    subtree:add(f_epoch_time, buffer(offset, 4):le_uint())
    offset = offset + 4  -- Update offset

    -- Nadir Sensor Raw X Angle (2 bytes, INT)
    local x_raw = buffer(offset, 2):le_int()
    subtree:add(f_nadir_x_angle, x_raw)
    offset = offset + 2  -- Update offset

    -- Nadir Sensor Raw Y Angle (2 bytes, INT)
    local y_raw = buffer(offset, 2):le_int()
    subtree:add(f_nadir_y_angle, y_raw)
    offset = offset + 2  -- Update offset

    -- Nadir Sensor Capture Status (1 byte, ENUM)
    local capture_status = buffer(offset, 1):le_uint()
    subtree:add(f_nadir_capture_status, capture_status)
    offset = offset + 1  -- Update offset

    -- Nadir Sensor Detection Result (1 byte, ENUM)
    local detection_result = buffer(offset, 1):le_uint()
    subtree:add(f_nadir_detection_result, detection_result)
    offset = offset + 1 
    end
end

function adcs_dissector_13(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

local f_operation_status = ProtoField.uint8("magnetic_field_protocol.operation_status", "Operation Status", base.DEC)
local f_epoch_time = ProtoField.uint32("magnetic_field_protocol.epoch_time", "Epoch Time", base.DEC)
local f_magnetic_field_x = ProtoField.float("adcs_protocol.magnetic_field_x", "X Axis Magnetic Field Vector", base.DEC)
local f_magnetic_field_y = ProtoField.float("adcs_protocol.magnetic_field_y", "Y Axis Magnetic Field Vector", base.DEC)
local f_magnetic_field_z = ProtoField.float("adcs_protocol.magnetic_field_z", "Z Axis Magnetic Field Vector", base.DEC)

-- Add the protocol fields to the protocol
adcs_protocol.fields = {
    f_operation_status,
    f_epoch_time,
    f_magnetic_field_x,
    f_magnetic_field_y,
    f_magnetic_field_z
}

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
    
    for i = 0, num_of_instance - 1 do
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
    subtree:add(f_operation_status, buffer(offset, 1):le_uint())
    offset = offset + 1  -- Update offset

    -- Epoch Time (4 bytes, UINT)
    subtree:add(f_epoch_time, buffer(offset, 4):le_uint())
    offset = offset + 4  -- Update offset

    -- X Axis Magnetic Field Vector (2 bytes, INT)
    local x_field = buffer(offset, 2):le_int()  -- Apply the scaling factor (RAWVAL * 0.01)
    local x_field1 = x_field * 0.01
    subtree:add(f_magnetic_field_x, x_field1)
    offset = offset + 2  -- Update offset

    -- Y Axis Magnetic Field Vector (2 bytes, INT)
    local y_field = buffer(offset, 2):le_int() -- Apply the scaling factor (RAWVAL * 0.01)
    local y_field1 = y_field * 0.01
    subtree:add(f_magnetic_field_y, y_field1)
    offset = offset + 2  -- Update offset

    -- Z Axis Magnetic Field Vector (2 bytes, INT)
    local z_field = buffer(offset, 2):le_int()   -- Apply the scaling factor (RAWVAL * 0.01)
     local z_field1 = y_field * 0.01
    subtree:add(f_magnetic_field_z, z_field1)
    offset = offset + 2  -- Update offset
    end
    
end

function adcs_dissector_32(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    -- Define ProtoFields for each field in the structure
    local f_op_status = ProtoField.uint8("OperationData.op_status", "Operation Status", base.DEC)
    local f_epoch_time = ProtoField.uint32("OperationData.epoch_time", "Epoch Time", base.DEC)
    local f_eci_x_velocity = ProtoField.int16("OperationData.eci_x_velocity", "ECI Referenced X Velocity", base.DEC)
    local f_eci_y_velocity = ProtoField.int16("OperationData.eci_y_velocity", "ECI Referenced Y Velocity", base.DEC)
    local f_eci_z_velocity = ProtoField.int16("OperationData.eci_z_velocity", "ECI Referenced Z Velocity", base.DEC)

    -- Add the fields to the protocol
    adcs_protocol.fields = {
        f_op_status, f_epoch_time, f_eci_x_velocity, f_eci_y_velocity, f_eci_z_velocity
    }
    local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
for i = 0, num_of_instance - 1 do
    -- Add the operation data subtree
    local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
    -- dissect operation status (1 byte, UINT)
    local op_status = buffer(offset, 1):le_uint()
    subtree:add(f_op_status, op_status)
    offset = offset + 1

    -- dissect epoch time (4 bytes, UINT)
    local epoch_time = buffer(offset, 4):le_uint()
    subtree:add(f_epoch_time, epoch_time)
    offset = offset + 4

    -- dissect ECI X velocity (2 bytes, INT)
    local eci_x_velocity = buffer(offset, 2):le_int()
    subtree:add(f_eci_x_velocity, eci_x_velocity)
    offset = offset + 2

    -- dissect ECI Y velocity (2 bytes, INT)
    local eci_y_velocity = buffer(offset, 2):le_int()
    subtree:add(f_eci_y_velocity, eci_y_velocity)
    offset = offset + 2

    -- dissect ECI Z velocity (2 bytes, INT)
    local eci_z_velocity = buffer(offset, 2):le_int()
    subtree:add(f_eci_z_velocity, eci_z_velocity)
    offset = offset + 2
end
end
----------------------------------------------------------------------------------------------------------------
function adcs_dissector_31(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    -- Define ProtoFields for each field in the structure
    local f_op_status = ProtoField.uint8("OperationCoordinates.op_status", "Operation Status", base.DEC)
    local f_epoch_time = ProtoField.uint32("OperationCoordinates.epoch_time", "Epoch Time", base.DEC)
    local f_eci_x_coord = ProtoField.int16("OperationCoordinates.eci_x_coord", "ECI Referenced X Coordinate", base.DEC)
    local f_eci_y_coord = ProtoField.int16("OperationCoordinates.eci_y_coord", "ECI Referenced Y Coordinate", base.DEC)
    local f_eci_z_coord = ProtoField.int16("OperationCoordinates.eci_z_coord", "ECI Referenced Z Coordinate", base.DEC)

    -- Add the fields to the protocol
    adcs_protocol.fields = {
        f_op_status, f_epoch_time, f_eci_x_coord, f_eci_y_coord, f_eci_z_coord
    }
    
local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

	for i = 0, num_of_instance - 1 do
    -- Add the operation data coordinates subtree
    local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

    -- dissect operation status (1 byte, UINT)
    local op_status = buffer(offset, 1):le_uint()
    subtree:add(f_op_status, op_status)
    offset = offset + 1

    -- dissect epoch time (4 bytes, UINT)
    local epoch_time = buffer(offset, 4):le_uint()
    subtree:add(f_epoch_time, epoch_time)
    offset = offset + 4

    -- dissect ECI X coordinate (2 bytes, INT)
    local eci_x_coord = buffer(offset, 2):le_int()
    subtree:add(f_eci_x_coord, eci_x_coord)
    offset = offset + 2

    -- dissect ECI Y coordinate (2 bytes, INT)
    local eci_y_coord = buffer(offset, 2):le_int()
    subtree:add(f_eci_y_coord, eci_y_coord)
    offset = offset + 2

    -- dissect ECI Z coordinate (2 bytes, INT)
    local eci_z_coord = buffer(offset, 2):le_int()
    subtree:add(f_eci_z_coord, eci_z_coord)
    offset = offset + 2
end
end
-------------------------------------------------------------------------------------------------------------


-- Define the dissector function for the new structure
function adcs_dissector_30(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)


-- Define ProtoFields for the new structure fields
local f_op_status = ProtoField.uint8("PowerSystemData.op_status", "Operation Status", base.DES)
local f_epoch_time = ProtoField.uint32("PowerSystemData.epoch_time", "Epoch Time", base.DES)
local f_x_coord = ProtoField.int16("PowerSystemData.x_coord", "ECEF X Coordinate", base.DEC)
local f_y_coord = ProtoField.int16("PowerSystemData.y_coord", "ECEF Y Coordinate", base.DEC)
local f_z_coord = ProtoField.int16("PowerSystemData.z_coord", "ECEF Z Coordinate", base.DEC)

-- Add the fields to the protocol
adcs_protocol.fields = { 
    f_op_status, f_epoch_time, f_x_coord, f_y_coord, f_z_coord
}

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop through the data (data3 could represent the number of iterations or packets to dissect)
    for i = 0, num_of_instance - 1 do
        -- Add the new structure data as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect ECEF X coordinate (2 bytes)
        local x_coord = buffer(offset, 2):le_int()
        subtree:add(f_x_coord, x_coord)
        offset = offset + 2

        -- dissect ECEF Y coordinate (2 bytes)
        local y_coord = buffer(offset, 2):le_int()
        subtree:add(f_y_coord, y_coord)
        offset = offset + 2

        -- dissect ECEF Z coordinate (2 bytes)
        local z_coord = buffer(offset, 2):le_int()
        subtree:add(f_z_coord, z_coord)
        offset = offset + 2
    end
end
----------------------------------------------------------------------------------------------------------------------------------


-- Define the dissector function for the new structure
function adcs_dissector_22(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

-- Define ProtoFields for the new structure fields
local f_op_status = ProtoField.uint8("PowerSystemData.op_status", "Operation Status", base.DES)
local f_epoch_time = ProtoField.uint32("PowerSystemData.epoch_time", "Epoch Time", base.DES)
local f_roll_angle = ProtoField.int16("PowerSystemData.roll_angle", "Commanded Roll Angle (degrees)", base.DEC)
local f_pitch_angle = ProtoField.int16("PowerSystemData.pitch_angle", "Commanded Pitch Angle (degrees)", base.DEC)
local f_yaw_angle = ProtoField.int16("PowerSystemData.yaw_angle", "Commanded Yaw Angle (degrees)", base.DEC)

-- Add the fields to the protocol
adcs_protocol.fields = { 
    f_op_status, f_epoch_time, f_roll_angle, f_pitch_angle, f_yaw_angle
}

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop through the data (data3 could represent the number of iterations or packets to dissect)
   for i = 0, num_of_instance - 1 do
        -- Add the new structure data as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect commanded roll angle (2 bytes)
        local roll_angle_raw = buffer(offset, 2):le_int()
        local roll_angle = roll_angle_raw   -- Apply scaling factor
        subtree:add(f_roll_angle, roll_angle)
        offset = offset + 2

        -- dissect commanded pitch angle (2 bytes)
        local pitch_angle_raw = buffer(offset, 2):le_int()
        local pitch_angle = pitch_angle_raw  -- Apply scaling factor
        subtree:add(f_pitch_angle, pitch_angle)
        offset = offset + 2

        -- dissect commanded yaw angle (2 bytes)
        local yaw_angle_raw = buffer(offset, 2):le_int()
        local yaw_angle = yaw_angle_raw  -- Apply scaling factor
        subtree:add(f_yaw_angle, yaw_angle)
        offset = offset + 2
   end 
end
----------------------------------------------------------------------------------------------------------


-- Define the dissector function for the new structure

function adcs_dissector_29(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)


-- Define ProtoFields for the new structure fields
local f_op_status = ProtoField.uint8("PowerSystemData.op_status", "Operation Status", base.DES)
local f_epoch_time = ProtoField.uint32("PowerSystemData.epoch_time", "Epoch Time", base.DES)
local f_innovation_x = ProtoField.int16("PowerSystemData.innovation_x", "Innovation Vector X", base.DEC)
local f_innovation_y = ProtoField.int16("PowerSystemData.innovation_y", "Innovation Vector Y", base.DEC)
local f_innovation_z = ProtoField.int16("PowerSystemData.innovation_z", "Innovation Vector Z", base.DEC)

-- Add the fields to the protocol
adcs_protocol.fields = { 
    f_op_status, f_epoch_time, f_innovation_x, f_innovation_y, f_innovation_z
}

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop through the data (data3 could represent the number of iterations or packets to dissect)
    for i = 0,num_of_instance - 1 do
        -- Add the new structure data as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect innovation vector X (2 bytes)
        local innovation_x_raw = buffer(offset, 2):le_int()
        local innovation_x = innovation_x_raw   -- Apply scaling factor
        subtree:add(f_innovation_x, innovation_x)
        offset = offset + 2

        -- dissect innovation vector Y (2 bytes)
        local innovation_y_raw = buffer(offset, 2):le_int()
        local innovation_y = innovation_y_raw   -- Apply scaling factor
        subtree:add(f_innovation_y, innovation_y)
        offset = offset + 2

        -- dissect innovation vector Z (2 bytes)
        local innovation_z_raw = buffer(offset, 2):le_int()
        local innovation_z = innovation_z_raw   -- Apply scaling factor
        subtree:add(f_innovation_z, innovation_z)
        offset = offset + 2
end    
end
---------------------------------------------------------------------------------------------------


-- Define the dissector function for the new structure
function adcs_dissector_28(buffer, pinfo, tree, adcs_protocol, offset,num_of_instance)

-- Define ProtoFields for the new structure fields
local f_op_status = ProtoField.uint8("PowerSystemData.op_status", "Operation Status", base.DES)
local f_epoch_time = ProtoField.uint32("PowerSystemData.epoch_time", "Epoch Time", base.DES)
local f_x_gyro_bias = ProtoField.int16("PowerSystemData.x_gyro_bias", "Estimated X-Gyro Bias", base.DEC)
local f_y_gyro_bias = ProtoField.int16("PowerSystemData.y_gyro_bias", "Estimated Y-Gyro Bias", base.DEC)
local f_z_gyro_bias = ProtoField.int16("PowerSystemData.z_gyro_bias", "Estimated Z-Gyro Bias", base.DEC)

-- Add the fields to the protocol
adcs_protocol.fields = { 
    f_op_status, f_epoch_time, f_x_gyro_bias, f_y_gyro_bias, f_z_gyro_bias
}

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop through the data (data3 could represent the number of iterations or packets to dissect)
    for i = 0, num_of_instance - 1 do
        -- Add the new structure data as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect estimated x-gyro bias (2 bytes)
        local x_gyro_bias_raw = buffer(offset, 2):le_int()
        local x_gyro_bias = x_gyro_bias_raw   -- Apply scaling factor
        subtree:add(f_x_gyro_bias, x_gyro_bias)
        offset = offset + 2

        -- dissect estimated y-gyro bias (2 bytes)
        local y_gyro_bias_raw = buffer(offset, 2):le_int()
        local y_gyro_bias = y_gyro_bias_raw   -- Apply scaling factor
        subtree:add(f_y_gyro_bias, y_gyro_bias)
        offset = offset + 2

        -- dissect estimated z-gyro bias (2 bytes)
        local z_gyro_bias_raw = buffer(offset, 2):le_int()
        local z_gyro_bias = z_gyro_bias_raw   -- Apply scaling factor
        subtree:add(f_z_gyro_bias, z_gyro_bias)
        offset = offset + 2
    end
end
----------------------------------------------------------------------------------------------------------------------
--2.2.1.2.27	ADCS_HM_QUAT_ERR_VEC 26-27

-- Define the dissector function for the new structure
function adcs_dissector_27(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

-- Define ProtoFields for the new structure fields
local f_op_status = ProtoField.uint8("PowerSystemData.op_status", "Operation Status", base.DES)
local f_epoch_time = ProtoField.uint32("PowerSystemData.epoch_time", "Epoch Time", base.DES)
local f_q1_error = ProtoField.int16("PowerSystemData.q1_error", "Quaternion Error - Q1", base.DEC)
local f_q2_error = ProtoField.int16("PowerSystemData.q2_error", "Quaternion Error - Q2", base.DEC)
local f_q3_error = ProtoField.int16("PowerSystemData.q3_error", "Quaternion Error - Q3", base.DEC)

-- Add the fields to the protocol
adcs_protocol.fields = { 
    f_op_status, f_epoch_time, f_q1_error, f_q2_error, f_q3_error
}

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop through the data (data3 could represent the number of iterations or packets to dissect)
    for i = 0, num_of_instance - 1 do
        -- Add the new structure data as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect quaternion error Q1 (2 bytes)
        local q1_error_raw = buffer(offset, 2):le_int()
        local q1_error = q1_error_raw   -- Apply scaling factor
        subtree:add(f_q1_error, q1_error)
        offset = offset + 2

        -- dissect quaternion error Q2 (2 bytes)
        local q2_error_raw = buffer(offset, 2):le_int()
        local q2_error = q2_error_raw   -- Apply scaling factor
        subtree:add(f_q2_error, q2_error)
        offset = offset + 2

        -- dissect quaternion error Q3 (2 bytes)
        local q3_error_raw = buffer(offset, 2):le_int()
        local q3_error = q3_error_raw   -- Apply scaling factor
        subtree:add(f_q3_error, q3_error)
        offset = offset + 2
    end
end
-----------------------------------------------------------------------------------------------------------------------------
--2.2.1.2.26	ADCS_HM_IGRF_MOD_VEC 25-14

-- Define the dissector function for the new structure
function adcs_dissector_14(buffer, pinfo, tree, adcs_protocol, offset,num_of_instance)

-- Define ProtoFields for the new structure fields
local f_op_status = ProtoField.uint8("PowerSystemData.op_status", "Operation Status", base.DES)
local f_epoch_time = ProtoField.uint32("PowerSystemData.epoch_time", "Epoch Time", base.DES)
local f_x_magnetic_field = ProtoField.int16("PowerSystemData.x_magnetic_field", "X axis Modelled Magnetic Field Vector", base.DEC)
local f_y_magnetic_field = ProtoField.int16("PowerSystemData.y_magnetic_field", "Y axis Modelled Magnetic Field Vector", base.DEC)
local f_z_magnetic_field = ProtoField.int16("PowerSystemData.z_magnetic_field", "Z axis Modelled Magnetic Field Vector", base.DEC)

-- Add the fields to the protocol
adcs_protocol.fields = { 
    f_op_status, f_epoch_time, f_x_magnetic_field, f_y_magnetic_field, f_z_magnetic_field
}

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop through the data (data3 could represent the number of iterations or packets to dissect)
    for i = 0, num_of_instance - 1 do
        -- Add the new structure data as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect x-axis magnetic field vector (2 bytes)
        local x_magnetic_field_raw = buffer(offset, 2):le_int()
        local x_magnetic_field = x_magnetic_field_raw   -- Apply scaling factor
        subtree:add(f_x_magnetic_field, x_magnetic_field)
        offset = offset + 2

        -- dissect y-axis magnetic field vector (2 bytes)
        local y_magnetic_field_raw = buffer(offset, 2):le_int()
        local y_magnetic_field = y_magnetic_field_raw  -- Apply scaling factor
        subtree:add(f_y_magnetic_field, y_magnetic_field)
        offset = offset + 2

        -- dissect z-axis magnetic field vector (2 bytes)
        local z_magnetic_field_raw = buffer(offset, 2):le_int()
        local z_magnetic_field = z_magnetic_field_raw  -- Apply scaling factor
        subtree:add(f_z_magnetic_field, z_magnetic_field)
        offset = offset + 2
    end
end
---------------------------------------------------------------------------------------------------------------------
--2.2.1.2.25	ADCS_HM_POS_LLH 24-26

-- Define the dissector function for the new structure
function adcs_dissector_26(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

-- Define ProtoFields for the new structure fields
local f_op_status = ProtoField.uint8("PowerSystemData.op_status", "Operation Status", base.DES)
local f_epoch_time = ProtoField.uint32("PowerSystemData.epoch_time", "Epoch Time", base.DES)
local f_geo_longitude = ProtoField.int16("PowerSystemData.geo_longitude", "Geocentric Longitude", base.DEC)
local f_geo_latitude = ProtoField.int16("PowerSystemData.geo_latitude", "Geocentric Latitude", base.DEC)
local f_geo_altitude = ProtoField.int16("PowerSystemData.geo_altitude", "Geocentric Altitude", base.DEC)

-- Add the fields to the protocol
adcs_protocol.fields = { 
    f_op_status, f_epoch_time, f_geo_longitude, f_geo_latitude, f_geo_altitude
}

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop through the data (data3 could represent the number of iterations or packets to dissect)
    for i = 0, num_of_instance - 1 do
        -- Add the new structure data as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect geocentric longitude (2 bytes)
        local geo_longitude_raw = buffer(offset, 2):le_int()
        local geo_longitude = geo_longitude_raw   -- Apply scaling factor
        subtree:add(f_geo_longitude, geo_longitude)
        offset = offset + 2

        -- dissect geocentric latitude (2 bytes)
        local geo_latitude_raw = buffer(offset, 2):le_int()
        local geo_latitude = geo_latitude_raw   -- Apply scaling factor
        subtree:add(f_geo_latitude, geo_latitude)
        offset = offset + 2

        -- dissect geocentric altitude (2 bytes)
        local geo_altitude_raw = buffer(offset, 2):le_int()
        local geo_altitude = geo_altitude_raw   -- Apply scaling factor
        subtree:add(f_geo_altitude, geo_altitude)
        offset = offset + 2
    end
end
----------------------------------------------------------------------------------------------------------

--2.2.1.2.24	ADCS_HM_RAW_STAR_TRKR_MEAS 23-20

function adcs_dissector_20(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    -- Define ProtoFields for the updated structure fields
    local f_op_status = ProtoField.uint8("StarTrackerData.op_status", "Operation Status", base.DES)
    local f_epoch_time = ProtoField.uint32("StarTrackerData.epoch_time", "Epoch Time", base.DES)
    local f_num_stars_detected = ProtoField.uint8("StarTrackerData.num_stars_detected", "Number of Stars Detected", base.DES)
    local f_star_image_noise = ProtoField.uint8("StarTrackerData.star_image_noise", "Star Image Noise", base.DES)
    local f_invalid_star = ProtoField.uint8("StarTrackerData.invalid_star", "Invalid Star", base.DES)
    local f_num_stars_identified = ProtoField.uint8("StarTrackerData.num_stars_identified", "Number of Stars Identified", base.DES)
    local f_ident_mode = ProtoField.uint8("StarTrackerData.ident_mode", "Identification Mode", base.ENUM)
    local f_image_dark_value = ProtoField.uint8("StarTrackerData.image_dark_value", "Image Dark Value", base.DES)

    -- Define ProtoFields for flags (1 byte with individual boolean flags)
    local f_flags = ProtoField.uint8("StarTrackerData.flags", "Flags", base.HEX)

    -- Define ProtoFields for star confidence and magnitudes
    local f_star_conf_1 = ProtoField.uint8("StarTrackerData.star_conf_1", "Star 1 Confidence", base.PERCENT)
    local f_star_conf_2 = ProtoField.uint8("StarTrackerData.star_conf_2", "Star 2 Confidence", base.PERCENT)
    local f_star_conf_3 = ProtoField.uint8("StarTrackerData.star_conf_3", "Star 3 Confidence", base.PERCENT)

    -- Define ProtoFields for instrument magnitudes
    local f_instrument_mag_1 = ProtoField.uint16("StarTrackerData.instrument_mag_1", "Instrument Magnitude Star 1", base.DEC)
    local f_instrument_mag_2 = ProtoField.uint16("StarTrackerData.instrument_mag_2", "Instrument Magnitude Star 2", base.DEC)
    local f_instrument_mag_3 = ProtoField.uint16("StarTrackerData.instrument_mag_3", "Instrument Magnitude Star 3", base.DEC)

    -- Define ProtoFields for capture, detection, and identification
    local f_capture = ProtoField.uint16("StarTrackerData.capture", "Capture", base.DEC)
    local f_detection = ProtoField.uint16("StarTrackerData.detection", "Detection", base.DEC)
    local f_identification = ProtoField.uint16("StarTrackerData.identification", "Identification", base.DEC)

    -- Define ProtoFields for the estimated rates and attitudes (X, Y, Z axes, Q1, Q2, Q3)
    local f_est_rate_x = ProtoField.int16("StarTrackerData.est_rate_x", "Estimated Rate X-axis", base.DEC)
    local f_est_rate_y = ProtoField.int16("StarTrackerData.est_rate_y", "Estimated Rate Y-axis", base.DEC)
    local f_est_rate_z = ProtoField.int16("StarTrackerData.est_rate_z", "Estimated Rate Z-axis", base.DEC)

    local f_est_attitude_q1 = ProtoField.int16("StarTrackerData.est_attitude_q1", "Estimated Attitude Q1", base.DEC)
    local f_est_attitude_q2 = ProtoField.int16("StarTrackerData.est_attitude_q2", "Estimated Attitude Q2", base.DEC)
    local f_est_attitude_q3 = ProtoField.int16("StarTrackerData.est_attitude_q3", "Estimated Attitude Q3", base.DEC)

    -- Define ProtoFields for star catalog and centroid information
    local f_catalogue_number = ProtoField.uint16("StarTrackerData.catalogue_number", "Catalogue Number of Star", base.DEC)
    local f_x_centroid = ProtoField.int16("StarTrackerData.x_centroid", "X Centroid of Star", base.DEC)
    local f_y_centroid = ProtoField.int16("StarTrackerData.y_centroid", "Y Centroid of Star", base.DEC)

    -- Define ProtoField for sample period
    local f_sample_period = ProtoField.uint16("StarTrackerData.sample_period", "Sample Period", base.DEC)

    -- Add the fields to the protocol
    adcs_protocol.fields = {
        f_op_status, f_epoch_time, f_num_stars_detected, f_star_image_noise, f_invalid_star, 
        f_num_stars_identified, f_ident_mode, f_image_dark_value, f_flags, 
        f_star_conf_1, f_star_conf_2, f_star_conf_3,
        f_instrument_mag_1, f_instrument_mag_2, f_instrument_mag_3,
        f_capture, f_detection, f_identification, 
        f_est_rate_x, f_est_rate_y, f_est_rate_z, 
        f_est_attitude_q1, f_est_attitude_q2, f_est_attitude_q3, 
        f_catalogue_number, f_x_centroid, f_y_centroid, f_sample_period
    }
    
local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop through the data (data3 could represent the number of iterations or packets to dissect)
    for i = 0, num_of_instance - 1 do
        -- Add the new structure data as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect number of stars detected (1 byte)
        local num_stars_detected = buffer(offset, 1):le_uint()
        subtree:add(f_num_stars_detected, num_stars_detected)
        offset = offset + 1

        -- dissect star image noise (1 byte)
        local star_image_noise = buffer(offset, 1):le_uint()
        subtree:add(f_star_image_noise, star_image_noise)
        offset = offset + 1

        -- dissect invalid star (1 byte)
        local invalid_star = buffer(offset, 1):le_uint()
        subtree:add(f_invalid_star, invalid_star)
        offset = offset + 1

        -- dissect number of stars identified (1 byte)
        local num_stars_identified = buffer(offset, 1):le_uint()
        subtree:add(f_num_stars_identified, num_stars_identified)
        offset = offset + 1

        -- dissect identification mode (1 byte, enum)
        local ident_mode = buffer(offset, 1):le_uint()
        subtree:add(f_ident_mode, ident_mode)
        offset = offset + 1

        -- dissect image dark value (1 byte)
        local image_dark_value = buffer(offset, 1):le_uint()
        subtree:add(f_image_dark_value, image_dark_value)
        offset = offset + 1

        -- dissect flags (8 flags, 1 byte)
        local flags = buffer(offset, 1):le_uint()
        subtree:add(f_flags, flags) -- in this each bit represents a value
        offset = offset + 1

        -- dissect star confidences (1 byte each)
        local star_conf_1 = buffer(offset, 1):le_uint()
        subtree:add(f_star_conf_1, star_conf_1)
        offset = offset + 1
        local star_conf_2 = buffer(offset, 1):le_uint()
        subtree:add(f_star_conf_2, star_conf_2)
        offset = offset + 1
        local star_conf_3 = buffer(offset, 1):le_uint()
        subtree:add(f_star_conf_3, star_conf_3)
        offset = offset + 1

        -- dissect instrument magnitudes (2 bytes each)
        local instrument_mag_1 = buffer(offset, 2):le_uint()
        subtree:add(f_instrument_mag_1, instrument_mag_1)
        offset = offset + 2
        local instrument_mag_2 = buffer(offset, 2):le_uint()
        subtree:add(f_instrument_mag_2, instrument_mag_2)
        offset = offset + 2
        local instrument_mag_3 = buffer(offset, 2):le_uint()
        subtree:add(f_instrument_mag_3, instrument_mag_3)
        offset = offset + 2

        -- dissect capture, detection, and identification (2 bytes each)
        local capture = buffer(offset, 2):le_uint()
        subtree:add(f_capture, capture)
        offset = offset + 2
        local detection = buffer(offset, 2):le_uint()
        subtree:add(f_detection, detection)
        offset = offset + 2
        local identification = buffer(offset, 2):le_uint()
        subtree:add(f_identification, identification)
        offset = offset + 2

        -- dissect estimated rate X-axis, Y-axis, Z-axis (2 bytes each)
        local est_rate_x_raw = buffer(offset, 2):le_int()
        local est_rate_x = est_rate_x_raw -- Apply scaling factor
        subtree:add(f_est_rate_x, est_rate_x)
        offset = offset + 2

        local est_rate_y_raw = buffer(offset, 2):le_int()
        local est_rate_y = est_rate_y_raw -- Apply scaling factor
        subtree:add(f_est_rate_y, est_rate_y)
        offset = offset + 2

        local est_rate_z_raw = buffer(offset, 2):le_int()
        local est_rate_z = est_rate_z_raw -- Apply scaling factor
        subtree:add(f_est_rate_z, est_rate_z)
        offset = offset + 2

        -- dissect estimated attitude (Q1, Q2, Q3)
        local est_attitude_q1_raw = buffer(offset, 2):le_int()
        local est_attitude_q1 = est_attitude_q1_raw -- Apply scaling factor
        subtree:add(f_est_attitude_q1, est_attitude_q1)
        offset = offset + 2

        local est_attitude_q2_raw = buffer(offset, 2):le_int()
        local est_attitude_q2 = est_attitude_q2_raw -- Apply scaling factor
        subtree:add(f_est_attitude_q2, est_attitude_q2)
        offset = offset + 2

        local est_attitude_q3_raw = buffer(offset, 2):le_int()
        local est_attitude_q3 = est_attitude_q3_raw  -- Apply scaling factor
        subtree:add(f_est_attitude_q3, est_attitude_q3)
        offset = offset + 2

        -- dissect catalogue number (2 bytes)
        local catalogue_number = buffer(offset, 2):le_uint()
        subtree:add(f_catalogue_number, catalogue_number)
        offset = offset + 2

        -- dissect centroids (X, Y)
        local x_centroid = buffer(offset, 2):le_int()
        subtree:add(f_x_centroid, x_centroid)
        offset = offset + 2

        local y_centroid = buffer(offset, 2):le_int()
        subtree:add(f_y_centroid, y_centroid)
        offset = offset + 2

        -- dissect sample period (2 bytes)
        local sample_period = buffer(offset, 2):le_uint()
        subtree:add(f_sample_period, sample_period)
        offset = offset + 2
    end
end
-------------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------------------------
--2.2.1.2.22	ADCS_HM_MGTRQR_CMD 21-25

-- Define the dissector function for the Magnetorquer data
function adcs_dissector_25(buffer, pinfo, tree,adcs_protocol, offset, num_of_instance)
-- Define ProtoFields for the new structure fields
local f_op_status = ProtoField.uint8("MagnetorquerData.op_status", "Operation Status", base.DES)
local f_epoch_time = ProtoField.uint32("MagnetorquerData.epoch_time", "Epoch Time", base.DES)
local f_x_magnetorquer_time = ProtoField.int16("MagnetorquerData.x_magnetorquer_time", "X Magnetorquer Commanded On-time (10ms)", base.DEC)
local f_y_magnetorquer_time = ProtoField.int16("MagnetorquerData.y_magnetorquer_time", "Y Magnetorquer Commanded On-time (10ms)", base.DEC)
local f_z_magnetorquer_time = ProtoField.int16("MagnetorquerData.z_magnetorquer_time", "Z Magnetorquer Commanded On-time (10ms)", base.DEC)

-- Add the fields to the protocol
adcs_protocol.fields = {
    f_op_status, f_epoch_time, f_x_magnetorquer_time, f_y_magnetorquer_time, f_z_magnetorquer_time
}
local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

for i = 0,num_of_instance - 1 do
    -- Add the new structure data as a subtree
    local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

    -- dissect operation status (1 byte)
    local op_status = buffer(offset, 1):le_uint()
    subtree:add(f_op_status, op_status)
    offset = offset + 1

    -- dissect epoch time (4 bytes)
    local epoch_time = buffer(offset, 4):le_uint()
    subtree:add(f_epoch_time, epoch_time)
    offset = offset + 4

    -- dissect X Magnetorquer Commanded on-time (2 bytes)
    local x_magnetorquer_time = buffer(offset, 2):le_int()
    subtree:add(f_x_magnetorquer_time, x_magnetorquer_time)
    offset = offset + 2

    -- dissect Y Magnetorquer Commanded on-time (2 bytes)
    local y_magnetorquer_time = buffer(offset, 2):le_int()
    subtree:add(f_y_magnetorquer_time, y_magnetorquer_time)
    offset = offset + 2

    -- dissect Z Magnetorquer Commanded on-time (2 bytes)
    local z_magnetorquer_time = buffer(offset, 2):le_int()
    subtree:add(f_z_magnetorquer_time, z_magnetorquer_time)
    offset = offset + 2
end
end
-----------------------------------------------------------------------------------------
--2.2.1.2.21	ADCS_HM_RW_SPEED_CMD 20-24
-- Define the dissector function for the Reaction Wheel data
function adcs_dissector_24(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

-- Define ProtoFields for the new structure fields
local f_op_status = ProtoField.uint8("ReactionWheelData.op_status", "Operation Status", base.DES)
local f_epoch_time = ProtoField.uint32("ReactionWheelData.epoch_time", "Epoch Time", base.DES)
local f_num_reaction_wheels = ProtoField.uint8("ReactionWheelData.num_reaction_wheels", "Number of Reaction Wheels", base.DES)
local f_wheel_speed = ProtoField.uint16("ReactionWheelData.wheel_speed_", "Measured Wheel Speed ", base.DEC)
-- Define the ProtoField for the array of Measured Wheel Speeds (N = 3, each 2 bytes)

-- Add the fields to the protocol
adcs_protocol.fields = {
    f_op_status, f_epoch_time, f_num_reaction_wheels, f_wheel_speed
}
local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

for i = 0,num_of_instance - 1 do
    -- Add the new structure data as a subtree
    local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

    -- dissect operation status (1 byte)
    local op_status = buffer(offset, 1):le_uint()
    subtree:add(f_op_status, op_status)
    offset = offset + 1

    -- dissect epoch time (4 bytes)
    local epoch_time = buffer(offset, 4):le_uint()
    subtree:add(f_epoch_time, epoch_time)
    offset = offset + 4

    -- dissect number of reaction wheels (1 byte)
    local num_reaction_wheels = buffer(offset, 1):le_uint()
    subtree:add(f_num_reaction_wheels, num_reaction_wheels)
    offset = offset + 1

    -- dissect wheel speeds (array of N * 2 bytes, with N = 3)
    for i = 1, 3 do
        local wheel_speed = buffer(offset, 2):le_uint()
        subtree:add(f_wheel_speed, wheel_speed)
        offset = offset + 2
    end
end
end
-----------------------------------------------------------------------------------------------------------
--2.2.1.2.20	ADCS_HM_MEAS_RW_SPEED 19-23



-- Define the dissector function for the Reaction Wheel Commanded Speed data
function adcs_dissector_23(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

-- Define ProtoFields for the new structure fields
local f_op_status = ProtoField.uint8("ReactionWheelData.op_status", "Operation Status", base.DES)
local f_epoch_time = ProtoField.uint32("ReactionWheelData.epoch_time", "Epoch Time", base.DES)
local f_num_reaction_wheels = ProtoField.uint8("ReactionWheelData.num_reaction_wheels", "Number of Reaction Wheels", base.DES)
local f_wheel_speed_cmd = ProtoField.uint16("ReactionWheelData.wheel_speed_cmd_","Commanded Wheel Speed ", base.DEC)

-- Define the ProtoField for the array of Commanded Wheel Speeds (N = 3, each 2 bytes)

-- Add the fields to the protocol
adcs_protocol.fields = {
    f_op_status, f_epoch_time, f_num_reaction_wheels,f_wheel_speed_cmd
}

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

for i = 0, num_of_instance - 1 do

    -- Add the new structure data as a subtree
    local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

    -- dissect operation status (1 byte)
    local op_status = buffer(offset, 1):le_uint()
    subtree:add(f_op_status, op_status)
    offset = offset + 1

    -- dissect epoch time (4 bytes)
    local epoch_time = buffer(offset, 4):le_uint()
    subtree:add(f_epoch_time, epoch_time)
    offset = offset + 4

    -- dissect number of reaction wheels (1 byte)
    local num_reaction_wheels = buffer(offset, 1):le_uint()
    subtree:add(f_num_reaction_wheels, num_reaction_wheels)
    offset = offset + 1

    -- dissect commanded wheel speeds (array of N * 2 bytes, with N = 3)
    for i = 1, 3 do 				-- value 3 is fixed in structure
        local wheel_speed_cmd = buffer(offset, 2):le_uint()
        subtree:add(f_wheel_speed_cmd, wheel_speed_cmd)
        offset = offset + 2
    end
end
end

--------------------------------------------------------------------------------------------------------
--2.2.1.2.15	ADCS_HM_FINE_EST_ANG_RATES 14-19
-- Define the dissector function for the Fine Estimated Angular Rates Data
function adcs_dissector_19(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

-- Define ProtoFields for the Fine Estimated Angular Rates structure
local f_op_status = ProtoField.uint8("AngularRateData.op_status", "Operation Status", base.DES)
local f_epoch_time = ProtoField.uint32("AngularRateData.epoch_time", "Epoch Time", base.DES)
local f_x_angular_rate = ProtoField.int16("AngularRateData.x_angular_rate", "Fine Estimated X Angular Rate", base.DEC)
local f_y_angular_rate = ProtoField.int16("AngularRateData.y_angular_rate", "Fine Estimated Y Angular Rate", base.DEC)
local f_z_angular_rate = ProtoField.int16("AngularRateData.z_angular_rate", "Fine Estimated Z Angular Rate", base.DEC)

-- Add the fields to the protocol
adcs_protocol.fields = {
    f_op_status, f_epoch_time, f_x_angular_rate, f_y_angular_rate, f_z_angular_rate
}

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

for i = 0, num_of_instance - 1 do
    -- Add the Fine Estimated Angular Rates data as a subtree
    local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

    -- dissect operation status (1 byte)
    local op_status = buffer(offset, 1):le_uint()
    subtree:add(f_op_status, op_status)
    offset = offset + 1

    -- dissect epoch time (4 bytes)
    local epoch_time = buffer(offset, 4):le_uint()
    subtree:add(f_epoch_time, epoch_time)
    offset = offset + 4

    -- dissect Fine Estimated X Angular Rate (2 bytes, formatted value = RAWVAL*0.001)
    local x_angular_rate = buffer(offset, 2):le_int()
    subtree:add(f_x_angular_rate, x_angular_rate)
    offset = offset + 2

    -- dissect Fine Estimated Y Angular Rate (2 bytes, formatted value = RAWVAL*0.001)
    local y_angular_rate = buffer(offset, 2):le_int()
    subtree:add(f_y_angular_rate, y_angular_rate)
    offset = offset + 2

    -- dissect Fine Estimated Z Angular Rate (2 bytes, formatted value = RAWVAL*0.001)
    local z_angular_rate = buffer(offset, 2):le_int()
    subtree:add(f_z_angular_rate, z_angular_rate)
    offset = offset + 2
end
end
-----------------------------------------------------------------------------------------------------------
--2.2.1.2.13	ADCS_HM_RATE_SENSOR_TEMPERATURE
-- Define the dissector function for the Rate Sensor Temperature Data
function adcs_dissector_12(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

    -- Define ProtoFields for the structure (adjust names as per your needs)
    local f_op_status = ProtoField.uint8("RateSensorData.op_status", "Operation Status", base.HEX)
    local f_epoch_time = ProtoField.uint32("RateSensorData.epoch_time", "Epoch Time", base.DEC)
    local f_x_rate_temp = ProtoField.int16("RateSensorData.x_rate_temp", "X Rate Sensor Temperature", base.DEC)
    local f_y_rate_temp = ProtoField.int16("RateSensorData.y_rate_temp", "Y Rate Sensor Temperature", base.DEC)
    local f_z_rate_temp = ProtoField.int16("RateSensorData.z_rate_temp", "Z Rate Sensor Temperature", base.DEC)

    -- Add the fields to the protocol
    adcs_protocol.fields = {
        f_op_status, f_epoch_time, f_x_rate_temp, f_y_rate_temp, f_z_rate_temp
    }
    
    local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop to process multiple data3 (if needed, as per your structure)
    for i = 0, num_of_instance - 1 do
        -- Add the data structure as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect X Rate Sensor Temperature (2 bytes, formatted value = RAWVAL)
        local x_rate_temp = buffer(offset, 2):le_int()
        subtree:add(f_x_rate_temp, x_rate_temp)
        offset = offset + 2

        -- dissect Y Rate Sensor Temperature (2 bytes, formatted value = RAWVAL)
        local y_rate_temp = buffer(offset, 2):le_int()
        subtree:add(f_y_rate_temp, y_rate_temp)
        offset = offset + 2

        -- dissect Z Rate Sensor Temperature (2 bytes, formatted value = RAWVAL)
        local z_rate_temp = buffer(offset, 2):le_int()
        subtree:add(f_z_rate_temp, z_rate_temp)
        offset = offset + 2
    end
end
--------------------------------------------------------------------------------------------------------------------
--2.2.1.2.12	ADCS_HM_TEMPERATURE
-- Define the dissector function for the Sensor Temperature Data
function adcs_dissector_11(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

    -- Define ProtoFields for the structure (adjust names as needed)
    local f_op_status = ProtoField.uint8("SensorTemperatureData.op_status", "Operation Status", base.HEX)
    local f_epoch_time = ProtoField.uint32("SensorTemperatureData.epoch_time", "Epoch Time", base.DEC)
    local f_mcu_temp = ProtoField.int16("SensorTemperatureData.mcu_temp", "MCU Temperature", base.DEC)
    local f_mag_temp = ProtoField.int16("SensorTemperatureData.mag_temp", "Magnetometer Temperature", base.DEC)
    local f_red_mag_temp = ProtoField.int16("SensorTemperatureData.red_mag_temp", "Redundant Magnetometer Temperature", base.DEC)

    -- Add the fields to the protocol
    adcs_protocol.fields = {
        f_op_status, f_epoch_time, f_mcu_temp, f_mag_temp, f_red_mag_temp
    }

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop to process multiple data3 (if needed, as per your structure)
    for i = 0, num_of_instance - 1 do
        -- Add the data structure as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect MCU Temperature (2 bytes, formatted value = RAWVAL)
        local mcu_temp = buffer(offset, 2):le_int()
        subtree:add(f_mcu_temp, mcu_temp)
        offset = offset + 2

        -- dissect Magnetometer Temperature (2 bytes, formatted value = RAWVAL*0.1)
        local mag_temp = buffer(offset, 2):le_int()
        local formatted_mag_temp = mag_temp 
        subtree:add(f_mag_temp, formatted_mag_temp)
        offset = offset + 2

        -- dissect Redundant Magnetometer Temperature (2 bytes, formatted value = RAWVAL*0.1)
        local red_mag_temp = buffer(offset, 2):le_int()
        local formatted_red_mag_temp = red_mag_temp 
        subtree:add(f_red_mag_temp, formatted_red_mag_temp)
        offset = offset + 2
    end
end
----------------------------------------------------------------------------------------------------------------------
function adcs_dissector_21(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)

   local f_operation_status = ProtoField.uint32("adcs_protocol.operation_status", "Operation Status", base.DEC)
   local f_epoch_time = ProtoField.uint32("adcs_protocol.epoch_time", "Epoch Time", base.DEC)
   local f_mcu_temperature = ProtoField.int16("adcs_protocol.mcu_temperature", "MCU Temperature ", base.DEC)
   local f_magnetometer_temperature = ProtoField.int16("adcs_protocol.magnetometer_temperature", "Magnetometer Temperature ", base.DEC)
   local f_redundant_magnetometer_temperature = ProtoField.int16("adcs_protocol.redundant_magnetometer_temperature", "Redundant Magnetometer Temperature ", base.DEC)

-- Add the fields to the protocol
adcs_protocol.fields = { f_operation_status, f_epoch_time, f_mcu_temperature, f_magnetometer_temperature, f_redundant_magnetometer_temperature }

    local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")
    
    for i = 0, num_of_instance - 1 do
	local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)
	
    subtree:add(f_operation_status, buffer(offset, 1):le_uint())  -- 1 bytes for Operation Status (UINT)
    offset = offset + 1
    
    subtree:add(f_epoch_time, buffer(offset, 4):le_uint())        -- 4 bytes for Epoch Time (UINT)
    offset = offset + 4
    
    -- Extract raw values for the temperatures (2 bytes each for INT)
    local mcu_temp = buffer(offset, 2):le_uint() * 0.01
    offset = offset + 2
    
    local magnetometer_temp = buffer(offset, 2):le_uint() * 0.01
    offset = offset + 2
    
    local redundant_magnetometer_temp = buffer(offset, 2):le_uint() * 0.01
    offset = offset + 2
    
    -- Add the temperature values to the tree with scaling applied
    subtree:add(f_mcu_temperature, mcu_temp)
    subtree:add(f_magnetometer_temperature, magnetometer_temp)
    subtree:add(f_redundant_magnetometer_temperature, redundant_magnetometer_temp)
    end
end
---------------------------------------------------------------------------------------------------------------------------------------
function adcs_dissector_18(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    -- Define ProtoFields for the updated structure fields
    local f_op_status = ProtoField.uint8("StarTrackerData.op_status", "Operation Status", base.DES)
    local f_epoch_time = ProtoField.uint32("StarTrackerData.epoch_time", "Epoch Time", base.DES)
    local f_est_rate_x = ProtoField.int16("StarTrackerData.est_rate_x", "Estimated X Angular Rate", base.DEC)
    local f_est_rate_y = ProtoField.int16("StarTrackerData.est_rate_y", "Estimated Y Angular Rate", base.DEC)
    local f_est_rate_z = ProtoField.int16("StarTrackerData.est_rate_z", "Estimated Z Angular Rate", base.DEC)

    -- Add the fields to the protocol
    adcs_protocol.fields = {
        f_op_status, f_epoch_time, f_est_rate_x, f_est_rate_y, f_est_rate_z
    }

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop through the data (num_of_instance represents the number of instances to dissect)
    for i = 0, num_of_instance - 1 do
        -- Add the new structure data as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect estimated X angular rate (2 bytes)
        local est_rate_x_raw = buffer(offset, 2):le_int()
        local est_rate_x = est_rate_x_raw   -- Apply scaling factor
        subtree:add(f_est_rate_x, est_rate_x)
        offset = offset + 2

        -- dissect estimated Y angular rate (2 bytes)
        local est_rate_y_raw = buffer(offset, 2):le_int()
        local est_rate_y = est_rate_y_raw   -- Apply scaling factor
        subtree:add(f_est_rate_y, est_rate_y)
        offset = offset + 2

        -- dissect estimated Z angular rate (2 bytes)
        local est_rate_z_raw = buffer(offset, 2):le_int()
        local est_rate_z = est_rate_z_raw  -- Apply scaling factor
        subtree:add(f_est_rate_z, est_rate_z)
        offset = offset + 2
    end
end
------------------------------------------------------------------------------------------------
function adcs_dissector_17(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    -- Define ProtoFields for the updated structure fields
    local f_op_status = ProtoField.uint8("StarTrackerData.op_status", "Operation Status", base.DES)
    local f_epoch_time = ProtoField.uint32("StarTrackerData.epoch_time", "Epoch Time", base.DES)
    local f_raw_rate_x = ProtoField.int16("StarTrackerData.raw_rate_x", "X Axis Raw Rate Sensor Measurement", base.DEC)
    local f_raw_rate_y = ProtoField.int16("StarTrackerData.raw_rate_y", "Y Axis Raw Rate Sensor Measurement", base.DEC)
    local f_raw_rate_z = ProtoField.int16("StarTrackerData.raw_rate_z", "Z Axis Raw Rate Sensor Measurement", base.DEC)

    -- Add the fields to the protocol
    adcs_protocol.fields = {
        f_op_status, f_epoch_time, f_raw_rate_x, f_raw_rate_y, f_raw_rate_z
    }
    
local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop through the data (num_of_instance represents the number of instances to dissect)
    for i = 0, num_of_instance - 1 do
        -- Add the new structure data as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect X axis raw rate sensor measurement (2 bytes)
        local raw_rate_x = buffer(offset, 2):le_int()
        subtree:add(f_raw_rate_x, raw_rate_x)
        offset = offset + 2

        -- dissect Y axis raw rate sensor measurement (2 bytes)
        local raw_rate_y = buffer(offset, 2):le_int()
        subtree:add(f_raw_rate_y, raw_rate_y)
        offset = offset + 2

        -- dissect Z axis raw rate sensor measurement (2 bytes)
        local raw_rate_z = buffer(offset, 2):le_int()
        subtree:add(f_raw_rate_z, raw_rate_z)
        offset = offset + 2
    end
end
---------------------------------------------------------------------------------------------------------------
function adcs_dissector_16(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    -- Define ProtoFields for the updated structure fields
    local f_op_status = ProtoField.uint8("StarTrackerData.op_status", "Operation Status", base.DES)
    local f_epoch_time = ProtoField.uint32("StarTrackerData.epoch_time", "Epoch Time", base.DES)
    local f_measured_rate_x = ProtoField.int16("StarTrackerData.measured_rate_x", "Measured X Axis Rate", base.DEC)
    local f_measured_rate_y = ProtoField.int16("StarTrackerData.measured_rate_y", "Measured Y Axis Rate", base.DEC)
    local f_measured_rate_z = ProtoField.int16("StarTrackerData.measured_rate_z", "Measured Z Axis Rate", base.DEC)

    -- Add the fields to the protocol
    adcs_protocol.fields = {
        f_op_status, f_epoch_time, f_measured_rate_x, f_measured_rate_y, f_measured_rate_z
    }

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop through the data (num_of_instance represents the number of instances to dissect)
    for i = 0, num_of_instance - 1 do
        -- Add the new structure data as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect measured X axis rate (2 bytes), scaled by 0.01
        local measured_rate_x_raw = buffer(offset, 2):le_int()
        local measured_rate_x = measured_rate_x_raw  -- Apply scaling factor
        subtree:add(f_measured_rate_x, measured_rate_x)
        offset = offset + 2

        -- dissect measured Y axis rate (2 bytes), scaled by 0.01
        local measured_rate_y_raw = buffer(offset, 2):le_int()
        local measured_rate_y = measured_rate_y_raw  -- Apply scaling factor
        subtree:add(f_measured_rate_y, measured_rate_y)
        offset = offset + 2

        -- dissect measured Z axis rate (2 bytes), scaled by 0.01
        local measured_rate_z_raw = buffer(offset, 2):le_int()
        local measured_rate_z = measured_rate_z_raw  -- Apply scaling factor
        subtree:add(f_measured_rate_z, measured_rate_z)
        offset = offset + 2
    end
end
------------------------------------------------------------------------------------------------------------------

function adcs_dissector_15(buffer, pinfo, tree, adcs_protocol, offset, num_of_instance)
    -- Define ProtoFields for the updated structure fields
    local f_op_status = ProtoField.uint8("StarTrackerData.op_status", "Operation Status", base.DES)
    local f_epoch_time = ProtoField.uint32("StarTrackerData.epoch_time", "Epoch Time", base.DES)
    local f_raw_mag_x = ProtoField.int16("StarTrackerData.raw_mag_x", "Raw Magnetometer X Measurement", base.DEC)
    local f_raw_mag_y = ProtoField.int16("StarTrackerData.raw_mag_y", "Raw Magnetometer Y Measurement", base.DEC)
    local f_raw_mag_z = ProtoField.int16("StarTrackerData.raw_mag_z", "Raw Magnetometer Z Measurement", base.DEC)

    -- Add the fields to the protocol
    adcs_protocol.fields = {
        f_op_status, f_epoch_time, f_raw_mag_x, f_raw_mag_y, f_raw_mag_z
    }

local subtree1 = tree:add(adcs_protocol, buffer(), "ADCS")

    -- Loop through the data (num_of_instance represents the number of instances to dissect)
    for i = 0, num_of_instance - 1 do
        -- Add the new structure data as a subtree
        local subtree = subtree1:add(adcs_protocol, buffer(), "INSTANCE " ..i)

        -- dissect operation status (1 byte)
        local op_status = buffer(offset, 1):le_uint()
        subtree:add(f_op_status, op_status)
        offset = offset + 1

        -- dissect epoch time (4 bytes)
        local epoch_time = buffer(offset, 4):le_uint()
        subtree:add(f_epoch_time, epoch_time)
        offset = offset + 4

        -- dissect raw magnetometer X measurement (2 bytes)
        local raw_mag_x = buffer(offset, 2):le_int()
        subtree:add(f_raw_mag_x, raw_mag_x)
        offset = offset + 2

        -- dissect raw magnetometer Y measurement (2 bytes)
        local raw_mag_y = buffer(offset, 2):le_int()
        subtree:add(f_raw_mag_y, raw_mag_y)
        offset = offset + 2

        -- dissect raw magnetometer Z measurement (2 bytes)
        local raw_mag_z = buffer(offset, 2):le_int()
        subtree:add(f_raw_mag_z, raw_mag_z)
        offset = offset + 2
    end
end
--------------------------------------------------------------------------------------------------------

