Skip to content

Commit

Permalink
Add support for cmd/tlm partials #170
Browse files Browse the repository at this point in the history
  • Loading branch information
jmthomas committed Jul 16, 2015
1 parent 9042623 commit 2294ef2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 176 deletions.
81 changes: 9 additions & 72 deletions demo/config/targets/INST/cmd_tlm/inst_cmds.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
COMMAND INST COLLECT BIG_ENDIAN "Starts a collect on the instrument"
PARAMETER CCSDSVER 0 3 UINT 0 0 0 "CCSDS primary header version number"
PARAMETER CCSDSTYPE 3 1 UINT 1 1 1 "CCSDS primary header packet type"
PARAMETER CCSDSSHF 4 1 UINT 0 0 0 "CCSDS primary header secondary header flag"
ID_PARAMETER CCSDSAPID 5 11 UINT 0 2047 999 "CCSDS primary header application id"
PARAMETER CCSDSSEQFLAGS 16 2 UINT 3 3 3 "CCSDS primary header sequence flags"
PARAMETER CCSDSSEQCNT 18 14 UINT 0 16383 0 "CCSDS primary header sequence count"
OVERFLOW TRUNCATE
PARAMETER CCSDSLENGTH 32 16 UINT 0 65535 12 "CCSDS primary header packet length"
<%= render "_ccsds_cmd.txt" %>
ID_PARAMETER PKTID 48 16 UINT 0 65535 1 "Packet id"
PARAMETER TYPE 64 16 UINT 0 65535 0 "Collect type"
REQUIRED
Expand All @@ -19,37 +12,16 @@ COMMAND INST COLLECT BIG_ENDIAN "Starts a collect on the instrument"
UNITS Celcius C

COMMAND INST ABORT BIG_ENDIAN "Aborts a collect on the instrument"
PARAMETER CCSDSVER 0 3 UINT 0 0 0 "CCSDS primary header version number"
PARAMETER CCSDSTYPE 3 1 UINT 1 1 1 "CCSDS primary header packet type"
PARAMETER CCSDSSHF 4 1 UINT 0 0 0 "CCSDS primary header secondary header flag"
ID_PARAMETER CCSDSAPID 5 11 UINT 0 2047 999 "CCSDS primary header application id"
PARAMETER CCSDSSEQFLAGS 16 2 UINT 3 3 3 "CCSDS primary header sequence flags"
PARAMETER CCSDSSEQCNT 18 14 UINT 0 16383 0 "CCSDS primary header sequence count"
OVERFLOW TRUNCATE
PARAMETER CCSDSLENGTH 32 16 UINT 0 65535 1 "CCSDS primary header packet length"
<%= render "_ccsds_cmd.txt" %>
ID_PARAMETER PKTID 48 16 UINT 0 65535 2 "Packet id"

COMMAND INST CLEAR BIG_ENDIAN "Clears counters on the instrument"
HAZARDOUS "Clearing counters may lose valuable information."
PARAMETER CCSDSVER 0 3 UINT 0 0 0 "CCSDS primary header version number"
PARAMETER CCSDSTYPE 3 1 UINT 1 1 1 "CCSDS primary header packet type"
PARAMETER CCSDSSHF 4 1 UINT 0 0 0 "CCSDS primary header secondary header flag"
ID_PARAMETER CCSDSAPID 5 11 UINT 0 2047 999 "CCSDS primary header application id"
PARAMETER CCSDSSEQFLAGS 16 2 UINT 3 3 3 "CCSDS primary header sequence flags"
PARAMETER CCSDSSEQCNT 18 14 UINT 0 16383 0 "CCSDS primary header sequence count"
OVERFLOW TRUNCATE
PARAMETER CCSDSLENGTH 32 16 UINT 0 65535 1 "CCSDS primary header packet length"
<%= render "_ccsds_cmd.txt" %>
ID_PARAMETER PKTID 48 16 UINT 0 65535 3 "Packet id"

