Advertisement
Spectrewiz

Pseudo-code for message listener

Jul 10th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. /// <summary>This function listens for a message and executes code accordingly.</summary>
  2. /// <param name="message">The message to analyse.</param>
  3. /// <remarks>This  function should be performed on all incoming serial data as soon as it arrives</remarks>
  4. void listener(int message[]){
  5.   int len = message.length - 1;
  6.   int header = message[0];
  7.   int args[len];
  8.   for(int i = 1; i < len; i++){
  9.     args[i - 1] = message[i];
  10.   }
  11.   switch(header){
  12.     case 255:
  13.       //do action corresponding to command
  14.       break;
  15.     case 254:
  16.       //do action
  17.       break;
  18.     //...
  19.     case 248:
  20.       //do action
  21.       break;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement