XBee API mode library
Scan.cpp@16:cdfcb63b2c4b, 2013-03-20 (annotated)
- Committer:
- yamaguch
- Date:
- Wed Mar 20 00:28:27 2013 +0000
- Revision:
- 16:cdfcb63b2c4b
- Parent:
- 5:b82970ef7fb0
- Child:
- 17:2f728fd13bc0
non rtos version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yamaguch | 0:0232a97b3883 | 1 | /* |
yamaguch | 5:b82970ef7fb0 | 2 | Copyright (c) 2013, 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 | 16:cdfcb63b2c4b | 83 | from = 2; |
yamaguch | 0:0232a97b3883 | 84 | break; |
yamaguch | 0:0232a97b3883 | 85 | case ZigBeeReceivePacket: |
yamaguch | 0:0232a97b3883 | 86 | case ZigBeeIODataSampleRxIndicator: |
yamaguch | 5:b82970ef7fb0 | 87 | case NodeIdentificationIndicator: |
yamaguch | 0:0232a97b3883 | 88 | from = 9; |
yamaguch | 0:0232a97b3883 | 89 | break; |
yamaguch | 0:0232a97b3883 | 90 | case RemoteCommandResponse: |
yamaguch | 0:0232a97b3883 | 91 | from = 10; |
yamaguch | 0:0232a97b3883 | 92 | break; |
yamaguch | 0:0232a97b3883 | 93 | } |
yamaguch | 0:0232a97b3883 | 94 | len = 2; |
yamaguch | 0:0232a97b3883 | 95 | break; |
yamaguch | 0:0232a97b3883 | 96 | case Address64: |
yamaguch | 0:0232a97b3883 | 97 | switch (frameType) { |
yamaguch | 0:0232a97b3883 | 98 | case ZigBeeReceivePacket: |
yamaguch | 0:0232a97b3883 | 99 | case ZigBeeIODataSampleRxIndicator: |
yamaguch | 5:b82970ef7fb0 | 100 | case NodeIdentificationIndicator: |
yamaguch | 0:0232a97b3883 | 101 | from = 1; |
yamaguch | 0:0232a97b3883 | 102 | break; |
yamaguch | 0:0232a97b3883 | 103 | case RemoteCommandResponse: |
yamaguch | 0:0232a97b3883 | 104 | from = 2; |
yamaguch | 0:0232a97b3883 | 105 | break; |
yamaguch | 0:0232a97b3883 | 106 | } |
yamaguch | 0:0232a97b3883 | 107 | len = 8; |
yamaguch | 0:0232a97b3883 | 108 | break; |
yamaguch | 5:b82970ef7fb0 | 109 | case RemoteAddress16: |
yamaguch | 5:b82970ef7fb0 | 110 | from = 12; |
yamaguch | 5:b82970ef7fb0 | 111 | len = 2; |
yamaguch | 5:b82970ef7fb0 | 112 | break; |
yamaguch | 5:b82970ef7fb0 | 113 | case RemoteAddress64: |
yamaguch | 5:b82970ef7fb0 | 114 | from = 14; |
yamaguch | 5:b82970ef7fb0 | 115 | len = 8; |
yamaguch | 5:b82970ef7fb0 | 116 | break; |
yamaguch | 5:b82970ef7fb0 | 117 | case ParentAddress16: |
yamaguch | 5:b82970ef7fb0 | 118 | from = SIZE(buf, index) - 8; |
yamaguch | 5:b82970ef7fb0 | 119 | len = 2; |
yamaguch | 5:b82970ef7fb0 | 120 | break; |
yamaguch | 0:0232a97b3883 | 121 | case RetryCount: |
yamaguch | 0:0232a97b3883 | 122 | from = 4; |
yamaguch | 0:0232a97b3883 | 123 | break; |
yamaguch | 0:0232a97b3883 | 124 | case DeliveryStatus: |
yamaguch | 0:0232a97b3883 | 125 | from = 5; |
yamaguch | 0:0232a97b3883 | 126 | break; |
yamaguch | 0:0232a97b3883 | 127 | case DiscoveryStatus: |
yamaguch | 0:0232a97b3883 | 128 | from = 6; |
yamaguch | 0:0232a97b3883 | 129 | break; |
yamaguch | 0:0232a97b3883 | 130 | case ReceiveOptions: |
yamaguch | 0:0232a97b3883 | 131 | from = 11; |
yamaguch | 0:0232a97b3883 | 132 | break; |
yamaguch | 0:0232a97b3883 | 133 | case ReceivedData: |
yamaguch | 0:0232a97b3883 | 134 | from = 12; |
yamaguch | 0:0232a97b3883 | 135 | len = SIZE(buf, index) - 12; |
yamaguch | 0:0232a97b3883 | 136 | break; |
yamaguch | 5:b82970ef7fb0 | 137 | case NIString: |
yamaguch | 5:b82970ef7fb0 | 138 | from = 22; |
yamaguch | 5:b82970ef7fb0 | 139 | len = SIZE(buf, index) - (22 + 8); |
yamaguch | 5:b82970ef7fb0 | 140 | break; |
yamaguch | 5:b82970ef7fb0 | 141 | case DeviceType: |
yamaguch | 5:b82970ef7fb0 | 142 | from = SIZE(buf, index) - 6; |
yamaguch | 5:b82970ef7fb0 | 143 | break; |
yamaguch | 5:b82970ef7fb0 | 144 | case SourceEvent: |
yamaguch | 5:b82970ef7fb0 | 145 | from = SIZE(buf, index) - 5; |
yamaguch | 5:b82970ef7fb0 | 146 | break; |
yamaguch | 0:0232a97b3883 | 147 | case RawData: |
yamaguch | 0:0232a97b3883 | 148 | from = 1; |
yamaguch | 0:0232a97b3883 | 149 | len = SIZE(buf, index) - 1; |
yamaguch | 0:0232a97b3883 | 150 | break; |
yamaguch | 0:0232a97b3883 | 151 | } |
yamaguch | 0:0232a97b3883 | 152 | |
yamaguch | 0:0232a97b3883 | 153 | if (from > 0) { |
yamaguch | 0:0232a97b3883 | 154 | copy(value, INDEX(index + 2 + from), min(len, maxlength)); |
yamaguch | 0:0232a97b3883 | 155 | if (length) *length = len; |
yamaguch | 0:0232a97b3883 | 156 | return true; |
yamaguch | 0:0232a97b3883 | 157 | } else |
yamaguch | 0:0232a97b3883 | 158 | return false; |
yamaguch | 0:0232a97b3883 | 159 | } |