COMMAND INST SETPARAMS BIG_ENDIAN "Sets numbered parameters"
PARAMETER CCSDSVER 0 3 UINT 0 0 0 "CCSDS primary header version number"
PARAMETER CCSDSTYPE 3 1 UINT 1 1 1 "CCSDS primary header packet type"
PARAMETER CCSDSSHF 4 1 UINT 0 0 0 "CCSDS primary header secondary header flag"
ID_PARAMETER CCSDSAPID 5 11 UINT 0 2047 999 "CCSDS primary header application id"
PARAMETER CCSDSSEQFLAGS 16 2 UINT 3 3 3 "CCSDS primary header sequence flags"
PARAMETER CCSDSSEQCNT 18 14 UINT 0 16383 0 "CCSDS primary header sequence count"
OVERFLOW TRUNCATE
PARAMETER CCSDSLENGTH 32 16 UINT 0 65535 11 "CCSDS primary header packet length"
<%= render "_ccsds_cmd.txt" %>
ID_PARAMETER PKTID 48 16 UINT 0 65535 4 "Packet id"
MACRO_APPEND_START 1 5
APPEND_PARAMETER VALUE 16 UINT 0 5 0 "A value setting"
Expand All @@ -58,64 +30,29 @@ COMMAND INST SETPARAMS BIG_ENDIAN "Sets numbered parameters"
POLY_WRITE_CONVERSION 0 2

COMMAND INST ASCIICMD BIG_ENDIAN "Enumerated ASCII command"
PARAMETER CCSDSVER 0 3 UINT 0 0 0 "CCSDS primary header version number"
PARAMETER CCSDSTYPE 3 1 UINT 1 1 1 "CCSDS primary header packet type"
PARAMETER CCSDSSHF 4 1 UINT 0 0 0 "CCSDS primary header secondary header flag"
ID_PARAMETER CCSDSAPID 5 11 UINT 0 2047 999 "CCSDS primary header application id"
PARAMETER CCSDSSEQFLAGS 16 2 UINT 3 3 3 "CCSDS primary header sequence flags"
PARAMETER CCSDSSEQCNT 18 14 UINT 0 16383 0 "CCSDS primary header sequence count"
OVERFLOW TRUNCATE
PARAMETER CCSDSLENGTH 32 16 UINT 0 65535 257 "CCSDS primary header packet length"
<%= render "_ccsds_cmd.txt" %>
ID_PARAMETER PKTID 48 16 UINT 0 65535 5 "Packet id"
PARAMETER STRING 64 2048 STRING "NOOP" "Enumerated string parameter"
STATE "NOOP" "NOOP"
STATE "ARM LASER" "ARM LASER" HAZARDOUS "Arming the laser poses an eye safety hazard."
STATE "FIRE LASER" "FIRE LASER" HAZARDOUS "WARNING Laser will be fired!"

COMMAND INST FLTCMD BIG_ENDIAN "Command with float parameters"
PARAMETER CCSDSVER 0 3 UINT 0 0 0 "CCSDS primary header version number"
PARAMETER CCSDSTYPE 3 1 UINT 1 1 1 "CCSDS primary header packet type"
PARAMETER CCSDSSHF 4 1 UINT 0 0 0 "CCSDS primary header secondary header flag"
ID_PARAMETER CCSDSAPID 5 11 UINT 0 2047 999 "CCSDS primary header application id"
PARAMETER CCSDSSEQFLAGS 16 2 UINT 3 3 3 "CCSDS primary header sequence flags"
PARAMETER CCSDSSEQCNT 18 14 UINT 0 16383 0 "CCSDS primary header sequence count"
OVERFLOW TRUNCATE
PARAMETER CCSDSLENGTH 32 16 UINT 0 65535 13 "CCSDS primary header packet length"
<%= render "_ccsds_cmd.txt" %>
ID_PARAMETER PKTID 48 16 UINT 0 65535 6 "Packet id"
PARAMETER FLOAT32 64 32 FLOAT MIN_FLOAT32 MAX_FLOAT32 0.0 "Float32 parameter"
PARAMETER FLOAT64 96 64 FLOAT MIN_FLOAT64 MAX_FLOAT64 0.0 "Float64 parameter"

COMMAND INST ARYCMD BIG_ENDIAN "Command with array parameter"
PARAMETER CCSDSVER 0 3 UINT 0 0 0 "CCSDS primary header version number"
PARAMETER CCSDSTYPE 3 1 UINT 1 1 1 "CCSDS primary header packet type"
PARAMETER CCSDSSHF 4 1 UINT 0 0 0 "CCSDS primary header secondary header flag"
ID_PARAMETER CCSDSAPID 5 11 UINT 0 2047 999 "CCSDS primary header application id"
PARAMETER CCSDSSEQFLAGS 16 2 UINT 3 3 3 "CCSDS primary header sequence flags"
PARAMETER CCSDSSEQCNT 18 14 UINT 0 16383 0 "CCSDS primary header sequence count"
OVERFLOW TRUNCATE
PARAMETER CCSDSLENGTH 32 16 UINT 0 65535 81 "CCSDS primary header packet length"
<%= render "_ccsds_cmd.txt" %>
ID_PARAMETER PKTID 48 16 UINT 0 65535 6 "Packet id"
ARRAY_PARAMETER ARRAY 64 32 UINT -8 "Array parameter"
PARAMETER CRC -8 8 UINT 0 255 0 "CRC"

COMMAND INST SLRPNLDEPLOY BIG_ENDIAN "Deploy solar array panels"
PARAMETER CCSDSVER 0 3 UINT 0 0 0 "CCSDS primary header version number"
PARAMETER CCSDSTYPE 3 1 UINT 1 1 1 "CCSDS primary header packet type"
PARAMETER CCSDSSHF 4 1 UINT 0 0 0 "CCSDS primary header secondary header flag"
ID_PARAMETER CCSDSAPID 5 11 UINT 0 2047 999 "CCSDS primary header application id"
PARAMETER CCSDSSEQFLAGS 16 2 UINT 3 3 3 "CCSDS primary header sequence flags"
PARAMETER CCSDSSEQCNT 18 14 UINT 0 16383 0 "CCSDS primary header sequence count"
OVERFLOW TRUNCATE
PARAMETER CCSDSLENGTH 32 16 UINT 0 65535 1 "CCSDS primary header packet length"
<%= render "_ccsds_cmd.txt" %>
ID_PARAMETER PKTID 48 16 UINT 0 65535 8 "Packet id"

