From 58440d5492732507c10885468bb3f51336901500 Mon Sep 17 00:00:00 2001 From: KRIEI Date: Thu, 6 Dec 2018 15:04:14 +0100 Subject: [PATCH] #25 Using C types from cse.h --- cse/cse.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/cse/cse.go b/cse/cse.go index c85edea..a6b87c6 100644 --- a/cse/cse.go +++ b/cse/cse.go @@ -24,8 +24,8 @@ func printLastError() { } func createExecution() (execution *C.cse_execution) { - startTime := C.int64_t(0.0 * 1e9) - stepSize := C.int64_t(0.1 * 1e9) + startTime := C.cse_time_point(0.0 * 1e9) + stepSize := C.cse_duration(0.1 * 1e9) execution = C.cse_execution_create(startTime, stepSize) return execution } @@ -48,7 +48,7 @@ func createObserver() (observer *C.cse_observer) { return } -func executionAddObserver(execution *C.cse_execution, observer *C.cse_observer) (observerIndex C.int) { +func executionAddObserver(execution *C.cse_execution, observer *C.cse_observer) (observerIndex C.cse_observer_index) { observerIndex = C.cse_execution_add_observer(execution, observer) return } @@ -75,12 +75,12 @@ func executionStop(execution *C.cse_execution) { } func observerGetReals(observer *C.cse_observer, fmu structs.FMU) (realSignals []structs.Signal) { - var realValueRefs []C.uint + var realValueRefs []C.cse_variable_index var realVariables []structs.Variable var numReals int for _, variable := range fmu.Variables { if variable.Type == "Real" { - ref := C.uint(variable.ValueReference) + ref := C.cse_variable_index(variable.ValueReference) realValueRefs = append(realValueRefs, ref) realVariables = append(realVariables, variable) numReals++ @@ -89,7 +89,7 @@ func observerGetReals(observer *C.cse_observer, fmu structs.FMU) (realSignals [] if numReals > 0 { realOutVal := make([]C.double, numReals) - C.cse_observer_slave_get_real(observer, C.int(fmu.ExecutionIndex), &realValueRefs[0], C.ulonglong(numReals), &realOutVal[0]) + C.cse_observer_slave_get_real(observer, C.cse_slave_index(fmu.ExecutionIndex), &realValueRefs[0], C.size_t(numReals), &realOutVal[0]) realSignals = make([]structs.Signal, numReals) for k := range realVariables { @@ -105,12 +105,12 @@ func observerGetReals(observer *C.cse_observer, fmu structs.FMU) (realSignals [] } func observerGetIntegers(observer *C.cse_observer, fmu structs.FMU) (intSignals []structs.Signal) { - var intValueRefs []C.uint + var intValueRefs []C.cse_variable_index var intVariables []structs.Variable var numIntegers int for _, variable := range fmu.Variables { if variable.Type == "Integer" { - ref := C.uint(variable.ValueReference) + ref := C.cse_variable_index(variable.ValueReference) intValueRefs = append(intValueRefs, ref) intVariables = append(intVariables, variable) numIntegers++ @@ -119,7 +119,7 @@ func observerGetIntegers(observer *C.cse_observer, fmu structs.FMU) (intSignals if numIntegers > 0 { intOutVal := make([]C.int, numIntegers) - C.cse_observer_slave_get_integer(observer, C.int(fmu.ExecutionIndex), &intValueRefs[0], C.ulonglong(numIntegers), &intOutVal[0]) + C.cse_observer_slave_get_integer(observer, C.cse_slave_index(fmu.ExecutionIndex), &intValueRefs[0], C.size_t(numIntegers), &intOutVal[0]) intSignals = make([]structs.Signal, numIntegers) for k := range intVariables { @@ -136,16 +136,16 @@ func observerGetIntegers(observer *C.cse_observer, fmu structs.FMU) (intSignals func observerGetRealSamples(observer *C.cse_observer, metaData structs.MetaData, signal *structs.TrendSignal, spec structs.TrendSpec) { fmu := findFmu(metaData, signal.Module) - slaveIndex := C.int(fmu.ExecutionIndex) - variableIndex := C.uint(findVariableIndex(fmu, signal.Signal, signal.Causality, signal.Type)) + slaveIndex := C.cse_slave_index(fmu.ExecutionIndex) + variableIndex := C.cse_variable_index(findVariableIndex(fmu, signal.Signal, signal.Causality, signal.Type)) - stepNumbers := make([]C.longlong, 2) + stepNumbers := make([]C.cse_step_number, 2) if spec.Auto { - duration := C.int64_t(spec.Range * 1e9) + duration := C.cse_duration(spec.Range * 1e9) C.cse_observer_get_step_numbers_for_duration(observer, slaveIndex, duration, &stepNumbers[0]) } else { - tBegin := C.int64_t(spec.Begin * 1e9) - tEnd := C.int64_t(spec.End * 1e9) + tBegin := C.cse_time_point(spec.Begin * 1e9) + tEnd := C.cse_time_point(spec.End * 1e9) C.cse_observer_get_step_numbers(observer, slaveIndex, tBegin, tEnd, &stepNumbers[0]) } @@ -153,10 +153,10 @@ func observerGetRealSamples(observer *C.cse_observer, metaData structs.MetaData, last := stepNumbers[1] numSamples := int(last) - int(first) + 1 - cnSamples := C.ulonglong(numSamples) + cnSamples := C.size_t(numSamples) realOutVal := make([]C.double, numSamples) timeVal := make([]C.cse_time_point, numSamples) - timeStamps := make([]C.longlong, numSamples) + timeStamps := make([]C.cse_step_number, numSamples) actualNumSamples := C.cse_observer_slave_get_real_samples(observer, slaveIndex, variableIndex, first, cnSamples, &realOutVal[0], &timeStamps[0], &timeVal[0]) trendVals := make([]float64, int(actualNumSamples)) @@ -302,7 +302,7 @@ func SimulationStatus(simulationStatus *structs.SimulationStatus, sim *Simulatio ConfigDir: simulationStatus.ConfigDir, TrendSignals: simulationStatus.TrendSignals, Memory: virtualMemoryStats, - Cpu: cpuInfo, + Cpu: cpuInfo, } } else { return structs.JsonResponse{