Skip to content

Commit

Permalink
Merge pull request #44 from jphickey/fix-38-ctf-json
Browse files Browse the repository at this point in the history
Fix #38, add ctf json output products
  • Loading branch information
dzbaker authored Mar 16, 2023
2 parents a078b29 + 792a6c5 commit 220185c
Show file tree
Hide file tree
Showing 3 changed files with 301 additions and 48 deletions.
55 changes: 7 additions & 48 deletions cfecfs/missionlib/eds/75-cfe_sb_dispatch_tables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ local mts_comp = SEDS.root:find_reference("CFE_SB/MTS", "COMPONENT")
local components = {}
local msgid_table = {}
local topicid_table = {}
local intf_commands = {}
local total_intfs = {}
local interface_list = {}
local indication_id = 0
Expand Down Expand Up @@ -128,7 +127,6 @@ end
for ds in SEDS.root:iterate_children(SEDS.basenode_filter) do
local first_intf = 1 + #total_intfs
local hdrout = SEDS.output_open(SEDS.to_filename("interface.h", ds.name),ds.xml_filename)
local cmdcode_list = {}
hdrout:write(string.format("#include \"%s\"", SEDS.to_filename("typedefs.h", ds.name)))
hdrout:add_whitespace(1)

Expand All @@ -155,8 +153,7 @@ for ds in SEDS.root:iterate_children(SEDS.basenode_filter) do
end
end

intfcmds[1 + #intfcmds] = { intf = reqintf, refnode = cmd, args = args,
subcommand_arg = subcommand_arg }
intfcmds[1 + #intfcmds] = { refnode = cmd, args = args, subcommand_arg = subcommand_arg }

local compcmds = localintfs[reqintf.type]
if (not compcmds) then
Expand Down Expand Up @@ -198,25 +195,9 @@ for ds in SEDS.root:iterate_children(SEDS.basenode_filter) do
hdrout:write(string.format("typedef struct %s %s;", cmdstructname, reqintf.mapping_info.cmdstruct_typedef))
hdrout:add_whitespace(1)
end
intf_commands[reqintf] = intfcmds
for _,cmd in ipairs(intfcmds) do
if (cmd.subcommand_arg) then
local argtype = cmd.args[cmd.subcommand_arg].type
for _,subcommand in ipairs(argtype.edslib_derivtable_list) do
-- Note that this list is not in value-order, the index relates to the lookup table, not the actual cmdcode value
-- To get the command code value, need to drill down into the constraint set. This assumes a single value constraint.
local cmdname = subcommand:get_flattened_name()
local constraint = subcommand:find_first("CONSTRAINT_SET")
if (constraint) then
constraint = constraint:find_first("VALUE_CONSTRAINT")
end
if (constraint) then
cmdcode_list[constraint.attributes["value"]] = cmdname
end
end
end
end
reqintf.intf_commands = intfcmds
hdrout:add_whitespace(1)

end
local sorted_localintfs = {}
for intf in pairs(localintfs) do
Expand Down Expand Up @@ -248,29 +229,6 @@ for ds in SEDS.root:iterate_children(SEDS.basenode_filter) do

SEDS.output_close(hdrout)

-- Create a "cc.h" header file containing the command/function codes specificed as EDS value constraints
-- This info was collected above, but is easier to use in C files if not mixed with the interface declarations
-- It also needs to be put in a reasonable order and the macro names need to be scrubbed/fixed to match
local all_cmdcodes = {}
for cc in pairs(cmdcode_list) do
all_cmdcodes[1 + #all_cmdcodes] = cc
end
if (#all_cmdcodes > 0) then
table.sort(all_cmdcodes)
hdrout = SEDS.output_open(SEDS.to_filename("cc.h", ds.name),ds.xml_filename)
for _,cc in ipairs(all_cmdcodes) do
local cmdname = cmdcode_list[cc]
local macroname = SEDS.to_macro_name(cmdname)
-- If the command name ends in "_CMD" then lop it off
if (string.sub(macroname, -4, -1) == "_CMD") then
macroname = string.sub(macroname, 1, -5)
end
hdrout:add_documentation(string.format("Command code associated with %s_t", cmdname))
hdrout:write(string.format("#define %-60s %s", macroname .. "_CC", cc))
end
SEDS.output_close(hdrout)
end

hdrout = SEDS.output_open(SEDS.to_filename("dispatcher.h", ds.name), ds.xml_filename)
hdrout:write(string.format("#include \"cfe_msg_dispatcher.h\""))
hdrout:write(string.format("#include \"%s\"", SEDS.to_filename("interfacedb.h", global_sym_prefix)))
Expand Down Expand Up @@ -365,8 +323,9 @@ for tid = 1,SEDS.get_define("CFE_MISSION/MAX_TOPICID") do
local chain = topicid_table[tid]
if (chain) then
local intf = chain.binding.reqintf
local cmdlist = intf.intf_commands or {}
local arg_list = {}
for j,cmd in ipairs(intf_commands[intf]) do
for j,cmd in ipairs(cmdlist) do
if (#cmd.args > 0) then
arg_list[j] = string.format("%s_%s_ARGUMENT_LIST",intf:get_flattened_name(), cmd.refnode.name)
dbout:write(string.format("static const CFE_MissionLib_Argument_Entry_t %s[] =", arg_list[j]))
Expand All @@ -384,7 +343,7 @@ for tid = 1,SEDS.get_define("CFE_MISSION/MAX_TOPICID") do
end
end

for j,cmd in ipairs(intf_commands[intf]) do
for j,cmd in ipairs(cmdlist) do
if (cmd.subcommand_arg) then
local derivlist = cmd.args[cmd.subcommand_arg].type.edslib_derivtable_list
dbout:write(string.format("static const CFE_MissionLib_Subcommand_Entry_t %s_%s_SUBCOMMAND_LIST[] =",
Expand All @@ -405,7 +364,7 @@ for tid = 1,SEDS.get_define("CFE_MISSION/MAX_TOPICID") do
local cmd_def = string.format("%s_COMMANDS",intf:get_flattened_name())
dbout:write(string.format("static const CFE_MissionLib_Command_Definition_Entry_t %s[] =",cmd_def))
dbout:start_group("{")
for j,cmd in ipairs(intf_commands[intf]) do
for j,cmd in ipairs(cmdlist) do
dbout:append_previous(",")
dbout:start_group("{")
if (cmd.subcommand_arg) then
Expand Down
96 changes: 96 additions & 0 deletions cfecfs/missionlib/eds/85-write_commandcode_headers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
--
-- LEW-19710-1, CCSDS SOIS Electronic Data Sheet Implementation
--
-- Copyright (c) 2020 United States Government as represented by
-- the Administrator of the National Aeronautics and Space Administration.
-- All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--


-- -------------------------
-- MAIN ROUTINE
-- -------------------------

for ds in SEDS.root:iterate_children(SEDS.basenode_filter) do

-- Note that each interface under the component could have its own separate set of command codes,
-- but most have just one. The goal is to combine all the cc's into a single header file.

local ds_all_subcmds = {}
local ds_cmdcode_lookup = {}

for comp in ds:iterate_subtree("COMPONENT") do
-- Locate all required intfs under this component that utilize subcommand/function codes
for reqintf in comp:iterate_subtree("REQUIRED_INTERFACE") do
for _,cmd in ipairs(reqintf.intf_commands or {}) do

if (cmd.subcommand_arg) then
local argtype = cmd.args[cmd.subcommand_arg].type
local constraint_values = {}
local constraint_argtype = {}

for _,subcommand in ipairs(argtype.edslib_derivtable_list) do
-- Note that this list is not in value-order, the index relates to the lookup table, not the actual cmdcode value
-- To get the command code value, need to drill down into the constraint set. This assumes a single value constraint.
local cmdname = subcommand:get_flattened_name()
local constraint = subcommand:find_first("CONSTRAINT_SET")
if (constraint) then
constraint = constraint:find_first("VALUE_CONSTRAINT")
end
if (constraint) then
constraint = constraint.attributes["value"]
end
if (constraint) then
constraint_values[1 + #constraint_values] = constraint
constraint_argtype[constraint] = subcommand
end
end

table.sort(constraint_values)
cmd.cc_list = {}
for i,constraint in ipairs(constraint_values) do
local subcommand = constraint_argtype[constraint]
local macroname = SEDS.to_macro_name(subcommand:get_flattened_name())
-- If the command name ends in "_CMD" then lop it off
if (string.sub(macroname, -4, -1) == "_CMD") then
macroname = string.sub(macroname, 1, -5)
end
macroname = macroname .. "_CC"
cmd.cc_list[i] = { value = constraint, argtype = subcommand, macroname = macroname }
end

ds_all_subcmds[1 + #ds_all_subcmds] = { intf=reqintf, cmd=cmd }
end
end
end
end

-- Create a "cc.h" header file containing the command/function codes specificed as EDS value constraints
-- This info was collected earlier, but is easier to use in C files if not mixed with the interface declarations
-- It also needs to be put in a reasonable order and the macro names need to be scrubbed/fixed to match
if (#ds_all_subcmds > 0) then
hdrout = SEDS.output_open(SEDS.to_filename("cc.h", ds.name),ds.xml_filename)
for _,sc in ipairs(ds_all_subcmds) do
hdrout:section_marker(string.format("Command Codes for \'%s\' Interface",sc.intf.name))
for _,cc in ipairs(sc.cmd.cc_list) do
hdrout:add_documentation(string.format("Command code associated with %s_t", cc.argtype:get_flattened_name()))
hdrout:write(string.format("#define %-60s %s", cc.macroname, cc.value))
end
hdrout:add_whitespace(1)
end
SEDS.output_close(hdrout)
end

end
Loading

0 comments on commit 220185c

Please sign in to comment.