feat: YAB-1785: Group chars before send
This commit is contained in:
+1
-1
@@ -11,4 +11,4 @@ ENV CGO_ENABLED=1
|
||||
ADD ./ /data
|
||||
WORKDIR /data
|
||||
|
||||
CMD ["make", "docker-deb"]
|
||||
CMD ["make", "deb"]
|
||||
@@ -20,6 +20,6 @@ deb: clean build
|
||||
cd ./debian && dpkg-buildpackage -rfakeroot --no-sign --target-arch amd64 --host-arch amd64
|
||||
|
||||
docker-deb: clean
|
||||
docker build -t ${BINARY_NAME} .
|
||||
docker image build -t ${BINARY_NAME} .
|
||||
docker container run --name ${BINARY_NAME} ${BINARY_NAME}
|
||||
docker container cp ${BINARY_NAME}:/data ./build
|
||||
|
||||
Vendored
+9
@@ -4,3 +4,12 @@ yablochkov-keyboard-reader (0.1.0) release; urgency=low
|
||||
* Initial version
|
||||
|
||||
-- Alexander Terekhin <alex@bearns> Sun, 03 Dec 2023 17:01:00 +0600
|
||||
|
||||
yablochkov-keyboard-reader (0.1.1) release; urgency=low
|
||||
|
||||
[ Alexander Terekhin ]
|
||||
* Group chars before sending
|
||||
* Docker build bugfixes
|
||||
* Change serial to model
|
||||
|
||||
-- Alexander Terekhin <alex@bearns> Sun, 04 Dec 2023 12:35:00 +0300
|
||||
Vendored
+1
-1
@@ -4,7 +4,7 @@ Priority: optional
|
||||
Maintainer: Alexander Terekhin <alex@bearns.me>
|
||||
|
||||
Package: yablochkov-keyboard-reader
|
||||
Version: 0.1
|
||||
Version: 0.1.1
|
||||
Architecture: amd64
|
||||
Installed-Size: 5008848
|
||||
Description: Yablochkov keyboard reader
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ WorkingDirectory=/opt/ocppc
|
||||
EnvironmentFile=/opt/conf/configuration_vars.env
|
||||
EnvironmentFile=/opt/conf/configuration_vars_model.env
|
||||
EnvironmentFile=/opt/conf/configuration_vars_personal.env
|
||||
ExecStart=/opt/ocppc/bin/keyboard-reader --serial=OEM_TWN4_B1.64_NKF4.64_STD2.04
|
||||
ExecStart=/opt/ocppc/bin/keyboard-reader --model=TWN4_B1.64_NKF4.64_STD2.04
|
||||
User=debian
|
||||
Group=input
|
||||
ExecStop=/bin/kill -TERM $MAINPID
|
||||
|
||||
+5
-7
@@ -15,7 +15,7 @@ const bufferLength = 32
|
||||
func main() {
|
||||
device := flag.String("dev", "", "Keyboard device")
|
||||
vendor := flag.String("vendor", "", "Device vendor")
|
||||
serial := flag.String("serial", "", "Device id serial")
|
||||
model := flag.String("model", "", "Device id model")
|
||||
list := flag.Bool("list", false, "List input devices")
|
||||
connectorId := flag.Uint("connector", 0, "Connector id")
|
||||
timeout := flag.Int("timeout", 5, "Http timeout, sec")
|
||||
@@ -32,7 +32,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
if len(*vendor) == 0 && len(*device) == 0 && len(*serial) == 0 && !*list {
|
||||
if len(*vendor) == 0 && len(*device) == 0 && len(*model) == 0 && !*list {
|
||||
flag.Usage()
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ func main() {
|
||||
device = getDevByProperty(*vendor, "ID_VENDOR")
|
||||
}
|
||||
|
||||
if len(*serial) > 0 {
|
||||
device = getDevByProperty(*serial, "ID_SERIAL")
|
||||
if len(*model) > 0 {
|
||||
device = getDevByProperty(*model, "ID_MODEL")
|
||||
}
|
||||
|
||||
if device == nil || len(*device) == 0 {
|
||||
@@ -87,9 +87,7 @@ func main() {
|
||||
}
|
||||
|
||||
if sb.Len() > 0 {
|
||||
id := sb.String()
|
||||
log.Printf("Send '%s'", id)
|
||||
client.Send(id)
|
||||
client.Send(sb.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,12 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
const timeout = 1 * time.Second
|
||||
|
||||
type MonitorIdTag struct {
|
||||
ConnectorId uint `json:"connectorId"`
|
||||
IdTag string `json:"idTag"`
|
||||
@@ -32,6 +35,9 @@ type rest struct {
|
||||
connectorId uint
|
||||
url string
|
||||
timeout time.Duration
|
||||
mutex sync.Mutex
|
||||
timer *time.Timer
|
||||
sb strings.Builder
|
||||
}
|
||||
|
||||
func NewRest(connectorId uint, url string, timeout time.Duration) RestInterface {
|
||||
@@ -40,7 +46,23 @@ func NewRest(connectorId uint, url string, timeout time.Duration) RestInterface
|
||||
}
|
||||
|
||||
func (r *rest) Send(id string) {
|
||||
go r.send(id)
|
||||
r.mutex.Lock()
|
||||
defer r.mutex.Unlock()
|
||||
|
||||
r.sb.WriteString(id)
|
||||
|
||||
if r.timer != nil {
|
||||
r.timer.Reset(timeout)
|
||||
} else {
|
||||
f := func() {
|
||||
s := r.sb.String()
|
||||
log.Printf("Send '%s'", s)
|
||||
go r.send(s)
|
||||
r.sb.Reset()
|
||||
}
|
||||
|
||||
r.timer = time.AfterFunc(timeout, f)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *rest) send(id string) {
|
||||
|
||||
Reference in New Issue
Block a user