You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a script that is continually running logging telemetry. I have a specific telemetry message that indicates an error that can be sent randomly. I would like to check for this message and if it appears print it, otherwise the script keeps looping printing out the other telemetry. Doesn't seem like I can do this though. It may just be my limited Ruby blocking me.
Example code,
loop do
# do a bunch of telemetry wait_check_packet commands here
# at the end see if we got any error messages as well
begin
if (wait_packet("#{target}", 'ERROR_MSG', 1, 5))
cmd = tlm("#{target} ERROR_MSG CMD")
line = tlm("#{target} ERROR_MSG LINE")
err = tlm("#{target} ERROR_MSG ERROR")
puts "!!! ERROR_MSG Received !!!"
puts "CMD : #{cmd} ... LINE : #{line} ... ERROR : #{err}"
end
end
If one message was ever received in the past this will just continue to print out the contents of that message every iteration; which I understand is why wait_check_packet is typically used but doesn't seem appropriate in this use case. I tried placing a not in front of wait_packet and it just always ignores it.
EDIT : Forgot to mention I am locked into using a legacy version of COSMOS, v4.3.0
The text was updated successfully, but these errors were encountered:
It looks like the issue you're facing is that once you receive an error message, it continues to get printed in every iteration of the loop. One way to solve this issue would be to introduce a flag that gets set to true when an error message is received and gets reset to false once it has been printed.
Here's an example code that uses a received_error flag to accomplish this:
`received_error = false
loop do
do a bunch of telemetry wait_check_packet commands here
at the end see if we got any error messages as well
if wait_packet("#{target}", 'ERROR_MSG', 1, 5)
cmd = tlm("#{target} ERROR_MSG CMD")
line = tlm("#{target} ERROR_MSG LINE")
err = tlm("#{target} ERROR_MSG ERROR")
if !received_error
puts "!!! ERROR_MSG Received !!!"
puts "CMD : #{cmd} ... LINE : #{line} ... ERROR : #{err}"
received_error = true
end
else
received_error = false
end
end
`
In this code, we initialize received_error to false before entering the loop. When an error message is received, we check if received_error is false. If it is, we print the error message and set received_error to true. If it is true, we skip printing the error message. In each iteration, we also check if an error message was not received (wait_packet returns false) and reset received_error to false. This way, we only print the error message once when it first appears and avoid printing it in every iteration of the loop.
I have a script that is continually running logging telemetry. I have a specific telemetry message that indicates an error that can be sent randomly. I would like to check for this message and if it appears print it, otherwise the script keeps looping printing out the other telemetry. Doesn't seem like I can do this though. It may just be my limited Ruby blocking me.
Example code,
If one message was ever received in the past this will just continue to print out the contents of that message every iteration; which I understand is why
wait_check_packet
is typically used but doesn't seem appropriate in this use case. I tried placing anot
in front ofwait_packet
and it just always ignores it.EDIT : Forgot to mention I am locked into using a legacy version of COSMOS, v4.3.0
The text was updated successfully, but these errors were encountered: