56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/cosmos/microservices/interface_microservice.rb', line 56
def run
InterfaceTopic.receive_commands(@interface, scope: @scope) do |topic, msg_hash|
if topic =~ /CMD}INTERFACE/
if msg_hash['shutdown']
Logger.info "#{@interface.name}: Shutdown requested"
return
end
if msg_hash['connect']
Logger.info "#{@interface.name}: Connect requested"
@tlm.attempting()
next 'SUCCESS'
end
if msg_hash['disconnect']
Logger.info "#{@interface.name}: Disconnect requested"
@tlm.disconnect(false)
next 'SUCCESS'
end
if msg_hash['raw']
Logger.info "#{@interface.name}: Write raw"
command = System.commands.packet('UNKNOWN', 'UNKNOWN')
command.received_count += 1
command = command.clone
command.buffer = msg_hash['raw']
command.received_time = Time.now
CommandTopic.write_packet(command, scope: @scope)
@interface.write_raw(msg_hash['raw'])
next 'SUCCESS'
end
if msg_hash['inject_tlm']
Logger.info "#{@interface.name}: Inject telemetry" if msg_hash['log']
@tlm.inject_tlm(msg_hash)
next 'SUCCESS'
end
if msg_hash.key?('log_raw')
if msg_hash['log_raw'] == 'true'
Logger.info "#{@interface.name}: Enable raw logging"
@interface.start_raw_logging
else
Logger.info "#{@interface.name}: Disable raw logging"
@interface.stop_raw_logging
end
next 'SUCCESS'
end
end
target_name = msg_hash['target_name']
cmd_name = msg_hash['cmd_name']
cmd_params = nil
cmd_buffer = nil
hazardous_check = nil
if msg_hash['cmd_params']
cmd_params = JSON.parse(msg_hash['cmd_params'])
range_check = ConfigParser.handle_true_false(msg_hash['range_check'])
raw = ConfigParser.handle_true_false(msg_hash['raw'])
hazardous_check = ConfigParser.handle_true_false(msg_hash['hazardous_check'])
elsif msg_hash['cmd_buffer']
cmd_buffer = msg_hash['cmd_buffer']
end
begin
begin
if cmd_params
command = System.commands.build_cmd(target_name, cmd_name, cmd_params, range_check, raw)
elsif cmd_buffer
if target_name
command = System.commands.identify(cmd_buffer, [target_name])
else
command = System.commands.identify(cmd_buffer, @target_names)
end
unless command
command = System.commands.packet('UNKNOWN', 'UNKNOWN')
command.received_count += 1
command = command.clone
command.buffer = cmd_buffer
end
else
raise "Invalid command received:\n #{msg_hash}"
end
command.received_time = Time.now
rescue => e
Logger.error "#{@interface.name}: #{e.formatted}"
next e.message
end
if hazardous_check
hazardous, hazardous_description = System.commands.cmd_pkt_hazardous?(command)
next "HazardousError\n#{hazardous_description}\n#{System.commands.format(command)}" if hazardous
end
begin
@interface.write(command)
CommandTopic.write_packet(command, scope: @scope)
CommandDecomTopic.write_packet(command, scope: @scope)
InterfaceStatusModel.set(@interface.as_json, scope: @scope)
next 'SUCCESS'
rescue => e
Logger.error "#{@interface.name}: #{e.formatted}"
next e.message
end
rescue => e
Logger.error "#{@interface.name}: #{e.formatted}"
next e.message
end
end
end
|