Skip to content
This repository was archived by the owner on May 16, 2021. It is now read-only.

Commit bb7650b

Browse files
author
Alexander Sowitzki
committed
Giant quality overhaul
1 parent 4cf542e commit bb7650b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1949
-1761
lines changed

Makefile

+4-15
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,11 @@ export GITTAG=$(shell git describe --tags --always)
55
export IMAGE=docker.pkg.github.com/eqrx/mauzr/mauzr
66

77
.PHONY: all
8-
all: dist
8+
all: build
99

10-
.PHONY: dist/amd64/mauzr
11-
dist/amd64/mauzr:
12-
GOARCH=amd64 go build -trimpath -ldflags "$(GOLDFLAGS)" -o $@ ./cmd/mauzr
13-
14-
.PHONY: dist/arm64/mauzr
15-
dist/arm64/mauzr:
16-
GOARCH=arm64 go build -trimpath -ldflags "$(GOLDFLAGS)" -o $@ ./cmd/mauzr
17-
18-
.PHONY: dist/arm/mauzr
19-
dist/arm/mauzr:
20-
GOARCH=arm go build -trimpath -ldflags "$(GOLDFLAGS)" -o $@ ./cmd/mauzr
21-
22-
.PHONY: dist
23-
dist: dist/amd64/mauzr dist/arm64/mauzr dist/arm/mauzr
10+
.PHONY: build
11+
build:
12+
go build -ldflags "$(GOLDFLAGS)" ./...
2413

2514
.PHONY: generate
2615
generate:

README.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
<a href="https://goreportcard.com/report/github.com/eqrx/mauzr-go"><img src="https://goreportcard.com/badge/github.com/eqrx/mauzr-go" alt="Go Report Card"/></a>
1+
<p align="center">
2+
<a href="https://godoc.org/github.com/eqrx/mauzr">
3+
<img src="https://godoc.org/github.com/eqrx/mauzr?status.svg" alt="GoDoc" />
4+
</a>
5+
<a href="https://goreportcard.com/report/github.com/eqrx/mauzr">
6+
<img src="https://goreportcard.com/badge/github.com/eqrx/mauzr" alt="Go Report Card" />
7+
</a>
8+
</p>
29

310
# mauzr (go)
411

@@ -7,10 +14,6 @@ Instead of buying a complete product that integrates (or doesn't) into your
714
setup you pick your own hardware, pick a driver and provide its services
815
securely to the network.
916

10-
## Usage
11-
This project is currently in the early makings and in alpha. Documentation
12-
will be added shortly.
13-
1417
## Licence
1518
This project is released under GNU Affero General Public License v3.0, see
1619
LICENCE file in this repo for more info.

cmd/bmecalibrator/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
func main() {
2727
dut := make(chan bme.Request)
2828
com := make(chan bme.Request)
29-
bme.NewBME680("/dev/i2c-1", 0x76, bme.Measurement{}, dut)
30-
bme.NewBME680("/dev/i2c-1", 0x77, bme.Measurement{}, com)
29+
bme.NewBME680("/dev/i2c-1", 0x76, bme.Measurement{}, map[string]string{}, dut)
30+
bme.NewBME680("/dev/i2c-1", 0x77, bme.Measurement{}, map[string]string{}, com)
3131
ticker := time.NewTicker(30 * time.Second)
3232
for {
3333
dutResponses := make(chan bme.Response, 1)

go.mod

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ go 1.14
55
require (
66
github.com/go-ocf/go-coap v0.0.0-20200511140640-db6048acfdd3
77
github.com/pion/dtls/v2 v2.0.0
8-
github.com/spf13/cobra v1.0.0
9-
github.com/spf13/pflag v1.0.5
10-
golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f
11-
gopkg.in/yaml.v2 v2.2.8 // indirect
8+
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
9+
golang.org/x/sys v0.0.0-20200523222454-059865788121
1210
)

go.sum

+3-130
Large diffs are not rendered by default.

init/mauzr@.service

-14
This file was deleted.

init/mauzr@.socket

-10
This file was deleted.

init/sysusers.conf

-1
This file was deleted.

init/udev.rules

-4
This file was deleted.

pkg/bme/bme.go

-87
This file was deleted.

pkg/bme/bme280/bme280.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"time"
2424

2525
"go.eqrx.net/mauzr/pkg/bme/common"
26-
"go.eqrx.net/mauzr/pkg/io"
27-
"go.eqrx.net/mauzr/pkg/io/i2c"
26+
"go.eqrx.net/mauzr/pkg/errors"
27+
"go.eqrx.net/mauzr/pkg/i2c"
2828
)
2929

3030
// calibrationInput contains variables that will be read out of the BME280 registers.
@@ -72,14 +72,13 @@ func (m *Model) Calibrations() Calibrations {
7272
func (m *Model) Reset() error {
7373
// See https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280-DS002.pdf on how this works
7474
var data [36]byte
75-
actions := []io.Action{
76-
m.device.Open(),
75+
err := errors.NewBatch(m.device.Open,
7776
m.device.Write(0xe0, 0xb6),
78-
io.Sleep(2 * time.Millisecond),
77+
errors.BatchSleepAction(2*time.Millisecond),
7978
m.device.WriteRead([]byte{0x88}, data[0:26]),
8079
m.device.WriteRead([]byte{0xe1}, data[26:35]),
81-
}
82-
if err := io.Execute("resetting bme280", actions, []io.Action{m.device.Close()}); err != nil {
80+
).Always(m.device.Close).Execute("resetting bme280")
81+
if err != nil {
8382
return err
8483
}
8584

@@ -98,14 +97,14 @@ func (m *Model) Reset() error {
9897
// Measure creates a measurement with the given BME280 behind the given address.
9998
func (m *Model) Measure() (common.Measurement, error) {
10099
var reading [8]byte
101-
actions := []io.Action{
102-
m.device.Open(),
100+
err := errors.NewBatch(m.device.Open,
103101
m.device.Write(0xf4, 0x3f),
104102
m.device.Write(0xf2, 0x01),
105103
m.device.Write(0xf4, 0x25),
106104
m.device.WriteRead([]byte{0xf7}, reading[:]),
107-
}
108-
if err := io.Execute("reading measurement from bme280", actions, []io.Action{m.device.Close()}); err != nil {
105+
).Always(m.device.Close).Execute("measuring with bme280")
106+
107+
if err != nil {
109108
return common.Measurement{}, err
110109
}
111110

pkg/bme/bme280/hardware_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import (
2323

2424
"go.eqrx.net/mauzr/pkg/bme/bme280"
2525
"go.eqrx.net/mauzr/pkg/bme/common"
26-
"go.eqrx.net/mauzr/pkg/io"
27-
"go.eqrx.net/mauzr/pkg/io/i2c"
26+
"go.eqrx.net/mauzr/pkg/i2c"
2827
)
2928

3029
// MeasurementMock fakes an BME280 device behind an I2C bus.
@@ -52,12 +51,12 @@ var (
5251
measurementResult = common.Measurement{Humidity: 60.5, Pressure: 100651.0, Temperature: 21.9}
5352
)
5453

55-
func (m MeasurementMock) Write(data ...byte) io.Action { return io.NoOperation }
56-
func (m MeasurementMock) Open() io.Action { return io.NoOperation }
57-
func (m MeasurementMock) Close() io.Action { return io.NoOperation }
54+
func (m MeasurementMock) Write(data ...byte) func() error { return func() error { return nil } }
55+
func (m MeasurementMock) Open() error { return nil }
56+
func (m MeasurementMock) Close() error { return nil }
5857

5958
// WriteRead returns data from the given array.
60-
func (m MeasurementMock) WriteRead(source []byte, destination []byte) io.Action {
59+
func (m MeasurementMock) WriteRead(source []byte, destination []byte) func() error {
6160
return func() error {
6261
if len(source) != 1 {
6362
panic(fmt.Sprintf("Expected i2c.RegisterAddress to have length 1, was %v", len(source)))

pkg/bme/bme680/bme680.go

+16-19
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"time"
2424

2525
"go.eqrx.net/mauzr/pkg/bme/common"
26-
"go.eqrx.net/mauzr/pkg/io"
27-
"go.eqrx.net/mauzr/pkg/io/i2c"
26+
"go.eqrx.net/mauzr/pkg/errors"
27+
"go.eqrx.net/mauzr/pkg/i2c"
2828
)
2929

3030
// calibrationInput contains variables that will be read out of the BME680 registers.
@@ -78,21 +78,19 @@ func (m *Model) Calibrations() Calibrations {
7878
return m.calibrations
7979
}
8080

81-
func (m *Model) setupGas() func() error {
82-
return func() error {
83-
target := uint8(3.4 * (((((float64(m.calibrations.Gas.G1)/16.0)+49.0)*(1.0+((((float64(m.calibrations.Gas.G2)/32768.0)*0.0005)+0.00235)*300)) + (float64(m.calibrations.Gas.G3) / 1024.0 * m.last.Temperature)) * (4.0 / (4.0 + float64(m.calibrations.Gas.HeatRange))) * (1.0 / (1.0 + (float64(m.calibrations.Gas.HeatValue) * 0.002)))) - 25))
84-
return m.device.Write(0x5a, target)()
85-
}
81+
func (m *Model) setupGas() error {
82+
target := uint8(3.4 * (((((float64(m.calibrations.Gas.G1)/16.0)+49.0)*(1.0+((((float64(m.calibrations.Gas.G2)/32768.0)*0.0005)+0.00235)*300)) + (float64(m.calibrations.Gas.G3) / 1024.0 * m.last.Temperature)) * (4.0 / (4.0 + float64(m.calibrations.Gas.HeatRange))) * (1.0 / (1.0 + (float64(m.calibrations.Gas.HeatValue) * 0.002)))) - 25))
83+
return m.device.Write(0x5a, target)()
8684
}
8785

8886
// Reset resets the BME680 behind the given address and fetches the calibration.
8987
func (m *Model) Reset() error {
9088
var data [42]byte
9189
var extraData [5]byte
92-
actions := []io.Action{
93-
m.device.Open(),
90+
return errors.NewBatch(
91+
m.device.Open,
9492
m.device.Write(0xe0, 0xb6),
95-
io.Sleep(100 * time.Millisecond),
93+
errors.BatchSleepAction(100*time.Millisecond),
9694
m.device.WriteRead([]byte{0x89}, data[0:25]),
9795
m.device.WriteRead([]byte{0xe1}, data[25:41]),
9896
m.device.WriteRead([]byte{0x00}, extraData[:]),
@@ -111,30 +109,29 @@ func (m *Model) Reset() error {
111109
},
112110
m.device.Write(0x72, 0b00000101, 0b10110101),
113111
m.device.Write(0x64, 0x59),
114-
m.setupGas(),
112+
m.setupGas,
115113
m.device.Write(0x71, 0b00010000),
116114
m.device.Write(0x75, 0b00010000),
117-
}
118-
return io.Execute("resetting bme680", actions, []io.Action{m.device.Close()})
115+
).Always(m.device.Close).Execute("reset bme680")
119116
}
120117

121118
// Measure creates a measurement with the given BME680 behind the given address.
122119
func (m *Model) Measure() (common.Measurement, error) {
123120
var reading [15]byte
124-
actions := []io.Action{
125-
m.device.Open(),
126-
m.setupGas(),
121+
err := errors.NewBatch(
122+
m.device.Open,
123+
m.setupGas,
127124
m.device.Write(0x74, 0b10110101),
128-
io.Sleep(500 * time.Millisecond),
125+
errors.BatchSleepAction(500*time.Millisecond),
129126
m.device.WriteRead([]byte{0x1d}, reading[:]),
130127
func() error {
131128
if reading[0]&0x80 == 0x00 {
132129
panic("sensor was not ready on readout")
133130
}
134131
return nil
135132
},
136-
}
137-
if err := io.Execute("reading measurement from bme680", actions, []io.Action{m.device.Close()}); err != nil {
133+
).Always(m.device.Close).Execute("measuring with bme680")
134+
if err != nil {
138135
return common.Measurement{}, err
139136
}
140137

pkg/bme/bme680/hardware_test.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import (
2323

2424
"go.eqrx.net/mauzr/pkg/bme/bme680"
2525
"go.eqrx.net/mauzr/pkg/bme/common"
26-
"go.eqrx.net/mauzr/pkg/io"
27-
"go.eqrx.net/mauzr/pkg/io/i2c"
26+
"go.eqrx.net/mauzr/pkg/i2c"
2827
)
2928

3029
//MeasurementMock fakes an BME680 device behind an I2C bus.
@@ -61,12 +60,12 @@ var (
6160
measurementResult = common.Measurement{GasResistance: 2898707, Humidity: 63, Pressure: 101304.8, Temperature: 25.4}
6261
)
6362

64-
func (m MeasurementMock) Write(data ...byte) io.Action { return io.NoOperation }
65-
func (m MeasurementMock) Open() io.Action { return io.NoOperation }
66-
func (m MeasurementMock) Close() io.Action { return io.NoOperation }
63+
func (m MeasurementMock) Write(data ...byte) func() error { return func() error { return nil } }
64+
func (m MeasurementMock) Open() error { return nil }
65+
func (m MeasurementMock) Close() error { return nil }
6766

6867
// WriteRead returns data from the given array.
69-
func (m MeasurementMock) WriteRead(source []byte, destination []byte) io.Action {
68+
func (m MeasurementMock) WriteRead(source []byte, destination []byte) func() error {
7069
return func() error {
7170
if len(source) != 1 {
7271
panic(fmt.Sprintf("Expected i2c.RegisterAddress to have length 1, was %v", len(source)))

0 commit comments

Comments
 (0)