Skip to content

Commit

Permalink
Feature/212 provide overview of modified variables (#94)
Browse files Browse the repository at this point in the history
* #212 Initial commit for server branch

* #212 Add manipulated variables to JsonResponse

* #212 Fixed server duplication issue when appending to array

* #212 Actually commit latest code for hungry reviewers

* #212 C API change

* Following up my own review comments
  • Loading branch information
restenb authored and eidekrist committed Jul 12, 2019
1 parent c27588f commit 5ca5968
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
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

0 comments on commit 5ca5968

Please sign in to comment.