4a0a055234
git-subtree-dir: faxmachine git-subtree-split: d23200bcfdedb9f8cc57e6a3c65b5ef93fcbfd19
71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package protocol
|
|
|
|
type DrawerKickoutConnectorStatus struct {
|
|
IsPin3High bool
|
|
}
|
|
|
|
type OnlineStatus struct {
|
|
IsOffline bool
|
|
IsCoverOpen bool
|
|
IsPaperFedByFeedButton bool
|
|
IsWaitingForOnlineRecovery bool
|
|
}
|
|
|
|
type PaperSensorStatus struct {
|
|
IsNearEnd bool
|
|
IsNotPresent bool
|
|
}
|
|
|
|
type ErrorStatus struct {
|
|
RecoverableErrorOccurred bool
|
|
AutocutterErrorOccurred bool
|
|
UnrecoverableErrorOccurred bool
|
|
AutomaticallyRecoverableErrorOccurred bool
|
|
}
|
|
|
|
type PanelSwitchStatus struct {
|
|
IsFeedButtonPressed bool
|
|
}
|
|
|
|
type ASBStatus struct {
|
|
DrawerKickoutConnector DrawerKickoutConnectorStatus
|
|
Online OnlineStatus
|
|
Paper PaperSensorStatus
|
|
Error ErrorStatus
|
|
PanelSwitch PanelSwitchStatus
|
|
}
|
|
|
|
func (p Protocol) ParsePaperSensorStatus(status byte) PaperSensorStatus {
|
|
return PaperSensorStatus{
|
|
IsNearEnd: status&0b00000011 != 0,
|
|
IsNotPresent: status&0b00001100 != 0,
|
|
}
|
|
}
|
|
|
|
func (p Protocol) ParseASBStatus(status [4]byte) ASBStatus {
|
|
checkbit := func(nbyte int, nbit int) bool {
|
|
return status[nbyte]&(1<<nbit) != 0
|
|
}
|
|
|
|
return ASBStatus{
|
|
DrawerKickoutConnector: DrawerKickoutConnectorStatus{
|
|
IsPin3High: checkbit(0, 2),
|
|
},
|
|
Online: OnlineStatus{
|
|
IsOffline: checkbit(0, 3),
|
|
IsCoverOpen: checkbit(0, 5),
|
|
IsPaperFedByFeedButton: checkbit(0, 5),
|
|
IsWaitingForOnlineRecovery: checkbit(1, 0),
|
|
},
|
|
Error: ErrorStatus{
|
|
RecoverableErrorOccurred: checkbit(1, 2),
|
|
AutocutterErrorOccurred: checkbit(1, 3),
|
|
UnrecoverableErrorOccurred: checkbit(1, 5),
|
|
AutomaticallyRecoverableErrorOccurred: checkbit(1, 6),
|
|
},
|
|
Paper: p.ParsePaperSensorStatus(status[2]),
|
|
PanelSwitch: PanelSwitchStatus{
|
|
IsFeedButtonPressed: checkbit(1, 1),
|
|
},
|
|
}
|
|
}
|