Compare commits
No commits in common. "cardEncoder" and "development" have entirely different histories.
cardEncode
...
developmen
@ -69,7 +69,7 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkStatus(statusResp []byte) ([]string, error) {
|
func checkStatus(statusResp []byte) (string, error) {
|
||||||
if len(statusResp) > 3 {
|
if len(statusResp) > 3 {
|
||||||
statusBytes := statusResp[7:11] // Extract the relevant bytes from the response
|
statusBytes := statusResp[7:11] // Extract the relevant bytes from the response
|
||||||
// For each position, get the ASCII character, hex value, and mapped meaning.
|
// For each position, get the ASCII character, hex value, and mapped meaning.
|
||||||
@ -84,17 +84,17 @@ func checkStatus(statusResp []byte) ([]string, error) {
|
|||||||
{pos: 4, value: statusBytes[3], mapper: statusPos3},
|
{pos: 4, value: statusBytes[3], mapper: statusPos3},
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make([]string, len(posStatus))
|
result := ""
|
||||||
for _, p := range posStatus {
|
for _, p := range posStatus {
|
||||||
statusMsg, exists := p.mapper[p.value]
|
statusMsg, exists := p.mapper[p.value]
|
||||||
if !exists {
|
if !exists {
|
||||||
statusMsg = "Unknown status"
|
statusMsg = "Unknown status"
|
||||||
}
|
}
|
||||||
if p.value != 0x30 {
|
if p.value != 0x30 {
|
||||||
result = append(result, fmt.Sprintf("Status: %s; ", statusMsg))
|
result += fmt.Sprintf("Status: %s; ", statusMsg)
|
||||||
}
|
}
|
||||||
if p.pos == 4 && p.value == 0x38 {
|
if p.pos == 4 && p.value == 0x38 {
|
||||||
return nil, fmt.Errorf("Card well empty")
|
return result, fmt.Errorf("Card well empty")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|||||||
@ -271,7 +271,7 @@ func (app *App) issueDoorCard(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// card to encoder position if not there already
|
// dispenser sequence
|
||||||
if status, err := dispenser.DispenserSequence(app.dispPort); err != nil {
|
if status, err := dispenser.DispenserSequence(app.dispPort); err != nil {
|
||||||
if status != "" {
|
if status != "" {
|
||||||
logging.Error(serviceName, status, "Dispense error", string(op), "", "", 0)
|
logging.Error(serviceName, status, "Dispense error", string(op), "", "", 0)
|
||||||
@ -294,11 +294,10 @@ func (app *App) issueDoorCard(w http.ResponseWriter, r *http.Request) {
|
|||||||
logging.Error(serviceName, err.Error(), "Key encoding", string(op), "", "", 0)
|
logging.Error(serviceName, err.Error(), "Key encoding", string(op), "", "", 0)
|
||||||
writeError(w, http.StatusBadGateway, err.Error())
|
writeError(w, http.StatusBadGateway, err.Error())
|
||||||
dispenser.CardOutOfMouth(app.dispPort)
|
dispenser.CardOutOfMouth(app.dispPort)
|
||||||
dispenser.DispenserSequence(app.dispPort)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// card out of mouth
|
// final dispenser steps
|
||||||
if status, err := dispenser.CardOutOfMouth(app.dispPort); err != nil {
|
if status, err := dispenser.CardOutOfMouth(app.dispPort); err != nil {
|
||||||
logging.Error(serviceName, err.Error(), "Dispenser eject error", string(op), "", "", 0)
|
logging.Error(serviceName, err.Error(), "Dispenser eject error", string(op), "", "", 0)
|
||||||
writeError(w, http.StatusServiceUnavailable, "Dispenser eject error: "+err.Error())
|
writeError(w, http.StatusServiceUnavailable, "Dispenser eject error: "+err.Error())
|
||||||
@ -307,20 +306,6 @@ func (app *App) issueDoorCard(w http.ResponseWriter, r *http.Request) {
|
|||||||
log.Info(status)
|
log.Info(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
// card to encoder position
|
|
||||||
if status, err := dispenser.DispenserSequence(app.dispPort); err != nil {
|
|
||||||
if status != "" {
|
|
||||||
logging.Error(serviceName, status, "Dispense error", string(op), "", "", 0)
|
|
||||||
writeError(w, http.StatusServiceUnavailable, "Dispense error: "+err.Error())
|
|
||||||
} else {
|
|
||||||
logging.Error(serviceName, err.Error(), "Dispense error", string(op), "", "", 0)
|
|
||||||
writeError(w, http.StatusServiceUnavailable, "Dispense error: "+err.Error()+"; check card stock")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
log.Info(status)
|
|
||||||
}
|
|
||||||
|
|
||||||
theResponse.Code = http.StatusOK
|
theResponse.Code = http.StatusOK
|
||||||
theResponse.Message = "Card issued successfully"
|
theResponse.Message = "Card issued successfully"
|
||||||
// success! return 200 and any data you like
|
// success! return 200 and any data you like
|
||||||
|
|||||||
3
main.go
3
main.go
@ -65,9 +65,6 @@ func main() {
|
|||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if status, err = dispenser.DispenserSequence(dispHandle); err != nil {
|
|
||||||
handlers.FatalError(err)
|
|
||||||
}
|
|
||||||
log.Infof("Dispenser initialized on port %s, %s", config.DispenserPort, status)
|
log.Infof("Dispenser initialized on port %s, %s", config.DispenserPort, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user