diff --git a/devices/geiger/geiger.go b/devices/geiger/geiger.go index 139ba58f06e620d3cf3273ec0ec8706e0ff15b5a..b1b2af4b7cf3fd7ef2b6af89a1b0526f7819e0fc 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 7bd8db4b7ab450fd2bd426774df29b451c5efc2d..069339e60f7112d0e303f03abaab00a52f1f1743 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) {