COMMAND INST SLRPNLRESET BIG_ENDIAN "Reset solar array panels"
PARAMETER CCSDSVER 0 3 UINT 0 0 0 "CCSDS primary header version number"
PARAMETER CCSDSTYPE 3 1 UINT 1 1 1 "CCSDS primary header packet type"
PARAMETER CCSDSSHF 4 1 UINT 0 0 0 "CCSDS primary header secondary header flag"
ID_PARAMETER CCSDSAPID 5 11 UINT 0 2047 999 "CCSDS primary header application id"
PARAMETER CCSDSSEQFLAGS 16 2 UINT 3 3 3 "CCSDS primary header sequence flags"
PARAMETER CCSDSSEQCNT 18 14 UINT 0 16383 0 "CCSDS primary header sequence count"
OVERFLOW TRUNCATE
PARAMETER CCSDSLENGTH 32 16 UINT 0 65535 1 "CCSDS primary header packet length"
<%= render "_ccsds_cmd.txt" %>
ID_PARAMETER PKTID 48 16 UINT 0 65535 9 "Packet id"
114 changes: 12 additions & 102 deletions demo/config/targets/INST/cmd_tlm/inst_tlm.txt
Original file line number Diff line number Diff line change
@@ -1,59 +1,41 @@
TELEMETRY INST HEALTH_STATUS BIG_ENDIAN "Health and status from the instrument"
ITEM CCSDSVER 0 3 UINT "CCSDS packet version number (See CCSDS 133.0-B-1)"
ITEM CCSDSTYPE 3 1 UINT "CCSDS packet type (command or telemetry)"
STATE TLM 0
STATE CMD 1
ITEM CCSDSSHF 4 1 UINT "CCSDS secondary header flag"
STATE FALSE 0
STATE TRUE 1
ID_ITEM CCSDSAPID 5 11 UINT 1 "CCSDS application process id"
ITEM CCSDSSEQFLAGS 16 2 UINT "CCSDS sequence flags"
STATE FIRST 1
STATE CONT 0
STATE LAST 2
STATE NOGROUP 3
ITEM CCSDSSEQCNT 18 14 UINT "CCSDS packet sequence count"
OVERFLOW TRUNCATE
ITEM CCSDSLENGTH 32 16 UINT "CCSDS packet data length"
ITEM TIMESEC 48 32 UINT "Seconds since epoch (January 1st, 1970, midnight)"
ITEM TIMEUS 80 32 UINT "Microseconds of second"
ID_ITEM PKTID 112 16 UINT 1 "Packet id (The combination of CCSDS_APID and PACKET_ID identify the packet)"
ITEM COLLECTS 128 16 UINT "Number of collects"
ITEM TEMP1 144 16 UINT "Temperature #1"
<%= render "_ccsds_tlm.txt" %>
APPEND_ITEM COLLECTS 16 UINT "Number of collects"
APPEND_ITEM TEMP1 16 UINT "Temperature #1"
POLY_READ_CONVERSION -100.0 0.00305
POLY_WRITE_CONVERSION 32768.885246 327.86885
UNITS CELCIUS C
FORMAT_STRING "%0.3f"
LIMITS DEFAULT 1 ENABLED -80.0 -70.0 60.0 80.0 -20.0 20.0
LIMITS TVAC 1 ENABLED -80.0 -30.0 30.0 80.0
LIMITS_RESPONSE example_limits_response.rb
ITEM TEMP2 160 16 UINT "Temperature #2"
APPEND_ITEM TEMP2 16 UINT "Temperature #2"
POLY_READ_CONVERSION -100.0 0.00305
POLY_WRITE_CONVERSION 32768.885246 327.86885
UNITS CELCIUS C
FORMAT_STRING "%0.3f"
LIMITS DEFAULT 1 ENABLED -60.0 -55.0 30.0 35.0
LIMITS TVAC 1 ENABLED -60.0 20.0 30.0 35.0
ITEM TEMP3 176 16 UINT "Temperature #3"
APPEND_ITEM TEMP3 16 UINT "Temperature #3"
POLY_READ_CONVERSION -100.0 0.00305
POLY_WRITE_CONVERSION 32768.885246 327.86885
UNITS CELCIUS C
FORMAT_STRING "%0.3f"
LIMITS DEFAULT 1 ENABLED -25.0 -10.0 50.0 55.0
LIMITS TVAC 1 ENABLED -15.0 -10.0 20.0 30.0
ITEM TEMP4 192 16 UINT "Temperature #4"
APPEND_ITEM TEMP4 16 UINT "Temperature #4"
POLY_READ_CONVERSION -100.0 0.00305
POLY_WRITE_CONVERSION 32768.885246 327.86885
UNITS CELCIUS C
FORMAT_STRING "%0.3f"
LIMITS DEFAULT 1 ENABLED -80.0 -70.0 60.0 80.0
ARRAY_ITEM ARY 208 8 UINT 80 "Array data"
APPEND_ARRAY_ITEM ARY 8 UINT 80 "Array data"
UNITS VOLTS V
APPEND_ITEM DURATION 32 FLOAT "Most recent collect duration"
APPEND_ITEM COLLECT_TYPE 16 UINT "Most recent collect type"
STATE NORMAL 0
STATE SPECIAL 1
APPEND_ARRAY_ITEM ARY2 64 FLOAT 640 "Double array"
APPEND_ARRAY_ITEM ARY2 64 FLOAT 640 "Double array"
UNITS CELCIUS C
APPEND_ITEM ASCIICMD 2048 STRING "Most recent ASCIICMD string"
STATE "NOOP" "NOOP"
Expand Down Expand Up @@ -88,25 +70,7 @@ TELEMETRY INST HEALTH_STATUS BIG_ENDIAN "Health and status from the instrument"

TELEMETRY INST ADCS BIG_ENDIAN "Position and attitude data"
META TYPE 'struct adcs'
ITEM CCSDSVER 0 3 UINT "CCSDS packet version number (See CCSDS 133.0-B-1)"
ITEM CCSDSTYPE 3 1 UINT "CCSDS packet type (command or telemetry)"
STATE TLM 0
STATE CMD 1
ITEM CCSDSSHF 4 1 UINT "CCSDS secondary header flag"
STATE FALSE 0
STATE TRUE 1
ID_ITEM CCSDSAPID 5 11 UINT 2 "CCSDS APPLICATION PROCESS ID"
ITEM CCSDSSEQFLAGS 16 2 UINT "CCSDS sequence flags"
STATE FIRST 1
STATE CONT 0
STATE LAST 2
STATE NOGROUP 3
ITEM CCSDSSEQCNT 18 14 UINT "CCSDS packet sequence count"
OVERFLOW TRUNCATE
ITEM CCSDSLENGTH 32 16 UINT "CCSDS packet data length"
ITEM TIMESEC 48 32 UINT "Seconds since epoch (January 1st, 1970, midnight)"
ITEM TIMEUS 80 32 UINT "Microseconds of second"
ID_ITEM PKTID 112 16 UINT 1 "Packet id (The combination of CCSDS_APID and PACKET_ID identify the packet)"
<%= render "_ccsds_tlm.txt" %>
ITEM POSX 128 32 FLOAT "Position X"
UNITS METERS M
ITEM POSY 160 32 FLOAT "Position Y"
Expand Down Expand Up @@ -153,25 +117,7 @@ TELEMETRY INST ADCS BIG_ENDIAN "Position and attitude data"
READ_CONVERSION unix_time_formatted_conversion.rb TIMESEC TIMEUS

TELEMETRY INST PARAMS BIG_ENDIAN "Params set by SETPARAMS command"
ITEM CCSDSVER 0 3 UINT "CCSDS packet version number (See CCSDS 133.0-B-1)"
ITEM CCSDSTYPE 3 1 UINT "CCSDS packet type (command or telemetry)"
STATE TLM 0
STATE CMD 1
ITEM CCSDSSHF 4 1 UINT "CCSDS secondary header flag"
STATE FALSE 0
STATE TRUE 1
ID_ITEM CCSDSAPID 5 11 UINT 3 "CCSDS application process id"
ITEM CCSDSSEQFLAGS 16 2 UINT "CCSDS sequence flags"
STATE FIRST 1
STATE CONT 0
STATE LAST 2
STATE NOGROUP 3
ITEM CCSDSSEQCNT 18 14 UINT "CCSDS packet sequence count"
OVERFLOW TRUNCATE
ITEM CCSDSLENGTH 32 16 UINT "CCSDS packet data length"
ITEM TIMESEC 48 32 UINT "Seconds since epoch (January 1st, 1970, midnight)"
ITEM TIMEUS 80 32 UINT "Microseconds of second"
ID_ITEM PKTID 112 16 UINT 1 "Packet id (The combination of CCSDS_APID and PACKET_ID identify the packet)"
<%= render "_ccsds_tlm.txt" %>
MACRO_APPEND_START 5 1
APPEND_ITEM Value 16 UINT "Value setting"
STATE GOOD 0 GREEN
Expand All @@ -184,25 +130,7 @@ TELEMETRY INST PARAMS BIG_ENDIAN "Params set by SETPARAMS command"
READ_CONVERSION unix_time_formatted_conversion.rb TIMESEC TIMEUS

TELEMETRY INST IMAGE BIG_ENDIAN "Packet with image data"
ITEM CCSDSVER 0 3 UINT "CCSDS packet version number (See CCSDS 133.0-B-1)"
ITEM CCSDSTYPE 3 1 UINT "CCSDS packet type (command or telemetry)"
STATE TLM 0
STATE CMD 1
ITEM CCSDSSHF 4 1 UINT "CCSDS secondary header flag"
STATE FALSE 0
STATE TRUE 1
ID_ITEM CCSDSAPID 5 11 UINT 4 "CCSDS application process id"
ITEM CCSDSSEQFLAGS 16 2 UINT "CCSDS sequence flags"
STATE FIRST 1
STATE CONT 0
STATE LAST 2
STATE NOGROUP 3
ITEM CCSDSSEQCNT 18 14 UINT "CCSDS packet sequence count"
OVERFLOW TRUNCATE
ITEM CCSDSLENGTH 32 16 UINT "CCSDS packet data length"
ITEM TIMESEC 48 32 UINT "Seconds since epoch (January 1st, 1970, midnight)"
ITEM TIMEUS 80 32 UINT "Microseconds of second"
ID_ITEM PKTID 112 16 UINT 1 "Packet id (The combination of CCSDS_APID and PACKET_ID identify the packet)"
<%= render "_ccsds_tlm.txt" %>
ITEM IMAGE 128 800 BLOCK "10x10 Image Data"
ITEM TIMESECONDS 0 0 DERIVED "Derived floating-point time since epoch in seconds"
READ_CONVERSION unix_time_seconds_conversion.rb TIMESEC TIMEUS
Expand All @@ -211,25 +139,7 @@ TELEMETRY INST IMAGE BIG_ENDIAN "Packet with image data"
READ_CONVERSION unix_time_formatted_conversion.rb TIMESEC TIMEUS

TELEMETRY INST MECH BIG_ENDIAN "Mechanism status"
ITEM CCSDSVER 0 3 UINT "CCSDS packet version number (See CCSDS 133.0-B-1)"
ITEM CCSDSTYPE 3 1 UINT "CCSDS packet type (command or telemetry)"
STATE TLM 0
STATE CMD 1
ITEM CCSDSSHF 4 1 UINT "CCSDS secondary header flag"
STATE FALSE 0
STATE TRUE 1
ID_ITEM CCSDSAPID 5 11 UINT 5 "CCSDS application process id"
ITEM CCSDSSEQFLAGS 16 2 UINT "CCSDS sequence flags"
STATE FIRST 1
STATE CONT 0
STATE LAST 2
STATE NOGROUP 3
ITEM CCSDSSEQCNT 18 14 UINT "CCSDS packet sequence count"
OVERFLOW TRUNCATE
ITEM CCSDSLENGTH 32 16 UINT "CCSDS packet data length"
ITEM TIMESEC 48 32 UINT "Seconds since epoch (January 1st, 1970, midnight)"
ITEM TIMEUS 80 32 UINT "Microseconds of second"
ID_ITEM PKTID 112 16 UINT 1 "Packet id (The combination of CCSDS_APID and PACKET_ID identify the packet)"
<%= render "_ccsds_tlm.txt" %>
APPEND_ITEM SLRPNL1 32 FLOAT "Solar panel 1 angle"
UNITS DEGREES DEG
APPEND_ITEM SLRPNL2 32 FLOAT "Solar panel 2 angle"
Expand Down
19 changes: 18 additions & 1 deletion lib/cosmos/config/config_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# attribution addendums as found in the LICENSE.txt

require 'cosmos/ext/config_parser'
require 'erb'

module Cosmos

Expand Down Expand Up @@ -143,6 +144,12 @@ def error(message, usage = "", url = @url)
return Error.new(self, message, usage, url)
end

# Called by the ERB template to render a partial
def render(template_name)
# Assume the file is there. If not we raise a pretty obvious error
File.read(File.join(File.dirname(@filename), template_name))
end

# Processes a file and yields |config| to the given block
#
# @param filename [String] The full name and path of the configuration file
Expand All @@ -158,7 +165,10 @@ def parse_file(filename,
remove_quotes = true,
&block)
@filename = filename
file = File.new(@filename, 'r')
# Create a temp file where we can write the ERB parsed output
file = Tempfile.new("parsed_#{File.basename(filename)}")
file.write(ERB.new(File.read(@filename)).result(binding))
file.rewind
begin
size = file.stat.size.to_f

Expand All @@ -173,6 +183,13 @@ def parse_file(filename,
size,
PARSING_REGEX,
&block)
rescue => e
# If we had an error parsing write out the parsed results for debugging
File.open(File.join(File.dirname(@filename), "parsed_#{File.basename(filename)}"), 'w') do |save_file|
file.rewind
save_file.write file.read
raise e
end
ensure
file.close unless file.closed?
end
Expand Down
3 changes: 2 additions & 1 deletion lib/cosmos/system/target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ def add_all_cmd_tlm(dir)
if Dir.exist?(File.join(dir, 'cmd_tlm'))
# Only grab *.txt files in the root of the cmd_tlm folder
Dir[File.join(dir, 'cmd_tlm', '*.txt')].each do |filename|
cmd_tlm_files << filename
# Don't add partial files which begin with '_'
cmd_tlm_files << filename unless filename[0] == '_'
end
end
cmd_tlm_files.sort!
Expand Down

0 comments on commit 2294ef2

Please sign in to comment.