XBee API mode library

Committer:
yamaguch
Date:
Thu Jul 26 10:33:11 2012 +0000
Revision:
0:0232a97b3883
Child:
5:b82970ef7fb0
[mbed] converted /XBeeExamples/XBee

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yamaguch 0:0232a97b3883 1 /*
yamaguch 0:0232a97b3883 2 Copyright (c) 2011, Senio Networks, Inc.
yamaguch 0:0232a97b3883 3
yamaguch 0:0232a97b3883 4 Permission is hereby granted, free of charge, to any person obtaining a copy
yamaguch 0:0232a97b3883 5 of this software and associated documentation files (the "Software"), to deal
yamaguch 0:0232a97b3883 6 in the Software without restriction, including without limitation the rights
yamaguch 0:0232a97b3883 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
yamaguch 0:0232a97b3883 8 copies of the Software, and to permit persons to whom the Software is
yamaguch 0:0232a97b3883 9 furnished to do so, subject to the following conditions:
yamaguch 0:0232a97b3883 10
yamaguch 0:0232a97b3883 11 The above copyright notice and this permission notice shall be included in
yamaguch 0:0232a97b3883 12 all copies or substantial portions of the Software.
yamaguch 0:0232a97b3883 13
yamaguch 0:0232a97b3883 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
yamaguch 0:0232a97b3883 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
yamaguch 0:0232a97b3883 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
yamaguch 0:0232a97b3883 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
yamaguch 0:0232a97b3883 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
yamaguch 0:0232a97b3883 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
yamaguch 0:0232a97b3883 20 THE SOFTWARE.
yamaguch 0:0232a97b3883 21 */
yamaguch 0:0232a97b3883 22
yamaguch 0:0232a97b3883 23 #include "XBee.h"
yamaguch 0:0232a97b3883 24
yamaguch 0:0232a97b3883 25 bool XBee::scan(ValueType type, char *value, int maxlength, int *length) {
yamaguch 0:0232a97b3883 26 if (received != out || (in == out && free != 0))
yamaguch 0:0232a97b3883 27 return false;
yamaguch 0:0232a97b3883 28
yamaguch 0:0232a97b3883 29 return scan(out, type, value, maxlength, length);
yamaguch 0:0232a97b3883 30 }
yamaguch 0:0232a97b3883 31
yamaguch 0:0232a97b3883 32 bool XBee::scan(int index, ValueType type, char *value, int maxlength, int *length) {
yamaguch 0:0232a97b3883 33 int from = 0;
yamaguch 0:0232a97b3883 34 int len = 1;
yamaguch 0:0232a97b3883 35 FrameType frameType = getFrameType(buf[INDEX(index + 2)]);
yamaguch 0:0232a97b3883 36
yamaguch 0:0232a97b3883 37 if (frameType == (FrameType) None)
yamaguch 0:0232a97b3883 38 return false;
yamaguch 0:0232a97b3883 39
yamaguch 0:0232a97b3883 40 switch (type) {
yamaguch 0:0232a97b3883 41 case FrameID:
yamaguch 0:0232a97b3883 42 from = 1;
yamaguch 0:0232a97b3883 43 break;
yamaguch 0:0232a97b3883 44 case ATCommand:
yamaguch 0:0232a97b3883 45 switch (frameType) {
yamaguch 0:0232a97b3883 46 case ATCommandResponse:
yamaguch 0:0232a97b3883 47 from = 2;
yamaguch 0:0232a97b3883 48 break;
yamaguch 0:0232a97b3883 49 case RemoteCommandResponse:
yamaguch 0:0232a97b3883 50 from = 12;
yamaguch 0:0232a97b3883 51 break;
yamaguch 0:0232a97b3883 52 }
yamaguch 0:0232a97b3883 53 len = 2;
yamaguch 0:0232a97b3883 54 break;
yamaguch 0:0232a97b3883 55 case Status:
yamaguch 0:0232a97b3883 56 switch (frameType) {
yamaguch 0:0232a97b3883 57 case ATCommandResponse:
yamaguch 0:0232a97b3883 58 from = 4;
yamaguch 0:0232a97b3883 59 break;
yamaguch 0:0232a97b3883 60 case ModemStatus:
yamaguch 0:0232a97b3883 61 from = 1;
yamaguch 0:0232a97b3883 62 break;
yamaguch 0:0232a97b3883 63 case RemoteCommandResponse:
yamaguch 0:0232a97b3883 64 from = 14;
yamaguch 0:0232a97b3883 65 break;
yamaguch 0:0232a97b3883 66 }
yamaguch 0:0232a97b3883 67 break;
yamaguch 0:0232a97b3883 68 case CommandData:
yamaguch 0:0232a97b3883 69 switch (frameType) {
yamaguch 0:0232a97b3883 70 case ATCommandResponse:
yamaguch 0:0232a97b3883 71 from = 5;
yamaguch 0:0232a97b3883 72 len = SIZE(buf, index) - 5;
yamaguch 0:0232a97b3883 73 break;
yamaguch 0:0232a97b3883 74 case RemoteCommandResponse:
yamaguch 0:0232a97b3883 75 from = 15;
yamaguch 0:0232a97b3883 76 len = SIZE(buf, index) - 15;
yamaguch 0:0232a97b3883 77 break;
yamaguch 0:0232a97b3883 78 }
yamaguch 0:0232a97b3883 79 break;
yamaguch 0:0232a97b3883 80 case Address16:
yamaguch 0:0232a97b3883 81 switch (frameType) {
yamaguch 0:0232a97b3883 82 case ZigBeeTransmitStatus:
yamaguch 0:0232a97b3883 83 from = 4;
yamaguch 0:0232a97b3883 84 break;
yamaguch 0:0232a97b3883 85 case ZigBeeReceivePacket:
yamaguch 0:0232a97b3883 86 case ZigBeeIODataSampleRxIndicator:
yamaguch 0:0232a97b3883 87 from = 9;
yamaguch 0:0232a97b3883 88 break;
yamaguch 0:0232a97b3883 89 case RemoteCommandResponse:
yamaguch 0:0232a97b3883 90 from = 10;
yamaguch 0:0232a97b3883 91 break;
yamaguch 0:0232a97b3883 92 }
yamaguch 0:0232a97b3883 93 len = 2;
yamaguch 0:0232a97b3883 94 break;
yamaguch 0:0232a97b3883 95 case Address64:
yamaguch 0:0232a97b3883 96 switch (frameType) {
yamaguch 0:0232a97b3883 97 case ZigBeeReceivePacket:
yamaguch 0:0232a97b3883 98 case ZigBeeIODataSampleRxIndicator:
yamaguch 0:0232a97b3883 99 from = 1;
yamaguch 0:0232a97b3883 100 break;
yamaguch 0:0232a97b3883 101 case RemoteCommandResponse:
yamaguch 0:0232a97b3883 102 from = 2;
yamaguch 0:0232a97b3883 103 break;
yamaguch 0:0232a97b3883 104 }
yamaguch 0:0232a97b3883 105 len = 8;
yamaguch 0:0232a97b3883 106 break;
yamaguch 0:0232a97b3883 107 case RetryCount:
yamaguch 0:0232a97b3883 108 from = 4;
yamaguch 0:0232a97b3883 109 break;
yamaguch 0:0232a97b3883 110 case DeliveryStatus:
yamaguch 0:0232a97b3883 111 from = 5;
yamaguch 0:0232a97b3883 112 break;
yamaguch 0:0232a97b3883 113 case DiscoveryStatus:
yamaguch 0:0232a97b3883 114 from = 6;
yamaguch 0:0232a97b3883 115 break;
yamaguch 0:0232a97b3883 116 case ReceiveOptions:
yamaguch 0:0232a97b3883 117 from = 11;
yamaguch 0:0232a97b3883 118 break;
yamaguch 0:0232a97b3883 119 case ReceivedData:
yamaguch 0:0232a97b3883 120 from = 12;
yamaguch 0:0232a97b3883 121 len = SIZE(buf, index) - 12;
yamaguch 0:0232a97b3883 122 break;
yamaguch 0:0232a97b3883 123 case RawData:
yamaguch 0:0232a97b3883 124 from = 1;
yamaguch 0:0232a97b3883 125 len = SIZE(buf, index) - 1;
yamaguch 0:0232a97b3883 126 break;
yamaguch 0:0232a97b3883 127 }
yamaguch 0:0232a97b3883 128
yamaguch 0:0232a97b3883 129 if (from > 0) {
yamaguch 0:0232a97b3883 130 copy(value, INDEX(index + 2 + from), min(len, maxlength));
yamaguch 0:0232a97b3883 131 if (length) *length = len;
yamaguch 0:0232a97b3883 132 return true;
yamaguch 0:0232a97b3883 133 } else
yamaguch 0:0232a97b3883 134 return false;
yamaguch 0:0232a97b3883 135 }