I am using this source code for an application of reading serial data from an XBee connected to my Windows machine to the Raspberry Pi. The data being sent is the y position of my left and right thumb stick on my XBee controller, for the purpose of controlling a robot through a skid type drive (i.e. press left forward and leave right alone, the car should turn right). I am able to successfully read the Xbox controller coordinates using the Xinput API, and send the coordinates to my XCTU. I can see the correct data being sent to the XCTU console, however, when using this program (the demo_rx) http://www.teuniz.net/RS-232/ , and including a line to convert from the char to an int
int x = atoi ((char * ) buf);
the only data being output is a stream of 0's. When I don't convert it to an int, i.e. get rid of that previous line of code, the data output is a stream of random ASCII characters, which is fine, except when the y value is negative, then it becomes a standard character no matter where the control stick is in the negative axis.
I would like to figure out how to convert the data correctly, because I believe I am sending and receiving it correctly, but I don't think the the ASCII conversion is the right way to go.
EDIT: I figured out why atoi is returning 0, it's because the first character in the char buffer is an ASCII value not a number, which is why sometimes I would get actual numbers instead of just 0's.