WIP vending v2 with serial backend
parent
cce3ff5237
commit
494f5ef2bc
|
@ -23,6 +23,7 @@ class BitvendCashlessMDBDevice(CashlessMDBDevice):
|
|||
# FIXME we report success here, because database write takes too much
|
||||
# time to respond in 5ms.
|
||||
self.send([0x05, 0x00, 0xff])
|
||||
self.poll_queue.put([0x05])
|
||||
self.current_request.processed = True
|
||||
|
||||
self.logger.info('got vend request: %r', self.current_tx_id)
|
||||
|
|
|
@ -84,10 +84,15 @@ class RaspiBackend(Backend):
|
|||
#
|
||||
class SerialBackend(Backend):
|
||||
def __init__(self, device='/dev/ttyACM0'):
|
||||
import serial
|
||||
self.ser = serial.Serial(device)
|
||||
|
||||
def read(self):
|
||||
return self.ser.read()
|
||||
buf = b''
|
||||
while len(buf) < 2:
|
||||
buf += self.ser.read(1)
|
||||
return buf
|
||||
|
||||
def write(self, data):
|
||||
self.ser.write(data)
|
||||
self.ser.flush()
|
||||
|
|
|
@ -9,7 +9,7 @@ except ImportError:
|
|||
|
||||
from mdb.utils import compute_checksum, compute_chk, bcd_decode
|
||||
from mdb.constants import *
|
||||
from mdb.backend import RaspiBackend, DummyBackend, pigpio
|
||||
from mdb.backend import RaspiBackend, DummyBackend, SerialBackend, pigpio
|
||||
|
||||
class MDBRequest(object):
|
||||
timestamp = None
|
||||
|
@ -64,7 +64,7 @@ class MDBDevice(object):
|
|||
self.backend = RaspiBackend()
|
||||
else:
|
||||
self.logger.warning('Running with dummy backend device')
|
||||
self.backend = DummyBackend()
|
||||
self.backend = SerialBackend()
|
||||
|
||||
def initialize(self):
|
||||
self.logger.info('Initializing...')
|
||||
|
@ -79,6 +79,7 @@ class MDBDevice(object):
|
|||
for b in range(0, len(data), 2):
|
||||
if data[b+1]:
|
||||
if self.current_request: # and not self.current_request.processed:
|
||||
if self.current_request.command not in [0xf2]:
|
||||
self.logger.debug(self.current_request)
|
||||
if self.current_request.processed and self.current_request.ack:
|
||||
self.logger.info('Got response: %d',self.current_request.data[-1])
|
||||
|
@ -150,21 +151,21 @@ class CashlessMDBDevice(MDBDevice):
|
|||
|
||||
def process_request(self, req):
|
||||
# FIXME this shouldn't be required...
|
||||
if req.command == 0x30 and req.validate_checksum():
|
||||
self.lockup_counter += 1
|
||||
#if req.command == 0x30 and req.validate_checksum():
|
||||
# self.lockup_counter += 1
|
||||
|
||||
if self.lockup_counter % 50 == 0:
|
||||
self.logger.info('YOLO')
|
||||
return []
|
||||
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 self.lockup_counter % 50 == 0:
|
||||
# self.logger.info('YOLO')
|
||||
# return []
|
||||
# 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
|
||||
|
|
|
@ -5,6 +5,7 @@ Flask-Login==0.4.0
|
|||
Flask-QRcode==0.10.0
|
||||
Flask-SQLAlchemy==2.1
|
||||
Flask-WTF==0.14.2
|
||||
Flask-OAuthlib==0.9.4
|
||||
itsdangerous==0.24
|
||||
Jinja2==2.9.4
|
||||
MarkupSafe==0.23
|
||||
|
|
Loading…
Reference in New Issue