Skip to content
Snippets Groups Projects
Commit 04cbaf04 authored by Kevin Lyda's avatar Kevin Lyda :speech_balloon:
Browse files

Add some model checks.

parent e87d2d8d
Branches
No related tags found
No related merge requests found
Pipeline #
......@@ -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)
......
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment