Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/212 provide overview of modified variables #94

Merged
merged 8 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions cse/cse.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,42 @@ func addVariableMetadata(execution *C.cse_execution, fmu *structs.FMU) error {
return nil
}

func fetchManipulatedVariables(execution *C.cse_execution) ([]structs.ManipulatedVariable, string) {
nVars := C.cse_get_num_modified_variables(execution)
if int(nVars) < 0 {
return nil, "Could not get number of manipulated variables"
}

var variables = make([]C.cse_variable_id, int(nVars))
var varStructs = make([]structs.ManipulatedVariable, int(nVars))

if int(nVars) == 0 {
varStructs = nil
return varStructs, "Simulation does not have any manipulated variables"
}

numVars := C.cse_get_modified_variables(execution, &variables[0], C.size_t(nVars))

if int(numVars) < int(nVars) {
return nil, "Could not fetch all modified variables from execution"
eidekrist marked this conversation as resolved.
Show resolved Hide resolved
}

for n, variable := range variables[0:int(nVars)] {
slaveIndex := int(variable.slave_index)
valueReference := int(variable.variable_index)
variableType, err := parseType(variable._type)

if err != nil {
return nil, "Problem parsing variabletype"
}

manipulatedVariable := structs.ManipulatedVariable{slaveIndex, variableType, valueReference}
varStructs[n] = manipulatedVariable
}

return varStructs, ""
}

func simulationTeardown(sim *Simulation) (bool, string) {
executionDestroy(sim.Execution)
observerDestroy(sim.Observer)
Expand Down Expand Up @@ -658,6 +694,10 @@ func GenerateJsonResponse(status *structs.SimulationStatus, sim *Simulation, fee
response.Module = findModuleData(status, sim.MetaData, sim.Observer)
response.ConfigDir = status.ConfigDir
response.Trends = status.Trends

manipulatedVars, _ := fetchManipulatedVariables(sim.Execution)

response.ManipulatedVariables = manipulatedVars
if sim.ScenarioManager != nil && isScenarioRunning(sim.ScenarioManager) {
response.RunningScenario = status.CurrentScenario
}
Expand Down
41 changes: 27 additions & 14 deletions structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,39 @@ type Signal struct {
Value interface{} `json:"value"`
}

type ModifiedSignal struct {
eidekrist marked this conversation as resolved.
Show resolved Hide resolved
SlaveIndex int `json:"slaveIndex"`
Type string `json:"type"`
ValueReference int `json:"valueReference"`
}

type Module struct {
Signals []Signal `json:"signals,omitempty"`
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 {
Expand Down