Commit 9537d57c authored by Kevin Lyda's avatar Kevin Lyda 💬

Add version checks.

parent 08ccf654
Pipeline #1217 passed with stage
in 36 seconds
......@@ -19,6 +19,7 @@ func main() {
gc geiger.Counter
cps, cpm uint16
volts int16
temp float64
ser string
err error
t time.Time
......@@ -71,4 +72,13 @@ func main() {
}
fmt.Printf("Volts: %d\n", volts)
temp, err = gc.GetTemp()
if err != nil {
fmt.Printf("Failed: '%s'\n", err)
return
}
fmt.Printf("Temp: %g\n", temp)
gc.GetConfiguration()
}
......@@ -36,6 +36,8 @@ type Counter interface {
SetConfiguration()
SetTime(time.Time)
GetTime() (time.Time, error)
GetTemp() (float64, error)
GetGyro() (int16, int16, int16, error)
FactoryReset()
Reboot()
}
......
......@@ -42,6 +42,11 @@ const (
cmdGetGyro = "<GETGYRO>>" // GMC-320 Re.3.01
)
var (
mod280n300 = []string{"GMC-280", "GMC-300"}
mod320 = []string{"GMC-320"}
)
// GQGMCCounter is a GQ GMC Counter
type GQGMCCounter struct {
port *serial.Port
......@@ -96,8 +101,14 @@ func (gc *GQGMCCounter) Model() string {
// SerialNum gets the serial number of the device
func (gc *GQGMCCounter) SerialNum() (string, error) {
serStr := ""
if !gc.supportedModels(mod280n300) {
return "", errors.New("Unsupported model")
}
if gc.versionLT("Re 2.11") {
return "", errors.New("Unsupported version")
}
serStr := ""
ser, err := gc.communicate(cmdGetSerial, 7)
if err == nil {
for _, b := range ser {
......@@ -127,17 +138,15 @@ func (gc *GQGMCCounter) GetCPS() (uint16, error) {
return gc.getReading(cmdGetCPS)
}
// Volts returns current battery voltage
// Volts returns current battery voltage (times 10)
func (gc *GQGMCCounter) Volts() (int16, error) {
// Do this differently - for 9.6 return 96. And if not supported,
// Return -1.
// Public method to read voltage value of battery. The GQ GMC returns
// a single byte whose integer value converted to a float divided by 10
// equals the battery voltage. For example, 0x60 = 96 converts to 9.6 Volts.
// The ideal value is 9.8 volts. So practically speaking, we should not
// expect to see a value higher than 100. The command is get_voltage_cmd
// (see GQ GMC COMMANDS above). If the voltage falls below 7.5V, GQ LLC
// says the geiger counter cannot be expected to operate properly.
if !gc.supportedModels(mod280n300) {
return 0, errors.New("Unsupported model")
}
if gc.versionLT("Re 2.00") {
return 0, errors.New("Unsupported version")
}
volts, err := gc.communicate(cmdGetVoltage, 1)
if err != nil {
return 0, err
......@@ -153,12 +162,26 @@ func (gc *GQGMCCounter) GetHistoryData() {
// TurnOnCPS turns on CPS collection
func (gc *GQGMCCounter) TurnOnCPS() error {
if !gc.supportedModels(mod280n300) {
return errors.New("Unsupported model")
}
if gc.versionLT("Re 2.10") {
return errors.New("Unsupported version")
}
gc.sendCmd(cmdTurnOnCPS)
return nil
}
// TurnOffCPS turns off CPS collection
func (gc *GQGMCCounter) TurnOffCPS() error {
if !gc.supportedModels(mod280n300) {
return errors.New("Unsupported model")
}
if gc.versionLT("Re 2.10") {
return errors.New("Unsupported version")
}
gc.sendCmd(cmdTurnOffCPS)
gc.Clear()
return nil
......@@ -177,18 +200,39 @@ func (gc *GQGMCCounter) GetAutoCPS() (uint16, error) {
// TurnOnPower turns the device on
func (gc *GQGMCCounter) TurnOnPower() {
if !gc.supportedModels(mod280n300) {
return
}
if gc.versionLT("Re 3.10") {
return
}
gc.sendCmd(cmdTurnOnPwr)
return
}
// TurnOffPower turns the device off
func (gc *GQGMCCounter) TurnOffPower() {
if !gc.supportedModels(mod280n300) {
return
}
if gc.versionLT("Re 2.11") {
return
}
gc.sendCmd(cmdTurnOffPwr)
return
}
// GetConfiguration reads configuration data
func (gc *GQGMCCounter) GetConfiguration() {
if !gc.supportedModels(mod280n300) {
return
}
if gc.versionLT("Re 2.10") {
return
}
cfg, err := gc.communicate(cmdGetCfg, 256)
if err != nil {
return
......@@ -198,12 +242,19 @@ func (gc *GQGMCCounter) GetConfiguration() {
// SetConfiguration writes configuration data
func (gc *GQGMCCounter) SetConfiguration() {
if !gc.supportedModels(mod280n300) {
return
}
if gc.versionLT("Re 2.10") {
return
}
// See the ConfigurationData functions in gqgmc.cc
}
// SetTime sets the time
func (gc *GQGMCCounter) SetTime(t time.Time) {
if !gc.supportedModels([]string{"GMC-280", "GMC-300"}) {
if !gc.supportedModels(mod280n300) {
return
}
if gc.versionLT("Re 2.23") {
......@@ -254,6 +305,13 @@ func (gc *GQGMCCounter) setTimeAll(t time.Time) {
// GetTime gets the time
func (gc *GQGMCCounter) GetTime() (time.Time, error) {
if !gc.supportedModels(mod280n300) {
return time.Unix(0, 0), errors.New("Unsupported model")
}
if gc.versionLT("Re 3.00") {
return time.Unix(0, 0), errors.New("Unsupported version")
}
b, err := gc.communicate(cmdGetTime, 7)
if err != nil {
return time.Unix(0, 0), err
......@@ -265,6 +323,13 @@ func (gc *GQGMCCounter) GetTime() (time.Time, error) {
// GetTemp gets the temp
func (gc *GQGMCCounter) GetTemp() (float64, error) {
if !gc.supportedModels(mod320) {
return 0, errors.New("Unsupported model")
}
if gc.versionLT("Re 3.01") {
return 0, errors.New("Unsupported version")
}
t, err := gc.communicate(cmdGetTemp, 4)
if err != nil {
return 0, err
......@@ -283,6 +348,13 @@ func (gc *GQGMCCounter) GetTemp() (float64, error) {
// GetGyro gets the position in space
func (gc *GQGMCCounter) GetGyro() (int16, int16, int16, error) {
if !gc.supportedModels(mod320) {
return 0, 0, 0, errors.New("Unsupported model")
}
if gc.versionLT("Re 3.01") {
return 0, 0, 0, errors.New("Unsupported version")
}
buf, err := gc.communicate(cmdGetGyro, 7)
if err != nil {
return 0, 0, 0, err
......@@ -298,12 +370,26 @@ func (gc *GQGMCCounter) GetGyro() (int16, int16, int16, error) {
// FactoryReset does a factory reset
func (gc *GQGMCCounter) FactoryReset() {
if !gc.supportedModels(mod280n300) {
return
}
if gc.versionLT("Re 3.00") {
return
}
gc.sendCmd(cmdFactoryReset)
return
}
// Reboot reboots the device
func (gc *GQGMCCounter) Reboot() {
if !gc.supportedModels(mod280n300) {
return
}
if gc.versionLT("Re 3.00") {
return
}
gc.sendCmd(cmdReboot)
return
}
......
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