Class: OpenC3::PacketBase

Inherits:
Object show all
Defined in:
lib/openc3/microservices/trigger_group_microservice.rb

Overview

Stored in the TriggerGroupShare this should be a thread safe hash that triggers will be added, updated, and removed from

Instance Method Summary collapse

Constructor Details

#initialize(scope:) ⇒ PacketBase

Returns a new instance of PacketBase.



37
38
39
40
41
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 37

def initialize(scope:)
  @scope = scope
  @mutex = Mutex.new
  @packets = Hash.new
end

Instance Method Details

#add(topic:, packet:) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 61

def add(topic:, packet:)
  @mutex.synchronize do
    @packets[topic] ||= []
    if @packets[topic].length == 2
      @packets[topic].shift
    end
    @packets[topic].push(packet)
  end
end

#packet(target:, packet:) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 43

def packet(target:, packet:)
  topic = "#{@scope}__DECOM__{#{target}}__#{packet}"
  @mutex.synchronize do
    return nil unless @packets[topic]
    # Deep copy the packet so it doesn't change under us
    return Marshal.load( Marshal.dump(@packets[topic][-1]) )
  end
end

#previous_packet(target:, packet:) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 52

def previous_packet(target:, packet:)
  topic = "#{@scope}__DECOM__{#{target}}__#{packet}"
  @mutex.synchronize do
    return nil unless @packets[topic] and @packets[topic].length == 2
    # Deep copy the packet so it doesn't change under us
    return Marshal.load( Marshal.dump(@packets[topic][0]) )
  end
end

#remove(topic:) ⇒ Object



71
72
73
74
75
# File 'lib/openc3/microservices/trigger_group_microservice.rb', line 71

def remove(topic:)
  @mutex.synchronize do
    @packets.delete(topic)
  end
end