63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package crm3000
|
|
|
|
import (
|
|
"time"
|
|
|
|
"src.dualinventive.com/go/dinet"
|
|
"src.dualinventive.com/go/dinet/rpc"
|
|
)
|
|
|
|
// Device represents a single CRM3000 device for DI-Net
|
|
type Device struct {
|
|
*dinet.ChildDevice
|
|
IMEI string
|
|
DeviceUID string
|
|
}
|
|
|
|
// SensorInfo is the request handler for sensor:info
|
|
func (d *Device) SensorInfo(req *rpc.Msg) *rpc.Msg {
|
|
rep := req.CreateReply()
|
|
rep.Result = rpc.NewResult([]rpc.ResultInfoItem{
|
|
rpc.SensorBattery1Voltage.Info(),
|
|
rpc.SensorBattery1State.Info(),
|
|
rpc.CRMSensorTemperature1.Info(),
|
|
rpc.CRMSensorTemperature2.Info(),
|
|
rpc.CRMSensorCapTouch.Info(),
|
|
})
|
|
return rep
|
|
}
|
|
|
|
// UID gets the 128 bits hex encoded DI-Net DeviceUID
|
|
func (d *Device) UID() string {
|
|
return d.DeviceUID
|
|
}
|
|
|
|
// Type gets the DI-Net RPC device type
|
|
func (d *Device) Type() rpc.DeviceType {
|
|
return rpc.DeviceTypeCRM3000
|
|
}
|
|
|
|
// Versions returns the device versions, none at the moment
|
|
func (d *Device) Versions() (rpc.VersionMap, rpc.ErrorCode) {
|
|
return rpc.VersionMap{}, rpc.Ok
|
|
}
|
|
|
|
// TimeoutDuration returns the timeout for a device
|
|
// 1.5 times the regular interval (1 hour * 1.5 = 90 minutes)
|
|
func (d *Device) TimeoutDuration() time.Duration {
|
|
return time.Minute * 90
|
|
}
|
|
|
|
// Transport returns the transport data for connection:info
|
|
func (d *Device) Transport() (interface{}, rpc.ErrorCode) {
|
|
return &rpc.ConnectionInfoNBIoT{
|
|
Imei: d.IMEI,
|
|
Operator: rpc.ConnectionOperatorTMobile,
|
|
}, rpc.Ok
|
|
}
|
|
|
|
// Close device
|
|
func (d *Device) Close() error {
|
|
return nil
|
|
}
|