X-Git-Url: http://git.droids-corp.org/?p=protos%2Fxbee.git;a=blobdiff_plain;f=main.c;fp=main.c;h=4847d11087363d4c5d24a7a57fca3cb30683877b;hp=94c0f345a742d519f58baa5751bd7dc68d1595fe;hb=9fdf7fa123e328a13ade691f4b724a187ee39a85;hpb=4ab039aeff9e145ff6f55d9fdcf74e911357e268 diff --git a/main.c b/main.c index 94c0f34..4847d11 100644 --- a/main.c +++ b/main.c @@ -243,6 +243,10 @@ static int dump_atcmd(struct xbee_ctx *ctx, struct xbee_atresp_hdr *frame, /* 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); @@ -330,7 +334,7 @@ void xbee_rx(struct xbee_dev *dev, int channel, int type, 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, @@ -415,8 +419,10 @@ static int xbeeapp_send(struct xbee_ctx *ctx, int type, void *buf, unsigned len, /* 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; @@ -441,6 +447,8 @@ int xbeeapp_send_atcmd(const char *atcmd_str, void *param, unsigned param_len, 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);