Commit 409c760c authored by Kevin Lyda's avatar Kevin Lyda 💬
Browse files

Add time setting function.

parent 7a6589b4
Pipeline #1202 failed with stage
in 1 minute and 7 seconds
......@@ -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
......
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment