updated lock server

This commit is contained in:
2025-06-18 11:54:29 +01:00
parent d9871e6a1c
commit b002c80b01
6 changed files with 104 additions and 23 deletions
+2 -2
View File
@@ -10,11 +10,11 @@ import (
)
// Build key encoding request command for the Assa Abloy lock server.
func (lock *AssaLockServer) BuildCommand(encoderAddr, lockId string, checkIn, checkOut time.Time) error {
func (lock *AssaLockServer) BuildCommand(lockId string, checkIn, checkOut time.Time) error {
ci := checkIn.Format("200601021504")
co := checkOut.Format("200601021504")
lock.command = fmt.Sprintf("CCA;EA%s;GR%s;CO%s;CI%s;AM1;\r\n", encoderAddr, lockId, co, ci)
lock.command = fmt.Sprintf("CCA;EA%s;GR%s;CO%s;CI%s;AM1;\r\n", lock.encoderAddr, lockId, co, ci)
return nil
}
+16 -2
View File
@@ -19,19 +19,33 @@ const (
type (
LockServer interface {
BuildCommand(lockId string, checkIn, checkOut time.Time) error
LockSequence(conn net.Conn) error
BuildCommand(encoderAddr, lockId string, checkIn, checkOut time.Time) error
}
AssaLockServer struct {
encoderAddr string
command string
}
OmniLockServer struct {
encoderAddr string // Encoder address for the lock server
command []byte // Command to be sent to the lock server
}
)
func NewLockServer(lockType, encoderAddr string, fatalError func(error)) LockServer {
switch lockType {
case AssaAbloy:
return &AssaLockServer{encoderAddr: encoderAddr}
case Omnitec:
return &OmniLockServer{encoderAddr: encoderAddr}
default:
fatalError(fmt.Errorf("unsupported LockType: %s; must be 'assaabloy' or 'omnitec'", lockType))
return nil // This line will never be reached, but is needed to satisfy the compiler
}
}
func InitializeServerConnection(LockserverUrl string) (net.Conn, error) {
const funcName = "InitializeServerConnection"
// Parse the URL to extract host and port
@@ -46,7 +60,7 @@ func InitializeServerConnection(LockserverUrl string) (net.Conn, error) {
// Establish a TCP connection to the Visionline server
conn, err := net.Dial("tcp", address)
if err != nil {
return nil, fmt.Errorf("failed to connect to Visionline server: %v", err)
return nil, fmt.Errorf("failed to connect to lock server: %v", err)
}
return conn, nil
}
+2 -2
View File
@@ -13,7 +13,7 @@ import (
)
// Build key encoding request command for the Omnitec lock server.
func (lock *OmniLockServer) BuildCommand(encoderAddr, lockId string, checkIn, checkOut time.Time) error {
func (lock *OmniLockServer) BuildCommand(lockId string, checkIn, checkOut time.Time) error {
const funcName = "OmniLockServer.BuildCommand"
hostname, err := os.Hostname()
if err != nil {
@@ -36,7 +36,7 @@ func (lock *OmniLockServer) BuildCommand(encoderAddr, lockId string, checkIn, ch
// Construct payload
payload := fmt.Sprintf(
"KR|KC%s|KTD|RN%s|%s|DT%s|G#75|GA%s|GD%s|KO0000|DA%s|TI%s|",
encoderAddr,
lock.encoderAddr,
formattedLockId,
hostname,
dt,