From 4c7ddf90eabf6d3fe5d56839077d528f456c43ba Mon Sep 17 00:00:00 2001 From: SunSung W541 Date: Wed, 11 Sep 2024 21:31:40 +0200 Subject: [PATCH] refactoring [v0.3.4] methods x5 --- 0_test.go | 4 +- methods.go | 6 +++ methods_device.go | 84 ++++++++++++++++++++++++++---------------- methods_orientation.go | 49 ++++++++++++++++++------ methods_variant.go | 38 ++++++++++++++----- 5 files changed, 126 insertions(+), 55 deletions(-) diff --git a/0_test.go b/0_test.go index 7d51fcb..58278ca 100644 --- a/0_test.go +++ b/0_test.go @@ -105,11 +105,11 @@ func TestConnect(t *testing.T) { t.Log("Invalid Connect") return } - t.Log(a.Method.GetDeviceSerialNumber()) + t.Log(a.Method.Device.Get.SerialNumber()) t.Log(a.Method.Bill.Get.Self()) t.Log(a.Method.Application.Get.PN()) t.Log(a.Method.Get.BootPN()) - t.Log(a.Method.GetDeviceType()) + t.Log(a.Method.Device.Get.Type()) t.Log(a.Method.Get.BNFStatus().String()) diff --git a/methods.go b/methods.go index 4f417e7..d49a495 100644 --- a/methods.go +++ b/methods.go @@ -24,6 +24,9 @@ type MethodsObj struct { Bill *MethodsBillObj CashBox *MethodsCashBoxObj Coupon *MethodsCouponObj + Device *MethodsDeviceObj + Orientation *MethodsOrientationObj + Variant *MethodsVariantObj } type MethodsGetObj struct{ a *MpostObj } @@ -46,6 +49,9 @@ func (a *MpostObj) newMethods() *MethodsObj { obj.Bill = obj.newBill() obj.CashBox = obj.newCashBox() obj.Coupon = obj.newCoupon() + obj.Device = obj.newDevice() + obj.Orientation = obj.newOrientation() + obj.Variant = obj.newVariant() return &obj } diff --git a/methods_device.go b/methods_device.go index 1609db0..15ee509 100644 --- a/methods_device.go +++ b/methods_device.go @@ -8,37 +8,30 @@ import ( //////////////////////////////////// -func (m *MethodsObj) GetCapDevicePaused() bool { - m.a.Log.Method("GetCapDevicePaused", nil) - return acceptor.Cap.DevicePaused +type MethodsDeviceObj struct { + a *MpostObj + Get MethodDeviceGetObj } -func (m *MethodsObj) GetCapDeviceSoftReset() bool { - m.a.Log.Method("GetCapDeviceSoftReset", nil) - return acceptor.Cap.DeviceSoftReset -} +type MethodDeviceGetObj struct{ a *MpostObj } -func (m *MethodsObj) GetCapDeviceType() bool { - m.a.Log.Method("GetCapDeviceType", nil) - return acceptor.Cap.DeviceType -} +func (m *MethodsObj) newDevice() *MethodsDeviceObj { + obj := MethodsDeviceObj{} -func (m *MethodsObj) GetCapDeviceResets() bool { - m.a.Log.Method("GetCapDeviceResets", nil) - return acceptor.Cap.DeviceResets -} + obj.a = m.a + obj.Get.a = m.a -func (m *MethodsObj) GetCapDeviceSerialNumber() bool { - m.a.Log.Method("GetCapDeviceSerialNumber", nil) - return acceptor.Cap.DeviceSerialNumber + return &obj } -func (m *MethodsObj) GetDeviceBusy() bool { +//////////////// + +func (m *MethodDeviceGetObj) Busy() bool { m.a.Log.Method("GetDeviceBusy", nil) return acceptor.Device.State != enum.StateIdling } -func (m *MethodsObj) GetDeviceCRC() int64 { +func (m *MethodDeviceGetObj) CRC() int64 { m.a.Log.Method("GetDeviceCRC", nil) err := acceptor.Verify(true, "DeviceCRC") @@ -67,37 +60,37 @@ func (m *MethodsObj) GetDeviceCRC() int64 { return crc } -func (m *MethodsObj) GetDeviceFailure() bool { +func (m *MethodDeviceGetObj) Failure() bool { m.a.Log.Method("GetDeviceFailure", nil) return acceptor.Device.State == enum.StateFailed } -func (m *MethodsObj) GetDeviceJammed() bool { +func (m *MethodDeviceGetObj) Jammed() bool { m.a.Log.Method("GetDeviceJammed", nil) return acceptor.Device.Jammed } -func (m *MethodsObj) GetDeviceModel() int { +func (m *MethodDeviceGetObj) Model() int { m.a.Log.Method("GetDeviceModel", nil) return acceptor.Device.Model } -func (m *MethodsObj) GetDevicePaused() bool { +func (m *MethodDeviceGetObj) Paused() bool { m.a.Log.Method("GetDevicePaused", nil) return acceptor.Device.Paused } -func (m *MethodsObj) GetDevicePortName() string { +func (m *MethodDeviceGetObj) PortName() string { m.a.Log.Method("GetDevicePortName", nil) return m.a.port.PortName } -func (m *MethodsObj) GetDevicePowerUp() enum.PowerUpType { +func (m *MethodDeviceGetObj) PowerUp() enum.PowerUpType { m.a.Log.Method("GetDevicePowerUp", nil) return acceptor.Device.PowerUp } -func (m *MethodsObj) GetDeviceResets() int { +func (m *MethodDeviceGetObj) Resets() int { m.a.Log.Method("GetDeviceResets", nil) err := acceptor.Verify(acceptor.Cap.DeviceResets, "DeviceResets") @@ -128,12 +121,12 @@ func (m *MethodsObj) GetDeviceResets() int { return resets } -func (m *MethodsObj) GetDeviceRevision() int { +func (m *MethodDeviceGetObj) Revision() int { m.a.Log.Method("GetDeviceRevision", nil) return acceptor.Device.Revision } -func (m *MethodsObj) GetDeviceSerialNumber() string { +func (m *MethodDeviceGetObj) SerialNumber() string { m.a.Log.Method("GetDeviceSerialNumber", nil) err := acceptor.Verify(acceptor.Cap.DeviceSerialNumber, "DeviceSerialNumber") @@ -159,17 +152,17 @@ func (m *MethodsObj) GetDeviceSerialNumber() string { return s } -func (m *MethodsObj) GetDeviceStalled() bool { +func (m *MethodDeviceGetObj) Stalled() bool { m.a.Log.Method("GetDeviceStalled", nil) return acceptor.Device.Stalled } -func (m *MethodsObj) GetDeviceState() enum.StateType { +func (m *MethodDeviceGetObj) State() enum.StateType { m.a.Log.Method("GetDeviceState", nil) return acceptor.Device.State } -func (m *MethodsObj) GetDeviceType() string { +func (m *MethodDeviceGetObj) Type() string { m.a.Log.Method("GetDeviceType", nil) err := acceptor.Verify(acceptor.Cap.DeviceType, "DeviceType") @@ -198,3 +191,30 @@ func (m *MethodsObj) GetDeviceType() string { return "" } + +// + +func (m *MethodDeviceGetObj) CapPaused() bool { + m.a.Log.Method("GetCapDevicePaused", nil) + return acceptor.Cap.DevicePaused +} + +func (m *MethodDeviceGetObj) CapSoftReset() bool { + m.a.Log.Method("GetCapDeviceSoftReset", nil) + return acceptor.Cap.DeviceSoftReset +} + +func (m *MethodDeviceGetObj) CapType() bool { + m.a.Log.Method("GetCapDeviceType", nil) + return acceptor.Cap.DeviceType +} + +func (m *MethodDeviceGetObj) CapResets() bool { + m.a.Log.Method("GetCapDeviceResets", nil) + return acceptor.Cap.DeviceResets +} + +func (m *MethodDeviceGetObj) CapSerialNumber() bool { + m.a.Log.Method("GetCapDeviceSerialNumber", nil) + return acceptor.Cap.DeviceSerialNumber +} diff --git a/methods_orientation.go b/methods_orientation.go index 654b06d..375de7d 100644 --- a/methods_orientation.go +++ b/methods_orientation.go @@ -7,12 +7,28 @@ import ( //////////////////////////////////// -func (m *MethodsObj) GetCapOrientationExt() bool { - m.a.Log.Method("GetCapOrientationExt", nil) - return acceptor.Cap.OrientationExt +type MethodsOrientationObj struct { + a *MpostObj + Get MethodsOrientationGetObj + Set MethodsOrientationSetObj } -func (m *MethodsObj) GetEscrowOrientation() enum.OrientationType { +type MethodsOrientationGetObj struct{ a *MpostObj } +type MethodsOrientationSetObj struct{ a *MpostObj } + +func (m *MethodsObj) newOrientation() *MethodsOrientationObj { + obj := MethodsOrientationObj{} + + obj.a = m.a + obj.Get.a = m.a + obj.Set.a = m.a + + return &obj +} + +//////////////// + +func (m *MethodsOrientationGetObj) Escrow() enum.OrientationType { m.a.Log.Method("GetEscrowOrientation", nil) if acceptor.Cap.OrientationExt { return acceptor.EscrowOrientation @@ -20,22 +36,31 @@ func (m *MethodsObj) GetEscrowOrientation() enum.OrientationType { return enum.OrientationUnknownOrientation } -func (m *MethodsObj) GetOrientationControl() enum.OrientationControlType { +func (m *MethodsOrientationGetObj) Control() enum.OrientationControlType { m.a.Log.Method("GetOrientationControl", nil) return acceptor.OrientationCtl } -func (m *MethodsObj) SetOrientationControl(v enum.OrientationControlType) { - m.a.Log.Method("SetOrientationControl", nil) - acceptor.OrientationCtl = v -} - -func (m *MethodsObj) GetOrientationCtlExt() enum.OrientationControlType { +func (m *MethodsOrientationGetObj) ControlEscrow() enum.OrientationControlType { m.a.Log.Method("GetOrientationCtlExt", nil) return acceptor.OrientationCtlExt } -func (m *MethodsObj) SetOrientationCtlExt(v enum.OrientationControlType) { +// + +func (m *MethodsOrientationGetObj) CapEscrow() bool { + m.a.Log.Method("GetCapOrientationExt", nil) + return acceptor.Cap.OrientationExt +} + +//// + +func (m *MethodsOrientationSetObj) Control(v enum.OrientationControlType) { + m.a.Log.Method("SetOrientationControl", nil) + acceptor.OrientationCtl = v +} + +func (m *MethodsOrientationSetObj) ControlEscrow(v enum.OrientationControlType) { m.a.Log.Method("SetOrientationCtlExt", nil) acceptor.OrientationCtlExt = v } diff --git a/methods_variant.go b/methods_variant.go index 56e24fc..38cfda0 100644 --- a/methods_variant.go +++ b/methods_variant.go @@ -7,17 +7,25 @@ import ( //////////////////////////////////// -func (m *MethodsObj) GetCapVariantID() bool { - m.a.Log.Method("GetCapVariantID", nil) - return acceptor.Cap.VariantID +type MethodsVariantObj struct { + a *MpostObj + Get MethodVariantGetObj } -func (m *MethodsObj) GetCapVariantPN() bool { - m.a.Log.Method("GetCapVariantPN", nil) - return acceptor.Cap.VariantPN +type MethodVariantGetObj struct{ a *MpostObj } + +func (m *MethodsObj) newVariant() *MethodsVariantObj { + obj := MethodsVariantObj{} + + obj.a = m.a + obj.Get.a = m.a + + return &obj } -func (m *MethodsObj) GetVariantNames() []string { +//////////////// + +func (m *MethodVariantGetObj) Names() []string { m.a.Log.Method("GetVariantNames", nil) err := acceptor.Verify(true, "VariantNames") @@ -49,7 +57,7 @@ func (m *MethodsObj) GetVariantNames() []string { return names } -func (m *MethodsObj) GetVariantID() string { +func (m *MethodVariantGetObj) ID() string { m.a.Log.Method("GetVariantID", nil) err := acceptor.Verify(acceptor.Cap.VariantID, "VariantID") @@ -73,7 +81,7 @@ func (m *MethodsObj) GetVariantID() string { return "" } -func (m *MethodsObj) GetVariantPN() string { +func (m *MethodVariantGetObj) PN() string { m.a.Log.Method("GetVariantPN", nil) err := acceptor.Verify(acceptor.Cap.VariantPN, "VariantPN") @@ -96,3 +104,15 @@ func (m *MethodsObj) GetVariantPN() string { return "" } + +// + +func (m *MethodVariantGetObj) CapID() bool { + m.a.Log.Method("GetCapVariantID", nil) + return acceptor.Cap.VariantID +} + +func (m *MethodVariantGetObj) CapPN() bool { + m.a.Log.Method("GetCapVariantPN", nil) + return acceptor.Cap.VariantPN +}