Skip to content

Commit

Permalink
Added restore-default-parameters to the IUHPPOTE interface type
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Feb 15, 2024
1 parent c6d4d33 commit d631a62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions uhppote/iuhppote.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ type IUHPPOTE interface {
SetInterlock(controllerID uint32, interlock types.Interlock) (bool, error) // sets door interlock mode
ActivateKeypads(controllerID uint32, readers map[uint8]bool) (bool, error) // enables/disables reader keypads

// Sends a RestoreDefaultParameters request to the designated controller, to reset it to the
// manufacturer default configuration.
//
// Returns true if the controller was successfully reset, false if the request failed for any reason.
// Returns an error if the request could not be sent or the response is invalid.
RestoreDefaultParameters(controllerID uint32) (bool, error)

// TODO: REMOVE (interim functions used by health-check)
DeviceList() map[uint32]Device
ListenAddr() *net.UDPAddr
Expand Down
10 changes: 5 additions & 5 deletions uhppote/restore_default_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ import (
// Returns true if the controller configuration was successfully reset, false if the request
// failed internally to the controller for any reason. Returns an error if the request could
// not be sent or the response is invalid.
func (u *uhppote) RestoreDefaultParameters(deviceID uint32) (bool, error) {
if deviceID == 0 {
return false, fmt.Errorf("invalid device ID (%v)", deviceID)
func (u *uhppote) RestoreDefaultParameters(controller uint32) (bool, error) {
if controller == 0 {
return false, fmt.Errorf("invalid controller ID (%v)", controller)
}

request := messages.RestoreDefaultParametersRequest{
SerialNumber: types.SerialNumber(deviceID),
SerialNumber: types.SerialNumber(controller),
MagicWord: 0x55aaaa55,
}

reply := messages.RestoreDefaultParametersResponse{}

if err := u.send(deviceID, request, &reply); err != nil {
if err := u.send(controller, request, &reply); err != nil {
return false, err
} else {
return reply.Succeeded, nil
Expand Down

0 comments on commit d631a62

Please sign in to comment.