Inbound Strings with Propeller C over the XBEE
egeis
Posts: 5
I am working on a Activity bot, equipped with 4 QTI sensors and an XBEE wireless antenna (starter kit), that uses an application to find the shortest path within a maze. Most decisions are made by the application which will require two-way communication to the activity bot and host PC. The application receives information on each node the robot discovers while the application decides that next course of action then replies to the robot awaiting instructions. Before I start writing the application I've been trying to send those commands using the X-CTU but I've ran into two problems. I cannot find a way to read or piece together an entire string on the Activity Bot side (using C). I have also been unable to locate any examples that are similar to what I'm trying to do on learn.parallax.com and on other websites. If anyone has any suggestions or knows how to read a string from an XBEE I could use some help. This was not the part of the project I though id be banging my head against the wall on... I figured it was going to be the modified depth first search I was also supposed to write this weekend
Below is the code I've been working with, I've removed most of the COG / sensor code from the QTI to keep it simple.
My idea was to send "::RECIEVED" for this test. Although for testing i was originally using "TEST" to see if the entire string could be echoed.
Below is the code I've been working with, I've removed most of the COG / sensor code from the QTI to keep it simple.
#include "simpletools.h" #include "simpletext.h" #include "fdserial.h" #include "abdrive.h" #include <driver.h> #define XBEE_CONF_RX_PIN 6 #define XBEE_CONF_TX_PIN 5 #define XBEE_CONF_BAUD 9600 #define XBEE_CONF_CONN_WAIT 10 //Timeout while Connecting or Reconnecting //QTI Configuration #define QTI_PIN_MIN 0 #define QTI_PIN_MAX 3 #define QTI_ARRAY_SIZE 100 //TODO: Test Speed and Distance this covers and adjust this size. //Global Variables //Full Duplex Serial Driver used for output. fdserial *xb; //Output buffer char buf[100]; //Forward Declarations void wireless(void *par); void sensors(void *par); int qti(int pin); int xbee_connect(); int main() { freqout(4,500,2000); xbee_connect(); while(1) { //TODO: Interpret Commands } dprint(xb, "[DRIVER] Stopping Robot, if not already stopped."); drive_speed(0,0); dprint(xb, "[XBEE Wireless] Shuting Down!"); fdserial_close(xb); freqout(4,5000,1500); return 0; } /** * Xbee Wireless Conncetion * * Creates the Serial connection and returns whether the two way test was a success. * * @return INT */ int xbee_connect() { int success = 0; //Create the Serial Connection xb = fdserial_open(XBEE_CONF_RX_PIN, XBEE_CONF_TX_PIN, 0, XBEE_CONF_BAUD); dprint(xb, "[XBEE Wireless] Started!\n"); //Empties the Recieving and Transmitting Buffers fdserial_rxFlush(xb); fdserial_txFlush(xb); //Signals the Application to Send a Response through the XBEE. dprint(xb, "::SEND_TEST\n"); //Wait for a response dprint(xb, "[XBEE Wireless] Waiting for test response.\n"); while(1) { //int ch = fdserial_rxCheck(xb); char buf[10] = {'\0'}; int n = read(xb,buf,10); if (buf[0] != '\0') { dprint(xb,buf); //Echo back the STRING } } return success; }
My idea was to send "::RECIEVED" for this test. Although for testing i was originally using "TEST" to see if the entire string could be echoed.
Comments
Use the simpletext functions like readStr(...), readDec(...), or dscan(...).
The fdserial functions can be used for non-blocking checks of data before reading fdserial_rxReady(...).
Documentation for simpletext and fdserial are in the Documents/SimpleIDE/Learn/Simple Libraries folders or on-line.
https://propsideworkspace.googlecode.com/hg/Learn/Simple Libraries Index.html
I kept looking in Serial and FdSerial for the answers, along with simple tools. Should have gone back to the main directory, next time I shall. Once this project is completed, I plan to release the code for others to use as a example.
xb is FdSerial connection
Based on my testing of readStr, it wont output till the buffer has the "max size to read" or the buffer contains an carriage return.
I easy solution is to either manually add 0D to the packet that is being sent form X-CTU and in the future on the application it is send from add the carriage return before sending.
Yes, that's right. the doc doesn't say anything about the return though.