Skip to content

Commit a691ec2

Browse files
committed
chore: update readme with tcp support, fix lint warnings, update fatih/color for example.
1 parent 91c55f9 commit a691ec2

21 files changed

+163
-139
lines changed

.golangci.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@ linters-settings:
88
linters:
99
enable-all: true
1010
disable:
11+
# might be good to have for future refactoring
12+
- wrapcheck
13+
- goerr113
14+
- gocyclo
15+
- cyclop
16+
- exhaustive
17+
- durationcheck
18+
- errname
19+
20+
# generally disabled linters
21+
- nolintlint
1122
- errcheck
1223
- gochecknoglobals
13-
- gocyclo
14-
- gocyclop
1524
- gocognit
1625
- lll
1726
- gomnd
@@ -24,8 +33,12 @@ linters:
2433
- varnamelen
2534
- nlreturn
2635
- exhaustruct
36+
- nonamedreturns
37+
- testpackage
38+
- thelper
39+
- ireturn
2740

28-
# offically deprecated
41+
# officially deprecated
2942
- nosnakecase
3043
- maligned
3144
- exhaustivestruct
@@ -37,10 +50,17 @@ linters:
3750
- golint
3851

3952
issues:
53+
exclude-rules:
54+
- path: "(.+)_test.go"
55+
linters:
56+
- maintidx
57+
- unused
58+
4059
exclude:
4160
- "G104: Errors unhandled." # turn off errcheck
42-
- "declaration of \"[a-z]\" shadows declaration at .*_test.go" # ignore shadowing a single charcter varibles in tests
61+
- "declaration of \"[a-z]\" shadows declaration at .*_test.go" # ignore shadowing a single character variables in tests
4362
- "receiver name [a-z]0 should be consistent with previous receiver name [a-z]" # when we want to operate on a copy
63+
- "ST1016: methods on the same type should have the same receiver name .seen .. \"[a-z]0\", .. \"[a-z]\""
4464
- "error strings should not be capitalized or end with punctuation or a newline" # doesn't matter
4565
- "lines are duplicate of `crc.crc.go:" # ignore duplications in crc.go
4666
- "package should be `crc_test` instead of `crc`" # ignore white listed internal testing

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,24 @@ Instead, a callback based API (like http server handler) is used for both server
220220
## Implemented
221221

222222
- Serial RTU
223+
- Modbus over TCP
223224
- Function Codes 1-6,15,16
224225
- Server and Client API
225226
- Server and Client Tester (examples/memory)
226227

227228
## Development
228229

229-
This project is mostly stable, and I am using it in production.
230+
This project and API is stable, and I am using it in production.
230231

231-
API stability is best effort. This means:
232+
My primary usage is RTU (over RS-485). TCP is also supported. Others may or may not be implemented in the future.
232233

233-
- Changes should not break users code unless there is a compelling reason.
234-
235-
- Code broken by API changes should not compile, new errors to user code should not be introduced silently.
234+
Contribution to new or existing functionally, or just changing a private identifier public are welcome, as well as documentation, test, example code or any other improvements.
236235

237-
- API changes will be documented to speed adoption of new versions.
236+
Development tools:
238237

239-
My primary usage is RTU (over RS-485). Others may or may not be implemented in the future.
240-
241-
Contribution to new or existing functionally, or just changing a private identifier public are welcome, as well as documentation, test, example code or any other improvements.
238+
- `go generate` runs `embedmd` to copy parts of the examples_test.go to this readme file
239+
- `golangci-lint run` for improvement hints. Ideally there are no warnings.
240+
- Use `go test -race -count=5 ./...` pre release.
242241

243242
## Breaking Changes
244243

@@ -255,16 +254,18 @@ Contribution to new or existing functionally, or just changing a private identif
255254

256255
Compatibility with a wide range of serial hardware/drivers. (good)
257256

258-
Compatibility with existing Modbus environments. (good)
257+
Compatibility with existing Modbus environments, including non-compliance and extensions. (good)
259258

260259
Recover from transmission errors and timeouts, to work continuously unattended. (good)
261260

262-
Better test coverage that also tests error conditions. (todo)
261+
Better test coverage that also tests error conditions. (todo)
263262

264-
Fuzz testing. (todo)
263+
Fuzz testing. (todo)
265264

266265
## Failover mode
267266

267+
TLDR: do not use.
268+
268269
Failover has landed in v0.2.0, but it should be considered less stable than the other parts.
269270

270271
In mission-critical applications, or anywhere hardware redundancy is cheaper than downtime, having a standby system taking over in case of the failure of the primary system is desirable.

crc/crc.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"io"
99
)
1010

