Advertisement
Guest User

Untitled

a guest
Aug 11th, 2011
1,276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.61 KB | None | 0 0
  1. //This is my read event callback called by libevent
  2.  
  3. static void cmd_read(int fd, short evtype, void *arg) {
  4.     if (!(evtype & EV_READ)) {
  5.         log(LOG_ERR, "Unknown event type in read callback: 0x%hx", evtype);
  6.         return;
  7.     }
  8.  
  9.     char buf[16] = { 0 };
  10.  
  11.     //This method does a standard read until a \n is found which is my
  12.     //end of the message from the arduino
  13.     serialport_read_until(fd, buf, '\n');
  14.  
  15.     //The message must start with 'XA' characters
  16.     if (buf[0] != 'X' && buf[1] != 'A')
  17.         return;
  18.  
  19.     //TODO parse the command and data here
  20.  
  21.     //Print the entire message to the screen
  22.     log(LOG_INFO, "Str: %s", buf);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement