From 409c760c5f09ab7568f9488b218fc6d79f2f436f Mon Sep 17 00:00:00 2001
From: Kevin Lyda <kevin@ie.suberic.net>
Date: Tue, 31 Jan 2017 00:10:15 +0000
Subject: [PATCH] Add time setting function.
---
devices/geiger/geiger.go | 5 ++--
devices/geiger/gqgmc.go | 55 +++++++++++++++-------------------------
2 files changed, 24 insertions(+), 36 deletions(-)
diff --git a/devices/geiger/geiger.go b/devices/geiger/geiger.go
index 139ba58..b1b2af4 100644
--- a/devices/geiger/geiger.go
+++ b/devices/geiger/geiger.go
@@ -7,6 +7,8 @@
package geiger
+import "time"
+
// New creates a new Counter instance
func New(c Config) (Counter, error) {
switch c.Model {
@@ -32,8 +34,7 @@ type Counter interface {
GetConfiguration()
SetConfiguration()
ResetConfiguration()
- SetDate(date string)
- SetTime(time string)
+ SetTime(t time.Time)
}
// Config contain the configuration for a Geiger Counter
diff --git a/devices/geiger/gqgmc.go b/devices/geiger/gqgmc.go
index 7bd8db4..069339e 100644
--- a/devices/geiger/gqgmc.go
+++ b/devices/geiger/gqgmc.go
@@ -268,41 +268,28 @@ func (gc *GQGMCCounter) ResetConfiguration() {
//communicate(erase_cfg_cmd, ret_char, retsize);
}
-// SetDate sets the date - format of YYYYMMDD
-func (gc *GQGMCCounter) SetDate(date string) {
- //setMonthCmd = "<SETDATEMM";
- //setMonthCmd += uint8_t(month);
- //setMonthCmd += ">>";
- //communicate(setMonthCmd, ret_char, retsize);
-
- //setDayCmd = "<SETDATEDD";
- //setDayCmd += uint8_t(day);
- //setDayCmd += ">>";
- //communicate(setDayCmd, ret_char, retsize);
-
- // year - last two digits
- //setYearCmd = "<SETDATEYY";
- //setYearCmd += uint8_t(year);
- //setYearCmd += ">>";
- //communicate(setYearCmd, ret_char, retsize);
-}
+// SetTime sets the time
+func (gc *GQGMCCounter) SetTime(t time.Time) {
+ cmd := make([]byte, 13)
+ var timeCmds = []struct {
+ cmd string
+ unit int
+ }{
+ {"<SETDATEYY", t.Year()},
+ {"<SETDATEMM", int(t.Month())},
+ {"<SETDATEDD", t.Day()},
+ {"<SETTIMEHH", t.Hour()},
+ {"<SETTIMEMM", t.Minute()},
+ {"<SETTIMESS", t.Second()},
+ }
-// SetTime sets the time (HH:MM:SS)
-func (gc *GQGMCCounter) SetTime(time string) {
- //setHourCmd = "<SETTIMEHH";
- //setHourCmd += uint8_t(hour);
- //setHourCmd += ">>";
- //communicate(setHourCmd, ret_char, retsize);
-
- //setMinuteCmd = "<SETTIMEMM";
- //setMinuteCmd += uint8_t(minute);
- //setMinuteCmd += ">>";
- //communicate(setMinuteCmd, ret_char, retsize);
-
- //setSecondCmd = "<SETTIMESS";
- //setSecondCmd += uint8_t(second);
- //setSecondCmd += ">>";
- //communicate(setSecondCmd, ret_char, retsize);
+ for _, c := range timeCmds {
+ copy(cmd[:], c.cmd)
+ cmd[10] = uint8(c.unit)
+ copy(cmd[11:], ">>")
+ gc.port.Write(cmd)
+ gc.readCmd(1)
+ }
}
func (gc *GQGMCCounter) communicate(cmd string, length uint32) ([]byte, error) {
--
GitLab