Skip to content

Commit ca14cd1

Browse files
authored
Merge pull request #6 from grid-x/fix/skip_linting_2
fix/skip_linting_2
2 parents 09e1fba + ece348d commit ca14cd1

File tree

14 files changed

+76
-56
lines changed

14 files changed

+76
-56
lines changed

.buildkite/pipeline.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ steps:
99
label: ":golang: Build"
1010
agents:
1111
- "queue=default"
12-
#- command:
13-
# - "make ci_lint"
14-
# label: ":llama: Linting"
15-
# agents:
16-
# - "queue=default"
12+
- command:
13+
- "make ci_lint"
14+
label: ":llama: Linting"
15+
agents:
16+
- "queue=default"

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ test:
1616

1717
.PHONY: lint
1818
lint:
19-
golint -set_exit_status $(shell glide nv)
19+
golint -set_exit_status
2020

2121
.PHONY: build
2222
build:
23-
go build $(shell glide nv)
23+
go build
2424

2525
ci_test:
2626
${GO_RUN} "make test"

api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
package modbus
66

7+
// Client declares the functionality of a Modbus client regardless of the underlying transport stream.
78
type Client interface {
89
// Bit access
910

asciiclient.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func ASCIIClient(address string) Client {
4343

4444
// asciiPackager implements Packager interface.
4545
type asciiPackager struct {
46-
SlaveId byte
46+
SlaveID byte
4747
}
4848

4949
// Encode encodes PDU in a ASCII frame:
@@ -59,7 +59,7 @@ func (mb *asciiPackager) Encode(pdu *ProtocolDataUnit) (adu []byte, err error) {
5959
if _, err = buf.WriteString(asciiStart); err != nil {
6060
return
6161
}
62-
if err = writeHex(&buf, []byte{mb.SlaveId, pdu.FunctionCode}); err != nil {
62+
if err = writeHex(&buf, []byte{mb.SlaveID, pdu.FunctionCode}); err != nil {
6363
return
6464
}
6565
if err = writeHex(&buf, pdu.Data); err != nil {
@@ -68,7 +68,7 @@ func (mb *asciiPackager) Encode(pdu *ProtocolDataUnit) (adu []byte, err error) {
6868
// Exclude the beginning colon and terminating CRLF pair characters
6969
var lrc lrc
7070
lrc.reset()
71-
lrc.pushByte(mb.SlaveId).pushByte(pdu.FunctionCode).pushBytes(pdu.Data)
71+
lrc.pushByte(mb.SlaveID).pushByte(pdu.FunctionCode).pushBytes(pdu.Data)
7272
if err = writeHex(&buf, []byte{lrc.value()}); err != nil {
7373
return
7474
}

asciiclient_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func TestASCIIEncoding(t *testing.T) {
1313
encoder := asciiPackager{}
14-
encoder.SlaveId = 17
14+
encoder.SlaveID = 17
1515

1616
pdu := ProtocolDataUnit{}
1717
pdu.FunctionCode = 3
@@ -29,7 +29,7 @@ func TestASCIIEncoding(t *testing.T) {
2929

3030
func TestASCIIDecoding(t *testing.T) {
3131
decoder := asciiPackager{}
32-
decoder.SlaveId = 247
32+
decoder.SlaveID = 247
3333
adu := []byte(":F7031389000A60\r\n")
3434

3535
pdu, err := decoder.Decode(adu)
@@ -48,7 +48,7 @@ func TestASCIIDecoding(t *testing.T) {
4848

4949
func BenchmarkASCIIEncoder(b *testing.B) {
5050
encoder := asciiPackager{
51-
SlaveId: 10,
51+
SlaveID: 10,
5252
}
5353
pdu := ProtocolDataUnit{
5454
FunctionCode: 1,
@@ -64,7 +64,7 @@ func BenchmarkASCIIEncoder(b *testing.B) {
6464

6565
func BenchmarkASCIIDecoder(b *testing.B) {
6666
decoder := asciiPackager{
67-
SlaveId: 10,
67+
SlaveID: 10,
6868
}
6969
adu := []byte(":F7031389000A60\r\n")
7070
for i := 0; i < b.N; i++ {

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ func dataBlockSuffix(suffix []byte, value ...uint16) []byte {
486486
}
487487

488488
func responseError(response *ProtocolDataUnit) error {
489-
mbError := &ModbusError{FunctionCode: response.FunctionCode}
489+
mbError := &Error{FunctionCode: response.FunctionCode}
490490
if response.Data != nil && len(response.Data) > 0 {
491491
mbError.ExceptionCode = response.Data[0]
492492
}

modbus.go

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,60 @@ import (
1212
)
1313

1414
const (
15-
// Bit access
15+
// FuncCodeReadDiscreteInputs for bit wise access
1616
FuncCodeReadDiscreteInputs = 2
17-
FuncCodeReadCoils = 1
18-
FuncCodeWriteSingleCoil = 5
17+
// FuncCodeReadCoils for bit wise access
18+
FuncCodeReadCoils = 1
19+
// FuncCodeWriteSingleCoil for bit wise access
20+
FuncCodeWriteSingleCoil = 5
21+
// FuncCodeWriteMultipleCoils for bit wise access
1922
FuncCodeWriteMultipleCoils = 15
2023

21-
// 16-bit access
22-
FuncCodeReadInputRegisters = 4
23-
FuncCodeReadHoldingRegisters = 3
24-
FuncCodeWriteSingleRegister = 6
25-
FuncCodeWriteMultipleRegisters = 16
24+
// FuncCodeReadInputRegisters 16-bit wise access
25+
FuncCodeReadInputRegisters = 4
26+
// FuncCodeReadHoldingRegisters 16-bit wise access
27+
FuncCodeReadHoldingRegisters = 3
28+
// FuncCodeWriteSingleRegister 16-bit wise access
29+
FuncCodeWriteSingleRegister = 6
30+
// FuncCodeWriteMultipleRegisters 16-bit wise access
31+
FuncCodeWriteMultipleRegisters = 16
32+
// FuncCodeReadWriteMultipleRegisters 16-bit wise access
2633
FuncCodeReadWriteMultipleRegisters = 23
27-
FuncCodeMaskWriteRegister = 22
28-
FuncCodeReadFIFOQueue = 24
34+
// FuncCodeMaskWriteRegister 16-bit wise access
35+
FuncCodeMaskWriteRegister = 22
36+
// FuncCodeReadFIFOQueue 16-bit wise access
37+
FuncCodeReadFIFOQueue = 24
2938
)
3039

3140
const (
32-
ExceptionCodeIllegalFunction = 1
33-
ExceptionCodeIllegalDataAddress = 2
34-
ExceptionCodeIllegalDataValue = 3
35-
ExceptionCodeServerDeviceFailure = 4
36-
ExceptionCodeAcknowledge = 5
37-
ExceptionCodeServerDeviceBusy = 6
38-
ExceptionCodeMemoryParityError = 8
39-
ExceptionCodeGatewayPathUnavailable = 10
41+
// ExceptionCodeIllegalFunction error code
42+
ExceptionCodeIllegalFunction = 1
43+
// ExceptionCodeIllegalDataAddress error code
44+
ExceptionCodeIllegalDataAddress = 2
45+
// ExceptionCodeIllegalDataValue error code
46+
ExceptionCodeIllegalDataValue = 3
47+
// ExceptionCodeServerDeviceFailure error code
48+
ExceptionCodeServerDeviceFailure = 4
49+
// ExceptionCodeAcknowledge error code
50+
ExceptionCodeAcknowledge = 5
51+
// ExceptionCodeServerDeviceBusy error code
52+
ExceptionCodeServerDeviceBusy = 6
53+
// ExceptionCodeMemoryParityError error code
54+
ExceptionCodeMemoryParityError = 8
55+
// ExceptionCodeGatewayPathUnavailable error code
56+
ExceptionCodeGatewayPathUnavailable = 10
57+
// ExceptionCodeGatewayTargetDeviceFailedToRespond error code
4058
ExceptionCodeGatewayTargetDeviceFailedToRespond = 11
4159
)
4260

43-
// ModbusError implements error interface.
44-
type ModbusError struct {
61+
// Error implements error interface.
62+
type Error struct {
4563
FunctionCode byte
4664
ExceptionCode byte
4765
}
4866

4967
// Error converts known modbus exception code to error message.
50-
func (e *ModbusError) Error() string {
68+
func (e *Error) Error() string {
5169
var name string
5270
switch e.ExceptionCode {
5371
case ExceptionCodeIllegalFunction:

rtuclient.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func RTUClient(address string) Client {
4141

4242
// rtuPackager implements Packager interface.
4343
type rtuPackager struct {
44-
SlaveId byte
44+
SlaveID byte
4545
}
4646

4747
// Encode encodes PDU in a RTU frame:
@@ -57,7 +57,7 @@ func (mb *rtuPackager) Encode(pdu *ProtocolDataUnit) (adu []byte, err error) {
5757
}
5858
adu = make([]byte, length)
5959

60-
adu[0] = mb.SlaveId
60+
adu[0] = mb.SlaveID
6161
adu[1] = pdu.FunctionCode
6262
copy(adu[2:], pdu.Data)
6363

rtuclient_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
func TestRTUEncoding(t *testing.T) {
1313
encoder := rtuPackager{}
14-
encoder.SlaveId = 0x01
14+
encoder.SlaveID = 0x01
1515

1616
pdu := ProtocolDataUnit{}
1717
pdu.FunctionCode = 0x03
@@ -70,7 +70,7 @@ func TestCalculateResponseLength(t *testing.T) {
7070

7171
func BenchmarkRTUEncoder(b *testing.B) {
7272
encoder := rtuPackager{
73-
SlaveId: 10,
73+
SlaveID: 10,
7474
}
7575
pdu := ProtocolDataUnit{
7676
FunctionCode: 1,
@@ -86,7 +86,7 @@ func BenchmarkRTUEncoder(b *testing.B) {
8686

8787
func BenchmarkRTUDecoder(b *testing.B) {
8888
decoder := rtuPackager{
89-
SlaveId: 10,
89+
SlaveID: 10,
9090
}
9191
adu := []byte{0x01, 0x10, 0x8A, 0x00, 0x00, 0x03, 0xAA, 0x10}
9292
for i := 0; i < b.N; i++ {

tcpclient.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const (
2626
tcpIdleTimeout = 60 * time.Second
2727
)
2828

29+
// ErrTCPHeaderLength informs about a wrong header length.
2930
type ErrTCPHeaderLength int
3031

3132
func (length ErrTCPHeaderLength) Error() string {
@@ -57,9 +58,9 @@ func TCPClient(address string) Client {
5758
// tcpPackager implements Packager interface.
5859
type tcpPackager struct {
5960
// For synchronization between messages of server & client
60-
transactionId uint32
61+
transactionID uint32
6162
// Broadcast address is 0
62-
SlaveId byte
63+
SlaveID byte
6364
}
6465

6566
// Encode adds modbus application protocol header:
@@ -73,15 +74,15 @@ func (mb *tcpPackager) Encode(pdu *ProtocolDataUnit) (adu []byte, err error) {
7374
adu = make([]byte, tcpHeaderSize+1+len(pdu.Data))
7475

7576
// Transaction identifier
76-
transactionId := atomic.AddUint32(&mb.transactionId, 1)
77-
binary.BigEndian.PutUint16(adu, uint16(transactionId))
77+
transactionID := atomic.AddUint32(&mb.transactionID, 1)
78+
binary.BigEndian.PutUint16(adu, uint16(transactionID))
7879
// Protocol identifier
7980
binary.BigEndian.PutUint16(adu[2:], tcpProtocolIdentifier)
80-
// Length = sizeof(SlaveId) + sizeof(FunctionCode) + Data
81+
// Length = sizeof(SlaveID) + sizeof(FunctionCode) + Data
8182
length := uint16(1 + 1 + len(pdu.Data))
8283
binary.BigEndian.PutUint16(adu[4:], length)
8384
// Unit identifier
84-
adu[6] = mb.SlaveId
85+
adu[6] = mb.SlaveID
8586

8687
// PDU
8788
adu[tcpHeaderSize] = pdu.FunctionCode

0 commit comments

Comments
 (0)