Commit 7af82baf authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #4349 from DonLakeFlyer/LinkReference

LinkInterface/LinkConfiguration now reference counter using QSharedPointer
parents e6d7a3d8 3b8a69ad
......@@ -65,103 +65,6 @@ DEPENDPATH += libs/qwt
INCLUDEPATH += libs/qwt
}
#
# [OPTIONAL] XBee wireless support. This is not necessary for basic serial/UART communications.
# It's only required for speaking directly to the Xbee using their proprietary API.
# Unsupported on Mac.
# Installation on Windows is unnecessary, as we just link to our included .dlls directly.
# Installing on Linux involves running `make;sudo make install` in `libs/thirdParty/libxbee`
# Uninstalling from Linux can be done with `sudo make uninstall`.
#
XBEE_DEPENDENT_HEADERS += \
src/comm/XbeeLinkInterface.h \
src/comm/XbeeLink.h \
src/comm/HexSpinBox.h \
src/ui/XbeeConfigurationWindow.h \
src/comm/CallConv.h
XBEE_DEPENDENT_SOURCES += \
src/comm/XbeeLink.cpp \
src/comm/HexSpinBox.cpp \
src/ui/XbeeConfigurationWindow.cpp
XBEE_DEFINES = QGC_XBEE_ENABLED
contains(DEFINES, DISABLE_XBEE) {
message("Skipping support for native XBee API (manual override from command line)")
DEFINES -= DISABLE_XBEE
# Otherwise the user can still disable this feature in the user_config.pri file.
} else:exists(user_config.pri):infile(user_config.pri, DEFINES, DISABLE_XBEE) {
message("Skipping support for native XBee API (manual override from user_config.pri)")
} else:LinuxBuild {
linux-g++-64 {
message("Skipping support for XBee API (64-bit Linux builds not supported)")
} else:exists(/usr/include/xbee.h) {
message("Including support for XBee API")
HEADERS += $$XBEE_DEPENDENT_HEADERS
SOURCES += $$XBEE_DEPENDENT_SOURCES
DEFINES += $$XBEE_DEFINES
LIBS += -L/usr/lib -lxbee
} else {
warning("Skipping support for XBee API (missing libraries, see README)")
}
} else:WindowsBuild {
message("Including support for XBee API")
HEADERS += $$XBEE_DEPENDENT_HEADERS
SOURCES += $$XBEE_DEPENDENT_SOURCES
DEFINES += $$XBEE_DEFINES
INCLUDEPATH += libs/thirdParty/libxbee
LIBS += -l$$BASEDIR/libs/thirdParty/libxbee/lib/libxbee
} else {
message("Skipping support for XBee API (unsupported platform)")
}
#
# [OPTIONAL] Opal RT-LAB Library. Provides integration with Opal-RT's RT-LAB simulator.
#
contains(DEFINES, DISABLE_RTLAB) {
message("Skipping support for RT-LAB (manual override from command line)")
DEFINES -= DISABLE_RTLAB
# Otherwise the user can still disable this feature in the user_config.pri file.
} else:exists(user_config.pri):infile(user_config.pri, DEFINES, DISABLE_RTLAB) {
message("Skipping support for RT-LAB (manual override from user_config.pri)")
} else:WindowsBuild {
exists(src/lib/opalrt/OpalApi.h) : exists(C:/OPAL-RT/RT-LAB7.2.4/Common/bin) {
message("Including support for RT-LAB")
DEFINES += QGC_RTLAB_ENABLED
INCLUDEPATH +=
src/lib/opalrt
libs/lib/opal/include \
FORMS += src/ui/OpalLinkSettings.ui
HEADERS += \
src/comm/OpalRT.h \
src/comm/OpalLink.h \
src/comm/Parameter.h \
src/comm/QGCParamID.h \
src/comm/ParameterList.h \
src/ui/OpalLinkConfigurationWindow.h
SOURCES += \
src/comm/OpalRT.cc \
src/comm/OpalLink.cc \
src/comm/Parameter.cc \
src/comm/QGCParamID.cc \
src/comm/ParameterList.cc \
src/ui/OpalLinkConfigurationWindow.cc
LIBS += \
-LC:/OPAL-RT/RT-LAB7.2.4/Common/bin \
-lOpalApi
} else {
warning("Skipping support for RT-LAB (missing libraries, see README)")
}
} else {
message("Skipping support for RT-LAB (unsupported platform)")
}
#
# [REQUIRED] SDL dependency. Provides joystick/gamepad support.
# The SDL is packaged with QGC for the Mac and Windows. Linux support requires installing the SDL
......
......@@ -63,7 +63,6 @@ WindowsBuild {
ReleaseBuild: DLL_QT_DEBUGCHAR = ""
COPY_FILE_LIST = \
$$BASEDIR\\libs\\lib\\sdl2\\msvc\\lib\\x86\\SDL2.dll \
$$BASEDIR\\libs\\thirdParty\\libxbee\\lib\\libxbee.dll \
$$BASEDIR\\deploy\\libeay32.dll
for(COPY_FILE, COPY_FILE_LIST) {
......
This diff is collapsed.
Welcome to libxbee!
I have proveded sample code in the ./sample directory. Hopefully this will help
get you up and running with libxbee. If you would like samples showing a different
aspect of libxbee, then please do not hesitate to file an 'issue' on the project
site, and I will get to it ASAP:
http://code.google.com/p/libxbee/issues/list
Documentation is avaliable via the man page system once you have installed the
library, or as HTML in the 'doc' directory.
$ man libxbee
Please note that this project is still in development, so should not be used for
any purpose other than learning/playing/testing etc... Basically don't use it to
make money, and then hold me responsible if it breaks!
Feel free to contact me directly with any queries:
attie@attie.co.uk
For those of you that are planning to use this on an embedded board, I have
included a small makefile (umakefile) that has only the information needed to
compile the library. I suggest you use this instead!
=== Installation ===
To install simply type:
$ make install
For more information, or if you can't install it, please see the wiki:
http://code.google.com/p/libxbee/wiki/install_libxbee
=== Usage ===
If you are compiling the object file directly into your executable instead
of making use of the shared library, you must include the following link
flags:
-lpthread -lrt
This diff is collapsed.
/*
libxbee - a C library to aid the use of Digi's Series 1 XBee modules
running in API mode (AP=2).
Copyright (C) 2009 Attie Grande (attie@attie.co.uk)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#ifdef __GNUC__ /* ---- */
#include <unistd.h>
#include <termios.h>
#define __USE_GNU
#include <pthread.h>
#undef __USE_GNU
#include <sys/time.h>
#else /* -------------- */
#include <Windows.h>
#include <io.h>
#include <time.h>
#include <sys/timeb.h>
#endif /* ------------- */
#ifdef __UMAKEFILE
#define HOST_OS "Embedded"
#elif defined(__GNUC__)
#define HOST_OS "Linux"
#elif defined(_WIN32)
#define HOST_OS "Win32"
#else
#define HOST_OS "UNKNOWN"
#endif
#define TRUE 1
#define FALSE 0
#define M8(x) (x & 0xFF)
/* various connection types */
#define XBEE_LOCAL_AT 0x88
#define XBEE_LOCAL_ATREQ 0x08
#define XBEE_LOCAL_ATQUE 0x09
#define XBEE_REMOTE_AT 0x97
#define XBEE_REMOTE_ATREQ 0x17
#define XBEE_MODEM_STATUS 0x8A
/* XBee Series 1 stuff */
#define XBEE_TX_STATUS 0x89
#define XBEE_64BIT_DATATX 0x00
#define XBEE_64BIT_DATARX 0x80
#define XBEE_16BIT_DATATX 0x01
#define XBEE_16BIT_DATARX 0x81
#define XBEE_64BIT_IO 0x82
#define XBEE_16BIT_IO 0x83
/* XBee Series 2 stuff */
#define XBEE2_DATATX 0x10
#define XBEE2_DATARX 0x90
#define XBEE2_TX_STATUS 0x8B
typedef struct xbee_hnd* xbee_hnd;
#define __LIBXBEE_API_H
#include "xbee.h"
typedef struct t_threadList t_threadList;
struct t_threadList {
xbee_thread_t thread;
t_threadList *next;
};
struct xbee_hnd {
xbee_file_t tty;
#ifdef __GNUC__ /* ---- */
int ttyfd;
#else /* -------------- */
int ttyr;
int ttyw;
int ttyeof;
OVERLAPPED ttyovrw;
OVERLAPPED ttyovrr;
OVERLAPPED ttyovrs;
#endif /* ------------- */
char *path; /* serial port path */
xbee_mutex_t logmutex;
FILE *log;
int logfd;
xbee_mutex_t conmutex;
xbee_con *conlist;
xbee_mutex_t pktmutex;
xbee_pkt *pktlist;
xbee_pkt *pktlast;
int pktcount;
xbee_mutex_t sendmutex;
xbee_thread_t listent;
xbee_thread_t threadt;
xbee_mutex_t threadmutex;
xbee_sem_t threadsem;
t_threadList *threadList;
int run;
int oldAPI;
char cmdSeq;
int cmdTime;
/* ready flag.
needs to be set to -1 so that the listen thread can begin. */
volatile int xbee_ready;
xbee_hnd next;
};
xbee_hnd default_xbee = NULL;
xbee_mutex_t xbee_hnd_mutex;
typedef struct t_data t_data;
struct t_data {
unsigned char data[128];
unsigned int length;
};
typedef struct t_LTinfo t_LTinfo;
struct t_LTinfo {
int i;
xbee_hnd xbee;
};
typedef struct t_CBinfo t_CBinfo;
struct t_CBinfo {
xbee_hnd xbee;
xbee_con *con;
};
typedef struct t_callback_list t_callback_list;
struct t_callback_list {
xbee_pkt *pkt;
t_callback_list *next;
};
static void *Xmalloc2(xbee_hnd xbee, size_t size);
static void *Xcalloc2(xbee_hnd xbee, size_t size);
static void *Xrealloc2(xbee_hnd xbee, void *ptr, size_t size);
static void Xfree2(void **ptr);
#define Xmalloc(x) Xmalloc2(xbee,(x))
#define Xcalloc(x) Xcalloc2(xbee,(x))
#define Xrealloc(x,y) Xrealloc2(xbee,(x),(y))
#define Xfree(x) Xfree2((void **)&x)
/* usage:
xbee_logSf() lock the log
xbee_logEf() unlock the log
xbee_log() lock print with \n unlock # to print a single line
xbee_logc() lock print with no \n # to print a single line with a custom ending
xbee_logcf() print \n unlock # to end a custom-ended single line
xbee_logS() lock print with \n # to start a continuous block
xbee_logI() print with \n # to continue a continuous block
xbee_logIc() print with no \n # to continue a continuous block with a custom ending
xbee_logIcf() print \n # to continue a continuous block with ended custom-ended line
xbee_logE() print with \n unlock # to end a continuous block
*/
static void xbee_logf(xbee_hnd xbee, const char *logformat, const char *file,
const int line, const char *function, char *format, ...);
#define LOG_FORMAT "[%s:%d] %s(): %s"
#define xbee_logSf() if (xbee->log) { xbee_mutex_lock(xbee->logmutex); }
#define xbee_logEf() if (xbee->log) { xbee_mutex_unlock(xbee->logmutex); }
#define xbee_log(...) if (xbee->log) { xbee_logSf(); xbee_logf(xbee,LOG_FORMAT"\n",__FILE__,__LINE__,__FUNCTION__,__VA_ARGS__); xbee_logEf(); }
#define xbee_logc(...) if (xbee->log) { xbee_logSf(); xbee_logf(xbee,LOG_FORMAT ,__FILE__,__LINE__,__FUNCTION__,__VA_ARGS__); }
#define xbee_logcf() if (xbee->log) { fprintf(xbee->log, "\n"); xbee_logEf(); }
#define xbee_logS(...) if (xbee->log) { xbee_logSf(); xbee_logf(xbee,LOG_FORMAT"\n",__FILE__,__LINE__,__FUNCTION__,__VA_ARGS__); }
#define xbee_logI(...) if (xbee->log) { xbee_logf(xbee,LOG_FORMAT"\n",__FILE__,__LINE__,__FUNCTION__,__VA_ARGS__); }
#define xbee_logIc(...) if (xbee->log) { xbee_logf(xbee,LOG_FORMAT ,__FILE__,__LINE__,__FUNCTION__,__VA_ARGS__); }
#define xbee_logIcf() if (xbee->log) { fprintf(xbee->log, "\n"); }
#define xbee_logE(...) if (xbee->log) { xbee_logf(xbee,LOG_FORMAT"\n",__FILE__,__LINE__,__FUNCTION__,__VA_ARGS__); xbee_logEf(); }
#define xbee_perror(str) \
if (xbee->log) xbee_logI("%s:%s",str,strerror(errno)); \
perror(str);
static int xbee_startAPI(xbee_hnd xbee);
static int xbee_sendAT(xbee_hnd xbee, char *command, char *retBuf, int retBuflen);
static int xbee_sendATdelay(xbee_hnd xbee, int guardTime, char *command, char *retBuf, int retBuflen);
static int xbee_parse_io(xbee_hnd xbee, xbee_pkt *p, unsigned char *d,
int maskOffset, int sampleOffset, int sample);
static void xbee_thread_watch(xbee_hnd xbee);
static void xbee_listen_wrapper(xbee_hnd xbee);
static int xbee_listen(xbee_hnd xbee);
static unsigned char xbee_getbyte(xbee_hnd xbee);
static unsigned char xbee_getrawbyte(xbee_hnd xbee);
static int xbee_matchpktcon(xbee_hnd xbee, xbee_pkt *pkt, xbee_con *con);
static t_data *xbee_make_pkt(xbee_hnd xbee, unsigned char *data, int len);
static int _xbee_send_pkt(xbee_hnd xbee, t_data *pkt, xbee_con *con);
static void xbee_callbackWrapper(t_CBinfo *info);
/* these functions can be found in the xsys files */
static int init_serial(xbee_hnd xbee, int baudrate);
static int xbee_select(xbee_hnd xbee, struct timeval *timeout);
#ifdef __GNUC__ /* ---- */
#include "xsys/linux.c"
#else /* -------------- */
#include "xsys\win32.c"
#endif /* ------------- */
#ifndef Win32Message
#define Win32Message()
#endif
#define ISREADY(a) if (!xbee || !xbee->xbee_ready) { \
if (stderr) fprintf(stderr,"libxbee: Run xbee_setup() first!...\n"); \
Win32Message(); \
a; \
}
#define ISREADYP() ISREADY(return)
#define ISREADYR(a) ISREADY(return a)
<HTML><HEAD><TITLE>Manpage of LIBXBEE</TITLE>
</HEAD><BODY>
<H1>LIBXBEE</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2009-11-01<BR><A HREF="#index">Index</A>
<A HREF="../index.html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
libxbee
<A NAME="lbAC">&nbsp;</A>
<H2>DESCRIPTION</H2>
libxbee is a C library to aid the use of Series 1 Digi XBee radios running in API mode (AP=2).
<P>
I have tried to keep flexibility to a maximum.
By allowing connections to individual nodes to be created you don't have to address each packet,
or filter through incomming packets to get at the one you are after. This is all taken care of
for you by
<B>libxbee!</B>
<P>
libxbee is still in development, so if you find any bugs or have any enhancement requests, please
feel free to submit an issue on the project page:
<PRE>
<A HREF="http://code.google.com/p/libxbee/">http://code.google.com/p/libxbee/</A>
</PRE>
or contact me (Attie) directly:
<PRE>
<A HREF="mailto:attie@attie.co.uk">attie@attie.co.uk</A>
</PRE>
<A NAME="lbAD">&nbsp;</A>
<H2>MAN PAGES</H2>
Documentation is avaliable via the following man pages, or by example in the 'sample' folder in the SVN repository
<P>
<B><A HREF="../man3/xbee_pkt.3.html">xbee_pkt</A></B>(3) - libxbee's packet structure
<B><A HREF="../man3/xbee_con.3.html">xbee_con</A></B>(3) - libxbee's connection structure
<P>
<B><A HREF="../man3/xbee_setup.3.html">xbee_setup</A></B>(3) - function to setup libxbee (and its variants)
<B><A HREF="../man3/xbee_end.3.html">xbee_end</A></B>(3) - function to end the libxbee session and close any open handles
<P>
<B><A HREF="../man3/xbee_logit.3.html">xbee_logit</A></B>(3) - function that allows the user to add to the xbee log output
<P>
<B><A HREF="../man3/xbee_newcon.3.html">xbee_newcon</A></B>(3) - function to create a new connection
<B><A HREF="../man3/xbee_flushcon.3.html">xbee_flushcon</A></B>(3) - function to flush packets from a connection
<B><A HREF="../man3/xbee_endcon.3.html">xbee_endcon</A></B>(3) - function to end a connection
<P>
<B><A HREF="../man3/xbee_senddata.3.html">xbee_senddata</A></B>(3) - function to send data to a remote XBee (and its variants)
<B><A HREF="../man3/xbee_getpacket.3.html">xbee_getpacket</A></B>(3) - function to get a packet from a connection (and its variants)
<P>
<B><A HREF="../man3/xbee_hasdigital.3.html">xbee_hasdigital</A></B>(3) - function to check if digital sample is in the packet
<B><A HREF="../man3/xbee_getdigital.3.html">xbee_getdigital</A></B>(3) - function to get digital sample from the packet
<P>
<B><A HREF="../man3/xbee_hasanalog.3.html">xbee_hasanalog</A></B>(3) - function to check if analog sample is in the packet
<B><A HREF="../man3/xbee_getanalog.3.html">xbee_getanalog</A></B>(3) - function to get the analog sample from the packet
<A NAME="lbAE">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="../man3/xbee_pkt.3.html">xbee_pkt</A></B>(3),
<B><A HREF="../man3/xbee_con.3.html">xbee_con</A></B>(3),
<B><A HREF="../man3/xbee_setup.3.html">xbee_setup</A></B>(3),
<B><A HREF="../man3/xbee_end.3.html">xbee_end</A></B>(3),
<B><A HREF="../man3/xbee_logit.3.html">xbee_logit</A></B>(3),
<B><A HREF="../man3/xbee_newcon.3.html">xbee_newcon</A></B>(3),
<B><A HREF="../man3/xbee_flushcon.3.html">xbee_flushcon</A></B>(3),
<B><A HREF="../man3/xbee_endcon.3.html">xbee_endcon</A></B>(3),
<B><A HREF="../man3/xbee_senddata.3.html">xbee_senddata</A></B>(3),
<B><A HREF="../man3/xbee_getpacket.3.html">xbee_getpacket</A></B>(3),
<B><A HREF="../man3/xbee_hasdigital.3.html">xbee_hasdigital</A></B>(3),
<B><A HREF="../man3/xbee_getdigital.3.html">xbee_getdigital</A></B>(3),
<B><A HREF="../man3/xbee_hasanalog.3.html">xbee_hasanalog</A></B>(3),
<B><A HREF="../man3/xbee_getanalog.3.html">xbee_getanalog</A></B>(3)
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
<DT><A HREF="#lbAC">DESCRIPTION</A><DD>
<DT><A HREF="#lbAD">MAN PAGES</A><DD>
<DT><A HREF="#lbAE">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:08:23 GMT, March 30, 2011
</BODY>
</HTML>
<HTML><HEAD><TITLE>Manpage of LIBXBEE</TITLE>
</HEAD><BODY>
<H1>LIBXBEE</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2009-11-01<BR><A HREF="#index">Index</A>
<A HREF="../index.html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
libxbee
<P>
This page has not been written yet...
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
</DL>
<HR>
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:08:23 GMT, March 30, 2011
</BODY>
</HTML>
<HTML><HEAD><TITLE>Manpage of LIBXBEE</TITLE>
</HEAD><BODY>
<H1>LIBXBEE</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2009-11-01<BR><A HREF="#index">Index</A>
<A HREF="../index.html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
libxbee
<P>
This page has not been written yet...
<P>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
</DL>
<HR>
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:08:23 GMT, March 30, 2011
</BODY>
</HTML>
<HTML><HEAD><TITLE>Invalid Manpage</TITLE></HEAD>
<BODY>
<H1>Invalid Manpage</H1>
The requested file ./man/man3/xbee_endcon.3 is not a valid (unformatted) man page.</BODY></HTML>
<HTML><HEAD><TITLE>Invalid Manpage</TITLE></HEAD>
<BODY>
<H1>Invalid Manpage</H1>
The requested file ./man/man3/xbee_flushcon.3 is not a valid (unformatted) man page.</BODY></HTML>
<HTML><HEAD><TITLE>Manpage of XBEE_GETPACKET</TITLE>
</HEAD><BODY>
<H1>XBEE_GETPACKET</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2009-11-01<BR><A HREF="#index">Index</A>
<A HREF="../index.html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
xbee_hasanalog, xbee_getanalog
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;</B>
<P>
<B>int xbee_hasanalog(xbee_pkt *</B><I>pkt</I><B>,int </B><I>sample</I><B>, int </B><I>input</I><B>);</B>
<P>
<B>double xbee_getanalog(xbee_pkt *</B><I>pkt</I><B>,int </B><I>sample</I><B>, int </B><I>input</I><B>, double </B><I>Vref</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>xbee_hasanalog</B>()
function will check the packet for the presence of an analog sample on the specified input.
<P>
The
<B>xbee_getanalog</B>()
function will read the packet and return the sample value for the specified analog input.
<P>
They both take 3 arguments, with the same purposes.
<P>
The argument
<I>pkt</I>
points to a packet that was previously retrieved with
<B>xbee_getpacket</B>()
<P>
The argument
<I>sample</I>
selects the sample within the packet to use.
<P>
The argument
<I>input</I>
specifies which input you are interested in testing.
<P>
<B>xbee_getanalog</B>()
also takes a fourth argument that allows you to provide a
<I>Vref</I>
value. This allows the function to convert the raw ADC value into a voltage for you.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
The
<B>xbee_hasanalog</B>()
function will return
<B>1</B>
if the provided packet has sample data for the specified input, otherwise
<B>0</B>.
<P>
The
<B>xbee_getanalog</B>()
function will return the raw ADC value (0 - 1023) if the provided packet has sample data for the specified input and Vref was given as zero.
If Vref was non-zero, then the return value will be the voltage read.
A
<B>-1</B>
will be returned if the packet does not contain sample data.
<P>
<A NAME="lbAF">&nbsp;</A>
<H2>EXAMPLE</H2>
To read sample data from previously made connection:
<PRE>
#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;
xbee_pkt *pkt;
double Vref = 3.3;
if ((pkt = xbee_getpacket(con)) != NULL) {
if (xbee_hasanalog(pkt,0,0)) {
printf(&quot;A0 read %fv,xbee_getanalog(pkt,0,0,Vref));
} else {
printf(&quot;No A0 data);
}
free(pkt);
}
</PRE>
<A NAME="lbAG">&nbsp;</A>
<H2>AUTHOR</H2>
Attie Grande &lt;<A HREF="mailto:attie@attie.co.uk">attie@attie.co.uk</A>&gt;
<A NAME="lbAH">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="../man3/libxbee.3.html">libxbee</A></B>(3),
<B><A HREF="../man3/xbee_pkt.3.html">xbee_pkt</A></B>(3),
<B><A HREF="../man3/xbee_getpacket.3.html">xbee_getpacket</A></B>(3),
<B><A HREF="../man3/xbee_hasdigital.3.html">xbee_hasdigital</A></B>(3),
<B><A HREF="../man3/xbee_getdigital.3.html">xbee_getdigital</A></B>(3)
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT><A HREF="#lbAF">EXAMPLE</A><DD>
<DT><A HREF="#lbAG">AUTHOR</A><DD>
<DT><A HREF="#lbAH">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:08:23 GMT, March 30, 2011
</BODY>
</HTML>
<HTML><HEAD><TITLE>Manpage of XBEE_GETPACKET</TITLE>
</HEAD><BODY>
<H1>XBEE_GETPACKET</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2009-11-01<BR><A HREF="#index">Index</A>
<A HREF="../index.html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
xbee_hasdigital, xbee_getdigital
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;</B>
<P>
<B>int xbee_hasdigital(xbee_pkt *</B><I>pkt</I><B>, int </B><I>sample</I><B>, int </B><I>input</I><B>);</B>
<P>
<B>int xbee_getdigital(xbee_pkt *</B><I>pkt</I><B>, int </B><I>sample</I><B>, int </B><I>input</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>xbee_hasdigital</B>()
function will check the packet for the presence of a given sample on the specified input.
<P>
The
<B>xbee_getdigital</B>()
function will read the packet and return the sample value for the specified input.
<P>
They both take 3 arguments, with the same purposes.
<P>
The argument
<I>pkt</I>
points to a packet that was previously retrieved with
<B>xbee_getpacket</B>()
<P>
The argument
<I>sample</I>
selects the sample within the packet to use.
<P>
The argument
<I>input</I>
specifies which input you are interested in testing.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
The
<B>xbee_hasdigital</B>()
function will return
<B>1</B>
if the provided packet has sample data for the specified input, otherwise
<B>0</B>.
<P>
The
<B>xbee_getdigital</B>()
function will return
<B>1</B>
if the provided packet has sample data for the specified input and the sample was HIGH.
A
<B>0</B>
will be returned if the sample was LOW, or the packet does not contain sample data.
<P>
<A NAME="lbAF">&nbsp;</A>
<H2>EXAMPLE</H2>
To read sample data from previously made connection:
<PRE>
#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;
xbee_pkt *pkt;
if ((pkt = xbee_getpacket(con)) != NULL) {
if (xbee_hasdigital(pkt,0,0)) {
printf(&quot;D0 read %d,xbee_getdigital(pkt,0));
} else {
printf(&quot;No D0 data);
}
free(pkt);
}
</PRE>
<A NAME="lbAG">&nbsp;</A>
<H2>AUTHOR</H2>
Attie Grande &lt;<A HREF="mailto:attie@attie.co.uk">attie@attie.co.uk</A>&gt;
<A NAME="lbAH">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="../man3/libxbee.3.html">libxbee</A></B>(3),
<B><A HREF="../man3/xbee_pkt.3.html">xbee_pkt</A></B>(3),
<B><A HREF="../man3/xbee_getpacket.3.html">xbee_getpacket</A></B>(3),
<B><A HREF="../man3/xbee_hasanalog.3.html">xbee_hasanalog</A></B>(3),
<B><A HREF="../man3/xbee_getanalog.3.html">xbee_getanalog</A></B>(3)
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT><A HREF="#lbAF">EXAMPLE</A><DD>
<DT><A HREF="#lbAG">AUTHOR</A><DD>
<DT><A HREF="#lbAH">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:08:23 GMT, March 30, 2011
</BODY>
</HTML>
<HTML><HEAD><TITLE>Manpage of XBEE_GETPACKET</TITLE>
</HEAD><BODY>
<H1>XBEE_GETPACKET</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2009-11-01<BR><A HREF="#index">Index</A>
<A HREF="../index.html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
xbee_getpacket
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;</B>
<P>
<B>xbee_pkt *xbee_getpacket(xbee_con *</B><I>con</I><B>);</B>
<P>
<B>xbee_pkt *xbee_getpacketwait(xbee_con *</B><I>con</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>xbee_getpacket</B>()
function will return the next avaliable packet for the provided connection.
It takes 1 argument.
<P>
The argument
<I>con</I>
points to a connection made previously with
<B>xbee_newcon</B>().
<P>
The
<B>xbee_getpacketwait</B>()
function behaves the same, but will wait for an internally specified time for a packet to arrive (currently around 1 second).
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
Upon successful return, this function returns the packet, having unlinked it from the internal list of packets.
You must keep hold of the packet until you are finished with it, and then you must
<B>free</B>()
it to prevent memory leaks.
<P>
If a packet was not avaliable for the provided connection, a
<B>NULL</B>
is returned.
<P>
If an error occured a
<B>NULL</B>
is also returned (though unlikely).
<P>
For more information on the structure of the packet, please see
<B><A HREF="../man3/xbee_pkt.3.html">xbee_pkt</A></B>(3)
<P>
For information on using callback functions with connections instead, please see
<B><A HREF="../man3/xbee_con.3.html">xbee_con</A></B>(3)
<A NAME="lbAF">&nbsp;</A>
<H2>EXAMPLE</H2>
To recieve a packet from a previously made connection:
<PRE>
#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;
xbee_pkt *pkt;
if ((pkt = xbee_getpacket(con)) != NULL) {
/* process packet... */
free(pkt);
}
</PRE>
<A NAME="lbAG">&nbsp;</A>
<H2>AUTHOR</H2>
Attie Grande &lt;<A HREF="mailto:attie@attie.co.uk">attie@attie.co.uk</A>&gt;
<A NAME="lbAH">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="../man3/libxbee.3.html">libxbee</A></B>(3),
<B><A HREF="../man3/xbee_setup.3.html">xbee_setup</A></B>(3),
<B><A HREF="../man3/xbee_newcon.3.html">xbee_newcon</A></B>(3),
<B><A HREF="../man3/xbee_senddata.3.html">xbee_senddata</A></B>(3),
<B><A HREF="../man3/xbee_pkt.3.html">xbee_pkt</A></B>(3),
<B><A HREF="../man3/xbee_con.3.html">xbee_con</A></B>(3),
<B><A HREF="../man3/xbee_hasDigital.3.html">xbee_hasDigital</A></B>(3),
<B><A HREF="../man3/xbee_getDigital.3.html">xbee_getDigital</A></B>(3),
<B><A HREF="../man3/xbee_hasAnalog.3.html">xbee_hasAnalog</A></B>(3),
<B><A HREF="../man3/xbee_getAnalog.3.html">xbee_getAnalog</A></B>(3)
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT><A HREF="#lbAF">EXAMPLE</A><DD>
<DT><A HREF="#lbAG">AUTHOR</A><DD>
<DT><A HREF="#lbAH">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:08:23 GMT, March 30, 2011
</BODY>
</HTML>
<HTML><HEAD><TITLE>Invalid Manpage</TITLE></HEAD>
<BODY>
<H1>Invalid Manpage</H1>
The requested file ./man/man3/xbee_hasanalog.3 is not a valid (unformatted) man page.</BODY></HTML>
<HTML><HEAD><TITLE>Invalid Manpage</TITLE></HEAD>
<BODY>
<H1>Invalid Manpage</H1>
The requested file ./man/man3/xbee_hasdigital.3 is not a valid (unformatted) man page.</BODY></HTML>
<HTML><HEAD><TITLE>Manpage of LIBXBEE</TITLE>
</HEAD><BODY>
<H1>LIBXBEE</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2009-11-01<BR><A HREF="#index">Index</A>
<A HREF="../index.html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
libxbee
<P>
This page has not been written yet...
<P>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
</DL>
<HR>
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:08:23 GMT, March 30, 2011
</BODY>
</HTML>
<HTML><HEAD><TITLE>Manpage of XBEE_NEWCON</TITLE>
</HEAD><BODY>
<H1>XBEE_NEWCON</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2009-11-01<BR><A HREF="#index">Index</A>
<A HREF="../index.html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
xbee_newcon
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;</B>
<P>
<B>xbee_con *xbee_newcon(unsigned char </B><I>frameID</I><B>, xbee_types </B><I>type</I><B>, ...);</B>
<P>
<B>void xbee_flushcon(xbee_con *</B><I>con</I><B>);</B>
<P>
<B>void xbee_endcon(xbee_con *</B><I>con</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>xbee_newcon</B>()
function will setup a new connection with the specified settings.
It takes at least 2 arguments, and possibly up to 4 depending on the
<I>type.</I>
<P>
<B>NOTE:</B>
Packets will only be collected when they match an active connection.
You must setup a connection in order to recieve packets.
<P>
The argument
<I>frameID</I>
allows similar functionality to that of TCP/IP port numbers. This is 1 character (or 8-bit integer) that
identifies where the data is coming from or going to.
The
<I>type</I>
specifies the type of connection you would like. The following types are avaliable:
<DL COMPACT>
<DT><B>xbee_localAT</B>
<DD>
communicates AT commands with the local XBee
<DT><B>xbee_txStatus</B>
<DD>
recieves transmit status information from the local XBee
<DT><B>xbee_modemStatus</B>
<DD>
recieves modem status information from the local XBee
<DT><B>xbee_16bitRemoteAT</B>
<DD>
communicates AT commands with a remote node (using 16-bit addressing)
<DT><B>xbee_64bitRemoteAT</B>
<DD>
communicates AT commands with a remote node (using 64-bit addressing)
<DT><B>xbee_16bitData</B>
<DD>
sends/recieves data through a remote node (using 16-bit addressing)
<DT><B>xbee_64bitData</B>
<DD>
sends/recieves data through a remote node (using 64-bit addressing)
<DT><B>xbee_16bitIO</B>
<DD>
sends/recieves I/O data through a remote node (using 16-bit addressing)
<DT><B>xbee_64bitIO</B>
<DD>
sends/recieves I/O data through a remote node (using 64-bit addressing)
</DL>
<P>
If you are using
<B>xbee_localAT</B>, <B>xbee_txStatus</B> or <B>xbee_modemStatus</B>
then only the
<I>frameID</I>
and
<I>type</I>
arguments are required.
<P>
If you are using any 16-bit connection, you must also specify 1 right aligned integer,
containing the 16-bit address (e.g. 0x1234).
<P>
If you are using any 64-bit connection, you must also specify 2 integers containing the
64-bit address, first the high 32-bits, then the low 32-bits.
<P>
The
<B>xbee_flushcon</B>()
function is very basic. It removes any packets that have been collected in the buffer for the specified connection.
<P>
The
<B>xbee_endcon</B>()
function is used to end a connection. This will stop collecting packets for the given connection, and remove any packets from the buffer.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
A pointer to the connection is returned. A connection can only be made once, using the same
<I>type</I>
,
<I>frameID</I>
and address (if needed). The second call using the same parameters will return the same
connection.
<P>
For information on using callback functions for packet handling please see
<B><A HREF="../man3/xbee_con.3.html">xbee_con</A></B>(3)
<A NAME="lbAF">&nbsp;</A>
<H2>EXAMPLE</H2>
To create a local AT connection:
<PRE>
#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;
xbee_con *con;
con = xbee_newcon('A', xbee_localAT);
</PRE>
<P>
To create a 16-bit Data connection:
<PRE>
#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;
xbee_con *con;
con = xbee_newcon('A', xbee_16bitData, 0x1234);
</PRE>
<P>
To create a 64-bit Data connection:
<PRE>
#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;
xbee_con *con;
con = xbee_newcon('A', xbee_64bitData, 0x0013A200, 0x40081826);
</PRE>
<A NAME="lbAG">&nbsp;</A>
<H2>AUTHOR</H2>
Attie Grande &lt;<A HREF="mailto:attie@attie.co.uk">attie@attie.co.uk</A>&gt;
<A NAME="lbAH">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="../man3/libxbee.3.html">libxbee</A></B>(3),
<B><A HREF="../man3/xbee_setup.3.html">xbee_setup</A></B>(3),
<B><A HREF="../man3/xbee_getpacket.3.html">xbee_getpacket</A></B>(3),
<B><A HREF="../man3/xbee_con.3.html">xbee_con</A></B>(3),
<B><A HREF="../man3/xbee_senddata.3.html">xbee_senddata</A></B>(3)
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT><A HREF="#lbAF">EXAMPLE</A><DD>
<DT><A HREF="#lbAG">AUTHOR</A><DD>
<DT><A HREF="#lbAH">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:08:23 GMT, March 30, 2011
</BODY>
</HTML>
<HTML><HEAD><TITLE>Invalid Manpage</TITLE></HEAD>
<BODY>
<H1>Invalid Manpage</H1>
The requested file ./man/man3/xbee_nsenddata.3 is not a valid (unformatted) man page.</BODY></HTML>
<HTML><HEAD><TITLE>Manpage of XBEE_PKT</TITLE>
</HEAD><BODY>
<H1>XBEE_PKT</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2009-11-01<BR><A HREF="#index">Index</A>
<A HREF="../index.html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
xbee_pkt
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
This is the packet structure. If you want to get more advanced information from connections (such as RSSI) then this is where it lives.
<P>
<PRE>
struct xbee_pkt {
unsigned char frameID; /* AT Status */
unsigned char atCmd[2]; /* AT */
unsigned char status; /* AT Data Status */ /* status / options */
unsigned char Addr64[8]; /* AT Data */
unsigned char Addr16[2]; /* AT Data */
unsigned char data[128]; /* AT Data */
unsigned char RSSI; /* Data */
unsigned int datalen;
/* X A5 A4 A3 A2 A1 A0 D8 D7 D6 D5 D4 D3 D2 D1 D0 */
unsigned short IOmask; /* IO */
/* X X X X X X X D8 D7 D6 D5 D4 D3 D2 D1 D0 */
unsigned short IOdata; /* IO */
/* X X X X X D D D D D D D D D D D */
unsigned short IOanalog[6]; /* IO */
};
typedef struct xbee_pkt xbee_pkt;
</PRE>
<P>
Most of these fields are fairly self explanatory, however some need attention brought to them
and others need explaining. I will touch on the most important here:
<DL COMPACT>
<DT><B>atCmd</B>
<DD>
This is the 2 character identifier for the AT command response you just recieved.
Of course if you didnt setup an AT connection, you should never see, or try to see data here.
<DT><B>Addr64</B> and <B>Addr16</B>
<DD>
These contain the address of the XBee that you recieved the packet from. You should really know this
because you setup the connection. However remote AT packets will contain both 16 and 64 bit
addresses.
<DT><B>data</B>
<DD>
This is the data you just recieved. Either the AT reponse, or the data from the remote XBee node.
<DT><B>datalen</B>
<DD>
Would you be suprised if I told you this is how much data there is?... Dont try and
<B>printf</B>()
the
<B>data</B>
as it isn't null terminated. Use this for processing instead.
</DL>
<A NAME="lbAE">&nbsp;</A>
<H2>AUTHOR</H2>
Attie Grande &lt;<A HREF="mailto:attie@attie.co.uk">attie@attie.co.uk</A>&gt;
<A NAME="lbAF">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="../man3/libxbee.3.html">libxbee</A></B>(3),
<B><A HREF="../man3/xbee_getpacket.3.html">xbee_getpacket</A></B>(3)
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT><A HREF="#lbAE">AUTHOR</A><DD>
<DT><A HREF="#lbAF">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:08:23 GMT, March 30, 2011
</BODY>
</HTML>
<HTML><HEAD><TITLE>Manpage of XBEE_SENDDATA</TITLE>
</HEAD><BODY>
<H1>XBEE_SENDDATA</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2009-11-01<BR><A HREF="#index">Index</A>
<A HREF="../index.html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
xbee_senddata, xbee_vsenddata
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;</B>
<P>
<B>int xbee_senddata(xbee_con *</B><I>con</I><B>, char *</B><I>format</I><B>, ...);</B>
<P>
<B>int xbee_nsenddata(xbee_con *</B><I>con</I><B>, char *</B><I>data</I><B>, int </B><I>length</I><B>);</B>
<P>
<B>#include &lt;<A HREF="file:/usr/include/stdarg.h">stdarg.h</A>&gt;</B>
<P>
<B>int xbee_vsenddata(xbee_con *</B><I>con</I><B>, char *</B><I>format</I><B>, va_list </B><I>ap</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>xbee_senddata</B>()
function will send data via a provided connection.
It takes at least 2 arguments, and possibly more depending on the format string.
<P>
The argument
<I>con</I>
points to a connection made previously with
<B>xbee_newcon</B>().
<P>
The
<I>format</I>
string and any following parameters are passed to
<B>sprintf</B>()
within these functions.
Please see the
<B><A HREF="../man3/printf.3.html">printf</A></B>(3)
man page for more information.
<P>
If you are using
<B>xbee_nsenddata</B>()
you must provide a character array of the data, and the data's length.
<P>
If you are using
<B>xbee_vsenddata</B>()
you must provide a va_list. See
<B><A HREF="../man3/stdarg.3.html">stdarg</A></B>(3).
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
Upon successful completion, these functions return 0.
<P>
If an invalid packet or connection was provided, -1 is returned.
<P>
If an unknown error occured, -2 is returned.
<P>
If
<I>con</I>
has
<I>waitforACK</I>
enabled, then these functions return 1 when an ACK was not recieved within 1 second.
<A NAME="lbAF">&nbsp;</A>
<H2>EXAMPLE</H2>
To send the string &quot;Hello World!&quot; through a previously made connection:
<PRE>
#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;
xbee_senddata(con,&quot;Hello World!&quot;);
</PRE>
<A NAME="lbAG">&nbsp;</A>
<H2>AUTHOR</H2>
Attie Grande &lt;<A HREF="mailto:attie@attie.co.uk">attie@attie.co.uk</A>&gt;
<A NAME="lbAH">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="../man3/libxbee.3.html">libxbee</A></B>(3),
<B><A HREF="../man3/xbee_setup.3.html">xbee_setup</A></B>(3),
<B><A HREF="../man3/xbee_newcon.3.html">xbee_newcon</A></B>(3),
<B><A HREF="../man3/xbee_getpacket.3.html">xbee_getpacket</A></B>(3)
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT><A HREF="#lbAF">EXAMPLE</A><DD>
<DT><A HREF="#lbAG">AUTHOR</A><DD>
<DT><A HREF="#lbAH">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:08:23 GMT, March 30, 2011
</BODY>
</HTML>
<HTML><HEAD><TITLE>Manpage of XBEE_SETUP</TITLE>
</HEAD><BODY>
<H1>XBEE_SETUP</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2009-11-01<BR><A HREF="#index">Index</A>
<A HREF="../index.html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
xbee_setup
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;</B>
<P>
<B>int xbee_setup(char *</B><I>path</I><B>, int </B><I>baudrate</I><B>);</B>
<P>
<B>int xbee_setuplog(char *</B><I>path</I><B>, int </B><I>baudrate</I><B>, int </B><I>logfd</I><B>);</B>
<P>
<B>int xbee_setupAPI(char *</B><I>path</I><B>, char </B><I>cmdSeq</I><B>, int </B><I>cmdTime</I><B>);</B>
<P>
<B>int xbee_setuplogAPI(char *</B><I>path</I><B>, int </B><I>baudrate</I><B>, int </B><I>logfd</I><B>, char </B><I>cmdSeq</I><B>, int </B><I>cmdTime</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
<P>
<B>A VERSION OF THIS FUNCTION MUST BE CALLED BEFORE ANY OTHER libxbee FUNCTION!</B>
The
<B>xbee_setup</B>()
function will setup libxbee so that it can handle an XBee.
It takes 2 arguments.
<P>
The argument
<I>path</I>
is the path to the serial port that the XBee is connected to (e.g. /dev/ttyUSB0).
<P>
The
<I>baudrate</I>
is the baud rate that the local XBee is configured to run at. The following are avaliable:
<PRE>
<B>1200</B>
<B>2400</B>
<B>4800</B>
<B>9600</B>
<B>19200</B>
<B>38400</B>
<B>57600</B>
<B>115200</B> - this is potentially unstable (read the XBee manual to find out why...)
</PRE>
<P>
Using
<B>xbee_setuplog</B>()
is exactly the same, but instead you give an open file descriptor. All log messages will be written to this file (you can use stderr or stdout if you want!).
<P>
Using
<B>xbee_setupAPI</B>()
is exactly the same, but instead you provide the 'Command Sequence' character and the 'Guard Time' that your local XBee has been configured with.
libxbee will then place your XBee in API mode 2, and when you call xbee_end() it will return your XBee to its previous API mode.
<P>
Using
<B>xbee_setuplogAPI</B>()
is simply a combination of
<B>xbee_setuplog</B>()
and
<B>xbee_setupAPI</B>()
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
If any error occures,
<B>-1</B>
is returned. Otherwise
<B>0</B>
is returned.
<A NAME="lbAF">&nbsp;</A>
<H2>EXAMPLE</H2>
To setup libxbee to use /dev/ttyUSB0 at 57600 baud:
<PRE>
#include &lt;<A HREF="file:/usr/include/xbee.h">xbee.h</A>&gt;
if (xbee_setup(&quot;/dev/ttyUSB0&quot;,57600) == -1) {
printf(&quot;Oh no...);
<A HREF="../man1/exit.1.html">exit</A>(1);
}
</PRE>
<A NAME="lbAG">&nbsp;</A>
<H2>AUTHOR</H2>
Attie Grande &lt;<A HREF="mailto:attie@attie.co.uk">attie@attie.co.uk</A>&gt;
<A NAME="lbAH">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="../man3/libxbee.3.html">libxbee</A></B>(3),
<B><A HREF="../man3/xbee_newcon.3.html">xbee_newcon</A></B>(3),
<B><A HREF="../man3/xbee_getpacket.3.html">xbee_getpacket</A></B>(3),
<B><A HREF="../man3/xbee_senddata.3.html">xbee_senddata</A></B>(3)
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT><A HREF="#lbAB">NAME</A><DD>
<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT><A HREF="#lbAF">EXAMPLE</A><DD>
<DT><A HREF="#lbAG">AUTHOR</A><DD>
<DT><A HREF="#lbAH">SEE ALSO</A><DD>
</DL>
<HR>
This document was created by
<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:08:23 GMT, March 30, 2011
</BODY>
</HTML>
<HTML><HEAD><TITLE>Invalid Manpage</TITLE></HEAD>
<BODY>
<H1>Invalid Manpage</H1>
The requested file ./man/man3/xbee_setupAPI.3 is not a valid (unformatted) man page.</BODY></HTML>
<HTML><HEAD><TITLE>Invalid Manpage</TITLE></HEAD>
<BODY>
<H1>Invalid Manpage</H1>
The requested file ./man/man3/xbee_setuplog.3 is not a valid (unformatted) man page.</BODY></HTML>
<HTML><HEAD><TITLE>Invalid Manpage</TITLE></HEAD>
<BODY>
<H1>Invalid Manpage</H1>
The requested file ./man/man3/xbee_setuplogAPI.3 is not a valid (unformatted) man page.</BODY></HTML>
<HTML><HEAD><TITLE>Invalid Manpage</TITLE></HEAD>
<BODY>
<H1>Invalid Manpage</H1>
The requested file ./man/man3/xbee_vsenddata.3 is not a valid (unformatted) man page.</BODY></HTML>
This diff is collapsed.
/*
libxbee - a C library to aid the use of Digi's Series 1 XBee modules
running in API mode (AP=2).
Copyright (C) 2009 Attie Grande (attie@attie.co.uk)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xbee.h"
int main(int argc, char *argv[]) {
xbee_con *con, *con2;
xbee_pkt *pkt, *p;
if (xbee_setuplog("/dev/ttyUSB0",57600,2) == -1) {
perror("xbee_setuplog()");
exit(1);
}
if (argc >= 2 && !strcmp(argv[1],"sleep")) {
for (;;) {
sleep(86400); /* sleep for a day... forever :) */
}
}
/*if ((con = xbee_newcon(NULL,'X',xbee_localAT)) == (void *)-1) {
printf("error creating connection...\n");
exit(1);
}
while(1){sleep(10);}
xbee_senddata(con,"CH%c",0x0C);
sleep(1);
xbee_senddata(con,"ID%c%c",0x33, 0x32);
sleep(1);
xbee_senddata(con,"DH%c%c%c%c",0x00,0x00,0x00,0x00);
sleep(1);
xbee_senddata(con,"DL%c%c%c%c",0x00,0x00,0x00,0x00);
sleep(1);
xbee_senddata(con,"MY%c%c",0x00,0x00);
sleep(1);
// SH - read only
// SL - read only
xbee_senddata(con,"RR%c",0x00);
sleep(1);
xbee_senddata(con,"RN%c",0x00);
sleep(1);
xbee_senddata(con,"MM%c",0x00);
sleep(1);
xbee_senddata(con,"NT%c",0x19);
sleep(1);
xbee_senddata(con,"NO%c",0x00);
sleep(1);
xbee_senddata(con,"CE%c",0x00);
sleep(1);
xbee_senddata(con,"SC%c%c",0x1F,0xFE);
sleep(1);
xbee_senddata(con,"SD%c",0x04);
sleep(1);
xbee_senddata(con,"A1%c",0x00);
sleep(1);
xbee_senddata(con,"A2%c",0x00);
sleep(1);
// AI - read only
xbee_senddata(con,"EE%c",0x00);
sleep(1);
//xbee_senddata(con,"KY%c",0x00);
//sleep(1);
xbee_senddata(con,"NI%s","TIGGER");
sleep(1);
xbee_senddata(con,"PL%c",0x04);
sleep(1);
xbee_senddata(con,"CA%c",0x2C);
sleep(1);
xbee_senddata(con,"SM%c",0x00);
sleep(1);
xbee_senddata(con,"ST%c%c",0x13,0x88);
sleep(1);
xbee_senddata(con,"SP%c%c",0x00,0x00);
sleep(1);
xbee_senddata(con,"DP%c%c",0x03,0xE8);
sleep(1);
xbee_senddata(con,"SO%c",0x00);
sleep(1);
xbee_senddata(con,"BD%c",0x06);
sleep(1);
xbee_senddata(con,"RO%c",0x03);
sleep(1);
xbee_senddata(con,"AP%c",0x02);
sleep(1);
xbee_senddata(con,"PR%c",0xFF);
sleep(1);
xbee_senddata(con,"D8%c",0x00);
sleep(1);
xbee_senddata(con,"D7%c",0x01);
sleep(1);
xbee_senddata(con,"D6%c",0x00);
sleep(1);
xbee_senddata(con,"D5%c",0x01);
sleep(1);
xbee_senddata(con,"D4%c",0x00);
sleep(1);
xbee_senddata(con,"D3%c",0x00);
sleep(1);
xbee_senddata(con,"D2%c",0x00);
sleep(1);
xbee_senddata(con,"D1%c",0x00);
sleep(1);
xbee_senddata(con,"D0%c",0x00);
sleep(1);
xbee_senddata(con,"IU%c",0x00);
sleep(1);
xbee_senddata(con,"IT%c",0x01);
sleep(1);
xbee_senddata(con,"IC%c",0x00);
sleep(1);
xbee_senddata(con,"IR%c%c",0x00,0x00);
sleep(1);
xbee_senddata(con,"IA%c%c%c%c%c%c%c%c",0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF);
sleep(1);
xbee_senddata(con,"T0%c",0xFF);
sleep(1);
xbee_senddata(con,"T1%c",0xFF);
sleep(1);
xbee_senddata(con,"T2%c",0xFF);
sleep(1);
xbee_senddata(con,"T3%c",0xFF);
sleep(1);
xbee_senddata(con,"T4%c",0xFF);
sleep(1);
xbee_senddata(con,"T5%c",0xFF);
sleep(1);
xbee_senddata(con,"T6%c",0xFF);
sleep(1);
xbee_senddata(con,"T7%c",0xFF);
sleep(1);
xbee_senddata(con,"P0%c",0x01);
sleep(1);
xbee_senddata(con,"P1%c",0x00);
sleep(1);
xbee_senddata(con,"PT%c",0xFF);
sleep(1);
xbee_senddata(con,"RP%c",0x28);
sleep(1);
// VR - read only
// HV - read only
// DB - read only
// EC - read only
// EA - read only
// DD - read only
xbee_senddata(con,"CT%c",0x64);
sleep(1);
xbee_senddata(con,"GT%c%c",0x03,0xE8);
sleep(1);
xbee_senddata(con,"CC%c",0x2B);
sleep(1);
sleep(10);
*/
/* test 64bit IO and Data */
con = xbee_newcon('I',xbee_64bitIO, 0x0013A200, 0x403af247);
con2 = xbee_newcon('I',xbee_64bitData, 0x0013A200, 0x403af247);
while (1) {
while ((pkt = xbee_getpacket(con)) != NULL) {
int i;
for (i = 0; i < pkt->samples; i++) {
int m;
for (m = 0; m <= 8; m++) {
if (xbee_hasdigital(pkt,i,m)) printf("D%d: %d ",m,xbee_getdigital(pkt,i,m));
}
#define Vref 3.23
for (m = 0; m <= 5; m++) {
if (xbee_hasanalog(pkt,i,m)) printf("A%d: %.2fv ",m,xbee_getanalog(pkt,i,m,Vref));
}
printf("\n");
}
if (xbee_senddata(con2, "the time is %d\r", time(NULL))) {
printf("Error: xbee_senddata\n");
return 1;
}
free(pkt);
if (p) {
switch (p->status) {
case 0x01: printf("XBee: txStatus: No ACK\n"); break;
case 0x02: printf("XBee: txStatus: CCA Failure\n"); break;
case 0x03: printf("XBee: txStatus: Purged\n"); break;
}
free(p);
}
}
while ((pkt = xbee_getpacket(con2)) != NULL) {
printf("he said '%s'\n", pkt->data);
if (xbee_senddata(con2, "you said '%s'\r", pkt->data)) {
printf("Error: xbee_senddata\n");
return 1;
}
free(pkt);
if (p) {
switch (p->status) {
case 0x01: printf("XBee: txStatus: No ACK\n"); break;
case 0x02: printf("XBee: txStatus: CCA Failure\n"); break;
case 0x03: printf("XBee: txStatus: Purged\n"); break;
}
free(p);
}
}
usleep(100);
}
return 0;
}
This diff is collapsed.
This diff is collapsed.
.\" libxbee - a C library to aid the use of Digi's Series 1 XBee modules
.\" running in API mode (AP=2).
.\"
.\" Copyright (C) 2009 Attie Grande (attie@attie.co.uk)
.\"
.\" This program is free software: you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation, either version 3 of the License, or
.\" (at your option) any later version.
.\"
.\" This program is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program. If not, see <http://www.gnu.org/licenses/>.
.TH LIBXBEE 3 2009-11-01 "GNU" "Linux Programmer's Manual"
.SH NAME
libxbee
.sp
This page has not been written yet...
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment