DMCP interface 03.18_025
Loading...
Searching...
No Matches
Serial Console System Commands

Serial Console System Commands.

Serial Console System Commands.

Channel 0 input to calc

Command 'B' - start bootloader

  "B"  (no args)
 (no reply) - USB switches from serial console to DFU mode

Command 'K' - key press/release

   "KR"       - release key
   "KPhh[hh]" - press key and hold
   "K hh[hh]" - perform short key press

   "hh[hh]" arg:
     - expecting 2 or 4 hex digits 
     - interpreted as a single integer number, bottom 8 bits go to k1, next 8 bits to k2

Command 'L' - trigger LCD repaint

  "L"  (no args)
calculator returns LCD buffer contents in OFF mode

Command 'S' - Enable/disable data sent by system

  "S"         - get current state only
  "S  <msk>"  - set data to send

   where
     <msk>   - state of data as a binary mask:
       1 - printf output enabled
       2 - LCD output enabled
       4 - Keys output enabled

  reply:
    see 'S' in Channel 0 output

Command 'V' - version info

  "V"  (no args)

  reply:
    see 'V' in Channel 0 output

Channel 0 output from calc

Command 'K' - key scan change

  "K k1 k2 tttttt"

  where
   k1 - two hex digits of first key
   k2 - two hex digits of second key
   tttttt - 6 digit centisecons counter (centiseconds in an hour)

Command 'L' - LCD line changed

   "L yy <data>"

   where
     yy     - line number in hexadecimal
     <data> - line contents (binary data)

Command 'S' - Select sent data reply

   "S <msk>"

   where
     <msk>   - state of data as a binary mask:
       1 - printf output enabled
       2 - LCD output enabled
       4 - Keys output enabled

Command 'V' - version info reply

  "V|HW {hw}|VER {ver}|DMCP5 {dmcp}|IFC {ifc}|SN {sn}"

  where
    {hw}   - Name of loaded application
    {ver}  - Version of loaded application
    {dmcp} - Version of DMCP5
    {ifc}  - Interface version of DMCP5
    {sn}   - Calculator serial number

Binary data

Systems encodes binary data by storing 7 bits of data per character and setting top bit to 1. Thus, binary data in system responses can be easily recognized by checking top bit of characters:

Example of binary data encoding:

  Sequence of three bytes 
    AB CD EF
  binary
    1010 1011   1100 1101   1110 1111
  split by 7bits
    1|010 1011  11|00 1101  111|0 1111
    b aaa aaaa  cc bb bbbb  ddd c cccc  <- output byte id below

  encoded to output
 a: 1 010 1011   = AB
 b: 1 001 1011   = 9B 
 c: 1 011 1111   = BF
 d: 1 xxx x111   = 87  (value of 'x' doesn't matter)

  So, 7bit encoding of 
    AB CD EF
  gives
    AB 9B BF 87

Example of encoding function

// Encode to 7bit byte array (used in serial communication)
// Destination array has to be sized correctly.
// Returns number of destination bytes used
int encode_7bit(uint8_t *d, uint8_t *s, int cnt) {
uint32_t a = 0; // Data out
uint8_t c = 0; // Number of data bits in a
int y = 0; // Destination index
for (int x=0; x<cnt; x++) { // Over source bytes
a |= s[x] << c;
c += 8;
while (c >= 7) {
d[y++] = (a & 0x7f)|0x80;
a >>= 7;
c -= 7;
}
}
if (c > 0)
d[y++] = (a & 0x7f)|0x80;
return y;
}