Commit f0262953 authored by Kevin Lyda's avatar Kevin Lyda 💬
Browse files

Work on GetConfiguration.

parent 13e4ab24
Pipeline #1236 passed with stage
in 3 minutes and 41 seconds
...@@ -17,6 +17,7 @@ import ( ...@@ -17,6 +17,7 @@ import (
func main() { func main() {
var ( var (
gc geiger.Counter gc geiger.Counter
cfg *geiger.DevConfig
cps, cpm uint16 cps, cpm uint16
volts int16 volts int16
temp float64 temp float64
...@@ -72,9 +73,11 @@ func main() { ...@@ -72,9 +73,11 @@ func main() {
fmt.Printf("Temp: %g\n", temp) fmt.Printf("Temp: %g\n", temp)
} }
err = gc.GetConfiguration() cfg, err = gc.GetConfiguration()
if err != nil { if err != nil {
fmt.Printf("Failed to get config: '%s'\n", err) fmt.Printf("Failed to get config: '%s'\n", err)
} else {
fmt.Printf("Cfg: %+v\n", cfg)
} }
} }
...@@ -27,12 +27,12 @@ type Counter interface { ...@@ -27,12 +27,12 @@ type Counter interface {
GetCPM() (uint16, error) GetCPM() (uint16, error)
GetCPS() (uint16, error) GetCPS() (uint16, error)
Volts() (int16, error) Volts() (int16, error)
GetHistoryData() GetHistory()
TurnOnCPS() error TurnOnCPS() error
TurnOffCPS() error TurnOffCPS() error
GetAutoCPS() (uint16, error) GetAutoCPS() (uint16, error)
TurnOffPower() TurnOffPower()
GetConfiguration() error GetConfiguration() (*DevConfig, error)
SetConfiguration() SetConfiguration()
SetTime(time.Time) SetTime(time.Time)
GetTime() (time.Time, error) GetTime() (time.Time, error)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
package geiger package geiger
import ( import (
"encoding/binary"
"encoding/hex" "encoding/hex"
"errors" "errors"
"fmt" "fmt"
...@@ -15,6 +16,7 @@ import ( ...@@ -15,6 +16,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/go-restruct/restruct"
"github.com/tarm/serial" "github.com/tarm/serial"
) )
...@@ -59,6 +61,66 @@ type GQGMCCounter struct { ...@@ -59,6 +61,66 @@ type GQGMCCounter struct {
mutex *sync.Mutex mutex *sync.Mutex
} }
// DevConfig is the gcgmc config block.
type DevConfig struct {
PowerOnOff int8 `struct:"int8"`
AlarmOnOff int8 `struct:"int8"`
SpeakerOnOff int8 `struct:"int8"`
GraphicModeOnOff int8 `struct:"int8"`
BackLightTimeoutSeconds int8 `struct:"int8"`
IdleTitleDisplayMode int8 `struct:"int8"`
AlarmCPMValue int16 `struct:"int16,big"`
CalibrationCPMHiByte0 byte `struct:"byte"`
CalibrationCPMLoByte0 byte `struct:"byte"`
CalibrationSvUcByte3p0 byte `struct:"byte"`
CalibrationSvUcByte2p0 byte `struct:"byte"`
CalibrationSvUcByte1p0 byte `struct:"byte"`
CalibrationSvUcByte0p0 byte `struct:"byte"`
CalibrationCPMHiByte1 byte `struct:"byte"`
CalibrationCPMLoByte1 byte `struct:"byte"`
CalibrationSvUcByte3p1 byte `struct:"byte"`
CalibrationSvUcByte2p1 byte `struct:"byte"`
CalibrationSvUcByte1p1 byte `struct:"byte"`
CalibrationSvUcByte0p1 byte `struct:"byte"`
CalibrationCPMHiByte2 byte `struct:"byte"`
CalibrationCPMLoByte2 byte `struct:"byte"`
CalibrationSvUcByte3p2 byte `struct:"byte"`
CalibrationSvUcByte2p2 byte `struct:"byte"`
CalibrationSvUcByte1p2 byte `struct:"byte"`
CalibrationSvUcByte0p2 byte `struct:"byte"`
IdleDisplayMode byte `struct:"byte"`
AlarmValueuSvByte3 byte `struct:"byte"`
AlarmValueuSvByte2 byte `struct:"byte"`
AlarmValueuSvByte1 byte `struct:"byte"`
AlarmValueuSvByte0 byte `struct:"byte"`
AlarmType byte `struct:"byte"`
SaveDataType byte `struct:"byte"`
SwivelDisplay byte `struct:"byte"`
ZoomByte3 byte `struct:"byte"`
ZoomByte2 byte `struct:"byte"`
ZoomByte1 byte `struct:"byte"`
ZoomByte0 byte `struct:"byte"`
SPIDataSaveAddress2 byte `struct:"byte"`
SPIDataSaveAddress1 byte `struct:"byte"`
SPIDataSaveAddress0 byte `struct:"byte"`
SPIDataReadAddress2 byte `struct:"byte"`
SPIDataReadAddress1 byte `struct:"byte"`
SPIDataReadAddress0 byte `struct:"byte"`
PowerSavingMode int8 `struct:"int8"`
SensitivityMode int8 `struct:"int8"`
CounterDelay int16 `struct:"int16,big"`
VoltageOffset int8 `struct:"int8"`
MaxCPM int16 `struct:"int16,big"`
SensitivityAutoModeThreshold int8 `struct:"int8"`
SaveDateTimeStamp6 byte `struct:"byte"`
SaveDateTimeStamp5 byte `struct:"byte"`
SaveDateTimeStamp4 byte `struct:"byte"`
SaveDateTimeStamp3 byte `struct:"byte"`
SaveDateTimeStamp2 byte `struct:"byte"`
SaveDateTimeStamp1 byte `struct:"byte"`
MaximumBytes byte `struct:"byte"`
}
// NewGQGMC creates a new GQGMC Counter instance // NewGQGMC creates a new GQGMC Counter instance
func NewGQGMC(c Config) (*GQGMCCounter, error) { func NewGQGMC(c Config) (*GQGMCCounter, error) {
var gc GQGMCCounter var gc GQGMCCounter
...@@ -86,7 +148,7 @@ func NewGQGMC(c Config) (*GQGMCCounter, error) { ...@@ -86,7 +148,7 @@ func NewGQGMC(c Config) (*GQGMCCounter, error) {
gc.serial = hex.EncodeToString(buf) gc.serial = hex.EncodeToString(buf)
} }
} }
//getConfigurationData() //getConfiguration()
return &gc, nil return &gc, nil
} }
...@@ -153,8 +215,8 @@ func (gc *GQGMCCounter) Volts() (int16, error) { ...@@ -153,8 +215,8 @@ func (gc *GQGMCCounter) Volts() (int16, error) {
return int16(volts[0]), err return int16(volts[0]), err
} }
// GetHistoryData Should return history data but is unimplemented for now // GetHistory Should return history data but is unimplemented for now
func (gc *GQGMCCounter) GetHistoryData() { func (gc *GQGMCCounter) GetHistory() {
// It's not recommended to use this so blank for now. // It's not recommended to use this so blank for now.
return return
} }
...@@ -235,20 +297,22 @@ func (gc *GQGMCCounter) TurnOffPower() { ...@@ -235,20 +297,22 @@ func (gc *GQGMCCounter) TurnOffPower() {
} }
// GetConfiguration reads configuration data // GetConfiguration reads configuration data
func (gc *GQGMCCounter) GetConfiguration() error { func (gc *GQGMCCounter) GetConfiguration() (*DevConfig, error) {
if !gc.supportedModels(mod280n300) { if !gc.supportedModels(mod280n300) {
return errors.New("Unsupported Model") return nil, errors.New("Unsupported Model")
} }
if gc.versionLT("Re 2.10") { if gc.versionLT("Re 2.10") {
return errors.New("Unsupported version") return nil, errors.New("Unsupported version")
} }
cfg, err := gc.communicate(cmdGetCfg, 256) data, err := gc.communicate(cmdGetCfg, 256)
if err != nil { if err != nil {
return err return nil, err
} }
fmt.Printf("Configuration: %+v\n", cfg) var cfg DevConfig
return nil restruct.Unpack(data[:58], binary.BigEndian, &cfg)
fmt.Printf("Configuration: %+v\n", data)
return &cfg, nil
} }
// SetConfiguration writes configuration data // SetConfiguration writes configuration data
...@@ -452,8 +516,9 @@ func (gc *GQGMCCounter) recv(length int) ([]byte, error) { ...@@ -452,8 +516,9 @@ func (gc *GQGMCCounter) recv(length int) ([]byte, error) {
} }
read := n read := n
if n != length { if n != length {
// Handle the case where we couldn't read it all.
// Really only happens for length > 32.
for i := 0; i < 20; i++ { for i := 0; i < 20; i++ {
fmt.Printf("%d(%d) ", n, read)
n, err = gc.port.Read(buf[read:]) n, err = gc.port.Read(buf[read:])
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -463,10 +528,8 @@ func (gc *GQGMCCounter) recv(length int) ([]byte, error) { ...@@ -463,10 +528,8 @@ func (gc *GQGMCCounter) recv(length int) ([]byte, error) {
break break
} }
} }
fmt.Printf("%d(%d)\n", n, read)
} }
if read != length { if read != length {
fmt.Printf("Short read: %+v\n", buf)
return nil, fmt.Errorf("Short read (got: %d, wanted: %d)", n, length) return nil, fmt.Errorf("Short read (got: %d, wanted: %d)", n, length)
} }
return buf, nil return buf, nil
......
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