Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Kevin Lyda
gqgmc
Commits
c1cdc990
Commit
c1cdc990
authored
Jan 30, 2017
by
Kevin Lyda
💬
Browse files
More implemented; tried.
parent
a7ce96ee
Pipeline
#1200
failed with stage
in 14 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
cmd/gqgmc/main.go
View file @
c1cdc990
...
...
@@ -16,7 +16,10 @@ func main() {
var
(
gc
geiger
.
Counter
cps
,
cpm
uint16
volts
int16
ser
string
err
error
ver
string
)
gc
,
err
=
geiger
.
New
(
geiger
.
Config
{
...
...
@@ -41,4 +44,26 @@ func main() {
return
}
fmt
.
Printf
(
"CPS: %d
\n
"
,
cps
)
ver
,
err
=
gc
.
Version
()
if
err
!=
nil
{
fmt
.
Printf
(
"Failed to connect to geiger counter: '%s'
\n
"
,
err
)
return
}
fmt
.
Printf
(
"Version: %s
\n
"
,
ver
)
ser
,
err
=
gc
.
SerialNum
()
if
err
!=
nil
{
fmt
.
Printf
(
"Failed to connect to geiger counter: '%s'
\n
"
,
err
)
return
}
fmt
.
Printf
(
"Version: %s
\n
"
,
ser
)
volts
,
err
=
gc
.
Volts
()
if
err
!=
nil
{
fmt
.
Printf
(
"Failed to connect to geiger counter: '%s'
\n
"
,
err
)
return
}
fmt
.
Printf
(
"Version: %d
\n
"
,
volts
)
}
devices/geiger/geiger.go
View file @
c1cdc990
...
...
@@ -23,7 +23,7 @@ type Counter interface {
SerialNum
()
(
string
,
error
)
GetCPM
()
(
uint16
,
error
)
GetCPS
()
(
uint16
,
error
)
Get
Volt
age
()
(
int16
,
error
)
Volt
s
()
(
int16
,
error
)
GetHistoryData
()
TurnOnCPS
()
error
TurnOffCPS
()
error
...
...
devices/geiger/gqgmc.go
View file @
c1cdc990
...
...
@@ -158,7 +158,6 @@ func NewGQGMC(c Config) (*GQGMCCounter, error) {
if
err
!=
nil
{
return
nil
,
err
}
//vers := getVersion()
//getConfigurationData()
return
&
GQGMCCounter
{
port
:
p
,
config
:
&
cfg
},
nil
}
...
...
@@ -172,26 +171,25 @@ func (gc *GQGMCCounter) Clear() error {
// Version gets the version of the device
func
(
gc
*
GQGMCCounter
)
Version
()
(
string
,
error
)
{
//communicate(get_version_cmd, version, versize);
// use cmdGetVersion. Returns 14 byte string.
return
""
,
nil
ver
,
err
:=
gc
.
communicate
(
cmdGetVersion
,
14
)
return
string
(
ver
),
err
}
// SerialNum gets the serial number of the device
func
(
gc
*
GQGMCCounter
)
SerialNum
()
(
string
,
error
)
{
//communicate(get_serial_cmd, serial_number, sernumsize);
// use cmdGetSerial. Returns 7 bytes.
// Turn each 4 bits into corresponging hex char.
bs
:=
[]
byte
{
0
,
0x30
,
0
,
0xE3
,
0x4A
,
0x35
,
0x1A
}
for
_
,
b
:=
range
bs
{
fmt
.
Printf
(
"%02X"
,
b
)
serStr
:=
""
ser
,
err
:=
gc
.
communicate
(
cmdGetSerial
,
7
)
if
err
!=
nil
{
for
_
,
b
:=
range
ser
{
serStr
+=
fmt
.
Sprintf
(
"%02X"
,
b
)
}
}
fmt
.
Println
(
""
)
return
""
,
nil
return
serStr
,
err
}
func
(
gc
*
GQGMCCounter
)
getReading
(
what
string
)
(
uint16
,
error
)
{
buf
,
err
:=
gc
.
communicate
(
[]
byte
(
what
)
,
2
)
buf
,
err
:=
gc
.
communicate
(
what
,
2
)
if
err
!=
nil
{
return
0
,
err
}
...
...
@@ -210,8 +208,8 @@ func (gc *GQGMCCounter) GetCPS() (uint16, error) {
return
gc
.
getReading
(
cmdGetCPS
)
}
//
Get
Volt
age
returns current battery voltage
func
(
gc
*
GQGMCCounter
)
Get
Volt
age
()
(
int16
,
error
)
{
// Volt
s
returns current battery voltage
func
(
gc
*
GQGMCCounter
)
Volt
s
()
(
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
...
...
@@ -221,15 +219,11 @@ func (gc *GQGMCCounter) GetVoltage() (int16, error) {
// 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.
//func (gc *GQGMCCounter) getBatteryVoltage()
//uint32_t voltsize = 1; // one byte of returned data
// Issue command to get battery voltage and read returned data.
//communicate(get_voltage_cmd, voltage_char, voltsize);
// If read of returned data succeeded, convert raw data to float,
//int32_t voltage_int = int16_t(voltage_char[0]);
//voltage = float(voltage_int) / 10.0;
return
0
,
nil
volts
,
err
:=
gc
.
communicate
(
cmdGetVoltage
,
1
)
if
err
!=
nil
{
return
0
,
err
}
return
int16
(
volts
[
0
]),
err
}
// GetHistoryData Should return history data but is unimplemented for now
...
...
@@ -253,34 +247,31 @@ func (gc *GQGMCCounter) TurnOnCPS() error {
// separate command. The command is turn_on_cps_cmd
// (see GQ GMC COMMANDS above). The returned data is always two
// bytes so that samples > 255 can be reported (even though unlikely).
//sendCmd(turn_on_cps_cmd);
// There is no pass/fail return from GQ GMC
gc
.
sendCmd
(
cmdTurnOnCPS
)
return
nil
}
// TurnOffCPS turns off CPS collection
func
(
gc
*
GQGMCCounter
)
TurnOffCPS
()
error
{
//
sendCmd(
turn_off_cps_cmd);
//call
Clear()
gc
.
sendCmd
(
cmdTurnOffCPS
)
gc
.
Clear
()
return
nil
}
// GetAutoCPS gets a reading once auto CPS is turned on
func
(
gc
*
GQGMCCounter
)
GetAutoCPS
()
(
uint16
,
error
)
{
//uint32_t cpssize = 2; // 2 bytes of returned data
//read-from-port(cps_char, cpssize);
// 1st byte is MSB, but note that upper two bits are reserved bits.
// Note that shifting and bitmasking performed in uP register, so
// endianess is irrevelant.
//cps_int |= ((uint16_t(cps_char[0]) << 8) & 0x3f00);
//cps_int |= (uint16_t(cps_char[1]) & 0x00ff);
return
0
,
nil
buf
,
err
:=
gc
.
readCmd
(
2
)
if
err
!=
nil
{
return
0
,
err
}
cps
:=
((
uint16
(
buf
[
0
])
<<
8
)
&
0x3f00
)
cps
|=
(
uint16
(
buf
[
1
])
&
0x00ff
)
return
cps
,
nil
}
// TurnOffPower turns the device off
func
(
gc
*
GQGMCCounter
)
TurnOffPower
()
{
//sendCmd(turn_off_pwr_cmd)
// Note that power off cannot fail because the GQ GMC returns nothing.
gc
.
sendCmd
(
cmdTurnOffPwr
)
return
}
...
...
@@ -339,7 +330,7 @@ func (gc *GQGMCCounter) SetTime(time string) {
//communicate(setSecondCmd, ret_char, retsize);
}
func
(
gc
*
GQGMCCounter
)
communicate
(
cmd
[]
byte
,
length
uint32
)
([]
byte
,
error
)
{
func
(
gc
*
GQGMCCounter
)
communicate
(
cmd
string
,
length
uint32
)
([]
byte
,
error
)
{
gc
.
Clear
()
if
len
(
cmd
)
>
0
{
gc
.
sendCmd
(
cmd
)
...
...
@@ -350,8 +341,8 @@ func (gc *GQGMCCounter) communicate(cmd []byte, length uint32) ([]byte, error) {
return
nil
,
nil
}
func
(
gc
*
GQGMCCounter
)
sendCmd
(
cmd
[]
byte
)
{
gc
.
port
.
Write
(
cmd
)
func
(
gc
*
GQGMCCounter
)
sendCmd
(
cmd
string
)
{
gc
.
port
.
Write
(
[]
byte
(
cmd
)
)
return
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment