Skip to content
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
4 changes: 3 additions & 1 deletion .gcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ cmd/ausoceantv/webapp/node_modules/
cmd/decode/*
cmd/cloudblue/*
cmd/oceancast/*
cmd/roadmap/*
cmd/roadmap/*

docs/*
2 changes: 1 addition & 1 deletion cmd/oceanbench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import (
)

const (
version = "v0.32.4"
version = "v0.32.5"
localSite = "localhost"
localDevice = "localdevice"
localEmail = "localuser@localhost"
Expand Down
28 changes: 20 additions & 8 deletions cmd/oceanbench/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,10 @@ func configDevicesHandler(w http.ResponseWriter, r *http.Request) {
}

// Create the device.
var sys *system.RigSystem
switch dt {
case model.DevTypeController:
// Create a controller with all default values defined in rig_system.go.
sys, err = system.NewRigSystem(skey, dev.Dkey, ma, dn,
sys, err := system.NewRigSystem(skey, dev.Dkey, ma, dn,
system.WithRigSystemDefaults(),
system.WithWifi(ssid, pass),
system.WithLocation(lat, long),
Expand All @@ -189,16 +188,29 @@ func configDevicesHandler(w http.ResponseWriter, r *http.Request) {
writeError(w, err)
return
}

err = system.PutRigSystem(ctx, settingsStore, sys)
if err != nil {
writeError(w, fmt.Errorf("unable to put rig system: %w", err))
return
}
case model.DevTypeCamera:
camSys, err := system.NewCamera(skey, dev.Dkey, dn, ma, system.WithCameraDefaults())
if err != nil {
writeError(w, err)
return
}

err = system.PutCameraSystem(ctx, settingsStore, camSys)
if err != nil {
writeError(w, fmt.Errorf("unable to put camera system: %w", err))
return
}

default:
writeError(w, errNotImplemented)
return
}

err = system.PutRigSystem(ctx, settingsStore, sys)
if err != nil {
writeError(w, fmt.Errorf("unable to put rig system: %w", err))
return
}
site, err := model.GetSite(ctx, settingsStore, int64(skey))
if err != nil {
writeError(w, fmt.Errorf("failed to get site: %v", err))
Expand Down
76 changes: 53 additions & 23 deletions system/rig_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,24 +270,32 @@ func (sys *CameraSystem) AddVariables(variables ...*model.Variable) {
}

// WithCameraDefaults applies all of the current defaults to the system.
func (sys *CameraSystem) WithCameraDefaults() {
sys.AddVariables(
model.NewAutoWhiteBalanceVar(camera.DefaultAutoWhiteBalance),
model.NewBitrateVar(camera.DefaultBitrate),
model.NewContrastVar(camera.DefaultContrast),
model.NewFrameRateVar(camera.DefaultFrameRate),
model.NewHDRVar(camera.DefaultHDR),
model.NewHeightVar(camera.DefaultHeight),
model.NewInputVar(camera.DefaultInput),
model.NewOutputVar(camera.DefaultOutput),
model.NewRotationVar(camera.DefaultRotation),
model.NewSaturationVar(camera.DefaultSaturation),
model.NewSharpnessVar(camera.DefaultSharpness),
model.NewWidthVar(camera.DefaultWidth),
model.NewLoggingVar(camera.DefaultLogging),
model.NewModeVar(camera.DefaultMode),
model.NewRTMPURLVar(""),
)
func WithCameraDefaults() Option {
return func(v any) error {
sys, ok := v.(*CameraSystem)
if !ok {
return fmt.Errorf("%v is not a CameraSystem", reflect.TypeOf(v).String())
}
sys.AddVariables(
model.NewAutoWhiteBalanceVar(camera.DefaultAutoWhiteBalance),
model.NewBitrateVar(camera.DefaultBitrate),
model.NewContrastVar(camera.DefaultContrast),
model.NewFrameRateVar(camera.DefaultFrameRate),
model.NewHDRVar(camera.DefaultHDR),
model.NewHeightVar(camera.DefaultHeight),
model.NewInputVar(camera.DefaultInput),
model.NewOutputVar(camera.DefaultOutput),
model.NewRotationVar(camera.DefaultRotation),
model.NewSaturationVar(camera.DefaultSaturation),
model.NewSharpnessVar(camera.DefaultSharpness),
model.NewWidthVar(camera.DefaultWidth),
model.NewLoggingVar(camera.DefaultLogging),
model.NewModeVar(camera.DefaultMode),
model.NewRTMPURLVar(""),
)

return nil
}
}

// NewCamera returns a new camera with the given name and mac address, with the given options applied.
Expand All @@ -299,11 +307,14 @@ func NewCamera(skey, dkey int64, name string, mac string, opts ...Option) (*Came

sys := &CameraSystem{
Cam: &model.Device{
Skey: skey,
Dkey: dkey,
Name: name,
Mac: MAC,
Type: model.DevTypeCamera,
Skey: skey,
Dkey: dkey,
Name: name,
Mac: MAC,
Type: model.DevTypeCamera,
Inputs: "V0,T0",
MonitorPeriod: 60,
ActPeriod: 60,
},
}

Expand All @@ -321,3 +332,22 @@ func NewCamera(skey, dkey int64, name string, mac string, opts ...Option) (*Came

return sys, nil
}

// PutCameraSystem puts a CameraSystem and all of its components into the datastore.
func PutCameraSystem(ctx context.Context, store datastore.Store, system *CameraSystem) error {
// Put the Camera.
err := model.PutDevice(ctx, store, system.Cam)
if err != nil {
return fmt.Errorf("unable to put system camera: %w", err)
}

// Put all variables.
for _, v := range system.Vars {
err = model.PutVariable(ctx, store, v.Skey, system.Cam.Hex()+"."+v.Name, v.Value)
if err != nil {
return fmt.Errorf("unable to put variable with name: %s, err: %w", v.Name, err)
}
}

return nil
}
58 changes: 35 additions & 23 deletions system/rig_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,14 @@ func TestNewCameraSystem(t *testing.T) {
cameraName: camName,
wantErr: nil,
expectedCamera: &model.Device{
Name: camName,
Dkey: testDevKey,
Skey: testSiteKey,
Type: model.DevTypeCamera,
Mac: model.MacEncode(strTestMAC),
Name: camName,
Dkey: testDevKey,
Skey: testSiteKey,
Type: model.DevTypeCamera,
Mac: model.MacEncode(strTestMAC),
Inputs: "V0,T0",
MonitorPeriod: 60,
ActPeriod: 60,
},
},
{
Expand All @@ -487,12 +490,15 @@ func TestNewCameraSystem(t *testing.T) {
options: []system.Option{system.WithWifi(testSSID, testPassword)},
wantErr: nil,
expectedCamera: &model.Device{
Name: camName,
Dkey: testDevKey,
Skey: testSiteKey,
Type: model.DevTypeCamera,
Mac: model.MacEncode(strTestMAC),
Wifi: testSSID + "," + testPassword,
Name: camName,
Dkey: testDevKey,
Skey: testSiteKey,
Type: model.DevTypeCamera,
Mac: model.MacEncode(strTestMAC),
Wifi: testSSID + "," + testPassword,
Inputs: "V0,T0",
MonitorPeriod: 60,
ActPeriod: 60,
},
},
{
Expand All @@ -504,13 +510,16 @@ func TestNewCameraSystem(t *testing.T) {
options: []system.Option{system.WithLocation(testLat, testLong)},
wantErr: nil,
expectedCamera: &model.Device{
Name: camName,
Dkey: testDevKey,
Skey: testSiteKey,
Type: model.DevTypeCamera,
Mac: model.MacEncode(strTestMAC),
Latitude: testLat,
Longitude: testLong,
Name: camName,
Dkey: testDevKey,
Skey: testSiteKey,
Type: model.DevTypeCamera,
Mac: model.MacEncode(strTestMAC),
Latitude: testLat,
Longitude: testLong,
Inputs: "V0,T0",
MonitorPeriod: 60,
ActPeriod: 60,
},
},
{
Expand All @@ -527,11 +536,14 @@ func TestNewCameraSystem(t *testing.T) {
}...)},
wantErr: nil,
expectedCamera: &model.Device{
Name: camName,
Dkey: testDevKey,
Skey: testSiteKey,
Type: model.DevTypeCamera,
Mac: model.MacEncode(strTestMAC),
Name: camName,
Dkey: testDevKey,
Skey: testSiteKey,
Type: model.DevTypeCamera,
Mac: model.MacEncode(strTestMAC),
Inputs: "V0,T0",
MonitorPeriod: 60,
ActPeriod: 60,
},
expectedVariables: []*model.Variable{
{
Expand Down
Loading