Generic Slave
The generic peripheral api/command set allows you to implement "any" peripheral device to the VMC; and you can implement up to three devices concurrently in one single hardware (plus the specific cashless device implementation)
To ease timing for the host, the interface usually answers commands from the VMC which require an answer with an ACK, posts the message to the host, and when an answer from the host is received, it is put in a buffer and delivered to the VMC with the next poll cycle initiated by the VMC.
When implementing a peripheral, first the host will have to set the address of the peripheral to which the interface should listen/respond. Up to four such addresses can be set to allow the implementation of multiple peripheral functions within the interface.
A,<address> #set slave addresses for peripheral mode
With the "A" Command, the host can set the address (or multiple addresses) the interface should listen to. Up to three addresses can be set, independent of the possible address set by the cashless high level implementation. The address is represented in 2 hex digits. As defined in the MDB specification, each kind of peripheral has a specified address, depending on its functionality (Ex. Cashless Reader is 0x10, Coin Acceptor is 0x08 and bill acceptor is 0x03).
A,10 #set the peripheral address 0x10 (Reserved For Cashless Readers) for buffer message
A,08,03 #set peripheral addresses 0x08 for a coin acceptor and 0x03 for a bill acceptor
Up to 3 addresses can be set
Possible Responses:
a,ACK/10 #address list has been successfully set for cashless reader
a,ACK/08/03 #address list has been successfully set for coin and bill acceptors
a,NACK #error setting the address list (for example, if the peripheral mode has been started already)
A,10 - register cashless device #1 address (this is actually range 0x10..0x17)
- note that the arguments are given in hexadecimal, 2 digits*
S,1 #start peripheral mode
S,0 #stop peripheral mode
Incoming Blocks from the Master
When the peripheralmode is started, messages from the master on the MDB bus to one of the previously set peripheraladdresses will be sent to the host in the following format:
r,xx,yyyyyy #message received from host to peripheral address xx
r,RESET #if a reset condition is detected in the bus
The host may provide an answer (but an answer is not required to all messages)
The interface itself will give ACK answers to comply with the short and strict timing requirements of the MDB specification
Answers sent to the Master
In the "P" and "Q" Responses, XXXXXXXX can have varying lengths, depending on what the peripheral is actually replying or informing the VMC.
For answer messages from the host to the MDB master one of two formats can be used ("P" and "Q" formats):
Answer to poll (Deprecated)
P,XXXXXXXX #Response sent by a Coin acceptor indicating its setup information into the bus
The message is buffered in the MDB interface until a “poll” is received from the host for the address XX (set as first address with the “A” command)
Example: First address is 0x08 (Coin Acceptor), but poll is made on 0B, so when the VMC polls 0B, the answer in P,XXXXXX will be sent back to it.
P,0318400102000f050a1964000000000000000000000000 #Response sent by a Coin acceptor indicating its setup information into the bus
P,0b01 #Response sent by a cashless device indicating its setup information into the bus
Please note that the two examples presented above differ in terms of length. The exact length and format is usually defined in the MDB specification . The decoding of these messages is a responsibility of the VMC.
Answer to Queries on a Specific Address
Q,xx,yyyyyy #send answer as peripheral device with address xx (must be set before using A command) to the Master
The cashless device, if started, will set its address using the same mechanism and start the peripheral functionality. The address used by the cashless high-level implementation must not also be set by the host using the peripheral set command!
Example:
This Example includes Master Commands as well for a better perception. Master and PeripheralModes are enabled in the MDB for this example.
Q,0B,01 # When VMC requests address 0x0b (Poll Coin Acceptor) , it will get the ANSWER 01
R,0B # Master Command requesting address 0B
r,0b,,c # peripheral receives Request on address 0B
p,01 # Master Receives Response 01 for previous request
r,ACK # Master sends "ACK" to peripheral
Store replies in cache
These commands are useful for situations where the response is not mutable, so the response can be always the same when a given address is requested.
In the command below, if there is no sub command, the value of YY should be "FF" , meaning "Don't Care".
S,C,XXYY,ZZZZZZ #Store in cache the answer ZZZZZZ for address XX with subcommand YY.
Examples:
This Example includes Master Commands as well for a better perception. Master and peripheral Modes are enabled in the MDB for this example.
S,C,09FF,0318400102000f050a1964000000000000000000000000 # Store Setup Data in address 09
s,ACK
S,C,0F03,00000000000000000000000000000000 # Store Expansion reply to Payout Status (0F03), answer means that there were no coins paid out
s,ACK
R,09 # Master Requests address 09 (Setup for coin Acceptor)
r,09,,c # peripheral gets the Request
p,0318400102000f050a1964000000000000000000000000 # Master gets the Cached Reply
r,ACK # Master Acks the Reply
# Now the same query again shows the same reply
R,09
r,09,,c
p,0318400102000f050a1964000000000000000000000000
r,ACK
# End of 2nd Setup Query
R,0F,03 # Request expansion address with subcommand for payout status
r,0f,03,c # peripheral gets request
p,00000000000000000000000000000000 #Master gets response
r,ACK # Master ACKS response
# Now the same query again shows the same reply
R,0F,03
r,0f,03,c
p,00000000000000000000000000000000
r,ACK