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

Reset overrides #66

Merged
merged 5 commits into from
Mar 18, 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
39 changes: 39 additions & 0 deletions cse/cse.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,28 @@ func setInteger(manipulator *C.cse_manipulator, slaveIndex int, variableIndex in
}
}

func resetReal(manipulator *C.cse_manipulator, slaveIndex int, variableIndex int) (bool, string) {
vi := make([]C.cse_variable_index, 1)
vi[0] = C.cse_variable_index(variableIndex)
success := C.cse_manipulator_slave_reset_real(manipulator, C.cse_slave_index(slaveIndex), &vi[0], C.size_t(1))
if int(success) < 0 {
return false, "Unable to reset real variable value"
} else {
return true, "Successfully reset real variable value"
}
}

func resetInteger(manipulator *C.cse_manipulator, slaveIndex int, variableIndex int) (bool, string) {
vi := make([]C.cse_variable_index, 1)
vi[0] = C.cse_variable_index(variableIndex)
success := C.cse_manipulator_slave_reset_integer(manipulator, C.cse_slave_index(slaveIndex), &vi[0], C.size_t(1))
if int(success) < 0 {
return false, "Unable to reset integer variable value"
} else {
return true, "Successfully reset integer variable value"
}
}

func setVariableValue(sim *Simulation, module string, signal string, causality string, valueType string, value string) (bool, string) {
fmu := findFmu(sim.MetaData, module)
varIndex := findVariableIndex(fmu, signal, causality, valueType)
Expand Down Expand Up @@ -319,6 +341,21 @@ func setVariableValue(sim *Simulation, module string, signal string, causality s
}
}

func resetVariableValue(sim *Simulation, module string, signal string, causality string, valueType string) (bool, string) {
fmu := findFmu(sim.MetaData, module)
varIndex := findVariableIndex(fmu, signal, causality, valueType)
switch valueType {
case "Real":
return resetReal(sim.OverrideManipulator, fmu.ExecutionIndex, varIndex)
case "Integer":
return resetInteger(sim.OverrideManipulator, fmu.ExecutionIndex, varIndex)
default:
message := strCat("Can't reset this variable: ", module, " - ", signal)
fmt.Println(message)
return false, message
}
}

func findVariableIndex(fmu structs.FMU, signalName string, causality string, valueType string) (index int) {
for _, variable := range fmu.Variables {
if variable.Name == signalName && variable.Type == valueType && variable.Causality == causality {
Expand Down Expand Up @@ -640,6 +677,8 @@ func executeCommand(cmd []string, sim *Simulation, status *structs.SimulationSta
message = strCat("Trending last ", cmd[1], " seconds")
case "set-value":
success, message = setVariableValue(sim, cmd[1], cmd[2], cmd[3], cmd[4], cmd[5])
case "reset-value":
success, message = resetVariableValue(sim, cmd[1], cmd[2], cmd[3], cmd[4])
case "get-module-data":
shorty.ModuleData = sim.MetaData
scenarios := findScenarios(status)
Expand Down
Loading