diff --git a/cse/cse.go b/cse/cse.go index 5a1f5fc..d9dcbab 100644 --- a/cse/cse.go +++ b/cse/cse.go @@ -364,6 +364,41 @@ func addVariableMetadata(execution *C.cse_execution, fmu *structs.FMU) error { return nil } +func fetchManipulatedVariables(execution *C.cse_execution) []structs.ManipulatedVariable { + nVars := int(C.cse_get_num_modified_variables(execution)) + if nVars <= 0 { + return nil + } + + var variables = make([]C.cse_variable_id, nVars) + numVars := int(C.cse_get_modified_variables(execution, &variables[0], C.size_t(nVars))) + + if numVars < 0 { + log.Println("Error while fetching modified variables: ", lastErrorMessage()) + return nil + } + + var varStructs = make([]structs.ManipulatedVariable, numVars) + for n, variable := range variables[0:numVars] { + slaveIndex := int(variable.slave_index) + valueReference := int(variable.variable_index) + variableType, err := parseType(variable._type) + + if err != nil { + log.Println("Problem parsing variable type: ", variable._type) + return nil + } + + varStructs[n] = structs.ManipulatedVariable{ + slaveIndex, + variableType, + valueReference, + } + } + + return varStructs +} + func simulationTeardown(sim *Simulation) (bool, string) { executionDestroy(sim.Execution) observerDestroy(sim.Observer) @@ -658,6 +693,7 @@ func GenerateJsonResponse(status *structs.SimulationStatus, sim *Simulation, fee response.Module = findModuleData(status, sim.MetaData, sim.Observer) response.ConfigDir = status.ConfigDir response.Trends = status.Trends + response.ManipulatedVariables = fetchManipulatedVariables(sim.Execution) if sim.ScenarioManager != nil && isScenarioRunning(sim.ScenarioManager) { response.RunningScenario = status.CurrentScenario } diff --git a/structs/structs.go b/structs/structs.go index 8649150..88a5c49 100644 --- a/structs/structs.go +++ b/structs/structs.go @@ -12,21 +12,28 @@ type Module struct { Name string `json:"name,omitempty"` } +type ManipulatedVariable struct { + SlaveIndex int `json:"slaveIndex"` + Type string `json:"type"` + ValueReference int `json:"valueReference"` +} + type JsonResponse struct { - Loaded bool `json:"loaded"` - SimulationTime float64 `json:"time"` - RealTimeFactor float64 `json:"realTimeFactor"` - RealTimeFactorTarget float64 `json:"realTimeFactorTarget"` - IsRealTimeSimulation bool `json:"isRealTime"` - ConfigDir string `json:"configDir,omitempty"` - Status string `json:"status,omitempty"` - Module Module `json:"module,omitempty"` - Trends []Trend `json:"trends"` - ModuleData *MetaData `json:"module-data,omitempty"` - Feedback *CommandFeedback `json:"feedback,omitempy"` - Scenarios *[]string `json:"scenarios,omitempty"` - Scenario *interface{} `json:"scenario,omitempty"` - RunningScenario string `json:"running-scenario"` + Loaded bool `json:"loaded"` + SimulationTime float64 `json:"time"` + RealTimeFactor float64 `json:"realTimeFactor"` + RealTimeFactorTarget float64 `json:"realTimeFactorTarget"` + IsRealTimeSimulation bool `json:"isRealTime"` + ConfigDir string `json:"configDir,omitempty"` + Status string `json:"status,omitempty"` + Module Module `json:"module,omitempty"` + Trends []Trend `json:"trends"` + ModuleData *MetaData `json:"module-data,omitempty"` + Feedback *CommandFeedback `json:"feedback,omitempy"` + Scenarios *[]string `json:"scenarios,omitempty"` + Scenario *interface{} `json:"scenario,omitempty"` + RunningScenario string `json:"running-scenario"` + ManipulatedVariables []ManipulatedVariable `json:"manipulatedVariables"` } type TrendSignal struct {