Open note5 opened 1 year ago
Hi @note5, apologies for the massive delay. $work has been busy and I've kind of abandoned this project since I no longer have access to any vending machines - you may have noticed that there's been no activity on this repo for ~5 years...
The teensy handles the MDB protocol on the host
serial port, the sniff
serial port is a read-only debugging aid to let me see what's happening on the MDB bus, and the usb serial is used for logging etc. It also acts as an i2c peripheral and exports a (very) limited command set to be used by a host device (i.e. raspberry pi) which is where the brains of the cashless device would sit.
The core MDB parsing is in teensy/src/mdb_parse.cpp
which handles decoding the actual messages, and the cashless device implementation is in teensy/src/mdb_cashless.cpp
. The parser uses "handlers" to allow it to be flexible about what commands it works with, these handlers are registered by passing the MDB command/subcommand pair to mdb_register_handler()
along with a function to actually decode it.
The I2C interface is defined in teensy/src/i2c_interface.cpp
, and it uses functions declared in the cashless device implementation to work with the device state. The i2c host app that ran on my pi is lost so I don't have a good example of how to use it.
Bear in mind that there's no guarantee any of this works properly - it's in a very early state, and MDB implementations have a long history of only vaguely adhering to the standards correctly. This did at least work well enough to add currency to our vending machine and allow us to dispense an item.
There's also an old kicad project in here which defines a hat that connects the i2c between a pi and a teensy, and has the necessary electronics to connect it all to MDB. It worked well enough at the time but I'm not sure how kicad would handle it now. I've got a pile of unpopulated boards floating around because I had to order a batch of 10 and only needed one 🤣
Hi and thank you for this repo. Is it possible to get a more comprehensive explanation of the code. I have the teensy board and I can confirm it is parsing the 9bit data correctly now I am trying to understand your code structure and flow so that I can develop a cashless device. Any feedback from you is highly welcomed.