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
68a4c89c
Commit
68a4c89c
authored
Feb 01, 2017
by
Kevin Lyda
💬
Browse files
Work on GetConfiguration.
parent
ed1aaa1f
Pipeline
#1232
passed with stage
in 5 minutes and 13 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
devices/geiger/gqgmc.go
View file @
68a4c89c
...
...
@@ -95,7 +95,7 @@ func (gc *GQGMCCounter) Clear() error {
// Read up to 10 chars until nothing comes back.
// error otherwise.
for
i
:=
0
;
i
<
10
;
i
++
{
if
_
,
err
:=
gc
.
re
adCmd
(
1
);
err
!=
nil
{
if
_
,
err
:=
gc
.
re
cv
(
1
);
err
!=
nil
{
break
}
}
...
...
@@ -169,7 +169,7 @@ func (gc *GQGMCCounter) TurnOnCPS() error {
}
gc
.
mutex
.
Lock
()
gc
.
send
Cmd
(
cmdTurnOnCPS
)
gc
.
send
(
cmdTurnOnCPS
)
gc
.
mutex
.
Unlock
()
return
nil
}
...
...
@@ -184,7 +184,7 @@ func (gc *GQGMCCounter) TurnOffCPS() error {
}
gc
.
mutex
.
Lock
()
gc
.
send
Cmd
(
cmdTurnOffCPS
)
gc
.
send
(
cmdTurnOffCPS
)
gc
.
Clear
()
gc
.
mutex
.
Unlock
()
return
nil
...
...
@@ -193,7 +193,7 @@ func (gc *GQGMCCounter) TurnOffCPS() error {
// GetAutoCPS gets a reading once auto CPS is turned on
func
(
gc
*
GQGMCCounter
)
GetAutoCPS
()
(
uint16
,
error
)
{
gc
.
mutex
.
Lock
()
buf
,
err
:=
gc
.
re
adCmd
(
2
)
buf
,
err
:=
gc
.
re
cv
(
2
)
gc
.
mutex
.
Unlock
()
if
err
!=
nil
{
...
...
@@ -214,7 +214,7 @@ func (gc *GQGMCCounter) TurnOnPower() {
}
gc
.
mutex
.
Lock
()
gc
.
send
Cmd
(
cmdTurnOnPwr
)
gc
.
send
(
cmdTurnOnPwr
)
gc
.
mutex
.
Unlock
()
return
}
...
...
@@ -229,7 +229,7 @@ func (gc *GQGMCCounter) TurnOffPower() {
}
gc
.
mutex
.
Lock
()
gc
.
send
Cmd
(
cmdTurnOffPwr
)
gc
.
send
(
cmdTurnOffPwr
)
gc
.
mutex
.
Unlock
()
return
}
...
...
@@ -299,7 +299,7 @@ func (gc *GQGMCCounter) setTimeParts(t time.Time) {
copy
(
cmd
[
11
:
],
">>"
)
// Mutex acquired in setTime()
gc
.
port
.
Write
(
cmd
)
gc
.
re
adCmd
(
1
)
gc
.
re
cv
(
1
)
}
}
...
...
@@ -315,7 +315,7 @@ func (gc *GQGMCCounter) setTimeAll(t time.Time) {
copy
(
cmd
[
18
:
],
">>"
)
// Mutex acquired in setTime()
gc
.
port
.
Write
(
cmd
)
gc
.
re
adCmd
(
1
)
gc
.
re
cv
(
1
)
}
// GetTime gets the time
...
...
@@ -393,7 +393,7 @@ func (gc *GQGMCCounter) FactoryReset() {
}
gc
.
mutex
.
Lock
()
gc
.
send
Cmd
(
cmdFactoryReset
)
gc
.
send
(
cmdFactoryReset
)
gc
.
mutex
.
Unlock
()
return
}
...
...
@@ -408,7 +408,7 @@ func (gc *GQGMCCounter) Reboot() {
}
gc
.
mutex
.
Lock
()
gc
.
send
Cmd
(
cmdReboot
)
gc
.
send
(
cmdReboot
)
gc
.
mutex
.
Unlock
()
return
}
...
...
@@ -426,31 +426,42 @@ func (gc *GQGMCCounter) versionLT(version string) bool {
return
gc
.
version
<
version
}
func
(
gc
*
GQGMCCounter
)
communicate
(
cmd
string
,
length
u
int
32
)
([]
byte
,
error
)
{
func
(
gc
*
GQGMCCounter
)
communicate
(
cmd
string
,
length
int
)
([]
byte
,
error
)
{
gc
.
mutex
.
Lock
()
defer
gc
.
mutex
.
Unlock
()
gc
.
Clear
()
if
len
(
cmd
)
>
0
{
gc
.
send
Cmd
(
cmd
)
gc
.
send
(
cmd
)
}
if
length
!=
0
{
return
gc
.
re
adCmd
(
length
)
return
gc
.
re
cv
(
length
)
}
return
nil
,
nil
}
func
(
gc
*
GQGMCCounter
)
send
Cmd
(
cmd
string
)
{
func
(
gc
*
GQGMCCounter
)
send
(
cmd
string
)
{
gc
.
port
.
Write
([]
byte
(
cmd
))
return
}
func
(
gc
*
GQGMCCounter
)
re
adCmd
(
length
u
int
32
)
([]
byte
,
error
)
{
func
(
gc
*
GQGMCCounter
)
re
cv
(
length
int
)
([]
byte
,
error
)
{
buf
:=
make
([]
byte
,
length
)
n
,
err
:=
gc
.
port
.
Read
(
buf
)
if
err
!=
nil
{
return
nil
,
err
}
if
uint32
(
n
)
!=
length
{
if
n
!=
length
{
for
i
:=
0
;
i
<
20
;
i
++
{
_
,
err
=
gc
.
port
.
Read
(
buf
[
len
(
buf
)
:
])
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
buf
)
==
length
{
break
}
}
}
if
n
!=
length
{
return
nil
,
fmt
.
Errorf
(
"Short read (got: %d, wanted: %d)"
,
uint32
(
n
),
length
)
}
return
buf
,
nil
...
...
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