-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequeststatus.go
More file actions
53 lines (41 loc) · 1.14 KB
/
requeststatus.go
File metadata and controls
53 lines (41 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2022 TrueLevel SA
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
// SPDX-License-Identifier: MPL-2.0
package nd300
import (
"go.bug.st/serial"
)
func (c *Conn) RequestStatus() (status Status, count byte, err error) {
var port serial.Port
port, err = c.Open()
if err != nil {
return
}
defer func() {
err = AppendErr(err, port.Close(), closeErrMsg)
c.port = nil
}()
status, count, err = requestStatus(c)
return
}
func requestStatus(conn *Conn) (status Status, count byte, err error) {
//nolint:goconst // False positive, see: https://github.com/jgautheron/goconst/issues/19
if conn.txBuff[idxCmd] != byte(RequestMachineStatus) || conn.txBuff[idxData] != 0x0 {
conn.txBuff[idxCmd] = byte(RequestMachineStatus)
conn.txBuff[idxData] = 0x0
conn.txBuff[idxCksum] = computeChecksum(conn.txBuff)
}
if err = conn.write(); err != nil {
return
}
if err = conn.read(); err != nil {
return
}
count = conn.rxBuff[idxData]
status = conn.rxBuff.Status()
return
}