]> git.droids-corp.org - protos/xbee-avr.git/commitdiff
propagate error to lower layer (xbee library)
authorOlivier Matz <zer0@droids-corp.org>
Tue, 12 Nov 2013 22:36:32 +0000 (23:36 +0100)
committerOlivier Matz <zer0@droids-corp.org>
Sun, 9 Mar 2014 21:13:02 +0000 (22:13 +0100)
main.c
main.h

diff --git a/main.c b/main.c
index 7dc45bb4cfd41f7c55c5df669ee575498d732935..20d368b120764d8127447994ff16ba43b407c833 100644 (file)
--- a/main.c
+++ b/main.c
@@ -274,11 +274,11 @@ int xbee_recv_data(struct xbee_recv_hdr *recvframe, unsigned len)
 }
 
 /* socat /dev/ttyUSB0,raw,echo=0,b115200 /dev/ttyACM1,raw,echo=0,b115200 */
-void xbeeapp_rx(struct xbee_dev *dev, int channel, int type,
+int8_t xbeeapp_rx(struct xbee_dev *dev, int channel, int type,
             void *frame, unsigned len, void *opaque)
 {
        struct xbee_ctx *ctx = opaque;
-       int do_hexdump = xbee_hexdump;
+       int8_t ret = 0;
 
        if (xbee_debug)
                printf_P(PSTR("type=0x%x, channel=%d, ctx=%p\r\n"),
@@ -320,24 +320,28 @@ void xbeeapp_rx(struct xbee_dev *dev, int channel, int type,
 
                        /* this answer contains an atcmd answer at offset 10 */
                        if (dump_atcmd(ctx, frame + 10, len - 10) < 0)
-                               do_hexdump = 1;
+                               ret = -1;
+
                        break;
                }
                case XBEE_TYPE_ATRESP: {
                        if (dump_atcmd(ctx, frame, len) < 0)
-                               do_hexdump = 1;
+                               ret = -1;
+
                        break;
                }
 
                case XBEE_TYPE_XMIT_STATUS: {
                        if (parse_xmit_status(ctx, frame, len) < 0)
-                               do_hexdump = 1;
+                               ret = -1;
+
                        break;
                }
 
                case XBEE_TYPE_RECV: {
                        if (xbee_recv_data(frame, len) < 0)
-                               do_hexdump = 1;
+                               ret = -1;
+
                        break;
                }
 
@@ -350,11 +354,13 @@ void xbeeapp_rx(struct xbee_dev *dev, int channel, int type,
                case XBEE_TYPE_NODE_ID:
                default:
                        printf_P(PSTR("Invalid frame\r\n"));
-                       do_hexdump = 1;
+                       ret = -1;
                        break;
        }
 
-       if (do_hexdump)
+       if (ret < 0)
+               hexdump("undecoded rx frame", frame, len);
+       else if (xbee_hexdump)
                hexdump("undecoded rx frame", frame, len);
 
        /* restart command line if it was a blocking query */
diff --git a/main.h b/main.h
index d28a3662502b13cf51fd567cf46dcd9dfbebfc73..1ad2c0b901b70738ecb133c3606a325403a72eb4 100644 (file)
--- a/main.h
+++ b/main.h
@@ -105,8 +105,8 @@ extern struct callout_manager cm;
 
 void bootloader(void);
 
-void xbeeapp_rx(struct xbee_dev *dev, int channel, int type,
-            void *frame, unsigned len, void *opaque);
+int8_t xbeeapp_rx(struct xbee_dev *dev, int channel, int type,
+                 void *frame, unsigned len, void *opaque);
 int xbeeapp_send_atcmd(const char *atcmd_str,
                       void *param, unsigned param_len, int foreground,
                       int (*func)(void *frame, unsigned len, void *arg),