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 all 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
36 changes: 36 additions & 0 deletions cse/cse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
35 changes: 21 additions & 14 deletions structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down