Compare commits

...
4 Commits
7 changed files with 54 additions and 29 deletions
+30 -20
View File
@@ -296,20 +296,25 @@ func (c *Client) DispenserStart(ctx context.Context) (string, error) {
return stockStatus, fmt.Errorf("[%s] to encoder: %w", funcName, err) return stockStatus, fmt.Errorf("[%s] to encoder: %w", funcName, err)
} }
deadline := time.Now().Add(3 * time.Second) halfway := time.Now().Add(6 * time.Second)
deadline := time.Now().Add(12 * time.Second)
for { for {
if time.Now().After(deadline) { time.Sleep(delay * 2)
return stockStatus, fmt.Errorf("[%s] timeout waiting keycard at encoder position", funcName) switch {
case time.Now().After(halfway):
if err := c.ToEncoder(ctx); err != nil {
return stockStatus, fmt.Errorf("[%s] to encoder: %w", funcName, err)
}
case time.Now().After(deadline):
return stockStatus, nil
} }
status, err = c.do(ctx, cmdStatus) status, _ = c.do(ctx, cmdStatus)
if err != nil {
return stockStatus, fmt.Errorf("[%s] re-check status: %w", funcName, err)
}
stockStatus = stockTake(status) stockStatus = stockTake(status)
c.setStock(status) c.setStock(status)
logStatus(status)
// error states first // error states first
if isCardWellEmpty(status) { if isCardWellEmpty(status) {
@@ -319,8 +324,6 @@ func (c *Client) DispenserStart(ctx context.Context) (string, error) {
if isAtEncoderPosition(status) { if isAtEncoderPosition(status) {
return stockStatus, nil return stockStatus, nil
} }
time.Sleep(100 * time.Millisecond)
} }
} }
@@ -333,8 +336,13 @@ func (c *Client) DispenserFinal(ctx context.Context) (string, error) {
return stockStatus, fmt.Errorf("[%s] out of mouth: %w", funcName, err) return stockStatus, fmt.Errorf("[%s] out of mouth: %w", funcName, err)
} }
time.Sleep(200 * time.Millisecond) time.Sleep(delay)
status, err := c.do(ctx, cmdStatus)
if err == nil && len(status) >= 4 {
c.setStock(status)
}
time.Sleep(delay)
if err := c.ToEncoder(ctx); err != nil { if err := c.ToEncoder(ctx); err != nil {
return stockStatus, fmt.Errorf("[%s] to encoder: %w", funcName, err) return stockStatus, fmt.Errorf("[%s] to encoder: %w", funcName, err)
} }
@@ -343,30 +351,32 @@ func (c *Client) DispenserFinal(ctx context.Context) (string, error) {
logStatus(status) logStatus(status)
}() }()
deadline := time.Now().Add(3 * time.Second) halfway := time.Now().Add(6 * time.Second)
deadline := time.Now().Add(12 * time.Second)
for { for {
if time.Now().After(deadline) { time.Sleep(delay * 2)
switch {
case time.Now().After(halfway):
if err := c.ToEncoder(ctx); err != nil {
return stockStatus, fmt.Errorf("[%s] to encoder: %w", funcName, err)
}
case time.Now().After(deadline):
return stockStatus, nil return stockStatus, nil
} }
status, err := c.do(ctx, cmdStatus) status, _ = c.do(ctx, cmdStatus)
if err != nil {
return stockStatus, nil
}
stockStatus = stockTake(status) stockStatus = stockTake(status)
c.setStock(status) c.setStock(status)
logStatus(status)
if isCardWellEmpty(status) { if isCardWellEmpty(status) {
return stockStatus, fmt.Errorf(stockStatus) return stockStatus, nil
} }
if isAtEncoderPosition(status) { if isAtEncoderPosition(status) {
return stockStatus, nil return stockStatus, nil
} }
time.Sleep(100 * time.Millisecond)
} }
} }
+1
View File
@@ -191,6 +191,7 @@ func (app *App) takePayment(w http.ResponseWriter, r *http.Request) {
writeTransactionResult(w, http.StatusServiceUnavailable, theResponse) writeTransactionResult(w, http.StatusServiceUnavailable, theResponse)
return return
} }
} }
if r.Method == http.MethodOptions { if r.Method == http.MethodOptions {
+4 -4
View File
@@ -1,15 +1,16 @@
// Package lockserver provides functionality for interacting with Assa Abloy lock servers.
package lockserver package lockserver
import ( import (
"fmt" "fmt"
"net" "net"
"time"
"strings" "strings"
"time"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// Build key encoding request command for the Assa Abloy lock server. // BuildCommand builds a key encoding request command for the Assa Abloy lock server.
func (lock *AssaLockServer) BuildCommand(doorReq DoorCardRequest, checkIn, checkOut time.Time) error { func (lock *AssaLockServer) BuildCommand(doorReq DoorCardRequest, checkIn, checkOut time.Time) error {
ci := checkIn.Format("200601021504") ci := checkIn.Format("200601021504")
co := checkOut.Format("200601021504") co := checkOut.Format("200601021504")
@@ -71,4 +72,3 @@ func parseAssaResponse(raw string) (string, error) {
} }
return "Success: " + clean, nil return "Success: " + clean, nil
} }
+1 -1
View File
@@ -29,7 +29,7 @@ import (
) )
const ( const (
buildVersion = "1.2.3" buildVersion = "1.2.7"
serviceName = "hardlink" serviceName = "hardlink"
pollingFrequency = 8 * time.Second pollingFrequency = 8 * time.Second
) )
+3 -2
View File
@@ -155,8 +155,9 @@ func BuildPreauthRedirectURL(result map[string]string) (string, bool) {
func BuildSuccessURL(result map[string]string) string { func BuildSuccessURL(result map[string]string) string {
q := url.Values{} q := url.Values{}
q.Set("CardNumber", hex.EncodeToString([]byte(result[types.PAN_MASKED]))) q.Set("CardNumber", hex.EncodeToString([]byte(result[types.PanMasked])))
q.Set("ExpiryDate", hex.EncodeToString([]byte(result[types.EXPIRY_DATE]))) q.Set("CardType", hex.EncodeToString([]byte(result[types.CardType])))
q.Set("ExpiryDate", hex.EncodeToString([]byte(result[types.ExpiryDate])))
q.Set("TxnReference", result[types.Reference]) q.Set("TxnReference", result[types.Reference])
q.Set("CardHash", hex.EncodeToString([]byte(result[types.CardHash]))) q.Set("CardHash", hex.EncodeToString([]byte(result[types.CardHash])))
q.Set("CardReference", hex.EncodeToString([]byte(result[types.CardReference]))) q.Set("CardReference", hex.EncodeToString([]byte(result[types.CardReference])))
+12
View File
@@ -2,6 +2,18 @@
builtVersion is a const in main.go builtVersion is a const in main.go
#### 1.2.7 - 13 May 2026
retrieve CardType from the ChepDNA response
#### 1.2.6 - 20 April 2026
added the second attempt to send the card to the encoder after 6 seconds
#### 1.2.5 - 20 March 2026
removed early return on error when checking dispenser status in the start and final loops.
#### 1.2.4 - 18 March 2026
added check if keycard at the encoder position before trying to encode key
#### 1.2.3 - 17 March 2026 #### 1.2.3 - 17 March 2026
added check if keycard at the encoder position before trying to encode key added check if keycard at the encoder position before trying to encode key
+3 -2
View File
@@ -39,8 +39,9 @@ const (
ReceiptDataMerchant = "RECEIPT_DATA_MERCHANT" ReceiptDataMerchant = "RECEIPT_DATA_MERCHANT"
ReceiptDataCardholder = "RECEIPT_DATA_CARDHOLDER" ReceiptDataCardholder = "RECEIPT_DATA_CARDHOLDER"
Reference = "REFERENCE" Reference = "REFERENCE"
PAN_MASKED = "PAN_MASKED" CardType = "CARD_SCHEME_ID"
EXPIRY_DATE = "EXPIRY_DATE" PanMasked = "PAN_MASKED"
ExpiryDate = "EXPIRY_DATE"
TransactionResult = "TRANSACTION_RESULT" TransactionResult = "TRANSACTION_RESULT"
TransactionType = "TRANSACTION_TYPE" TransactionType = "TRANSACTION_TYPE"
TransactionState = "TRANSACTION_STATE" TransactionState = "TRANSACTION_STATE"