One implementation in C with the space character handled separately is:
const unsigned char LookUpTable[] = {0x1,0xA,0xB,0xA,0x2,0xD,0xB,0xD, 0x3,0xF,0xC,0x8,0xE,0x9,0x4,0xC,0xF,0x9,0x7,0x8,0x5,0xE,0xE,0xF,0x6,0xF};
These two examples show the encoding of SCPI commands:
CLS translates to 0xB870
CALCulate:AVERage:COUNt translates to 0xB18B,0x1E29,0xB459
After encoding the incoming text, parsing is just a matter of checking 16-bit numbers rather than text strings. This can be done as a CASE statement or series of IF statements, either of which is much simpler (and usually faster) than handling text strings in a microcontroller. Using this approach greatly reduced the amount of code needed.
Read more articles in the Ideas for Design Series: Vol. 3
David Hunter is an electrical engineer with First Consulting Inc. in Rochester, N.Y. He has a BSEE and an MSEE from the Rochester Institute of Technology and has worked for more than 25 years as a design engineer in embedded-systems software, digital, analog, and RF circuit hardware design.