Skip to content

Commit

Permalink
DEV: Add script engine
Browse files Browse the repository at this point in the history
  • Loading branch information
jphickey committed Nov 9, 2022
1 parent 4327314 commit 64678f8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_cfe_app(sample_app

# Include the public API from sample_lib to demonstrate how
# to call library-provided functions
add_cfe_app_dependency(sample_app sample_lib)
add_cfe_app_dependency(sample_app sample_lib scriptengine)

# Add table
add_cfe_tables(sampleAppTable fsw/tables/sample_app_tbl.c)
Expand All @@ -23,3 +23,9 @@ add_cfe_tables(sampleAppTable fsw/tables/sample_app_tbl.c)
if (ENABLE_UNIT_TESTS)
add_subdirectory(unit-test)
endif (ENABLE_UNIT_TESTS)

if (INSTALL_TARGET_LIST)
foreach(TGT ${INSTALL_TARGET_LIST})
install(FILES scripts/handler.lua DESTINATION ${TGT}/${INSTALL_SUBDIR})
endforeach()
endif()
9 changes: 9 additions & 0 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
#include "sample_app.h"
#include "sample_app_table.h"

#include "cfe_mission_eds_parameters.h"
#include "scriptengine.h"

/* The sample_lib module provides the SAMPLE_LIB_Function() prototype */
#include <string.h>
#include "sample_lib.h"
Expand Down Expand Up @@ -191,6 +194,8 @@ int32 SAMPLE_APP_Init(void)
status = CFE_TBL_Load(SAMPLE_APP_Data.TblHandles[0], CFE_TBL_SRC_FILE, SAMPLE_APP_TABLE_FILE);
}

SCRIPTENGINE_LoadFile("./cf/handler.lua");

CFE_EVS_SendEvent(SAMPLE_APP_STARTUP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE App Initialized.%s",
SAMPLE_APP_VERSION_STRING);

Expand Down Expand Up @@ -312,6 +317,10 @@ int32 SAMPLE_APP_DoExample(const SAMPLE_APP_DoExampleCmd_t *Msg)
{
CFE_ES_WriteToSysLog("%s: Command Value=%u", __func__, (unsigned int)Msg->Payload.Value);

/* JPHFIX: Lua bindings need update to allow proper "const" objects */
SCRIPTENGINE_CallFunctionArg("TestFunc2", (void*)&Msg->Payload,
EDS_INDEX(SAMPLE_APP), SAMPLE_APP_DoExample_Payload_DATADICTIONARY);

return CFE_SUCCESS;
}

Expand Down
19 changes: 19 additions & 0 deletions scripts/handler.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
print "handler.lua is being loaded!"

function TestFunc2(msg)
print "This is TestFunc2()"

if (msg) then
print ("Got A Message: " .. tostring(msg))

-- Using the "call" syntax returns the actual value
print ("The Input value is: " .. msg.Value())
end

cmd = EdsDB.GetInterface("CFE_ES/Application/CMD")
testobj = EdsDB.NewMessage(cmd, "NoopCMD")

print("obj=" .. EdsDB.ToHexString(testobj))

CFE.SendMsg(testobj)
end

0 comments on commit 64678f8

Please sign in to comment.