Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
gqgmc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kevin Lyda
gqgmc
Commits
b04758da
There was a problem fetching the pipeline summary.
Commit
b04758da
authored
8 years ago
by
Kevin Lyda
Browse files
Options
Downloads
Patches
Plain Diff
Add mutexes for serial access.
parent
c4a8662d
No related branches found
No related tags found
No related merge requests found
Pipeline
#
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/gqgmcd/main.go
+0
-1
0 additions, 1 deletion
cmd/gqgmcd/main.go
devices/geiger/gqgmc.go
+24
-0
24 additions, 0 deletions
devices/geiger/gqgmc.go
with
24 additions
and
1 deletion
cmd/gqgmcd/main.go
+
0
−
1
View file @
b04758da
...
@@ -13,7 +13,6 @@ import (
...
@@ -13,7 +13,6 @@ import (
"log"
"log"
"net/http"
"net/http"
"path"
"path"
//"sync"
"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"
...
...
This diff is collapsed.
Click to expand it.
devices/geiger/gqgmc.go
+
24
−
0
View file @
b04758da
...
@@ -12,6 +12,7 @@ import (
...
@@ -12,6 +12,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"strconv"
"strconv"
"sync"
"time"
"time"
"github.com/tarm/serial"
"github.com/tarm/serial"
...
@@ -55,6 +56,7 @@ type GQGMCCounter struct {
...
@@ -55,6 +56,7 @@ type GQGMCCounter struct {
version
,
version
,
model
,
model
,
serial
string
serial
string
mutex
*
sync
.
Mutex
}
}
// NewGQGMC creates a new GQGMC Counter instance
// NewGQGMC creates a new GQGMC Counter instance
...
@@ -72,6 +74,7 @@ func NewGQGMC(c Config) (*GQGMCCounter, error) {
...
@@ -72,6 +74,7 @@ func NewGQGMC(c Config) (*GQGMCCounter, error) {
return
nil
,
err
return
nil
,
err
}
}
gc
.
port
=
p
gc
.
port
=
p
gc
.
mutex
=
&
sync
.
Mutex
{}
buf
,
err
=
gc
.
communicate
(
cmdGetVersion
,
14
)
buf
,
err
=
gc
.
communicate
(
cmdGetVersion
,
14
)
if
err
==
nil
{
if
err
==
nil
{
gc
.
model
=
string
(
buf
[
:
7
])
gc
.
model
=
string
(
buf
[
:
7
])
...
@@ -165,7 +168,9 @@ func (gc *GQGMCCounter) TurnOnCPS() error {
...
@@ -165,7 +168,9 @@ func (gc *GQGMCCounter) TurnOnCPS() error {
return
errors
.
New
(
"Unsupported version"
)
return
errors
.
New
(
"Unsupported version"
)
}
}
gc
.
mutex
.
Lock
()
gc
.
sendCmd
(
cmdTurnOnCPS
)
gc
.
sendCmd
(
cmdTurnOnCPS
)
gc
.
mutex
.
Unlock
()
return
nil
return
nil
}
}
...
@@ -178,14 +183,19 @@ func (gc *GQGMCCounter) TurnOffCPS() error {
...
@@ -178,14 +183,19 @@ func (gc *GQGMCCounter) TurnOffCPS() error {
return
errors
.
New
(
"Unsupported version"
)
return
errors
.
New
(
"Unsupported version"
)
}
}
gc
.
mutex
.
Lock
()
gc
.
sendCmd
(
cmdTurnOffCPS
)
gc
.
sendCmd
(
cmdTurnOffCPS
)
gc
.
Clear
()
gc
.
Clear
()
gc
.
mutex
.
Unlock
()
return
nil
return
nil
}
}
// GetAutoCPS gets a reading once auto CPS is turned on
// GetAutoCPS gets a reading once auto CPS is turned on
func
(
gc
*
GQGMCCounter
)
GetAutoCPS
()
(
uint16
,
error
)
{
func
(
gc
*
GQGMCCounter
)
GetAutoCPS
()
(
uint16
,
error
)
{
gc
.
mutex
.
Lock
()
buf
,
err
:=
gc
.
readCmd
(
2
)
buf
,
err
:=
gc
.
readCmd
(
2
)
gc
.
mutex
.
Unlock
()
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
...
@@ -203,7 +213,9 @@ func (gc *GQGMCCounter) TurnOnPower() {
...
@@ -203,7 +213,9 @@ func (gc *GQGMCCounter) TurnOnPower() {
return
return
}
}
gc
.
mutex
.
Lock
()
gc
.
sendCmd
(
cmdTurnOnPwr
)
gc
.
sendCmd
(
cmdTurnOnPwr
)
gc
.
mutex
.
Unlock
()
return
return
}
}
...
@@ -216,7 +228,9 @@ func (gc *GQGMCCounter) TurnOffPower() {
...
@@ -216,7 +228,9 @@ func (gc *GQGMCCounter) TurnOffPower() {
return
return
}
}
gc
.
mutex
.
Lock
()
gc
.
sendCmd
(
cmdTurnOffPwr
)
gc
.
sendCmd
(
cmdTurnOffPwr
)
gc
.
mutex
.
Unlock
()
return
return
}
}
...
@@ -256,6 +270,8 @@ func (gc *GQGMCCounter) SetTime(t time.Time) {
...
@@ -256,6 +270,8 @@ func (gc *GQGMCCounter) SetTime(t time.Time) {
if
gc
.
versionLT
(
"Re 2.23"
)
{
if
gc
.
versionLT
(
"Re 2.23"
)
{
return
return
}
}
gc
.
mutex
.
Lock
()
defer
gc
.
mutex
.
Unlock
()
if
gc
.
versionLT
(
"Re 3.30"
)
{
if
gc
.
versionLT
(
"Re 3.30"
)
{
gc
.
setTimeParts
(
t
)
gc
.
setTimeParts
(
t
)
}
}
...
@@ -280,6 +296,7 @@ func (gc *GQGMCCounter) setTimeParts(t time.Time) {
...
@@ -280,6 +296,7 @@ func (gc *GQGMCCounter) setTimeParts(t time.Time) {
copy
(
cmd
[
:
],
c
.
cmd
)
copy
(
cmd
[
:
],
c
.
cmd
)
cmd
[
10
]
=
uint8
(
c
.
unit
)
cmd
[
10
]
=
uint8
(
c
.
unit
)
copy
(
cmd
[
11
:
],
">>"
)
copy
(
cmd
[
11
:
],
">>"
)
// Mutex acquired in setTime()
gc
.
port
.
Write
(
cmd
)
gc
.
port
.
Write
(
cmd
)
gc
.
readCmd
(
1
)
gc
.
readCmd
(
1
)
}
}
...
@@ -295,6 +312,7 @@ func (gc *GQGMCCounter) setTimeAll(t time.Time) {
...
@@ -295,6 +312,7 @@ func (gc *GQGMCCounter) setTimeAll(t time.Time) {
cmd
[
16
]
=
uint8
(
t
.
Minute
())
cmd
[
16
]
=
uint8
(
t
.
Minute
())
cmd
[
17
]
=
uint8
(
t
.
Second
())
cmd
[
17
]
=
uint8
(
t
.
Second
())
copy
(
cmd
[
18
:
],
">>"
)
copy
(
cmd
[
18
:
],
">>"
)
// Mutex acquired in setTime()
gc
.
port
.
Write
(
cmd
)
gc
.
port
.
Write
(
cmd
)
gc
.
readCmd
(
1
)
gc
.
readCmd
(
1
)
}
}
...
@@ -373,7 +391,9 @@ func (gc *GQGMCCounter) FactoryReset() {
...
@@ -373,7 +391,9 @@ func (gc *GQGMCCounter) FactoryReset() {
return
return
}
}
gc
.
mutex
.
Lock
()
gc
.
sendCmd
(
cmdFactoryReset
)
gc
.
sendCmd
(
cmdFactoryReset
)
gc
.
mutex
.
Unlock
()
return
return
}
}
...
@@ -386,7 +406,9 @@ func (gc *GQGMCCounter) Reboot() {
...
@@ -386,7 +406,9 @@ func (gc *GQGMCCounter) Reboot() {
return
return
}
}
gc
.
mutex
.
Lock
()
gc
.
sendCmd
(
cmdReboot
)
gc
.
sendCmd
(
cmdReboot
)
gc
.
mutex
.
Unlock
()
return
return
}
}
...
@@ -404,6 +426,8 @@ func (gc *GQGMCCounter) versionLT(version string) bool {
...
@@ -404,6 +426,8 @@ func (gc *GQGMCCounter) versionLT(version string) bool {
}
}
func
(
gc
*
GQGMCCounter
)
communicate
(
cmd
string
,
length
uint32
)
([]
byte
,
error
)
{
func
(
gc
*
GQGMCCounter
)
communicate
(
cmd
string
,
length
uint32
)
([]
byte
,
error
)
{
gc
.
mutex
.
Lock
()
defer
gc
.
mutex
.
Unlock
()
gc
.
Clear
()
gc
.
Clear
()
if
len
(
cmd
)
>
0
{
if
len
(
cmd
)
>
0
{
gc
.
sendCmd
(
cmd
)
gc
.
sendCmd
(
cmd
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment