summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dobrowolski <admin@tastycode.pl>2017-02-17 14:05:01 +0100
committerPiotr Dobrowolski <admin@tastycode.pl>2017-02-17 14:06:15 +0100
commit940ca43f5ba584aed88f9d104bd2008341fe0f89 (patch)
tree4a6f56cac8cd4c2b70bc99e4316dfe0508d79173
parent6d476f6ac23474b2563397ae930049e33226ff35 (diff)
downloadbitvend-940ca43f5ba584aed88f9d104bd2008341fe0f89.tar.gz
bitvend-940ca43f5ba584aed88f9d104bd2008341fe0f89.tar.bz2
bitvend-940ca43f5ba584aed88f9d104bd2008341fe0f89.tar.xz
bitvend-940ca43f5ba584aed88f9d104bd2008341fe0f89.zip
Add dumb lockup prevention
This tends to happen, because we seem to be tiny bit too slow sometimes and VMC considers our ACK as bill validator ACK and then it furiously tries to initialize it. In such case, if we get 20 consecutive bill validator RESET requests, we just ACK every other bill validator message, but don't response to POLL. It'll just unlock after a second... This needs to be fixed properly by figuring out why there's some latency sometimes. (well, maybe it's just because of python?)
-rw-r--r--mdb/device.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/mdb/device.py b/mdb/device.py
index 0b1940c..5f789b5 100644
--- a/mdb/device.py
+++ b/mdb/device.py
@@ -143,7 +143,25 @@ class CashlessMDBDevice(MDBDevice):
model_number = '123456789012'
software_version = (0x21, 0x37)
+ lockup_counter = 0
+
def process_request(self, req):
+ # FIXME this shouldn't be required...
+ if req.command == 0x30 and req.validate_checksum():
+ self.lockup_counter += 1
+
+ if self.lockup_counter >= 20:
+ self.logger.info('YOLO')
+ return []
+ if req.command == 0x31 and req.validate_checksum():
+ return []
+ if req.command == 0x37 and req.validate_checksum():
+ return []
+ if req.command == 0x36 and req.validate_checksum():
+ return []
+ if req.command == 0x34 and req.validate_checksum():
+ return []
+
if (req.command & self.base_address) != self.base_address:
# Target mismatch
return
@@ -152,6 +170,8 @@ class CashlessMDBDevice(MDBDevice):
# Invalid checksum
return
+ self.lockup_counter = 0
+
if req.command == CASHLESS_RESET:
self.state = 'RESET'
self.logger.info('RESET: Device reset')
@@ -241,6 +261,7 @@ class CashlessMDBDevice(MDBDevice):
return []
def begin_session(self, amount):
+ self.logger.info('Beginning session for %d', amount)
# Begins new session with balance provided
if amount > 65535:
amount = 65535