11-
// Table of CRC values for high–order byte
12-
var crcHighBytes = []byte{
11+
// Table of CRC values for high–order byte.
12+
var crcHighBytes = []byte{ //nolint:dupl
1313
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
1414
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
1515
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40, 0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
@@ -28,8 +28,8 @@ var crcHighBytes = []byte{
2828
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41, 0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
2929
}
3030

31-
// Table of CRC values for low-order byte
32-
var crcLowBytes = []byte{
31+
// Table of CRC values for low-order byte.
32+
var crcLowBytes = []byte{ //nolint:dupl
3333
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2, 0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04,
3434
0xCC, 0x0C, 0x0D, 0xCD, 0x0F, 0xCF, 0xCE, 0x0E, 0x0A, 0xCA, 0xCB, 0x0B, 0xC9, 0x09, 0x08, 0xC8,
3535
0xD8, 0x18, 0x19, 0xD9, 0x1B, 0xDB, 0xDA, 0x1A, 0x1E, 0xDE, 0xDF, 0x1F, 0xDD, 0x1D, 0x1C, 0xDC,
@@ -48,7 +48,7 @@ var crcLowBytes = []byte{
4848
0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40,
4949
}
5050

51-
// Cyclical Redundancy Checking
51+
// crc is Cyclical Redundancy Checking.
5252
type crc struct {
5353
high byte
5454
low byte
@@ -87,7 +87,7 @@ func (c *crc) Sum16() uint16 {
8787
return uint16(c.low)<<8 | uint16(c.high)
8888
}
8989

90-
// Hash is a subset of hash.Hash
90+
// Hash is a subset of hash.Hash.
9191
type Hash interface {
9292
// Write (via the embedded io.Writer interface) adds more data to the running hash.
9393
// It never returns an error.

crc/rtu.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package crc
22

3-
// Validate return true if byte slice ends with valid crc
3+
// Validate return true if byte slice ends with valid CRC.
44
func Validate(bs []byte) bool {
55
if len(bs) <= 2 {
66
return false

examples_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//go:generate embedmd -w README.md
22
//go:generate sed -i -e 's/\t/\ \ \ \ /g' README.md
33

4+
//nolint:forbidigo
45
package modbusone_test
56

67
import (

failover_client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func TestFailoverClient(t *testing.T) {
6565
// t.Skip()
6666

6767
id := byte(0x77)
68-
clientA, clientB, pc, countA, countB, countC, close := connectMockClients(t, id)
69-
defer close()
68+
clientA, clientB, pc, countA, countB, countC, closeClients := connectMockClients(t, id)
69+
defer closeClients()
7070
exCount := &counter{Stats: &Stats{}}
7171
resetCounts := func() {
7272
exCount.reset()
@@ -106,7 +106,7 @@ func TestFailoverClient(t *testing.T) {
106106
}
107107
time.Sleep(serverProcessingTime)
108108
if !pc.IsActive() {
109-
t.Fatal("primaray client should be active")
109+
t.Fatal("primary client should be active")
110110
}
111111
})
112112

failover_rtu_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type FailoverRTUClient struct {
1818
actions chan rtuAction
1919
}
2020

21-
// FailoverRTUClient is also a Server
21+
// FailoverRTUClient is also a Server.
2222
var _ Server = &FailoverRTUClient{}
2323

2424
// NewFailoverRTUClient create a new client with failover function communicating over SerialContext with the

failover_server_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ func connectToMockServers(t *testing.T, slaveID byte) (*RTUClient, *FailoverSeri
115115

116116
func TestFailoverServer(t *testing.T) {
117117
id := byte(0x77)
118-
client, pc, countA, countB, countC, close := connectToMockServers(t, id)
119-
defer close()
118+
client, pc, countA, countB, countC, closeServers := connectToMockServers(t, id)
119+
defer closeServers()
120120
exCount := counter{Stats: &Stats{}}
121121
resetCounts := func() {
122122
exCount.reset()
@@ -155,7 +155,7 @@ func TestFailoverServer(t *testing.T) {
155155
}
156156
time.Sleep(serverProcessingTime * 2)
157157
if !pc.IsActive() {
158-
t.Fatal("primaray servers should be active")
158+
t.Fatal("primary servers should be active")
159159
}
160160
})
161161

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/xiegeo/modbusone
33
go 1.14
44

55
require (
6-
github.com/fatih/color v1.9.0
6+
github.com/fatih/color v1.13.0
77
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
88
github.com/xiegeo/coloredgoroutine v0.1.1
99
)

go.sum

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
2-
github.com/fatih/color v1.9.0 h1:8xPHl4/q1VyqGIPif1F+1V3Y3lSmrq01EabUW3CoW5s=
3-
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
2+
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
3+
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
44
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
5-
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
6-
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
5+
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
6+
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
77
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
8-
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
9-
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
10-
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
8+
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
9+
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
10+
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
1111
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07 h1:UyzmZLoiDWMRywV4DUYb9Fbt8uiOSooupjTq10vpvnU=
1212
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
1313
github.com/xiegeo/coloredgoroutine v0.1.1 h1:L6EaQHWIY+oIlKpj5ORu9hIorsLbQwTAStEHSp1SoAs=
1414
github.com/xiegeo/coloredgoroutine v0.1.1/go.mod h1:d3jyamWlthEBXOL5qUpKOaaKSJM75HuCIn/z9f4ylrs=
1515
golang.org/x/sys v0.0.0-20180831094639-fa5fdf94c789/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
16-
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
17-
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
18-
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
16+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
17+
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
18+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
19+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

0 commit comments

Comments
 (0)