Skip to content

Commit

Permalink
events: handle comm events directly instead of via flag and trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
Noiredd committed Aug 25, 2022
1 parent 153d42f commit 2fafa90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
10 changes: 5 additions & 5 deletions kOS/pegas.ks
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ SET CONFIG:IPU TO kOS_IPU.
GLOBAL upfgStage IS -1. // System initializes at passive guidance
GLOBAL stageEndTime IS TIME. // For Tgo calculation during active guidance (global time)
GLOBAL eventPointer IS -1. // Index of the last executed event (-1 means none yet)
GLOBAL commsEventFlag IS FALSE.
GLOBAL throttleSetting IS 1. // This is what actually controls the throttle,
GLOBAL throttleDisplay IS 1. // and this is what to display on the GUI - see throttleControl() for details.
GLOBAL steeringVector IS LOOKDIRUP(SHIP:FACING:FOREVECTOR, SHIP:FACING:TOPVECTOR).
Expand Down Expand Up @@ -60,7 +59,6 @@ IF controls:HASKEY("initialRoll") {
}
// Set up the system for flight
setVehicle(). // Complete vehicle definition (as given by user)
setComms(). // Setting up communications
callHooks("init"). // System initialized, run hooks


Expand All @@ -74,9 +72,10 @@ SET ascentFlag TO 0. // 0 = vertical, 1 = pitching over, 2 = notify about holdin
UNTIL ABORT {
// User hooks
callHooks("passivePre").
// Sequence handling
// Event handling
eventHandler().
IF commsEventFlag = TRUE { commsEventHandler(). }
// Communication system handling
commsHandler().
// Control handling
IF ascentFlag = 0 {
// The vehicle is going straight up for given amount of time
Expand Down Expand Up @@ -143,7 +142,8 @@ UNTIL ABORT {
callHooks("activePre").
// Event handling
eventHandler().
IF commsEventFlag = TRUE { commsEventHandler(). }
// Communication system handling
commsHandler().
// Update UPFG target and vehicle state
SET upfgTarget["normal"] TO targetNormal(mission["inclination"], mission["LAN"]).
SET upfgState TO acquireState().
Expand Down
21 changes: 7 additions & 14 deletions kOS/pegas_comm.ks
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// Communication system functions

// Setup a trigger listening for mesages from other CPUs
FUNCTION setComms {
WHEN NOT CORE:MESSAGES:EMPTY THEN {
SET commsEventFlag TO TRUE.
}
}

// Handles communication with other CPUs
FUNCTION commsEventHandler {
FUNCTION commsHandler {
// Only run if the message queue is not empty
IF CORE:MESSAGES:EMPTY {
RETURN.
}
// Get the oldest message in the queue but don't delete it yet
LOCAL message IS CORE:MESSAGES:PEEK:CONTENT.
// Create a response lexicon to send back
Expand Down Expand Up @@ -94,17 +91,13 @@ FUNCTION commsEventHandler {

// After everything is done, remove the message from message queue
CORE:MESSAGES:POP.
// Reset event flag
SET commsEventFlag TO FALSE.
// Re-create the comms event trigger
setComms().
}

// Make sure message is in the correct format
FUNCTION verifyMessageFormat {
PARAMETER type.
PARAMETER data.

// Response is a lexicon by default. If we encounter any error, it will change type to a string,
// and this is how we know that the format verification failed.
SET responseData TO LEXICON().
Expand Down Expand Up @@ -203,4 +196,4 @@ GLOBAL availableCommands IS LEXICON(
"setUpfgTime", command_setUpfgTime@,
"engineShutdown", command_engineShutdown@,
"setThrottle", command_setThrottle@
).
).

0 comments on commit 2fafa90

Please sign in to comment.