mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
allow signal indices to start at 0 instead of 1
This commit is contained in:
parent
5cd136c558
commit
a4947a53e9
4 changed files with 29 additions and 32 deletions
|
@ -353,43 +353,43 @@
|
||||||
"name": "outSignal_A",
|
"name": "outSignal_A",
|
||||||
"direction": "out",
|
"direction": "out",
|
||||||
"unit": "V",
|
"unit": "V",
|
||||||
"index": 1
|
"index": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "outSignal_B",
|
"name": "outSignal_B",
|
||||||
"direction": "out",
|
"direction": "out",
|
||||||
"unit": "V",
|
"unit": "V",
|
||||||
"index": 2
|
"index": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "outSignal_C",
|
"name": "outSignal_C",
|
||||||
"direction": "out",
|
"direction": "out",
|
||||||
"unit": "---",
|
"unit": "---",
|
||||||
"index": 3
|
"index": 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "outSignal_D",
|
"name": "outSignal_D",
|
||||||
"direction": "out",
|
"direction": "out",
|
||||||
"unit": "---",
|
"unit": "---",
|
||||||
"index": 4
|
"index": 3
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "outSignal_E",
|
"name": "outSignal_E",
|
||||||
"direction": "out",
|
"direction": "out",
|
||||||
"unit": "---",
|
"unit": "---",
|
||||||
"index": 5
|
"index": 4
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "inSignal_A",
|
"name": "inSignal_A",
|
||||||
"direction": "in",
|
"direction": "in",
|
||||||
"unit": "---",
|
"unit": "---",
|
||||||
"index": 1
|
"index": 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "inSignal_B",
|
"name": "inSignal_B",
|
||||||
"direction": "in",
|
"direction": "in",
|
||||||
"unit": "---",
|
"unit": "---",
|
||||||
"index": 2
|
"index": 1
|
||||||
}
|
}
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -44,7 +44,7 @@ var router *gin.Engine
|
||||||
type SignalRequest struct {
|
type SignalRequest struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Unit string `json:"unit,omitempty"`
|
Unit string `json:"unit,omitempty"`
|
||||||
Index uint `json:"index,omitempty"`
|
Index *uint `json:"index,omitempty"`
|
||||||
Direction string `json:"direction,omitempty"`
|
Direction string `json:"direction,omitempty"`
|
||||||
ScalingFactor float32 `json:"scalingFactor,omitempty"`
|
ScalingFactor float32 `json:"scalingFactor,omitempty"`
|
||||||
ConfigID uint `json:"configID,omitempty"`
|
ConfigID uint `json:"configID,omitempty"`
|
||||||
|
@ -76,11 +76,14 @@ type ScenarioRequest struct {
|
||||||
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var signalIndex0 uint = 0
|
||||||
|
var signalIndex1 uint = 1
|
||||||
|
|
||||||
var newSignal1 = SignalRequest{
|
var newSignal1 = SignalRequest{
|
||||||
Name: "outSignal_A",
|
Name: "outSignal_A",
|
||||||
Unit: "V",
|
Unit: "V",
|
||||||
Direction: "out",
|
Direction: "out",
|
||||||
Index: 1,
|
Index: &signalIndex0,
|
||||||
}
|
}
|
||||||
|
|
||||||
func newFalse() *bool {
|
func newFalse() *bool {
|
||||||
|
@ -226,6 +229,7 @@ func TestAddSignal(t *testing.T) {
|
||||||
"/api/v2/signals", "POST", helper.KeyModels{"signal": newSignal1})
|
"/api/v2/signals", "POST", helper.KeyModels{"signal": newSignal1})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
fmt.Println(resp)
|
||||||
|
|
||||||
// Compare POST's response with the newSignal
|
// Compare POST's response with the newSignal
|
||||||
err = helper.CompareResponse(resp, helper.KeyModels{"signal": newSignal1})
|
err = helper.CompareResponse(resp, helper.KeyModels{"signal": newSignal1})
|
||||||
|
@ -296,7 +300,7 @@ func TestUpdateSignal(t *testing.T) {
|
||||||
updatedSignal := SignalRequest{
|
updatedSignal := SignalRequest{
|
||||||
Name: "outSignal_B",
|
Name: "outSignal_B",
|
||||||
Unit: "A",
|
Unit: "A",
|
||||||
Index: 1,
|
Index: &signalIndex1,
|
||||||
}
|
}
|
||||||
|
|
||||||
// authenticate as normal userB who has no access to new scenario
|
// authenticate as normal userB who has no access to new scenario
|
||||||
|
@ -379,7 +383,7 @@ func TestDeleteSignal(t *testing.T) {
|
||||||
Name: "insignalA",
|
Name: "insignalA",
|
||||||
Unit: "s",
|
Unit: "s",
|
||||||
Direction: "in",
|
Direction: "in",
|
||||||
Index: 1,
|
Index: &signalIndex0,
|
||||||
ConfigID: configID,
|
ConfigID: configID,
|
||||||
}
|
}
|
||||||
code, resp, err := helper.TestEndpoint(router, token,
|
code, resp, err := helper.TestEndpoint(router, token,
|
||||||
|
@ -470,7 +474,7 @@ func TestGetAllInputSignalsOfConfig(t *testing.T) {
|
||||||
Name: "inA",
|
Name: "inA",
|
||||||
Unit: "s",
|
Unit: "s",
|
||||||
Direction: "in",
|
Direction: "in",
|
||||||
Index: 1,
|
Index: &signalIndex0,
|
||||||
ConfigID: configID,
|
ConfigID: configID,
|
||||||
}
|
}
|
||||||
code, resp, err := helper.TestEndpoint(router, token,
|
code, resp, err := helper.TestEndpoint(router, token,
|
||||||
|
@ -483,7 +487,7 @@ func TestGetAllInputSignalsOfConfig(t *testing.T) {
|
||||||
Name: "inB",
|
Name: "inB",
|
||||||
Unit: "m",
|
Unit: "m",
|
||||||
Direction: "in",
|
Direction: "in",
|
||||||
Index: 2,
|
Index: &signalIndex1,
|
||||||
ConfigID: configID,
|
ConfigID: configID,
|
||||||
}
|
}
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
|
@ -503,7 +507,7 @@ func TestGetAllInputSignalsOfConfig(t *testing.T) {
|
||||||
Name: "outB",
|
Name: "outB",
|
||||||
Unit: "A",
|
Unit: "A",
|
||||||
Direction: "out",
|
Direction: "out",
|
||||||
Index: 1,
|
Index: &signalIndex1,
|
||||||
ConfigID: configID,
|
ConfigID: configID,
|
||||||
}
|
}
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
|
|
|
@ -30,7 +30,7 @@ var validate *validator.Validate
|
||||||
type validNewSignal struct {
|
type validNewSignal struct {
|
||||||
Name string `form:"Name" validate:"required"`
|
Name string `form:"Name" validate:"required"`
|
||||||
Unit string `form:"unit" validate:"omitempty"`
|
Unit string `form:"unit" validate:"omitempty"`
|
||||||
Index uint `form:"index" validate:"required"`
|
Index *uint `form:"index" validate:"required"`
|
||||||
Direction string `form:"direction" validate:"required,oneof=in out"`
|
Direction string `form:"direction" validate:"required,oneof=in out"`
|
||||||
ScalingFactor float32 `form:"scalingFactor" validate:"omitempty"`
|
ScalingFactor float32 `form:"scalingFactor" validate:"omitempty"`
|
||||||
ConfigID uint `form:"configID" validate:"required"`
|
ConfigID uint `form:"configID" validate:"required"`
|
||||||
|
@ -39,7 +39,7 @@ type validNewSignal struct {
|
||||||
type validUpdatedSignal struct {
|
type validUpdatedSignal struct {
|
||||||
Name string `form:"Name" validate:"omitempty"`
|
Name string `form:"Name" validate:"omitempty"`
|
||||||
Unit string `form:"unit" validate:"omitempty"`
|
Unit string `form:"unit" validate:"omitempty"`
|
||||||
Index uint `form:"index" validate:"omitempty"`
|
Index *uint `form:"index" validate:"omitempty"`
|
||||||
ScalingFactor float32 `form:"scalingFactor" validate:"omitempty"`
|
ScalingFactor float32 `form:"scalingFactor" validate:"omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ func (r *addSignalRequest) createSignal() Signal {
|
||||||
|
|
||||||
s.Name = r.Signal.Name
|
s.Name = r.Signal.Name
|
||||||
s.Unit = r.Signal.Unit
|
s.Unit = r.Signal.Unit
|
||||||
s.Index = r.Signal.Index
|
s.Index = *r.Signal.Index
|
||||||
s.Direction = r.Signal.Direction
|
s.Direction = r.Signal.Direction
|
||||||
s.ScalingFactor = r.Signal.ScalingFactor
|
s.ScalingFactor = r.Signal.ScalingFactor
|
||||||
s.ConfigID = r.Signal.ConfigID
|
s.ConfigID = r.Signal.ConfigID
|
||||||
|
@ -80,18 +80,9 @@ func (r *updateSignalRequest) updatedSignal(oldSignal Signal) Signal {
|
||||||
// Use the old Signal as a basis for the updated Signal `s`
|
// Use the old Signal as a basis for the updated Signal `s`
|
||||||
s := oldSignal
|
s := oldSignal
|
||||||
|
|
||||||
if r.Signal.Name != "" {
|
s.Name = r.Signal.Name
|
||||||
s.Name = r.Signal.Name
|
s.Index = *r.Signal.Index
|
||||||
}
|
s.Unit = r.Signal.Unit
|
||||||
|
|
||||||
if r.Signal.Index != 0 {
|
|
||||||
// TODO this implies that we start indexing at 1
|
|
||||||
s.Index = r.Signal.Index
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.Signal.Unit != "" {
|
|
||||||
s.Unit = r.Signal.Unit
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.Signal.ScalingFactor != 0 {
|
if r.Signal.ScalingFactor != 0 {
|
||||||
// scaling factor of 0 is not allowed
|
// scaling factor of 0 is not allowed
|
||||||
|
|
|
@ -1586,17 +1586,19 @@ func addSignals(token string) error {
|
||||||
type SignalRequest struct {
|
type SignalRequest struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Unit string `json:"unit,omitempty"`
|
Unit string `json:"unit,omitempty"`
|
||||||
Index uint `json:"index,omitempty"`
|
Index *uint `json:"index,omitempty"`
|
||||||
Direction string `json:"direction,omitempty"`
|
Direction string `json:"direction,omitempty"`
|
||||||
ScalingFactor float32 `json:"scalingFactor,omitempty"`
|
ScalingFactor float32 `json:"scalingFactor,omitempty"`
|
||||||
ConfigID uint `json:"configID,omitempty"`
|
ConfigID uint `json:"configID,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var signalIndex0 uint = 0
|
||||||
|
var signalIndex1 uint = 1
|
||||||
var newSignalOut = SignalRequest{
|
var newSignalOut = SignalRequest{
|
||||||
Name: "outSignal_A",
|
Name: "outSignal_A",
|
||||||
Unit: "V",
|
Unit: "V",
|
||||||
Direction: "out",
|
Direction: "out",
|
||||||
Index: 1,
|
Index: &signalIndex0,
|
||||||
ConfigID: 1,
|
ConfigID: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1604,7 +1606,7 @@ func addSignals(token string) error {
|
||||||
Name: "inSignal_A",
|
Name: "inSignal_A",
|
||||||
Unit: "V",
|
Unit: "V",
|
||||||
Direction: "in",
|
Direction: "in",
|
||||||
Index: 2,
|
Index: &signalIndex1,
|
||||||
ConfigID: 1,
|
ConfigID: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue