int main(int argc, char**argv) { Xbee xbee("/dev/ttyUSB0",9); Angles joystick_des_angles = {0}; uint8_t joystick_thrust = 0, flight_mode = 0; ros::init(argc,argv,"xbee"); ros::NodeHandle nh; ros::Publisher xbee_pub; xbee_pub = nh.advertise<quad_msgs::XbeeData>("xbee/xbee_cmds",1); int suc = 0; while(ros::ok()) { suc = xbee.get_xbee_data(joystick_des_angles, joystick_thrust, flight_mode); //printf("suc: %i \n",suc); if(suc > 0){ //xbee.printData(joystick_des_angles, joystick_thrust, flight_mode); quad_msgs::XbeeData xb_msg; //printf("im in here"); xb_msg.header.stamp = ros::Time::now(); xb_msg.joy_des_angles[0] = joystick_des_angles.phi; xb_msg.joy_des_angles[1] = joystick_des_angles.theta; xb_msg.joy_des_angles[2] = joystick_des_angles.psi; xb_msg.joy_thrust = joystick_thrust; xb_msg.flight_mode = flight_mode; xbee_pub.publish(xb_msg); } } }
int main(){ char *device = (char *)"/dev/ttyUSB0"; Serial xbee(device, 57600); Message msg(device); int fd = xbee.Open(); std::cout << "Send Image signal\n"; msg.sendingImage(); std::cout << "Transmitting Image\n"; int result = XSend(fd, "testing9.jpeg"); if(result == 0){ std::cout << "Image transmitted successfully\n"; } else{ std::cout << "Error during image transmission\n"; } xbee.Close(); return 0; }
/****************************** Main function ***************************/ void main() { init_devices(); xbee_reset(); xbee(); while(1) { if(DATA_RECEIVED == 1) { int val; val=RECEIVE(); xbee_I_RECEIVE(val); } xbee_I_FRONT_IR_VALUE(FRONT_IR); xbee(); } }
int main(int argc, char *argv[]) { int i; try { /* setup libxbee */ libxbee::XBee xbee("xbee1", "/dev/ttyUSB0", 57600); { /* make a local connection */ myConnection local_con(xbee, "Local AT"); /* with a callback */ struct xbee_conAddress addr; memset(&addr, 0, sizeof(addr)); addr.addr64_enabled = 1; addr.addr64[0] = 0x00; addr.addr64[1] = 0x13; addr.addr64[2] = 0xA2; addr.addr64[3] = 0x00; addr.addr64[4] = 0x40; addr.addr64[5] = 0x3C; addr.addr64[6] = 0xB2; addr.addr64[7] = 0x6D; /* make a remote connection */ myConnection remote_con(xbee, "Remote AT", &addr); /* with a callback */ /* send data */ local_con << "NI"; remote_con << "NI"; /* wait a bit... */ usleep(1000000); /* the connections are terminated when they go out of scope... */ } usleep(1000000); /* the libxbee instance is shutdown when it goes out of scope... */ } catch (xbee_err err) { std::cout << "Error " << err << "\n"; } usleep(5000000); return 0; }
void Message::sendMessage(char type){ Serial xbee(this->device, 57600); xbee.PutChar(type); }
int main(int argc, char *argv[]) { int i; /* get available libxbee modes */ try { std::list<std::string> modes = libxbee::getModes(); std::list<std::string>::iterator i; std::cout << "Available libxbee modes:\n"; for (i = modes.begin(); i != modes.end(); i++) { std::cout << " " << *i; } std::cout << "\n"; } catch (xbee_err ret) { std::cout << "Error while retrieving libxbee modes...\n"; } try { /* setup libxbee */ libxbee::XBee xbee("xbee1", "/dev/ttyUSB0", 57600); std::cout << "Running libxbee in mode '" << xbee.mode() << "'\n"; /* get available connection types */ try { std::list<std::string> types = xbee.getConTypes(); std::list<std::string>::iterator i; std::cout << "Available connection types:\n"; for (i = types.begin(); i != types.end(); i++) { std::cout << " " << *i; } std::cout << "\n"; } catch (xbee_err ret) { std::cout << "Error while retrieving connection types...\n"; } /* make a connection */ #ifdef LOCAL_CONNECTION #ifdef USE_CALLBACKS myConnection con(xbee, "Local AT"); /* with a callback */ con.myData = "Testing, 1... 2... 3...\n"; #else libxbee::Con con(xbee, "Local AT"); /* without a callback */ #endif #else /* LOCAL_CONNECTION */ struct xbee_conAddress addr; memset(&addr, 0, sizeof(addr)); addr.addr64_enabled = 1; addr.addr64[0] = 0x00; addr.addr64[1] = 0x13; addr.addr64[2] = 0xA2; addr.addr64[3] = 0x00; addr.addr64[4] = 0x40; addr.addr64[5] = 0x33; addr.addr64[6] = 0xCA; addr.addr64[7] = 0xCB; #ifdef USE_CALLBACKS myConnection con(xbee, "Remote AT", &addr); /* with a callback */ con.myData = "Testing, 1... 2... 3...\n"; #else libxbee::Con con(xbee, "Remote AT", &addr); /* without a callback */ #endif #endif /* LOCAL_CONNECTION */ /* send data */ //con.Tx("NI"); /* like this */ con << "NI"; /* or like this */ sleep(1); #ifndef USE_CALLBACKS libxbee::Pkt pkt; try { //con >> pkt; /* like this */ pkt << con; /* or this */ } catch (xbee_err err) { std::cout << "Error on Rx! " << err << "\n"; return 1; } try { std::cout << "Packet length: " << pkt.size() << "\n"; for (i = 0; i < pkt.size(); i++) { std::cout << " " << i << " " << pkt[i] << "\n"; } } catch (xbee_err err) { std::cout << "Error accessing packet! " << err << "\n"; return 1; } sleep(1); #endif /* !USE_CALLBACKS */ } catch (xbee_err err) { std::cout << "Error " << err << "\n"; } return 0; }