diff --git a/cmd/gqgmc/main.go b/cmd/gqgmc/main.go index 3f0f70078988d246f0f9166c6d27f2cc28ae3660..82614368a9fa86a5934f7fc764549ef5707b29ad 100644 --- a/cmd/gqgmc/main.go +++ b/cmd/gqgmc/main.go @@ -9,8 +9,9 @@ package main import ( "fmt" - "gitlab.com/lyda/gqgmc/devices/geiger" "time" + + "gitlab.com/lyda/gqgmc/devices/geiger" ) func main() { @@ -32,6 +33,8 @@ func main() { return } + gc.SetTime(time.Now()) + t, err = gc.GetTime() if err != nil { fmt.Printf("Failed: '%s'\n", err) diff --git a/devices/geiger/gqgmc.go b/devices/geiger/gqgmc.go index 4fc3b13649afa0fbfba09b3deafc335f55cf7442..95cedb2af2f5eefb1e8d82d0784e251e10e5c889 100644 --- a/devices/geiger/gqgmc.go +++ b/devices/geiger/gqgmc.go @@ -203,9 +203,19 @@ func (gc *GQGMCCounter) SetConfiguration() { // 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 + if !gc.supportedModels([]string{"GMC-280", "GMC-300"}) { + return + } + if gc.versionLT("Re 2.23") { + return + } + if gc.versionLT("Re 3.30") { + gc.setTimeParts(t) + } + gc.setTimeAll(t) +} +func (gc *GQGMCCounter) setTimeParts(t time.Time) { cmd := make([]byte, 13) var timeCmds = []struct { cmd string @@ -223,11 +233,27 @@ func (gc *GQGMCCounter) SetTime(t time.Time) { copy(cmd[:], c.cmd) cmd[10] = uint8(c.unit) copy(cmd[11:], ">>") - gc.port.Write(cmd) - gc.readCmd(1) + fmt.Printf("%s: %+v\n", c.cmd, cmd) + //gc.port.Write(cmd) + //gc.readCmd(1) } } +func (gc *GQGMCCounter) setTimeAll(t time.Time) { + cmd := make([]byte, 13) + copy(cmd[:], "<SETDATETIME") + cmd[12] = uint8(t.Year()) + cmd[13] = uint8(int(t.Month())) + cmd[14] = uint8(t.Day()) + cmd[15] = uint8(t.Hour()) + cmd[16] = uint8(t.Minute()) + cmd[17] = uint8(t.Second()) + copy(cmd[18:], ">>") + fmt.Printf("setTimeAll: %+v\n", cmd) + //gc.port.Write(cmd) + //gc.readCmd(1) +} + // GetTime gets the time func (gc *GQGMCCounter) GetTime() (time.Time, error) { b, err := gc.communicate(cmdGetTime, 7) @@ -284,6 +310,19 @@ func (gc *GQGMCCounter) Reboot() { return } +func (gc *GQGMCCounter) supportedModels(models []string) bool { + for _, model := range models { + if model == gc.model { + return true + } + } + return false +} + +func (gc *GQGMCCounter) versionLT(version string) bool { + return gc.version < version +} + func (gc *GQGMCCounter) communicate(cmd string, length uint32) ([]byte, error) { gc.Clear() if len(cmd) > 0 {