From 616f1be29efd33a5892cb0e9a1877ce1513774d5 Mon Sep 17 00:00:00 2001 From: Kevin Lyda <kevin@ie.suberic.net> Date: Tue, 31 Jan 2017 10:53:31 +0000 Subject: [PATCH] Add new commands. --- devices/geiger/geiger.go | 5 +++- devices/geiger/gqgmc.go | 51 +++++++++++++++++++++++++++++++--------- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/devices/geiger/geiger.go b/devices/geiger/geiger.go index b1b2af4..d04835a 100644 --- a/devices/geiger/geiger.go +++ b/devices/geiger/geiger.go @@ -34,7 +34,10 @@ type Counter interface { GetConfiguration() SetConfiguration() ResetConfiguration() - SetTime(t time.Time) + SetTime(time.Time) + GetTime() (time.Time, error) + FactoryReset() + Reboot() } // Config contain the configuration for a Geiger Counter diff --git a/devices/geiger/gqgmc.go b/devices/geiger/gqgmc.go index b7712f7..37f8f08 100644 --- a/devices/geiger/gqgmc.go +++ b/devices/geiger/gqgmc.go @@ -103,17 +103,20 @@ const ( ) const ( - cmdGetSerial = "<GETSERIAL>>" - cmdGetVersion = "<GETVER>>" - cmdGetVoltage = "<GETVOLT>>" - cmdGetCPM = "<GETCPM>>" - cmdGetCPS = "<GETCPS>>" - cmdGetCfg = "<GETCFG>>" - cmdEraseCfg = "<ECFG>>" - cmdUpdateCfg = "<CFGUPDATE>>" - cmdTurnOnCPS = "<HEARTBEAT1>>" - cmdTurnOffCPS = "<HEARTBEAT0>>" - cmdTurnOffPwr = "<POWEROFF>>" + cmdGetSerial = "<GETSERIAL>>" + cmdGetVersion = "<GETVER>>" + cmdGetVoltage = "<GETVOLT>>" + cmdGetCPM = "<GETCPM>>" + cmdGetCPS = "<GETCPS>>" + cmdGetCfg = "<GETCFG>>" + cmdEraseCfg = "<ECFG>>" + cmdUpdateCfg = "<CFGUPDATE>>" + cmdTurnOnCPS = "<HEARTBEAT1>>" + cmdTurnOffCPS = "<HEARTBEAT0>>" + cmdTurnOffPwr = "<POWEROFF>>" + cmdFactoryReset = "<FACTORYRESET>>" + cmdReboot = "<REBOOT>>" + cmdGetTime = "<GETDATETIME>>" ) // GQGMCCounter is a GQ GMC Counter @@ -275,6 +278,9 @@ func (gc *GQGMCCounter) ResetConfiguration() { // SetTime sets the time func (gc *GQGMCCounter) SetTime(t time.Time) { + //command: <SETDATETIME[YYMMDDHHMMSS]>> + //Firmware supported: GMC-280, GMC-300 Re.3.00 or later + cmd := make([]byte, 13) var timeCmds = []struct { cmd string @@ -297,6 +303,29 @@ func (gc *GQGMCCounter) SetTime(t time.Time) { } } +// GetTime gets the time +func (gc *GQGMCCounter) GetTime() (time.Time, error) { + b, err := gc.communicate(cmdGetTime, 7) + if err != nil { + return time.Unix(0, 0), err + } + t := time.Date(int(b[0])+2000, time.Month(b[1]), int(b[2]), + int(b[3]), int(b[4]), int(b[5]), 0, nil) + return t, nil +} + +// FactoryReset does a factory reset +func (gc *GQGMCCounter) FactoryReset() { + gc.sendCmd(cmdFactoryReset) + return +} + +// Reboot reboots the device +func (gc *GQGMCCounter) Reboot() { + gc.sendCmd(cmdReboot) + return +} + func (gc *GQGMCCounter) communicate(cmd string, length uint32) ([]byte, error) { gc.Clear() if len(cmd) > 0 { -- GitLab