#include <time.h>
#include <netinet/in.h>
#include <sys/queue.h>
+#include <linux/joystick.h>
#include <getopt.h>
#include "xbee_buf.h"
#include "xbee_proto.h"
#include "xbee.h"
+#include "joystick.h"
#include "main.h"
#define TIMEOUT_US 1000000
/* events */
static struct event stdin_read_event, xbee_read_event;
+static struct event joystick_read_event;
static struct cmdline *xbee_cl;
int xbee_hexdump = 0;
int xbee_debug = 0;
FILE *xbee_logfile;
+static char *joystick_devname = NULL;
+struct joystick_info joyinfo;
void xbeeapp_log(int always_on_stdout, const char *fmt, ...)
{
/* dump frame */
if (atcmd_frame_status(frame, len) == 0) {
+ /* callback */
+ if (ctx->func != NULL)
+ ctx->func(frame, len, ctx->arg);
+
if (len == sizeof(struct xbee_atresp_hdr))
xbeeapp_log(ctx->foreground, "<%s>: ok\n",
ctx->atcmd_query->name);
if (recvlen >= strlen("range") &&
!strncmp((char *)recvframe->data,
"range", strlen("range"))) {
- xbeeapp_send_atcmd("DB", NULL, 0, 0);
+ xbeeapp_send_atcmd("DB", NULL, 0, 0, NULL, NULL);
on_stdout = 0;
}
hexdump(on_stdout, "rx data", recvframe->data,
/* send an AT command with parameters filled by caller. Disable
* command line until we get the answer or until a timeout occurs */
-int xbeeapp_send_atcmd(const char *atcmd_str, void *param, unsigned param_len,
- int foreground)
+int xbeeapp_send_atcmd(const char *atcmd_str,
+ void *param, unsigned param_len, int foreground,
+ int (*func)(void *frame, unsigned len, void *arg),
+ void *arg)
{
struct xbee_ctx *ctx;
struct xbee_atcmd *cmd;
memset(ctx, 0, sizeof(*ctx));
ctx->type = ATCMD;
ctx->atcmd_query = cmd;
+ ctx->func = func;
+ ctx->arg = arg;
memcpy(&frame.atcmd.cmd, atcmd_str, 2);
memcpy(&frame.buf, param, param_len);
argvopt = argv;
- while ((opt = getopt_long(argc, argvopt, "hd:s:",
+ while ((opt = getopt_long(argc, argvopt, "hd:s:j:",
lgopts, &option_index)) != EOF) {
switch (opt) {
xbee_raw = 1;
break;
+ case 'j':
+ joystick_devname = optarg;
+ break;
+
/* long options */
case 0:
/* if (!strcmp(lgopts[option_index].name, "option")) */
if (err < 0)
return -1;
+ /* init joystick */
+ if (joystick_devname != NULL) {
+ if (joystick_init(joystick_devname, &joyinfo) < 0) {
+ fprintf(stderr, "error in joystick init\n");
+ return -1;
+ }
+ event_set(&joystick_read_event, joyinfo.fd, EV_READ | EV_PERSIST,
+ joystick_input, &joyinfo);
+ event_add(&joystick_read_event, NULL);
+ }
+
/* open xbee device */
xbee_dev = xbee_open(xbee_devname, xbee_baud);
if (xbee_dev == NULL)