Commit c5a09d9d authored by Kevin Lyda's avatar Kevin Lyda 💬

Fixed serial.

parent 88ac98bd
Pipeline #1222 passed with stage
in 1 minute and 11 seconds
...@@ -20,7 +20,6 @@ func main() { ...@@ -20,7 +20,6 @@ func main() {
cps, cpm uint16 cps, cpm uint16
volts int16 volts int16
temp float64 temp float64
ser string
err error err error
t time.Time t time.Time
) )
...@@ -57,13 +56,7 @@ func main() { ...@@ -57,13 +56,7 @@ func main() {
fmt.Printf("Version: %s\n", gc.Version()) fmt.Printf("Version: %s\n", gc.Version())
fmt.Printf("Model: %s\n", gc.Model()) fmt.Printf("Model: %s\n", gc.Model())
fmt.Printf("Serial: %s\n", gc.Serial())
ser, err = gc.SerialNum()
if err != nil {
fmt.Printf("Serial failed: '%s'\n", err)
return
}
fmt.Printf("Serial: %s\n", ser)
volts, err = gc.Volts() volts, err = gc.Volts()
if err != nil { if err != nil {
......
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"html/template" "html/template"
"log" "log"
"net/http" "net/http"
"path"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"gitlab.com/lyda/gqgmc/devices/geiger" "gitlab.com/lyda/gqgmc/devices/geiger"
...@@ -20,6 +21,7 @@ import ( ...@@ -20,6 +21,7 @@ import (
var addr = flag.String("listen-address", ":8080", "Address for HTTP requests.") var addr = flag.String("listen-address", ":8080", "Address for HTTP requests.")
var device = flag.String("device", "/dev/gqgmc", "Device for Geiger Counter.") var device = flag.String("device", "/dev/gqgmc", "Device for Geiger Counter.")
var model = flag.String("model", "gqgmc", "Model of Geiger Counter.") var model = flag.String("model", "gqgmc", "Model of Geiger Counter.")
var templateDir = flag.String("template_dir", "templates", "Template directory.")
type indexPage struct { type indexPage struct {
Model string Model string
...@@ -34,7 +36,7 @@ var indexPg indexPage ...@@ -34,7 +36,7 @@ var indexPg indexPage
func indexHandler(w http.ResponseWriter, r *http.Request) { func indexHandler(w http.ResponseWriter, r *http.Request) {
indexPg.CPM, _ = gc.GetCPM() indexPg.CPM, _ = gc.GetCPM()
t, err := template.ParseFiles("index.html") t, err := template.ParseFiles(path.Join(*templateDir, "index.html"))
if err != nil { if err != nil {
log.Printf("Template error: %s\n", err) log.Printf("Template error: %s\n", err)
} }
...@@ -47,7 +49,7 @@ func main() { ...@@ -47,7 +49,7 @@ func main() {
gc, _ = geiger.New(geiger.Config{Model: *model, Device: *device}) gc, _ = geiger.New(geiger.Config{Model: *model, Device: *device})
indexPg.Model = gc.Model() indexPg.Model = gc.Model()
indexPg.Version = gc.Version() indexPg.Version = gc.Version()
indexPg.Serial, _ = gc.SerialNum() indexPg.Serial = gc.Serial()
indexPg.Volts, _ = gc.Volts() indexPg.Volts, _ = gc.Volts()
http.HandleFunc("/", indexHandler) http.HandleFunc("/", indexHandler)
http.Handle("/metrics", promhttp.Handler()) http.Handle("/metrics", promhttp.Handler())
......
...@@ -23,7 +23,7 @@ type Counter interface { ...@@ -23,7 +23,7 @@ type Counter interface {
Clear() error Clear() error
Model() string Model() string
Version() string Version() string
SerialNum() (string, error) Serial() string
GetCPM() (uint16, error) GetCPM() (uint16, error)
GetCPS() (uint16, error) GetCPS() (uint16, error)
Volts() (int16, error) Volts() (int16, error)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
package geiger package geiger
import ( import (
"encoding/hex"
"errors" "errors"
"fmt" "fmt"
"strconv" "strconv"
...@@ -52,13 +53,14 @@ type GQGMCCounter struct { ...@@ -52,13 +53,14 @@ type GQGMCCounter struct {
port *serial.Port port *serial.Port
config *serial.Config config *serial.Config
version, version,
model string model,
serial string
} }
// 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
var v []byte var buf []byte
gc.config = &serial.Config{ gc.config = &serial.Config{
Name: c.Device, Name: c.Device,
...@@ -70,9 +72,17 @@ func NewGQGMC(c Config) (*GQGMCCounter, error) { ...@@ -70,9 +72,17 @@ func NewGQGMC(c Config) (*GQGMCCounter, error) {
return nil, err return nil, err
} }
gc.port = p gc.port = p
v, err = gc.communicate(cmdGetVersion, 14) buf, err = gc.communicate(cmdGetVersion, 14)
gc.model = string(v[:7]) if err == nil {
gc.version = string(v[7:]) gc.model = string(buf[:7])
gc.version = string(buf[7:])
}
if gc.supportedModels(mod280n300) && !gc.versionLT("Re 2.11") {
buf, err := gc.communicate(cmdGetSerial, 7)
if err == nil {
gc.serial = hex.EncodeToString(buf)
}
}
//getConfigurationData() //getConfigurationData()
return &gc, nil return &gc, nil
} }
...@@ -99,23 +109,9 @@ func (gc *GQGMCCounter) Model() string { ...@@ -99,23 +109,9 @@ func (gc *GQGMCCounter) Model() string {
return gc.model return gc.model
} }
// SerialNum gets the serial number of the device // Serial gets the serial number of the device
func (gc *GQGMCCounter) SerialNum() (string, error) { func (gc *GQGMCCounter) Serial() string {
if !gc.supportedModels(mod280n300) { return gc.serial
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 {
serStr += fmt.Sprintf("%02X", b)
}
}
return serStr, err
} }
func (gc *GQGMCCounter) getReading(what string) (uint16, error) { func (gc *GQGMCCounter) getReading(what string) (uint16, 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