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