TCP/IP connection to the lock server is now established before encoding the keycard and closed after the encoding is done

This commit is contained in:
2025-08-21 19:26:42 +01:00
parent e6ff292706
commit 251afd6aeb
7 changed files with 38 additions and 26 deletions
+8 -1
View File
@@ -19,8 +19,15 @@ func (lock *AssaLockServer) BuildCommand(doorReq DoorCardRequest, checkIn, check
}
// Checks heart beat of the Assa Abloy lock server and perform key encoding
func (lock *AssaLockServer) LockSequence(conn net.Conn) error {
func (lock *AssaLockServer) LockSequence() error {
const funcName = "AssaLockServer.LockSequence"
conn, err := InitializeServerConnection(lock.encoderAddr)
if err != nil {
return err
}
defer conn.Close()
resp, err := sendHeartbeatToServer(conn)
if err != nil {
return fmt.Errorf("[%s] heartbeat failed: %v", funcName, err)
+1 -1
View File
@@ -35,7 +35,7 @@ var (
type (
LockServer interface {
BuildCommand(doorReq DoorCardRequest, checkIn, checkOut time.Time) error
LockSequence(conn net.Conn) error
LockSequence() error
}
AssaLockServer struct {
+8 -1
View File
@@ -53,8 +53,15 @@ func (lock *OmniLockServer) BuildCommand(doorReq DoorCardRequest, checkIn, check
}
// Starts link to the Omnitec lock server and perform key encoding
func (lock *OmniLockServer) LockSequence(conn net.Conn) error {
func (lock *OmniLockServer) LockSequence() error {
const funcName = "OmniLockServer.LockSequence"
conn, err := net.Dial("tcp", lock.encoderAddr)
if err != nil {
return err
}
defer conn.Close()
// Start the link with the lock server
regs, err := lock.linkStart(conn)
if err != nil {
+9 -2
View File
@@ -139,14 +139,21 @@ func (lock *SaltoLockServer) waitForAck(conn net.Conn, reader *bufio.Reader, tim
}
// LockSequence performs the full ENQ/ACK handshake and command exchange
func (lock *SaltoLockServer) LockSequence(conn net.Conn) error {
func (lock *SaltoLockServer) LockSequence() error {
const timeout = 10 * time.Second
var (
resp []byte
reader = bufio.NewReader(conn)
drained = 0 // count of stale frames consumed across waits
)
conn, err := InitializeServerConnection(lock.encoderAddr)
if err != nil {
return err
}
defer conn.Close()
reader := bufio.NewReader(conn)
// 1. Send ENQ
log.Infof("Sending ENQ")
if _, e := conn.Write([]byte{ENQ}); e != nil {
+1 -2
View File
@@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"net"
"net/http"
"net/url"
"time"
@@ -36,7 +35,7 @@ func (lock *TLJLockServer) BuildCommand(doorReq DoorCardRequest, checkIn, checkO
return nil
}
func (lock *TLJLockServer) LockSequence(conn net.Conn) error {
func (lock *TLJLockServer) LockSequence() error {
log.Infof("Sending command: %q", lock.command)
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Get(lock.command)