Added some basic command handling for the devices
This commit is contained in:
@@ -23,6 +23,14 @@ type Device struct {
|
||||
API map[string]DeviceCMD
|
||||
}
|
||||
|
||||
func (dev *Device) HasFunction(f string) *DeviceCMD {
|
||||
if cmd, ok := dev.API[f]; ok {
|
||||
return &cmd
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type DeviceCMDHeader struct {
|
||||
Payload [64]byte
|
||||
}
|
||||
@@ -34,7 +42,7 @@ type DeviceCMDPayload struct {
|
||||
// DeviceCMDFn defines the basic type for the functions the devices can have
|
||||
// The function will receive a []byte that should be the arguments the user
|
||||
// types in the REPL - or however this will be used
|
||||
type DeviceCMDFn func(data []byte)
|
||||
type DeviceCMDFn func(dCMD *DeviceCMD, args []string) (types.CommandID, []byte, error)
|
||||
|
||||
type DeviceCMD struct {
|
||||
Identifier types.CommandID
|
||||
@@ -44,3 +52,15 @@ type DeviceCMD struct {
|
||||
Data DeviceCMDPayload
|
||||
Fn DeviceCMDFn
|
||||
}
|
||||
|
||||
func (dCMD *DeviceCMD) GetIdentifier() types.CommandID {
|
||||
return dCMD.Identifier
|
||||
}
|
||||
|
||||
func (dCMD *DeviceCMD) GetName() string {
|
||||
return dCMD.Name
|
||||
}
|
||||
|
||||
func (dCMD *DeviceCMD) GetDesc() string {
|
||||
return dCMD.Desc
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user