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