save fuse prog command line in a comment
[protos/xbee-avr.git] / xbee_proto.c
index bd284dd..409d9a9 100644 (file)
@@ -26,6 +26,7 @@
  */
 
 #include <aversive.h>
  */
 
 #include <aversive.h>
+#include <aversive/pgmspace.h>
 #include <aversive/queue.h>
 #include <aversive/endian.h>
 
 #include <aversive/queue.h>
 #include <aversive/endian.h>
 
@@ -138,7 +139,7 @@ static int xbee_proto_parse_frame(struct xbee_dev *dev)
        /* check frame len */
        if (len < (hdrlen + 1)) {
                dev->stats.rx_frame_too_small++;
        /* check frame len */
        if (len < (hdrlen + 1)) {
                dev->stats.rx_frame_too_small++;
-               fprintf(stderr, "Frame too small\n");
+               fprintf_P(stderr, PSTR("Frame too small\r\n"));
                return -1;
        }
 
                return -1;
        }
 
@@ -147,7 +148,7 @@ static int xbee_proto_parse_frame(struct xbee_dev *dev)
                cksum += ((uint8_t *)buf)[i];
        cksum = 0xff - cksum;
        if (cksum != ((uint8_t *)buf)[len-1]) {
                cksum += ((uint8_t *)buf)[i];
        cksum = 0xff - cksum;
        if (cksum != ((uint8_t *)buf)[len-1]) {
-               fprintf(stderr, "Invalid cksum\n");
+               fprintf_P(stderr, PSTR("Invalid cksum\r\n"));
                dev->stats.rx_invalid_cksum++;
                return -1;
        }
                dev->stats.rx_invalid_cksum++;
                return -1;
        }
@@ -229,7 +230,7 @@ int xbee_proto_xmit(struct xbee_dev *dev, uint8_t channel_id, uint8_t type,
        hdr.type = type;
        hdr.id = channel_id;
 
        hdr.type = type;
        hdr.id = channel_id;
 
-       if (channel_id < 0 || channel_id >= XBEE_MAX_CHANNEL ||
+       if (channel_id >= XBEE_MAX_CHANNEL ||
            dev->channel[channel_id].registered == 0) {
                dev->stats.tx_invalid_channel ++;
                return -1;
            dev->channel[channel_id].registered == 0) {
                dev->stats.tx_invalid_channel ++;
                return -1;
@@ -273,7 +274,8 @@ int xbee_proto_xmit(struct xbee_dev *dev, uint8_t channel_id, uint8_t type,
                case XBEE_TYPE_RMT_ATRESP:
                default:
                        dev->stats.tx_invalid_type ++;
                case XBEE_TYPE_RMT_ATRESP:
                default:
                        dev->stats.tx_invalid_type ++;
-                       fprintf(stderr, "unhandled xmit type=%x\n", hdr.type);
+                       fprintf_P(stderr, PSTR("unhandled xmit type=%x\r\n"),
+                                 hdr.type);
                        return -1;
        }
 
                        return -1;
        }
 
@@ -325,8 +327,9 @@ void xbee_proto_rx(struct xbee_dev *dev)
                /* not enough data */
                if (dev->frame_len < framelen)
                        continue;
                /* not enough data */
                if (dev->frame_len < framelen)
                        continue;
-               if (xbee_proto_parse_frame(dev) < 0)
+               if (xbee_proto_parse_frame(dev) < 0) {
                        ;//XXX stats
                        ;//XXX stats
+               }
                dev->frame_len = 0;
        }
 }
                dev->frame_len = 0;
        }
 }