XBee API mode library
Dump.cpp@7:19f03567ec4e, 2013-01-25 (annotated)
- Committer:
- yamaguch
- Date:
- Fri Jan 25 02:26:14 2013 +0000
- Revision:
- 7:19f03567ec4e
- Parent:
- 5:b82970ef7fb0
- Child:
- 8:776b8dc51932
fixed XBeeNodeIdentifier conflicts
Who changed what in which revision?
User | Revision | Line number | New 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 | #include <ctype.h> |
yamaguch | 0:0232a97b3883 | 25 | |
yamaguch | 0:0232a97b3883 | 26 | void XBee::dump() { |
yamaguch | 0:0232a97b3883 | 27 | if (received != out || (in == out && free != 0)) |
yamaguch | 0:0232a97b3883 | 28 | return; |
yamaguch | 0:0232a97b3883 | 29 | |
yamaguch | 0:0232a97b3883 | 30 | switch (getFrameType(buf[INDEX(out + 2)])) { |
yamaguch | 0:0232a97b3883 | 31 | case ATCommandResponse: { |
yamaguch | 0:0232a97b3883 | 32 | char id, name[2], status, data[16]; |
yamaguch | 0:0232a97b3883 | 33 | int length = 0; |
yamaguch | 0:0232a97b3883 | 34 | scan(FrameID, &id); |
yamaguch | 0:0232a97b3883 | 35 | scan(ATCommand, name, sizeof(name)); |
yamaguch | 0:0232a97b3883 | 36 | scan(Status, &status); |
yamaguch | 0:0232a97b3883 | 37 | scan(CommandData, data, sizeof(data), &length); |
yamaguch | 0:0232a97b3883 | 38 | mon.printf("ATCommandResponse, Id=%d, Nm=%c%c, St=%02X, ", id & 255, name[0], name[1], status); |
yamaguch | 0:0232a97b3883 | 39 | if (name[0] == 'I' && name[1] == 'S' && status == 0) |
yamaguch | 0:0232a97b3883 | 40 | dumpIOSample(data, length); |
yamaguch | 0:0232a97b3883 | 41 | else |
yamaguch | 0:0232a97b3883 | 42 | dump(data, length); |
yamaguch | 0:0232a97b3883 | 43 | } |
yamaguch | 0:0232a97b3883 | 44 | break; |
yamaguch | 0:0232a97b3883 | 45 | |
yamaguch | 0:0232a97b3883 | 46 | case ModemStatus: { |
yamaguch | 0:0232a97b3883 | 47 | char status; |
yamaguch | 0:0232a97b3883 | 48 | scan(Status, &status); |
yamaguch | 0:0232a97b3883 | 49 | mon.printf("ModemStatus, St=%02X\n", status); |
yamaguch | 0:0232a97b3883 | 50 | } |
yamaguch | 0:0232a97b3883 | 51 | break; |
yamaguch | 0:0232a97b3883 | 52 | |
yamaguch | 0:0232a97b3883 | 53 | case ZigBeeTransmitStatus: { |
yamaguch | 0:0232a97b3883 | 54 | char id, address16[2], retry, delivery, discovery; |
yamaguch | 0:0232a97b3883 | 55 | scan(FrameID, &id); |
yamaguch | 0:0232a97b3883 | 56 | scan(Address16, address16, sizeof(address16)); |
yamaguch | 0:0232a97b3883 | 57 | scan(RetryCount, &retry); |
yamaguch | 0:0232a97b3883 | 58 | scan(DeliveryStatus, &delivery); |
yamaguch | 0:0232a97b3883 | 59 | scan(DiscoveryStatus, &discovery); |
yamaguch | 0:0232a97b3883 | 60 | mon.printf("ZigBeeTransmitStatus, Id=%d, ad=%02X%02X, Rty=%d, Dlv=%02X, Dsc=%02X\n", |
yamaguch | 0:0232a97b3883 | 61 | id & 255, address16[0], address16[1], retry & 255, delivery, discovery); |
yamaguch | 0:0232a97b3883 | 62 | } |
yamaguch | 0:0232a97b3883 | 63 | break; |
yamaguch | 0:0232a97b3883 | 64 | |
yamaguch | 0:0232a97b3883 | 65 | case ZigBeeReceivePacket: { |
yamaguch | 0:0232a97b3883 | 66 | char address64[8], address16[2], options, data[32]; |
yamaguch | 0:0232a97b3883 | 67 | int length = 0; |
yamaguch | 0:0232a97b3883 | 68 | scan(Address64, address64, sizeof(address64)); |
yamaguch | 0:0232a97b3883 | 69 | scan(Address16, address16, sizeof(address16)); |
yamaguch | 0:0232a97b3883 | 70 | scan(ReceiveOptions, &options); |
yamaguch | 0:0232a97b3883 | 71 | scan(ReceivedData, data, sizeof(data), &length); |
yamaguch | 0:0232a97b3883 | 72 | mon.printf("ZigBeeReceivePacket, AD=%02X%02X%02X%02X %02X%02X%02X%02X, ad=%02X%02X, Op=%02X, Length=%d, ", |
yamaguch | 0:0232a97b3883 | 73 | address64[0], address64[1], address64[2], address64[3], address64[4], address64[5], |
yamaguch | 0:0232a97b3883 | 74 | address64[6], address64[7], address16[0], address16[1], options, length); |
yamaguch | 0:0232a97b3883 | 75 | dump(data, min(sizeof(data), length)); |
yamaguch | 0:0232a97b3883 | 76 | } |
yamaguch | 0:0232a97b3883 | 77 | break; |
yamaguch | 0:0232a97b3883 | 78 | |
yamaguch | 0:0232a97b3883 | 79 | case ZigBeeIODataSampleRxIndicator: { |
yamaguch | 0:0232a97b3883 | 80 | char address64[8], address16[2], options, data[16]; |
yamaguch | 0:0232a97b3883 | 81 | int length = 0; |
yamaguch | 0:0232a97b3883 | 82 | scan(Address64, address64, sizeof(address64)); |
yamaguch | 0:0232a97b3883 | 83 | scan(Address16, address16, sizeof(address16)); |
yamaguch | 0:0232a97b3883 | 84 | scan(ReceiveOptions, &options); |
yamaguch | 0:0232a97b3883 | 85 | scan(ReceivedData, data, sizeof(data), &length); |
yamaguch | 0:0232a97b3883 | 86 | mon.printf("ZigBeeIODataSampleRxIndicator, AD=%02X%02X%02X%02X %02X%02X%02X%02X, ad=%02X%02X, Op=%02X, ", |
yamaguch | 0:0232a97b3883 | 87 | address64[0], address64[1], address64[2], address64[3], address64[4], address64[5], |
yamaguch | 0:0232a97b3883 | 88 | address64[6], address64[7], address16[0], address16[1], options); |
yamaguch | 0:0232a97b3883 | 89 | dumpIOSample(data, length); |
yamaguch | 0:0232a97b3883 | 90 | } |
yamaguch | 0:0232a97b3883 | 91 | break; |
yamaguch | 0:0232a97b3883 | 92 | |
yamaguch | 5:b82970ef7fb0 | 93 | case NodeIdentificationIndicator: { |
yamaguch | 5:b82970ef7fb0 | 94 | char address64[8], address16[2], options, remote64[8], remote16[2], parent16[2], ni[20], device, event; |
yamaguch | 5:b82970ef7fb0 | 95 | scan(Address64, address64, sizeof(address64)); |
yamaguch | 5:b82970ef7fb0 | 96 | scan(Address16, address16, sizeof(address16)); |
yamaguch | 5:b82970ef7fb0 | 97 | scan(ReceiveOptions, &options); |
yamaguch | 5:b82970ef7fb0 | 98 | scan(RemoteAddress64, remote64, sizeof(remote64)); |
yamaguch | 5:b82970ef7fb0 | 99 | scan(RemoteAddress16, remote16, sizeof(remote16)); |
yamaguch | 5:b82970ef7fb0 | 100 | scan(ParentAddress16, parent16, sizeof(parent16)); |
yamaguch | 5:b82970ef7fb0 | 101 | scan(NIString, ni, sizeof(ni)); |
yamaguch | 5:b82970ef7fb0 | 102 | scan(DeviceType, &device); |
yamaguch | 5:b82970ef7fb0 | 103 | scan(SourceEvent, &event); |
yamaguch | 5:b82970ef7fb0 | 104 | mon.printf("NodeIdentificationIndicator, AD=%02X%02X%02X%02X %02X%02X%02X%02X, ad=%02X%02X, Op=%02X,\n" |
yamaguch | 7:19f03567ec4e | 105 | " RM=%02X%02X%02X%02X %02X%02X%02X%02X, rm=%02X%02X, Pa=%02X%02X, Dev=%02X, Ev=%02X, NI=%s\n", |
yamaguch | 5:b82970ef7fb0 | 106 | address64[0], address64[1], address64[2], address64[3], address64[4], address64[5], |
yamaguch | 5:b82970ef7fb0 | 107 | address64[6], address64[7], address16[0], address16[1], options, |
yamaguch | 5:b82970ef7fb0 | 108 | remote64[0], remote64[1], remote64[2], remote64[3], remote64[4], remote64[5], |
yamaguch | 5:b82970ef7fb0 | 109 | remote64[6], remote64[7], remote16[0], remote16[1], parent16[0], parent16[1], device, event, ni); |
yamaguch | 5:b82970ef7fb0 | 110 | } |
yamaguch | 5:b82970ef7fb0 | 111 | break; |
yamaguch | 5:b82970ef7fb0 | 112 | |
yamaguch | 0:0232a97b3883 | 113 | case RemoteCommandResponse: { |
yamaguch | 0:0232a97b3883 | 114 | char address64[8], address16[2], id, name[2], status, data[16]; |
yamaguch | 0:0232a97b3883 | 115 | int length = 0; |
yamaguch | 0:0232a97b3883 | 116 | scan(Address64, address64, sizeof(address64)); |
yamaguch | 0:0232a97b3883 | 117 | scan(Address16, address16, sizeof(address16)); |
yamaguch | 0:0232a97b3883 | 118 | scan(FrameID, &id); |
yamaguch | 0:0232a97b3883 | 119 | scan(ATCommand, name, sizeof(name)); |
yamaguch | 0:0232a97b3883 | 120 | scan(Status, &status); |
yamaguch | 0:0232a97b3883 | 121 | scan(CommandData, data, sizeof(data), &length); |
yamaguch | 0:0232a97b3883 | 122 | mon.printf("RemoteCommandResponse, AD=%02X%02X%02X%02X %02X%02X%02X%02X, ad=%02X%02X, Id=%d, Nm=%c%c, St=%02X, ", |
yamaguch | 0:0232a97b3883 | 123 | address64[0], address64[1], address64[2], address64[3], address64[4], address64[5], |
yamaguch | 0:0232a97b3883 | 124 | address64[6], address64[7], address16[0], address16[1], id & 255, name[0], name[1], status); |
yamaguch | 0:0232a97b3883 | 125 | if (name[0] == 'I' && name[1] == 'S' && status == 0) |
yamaguch | 0:0232a97b3883 | 126 | dumpIOSample(data, length); |
yamaguch | 0:0232a97b3883 | 127 | else |
yamaguch | 0:0232a97b3883 | 128 | dump(data, length); |
yamaguch | 0:0232a97b3883 | 129 | } |
yamaguch | 0:0232a97b3883 | 130 | break; |
yamaguch | 0:0232a97b3883 | 131 | |
yamaguch | 0:0232a97b3883 | 132 | default: { |
yamaguch | 0:0232a97b3883 | 133 | char data[32]; |
yamaguch | 0:0232a97b3883 | 134 | int length = 0; |
yamaguch | 0:0232a97b3883 | 135 | scan(RawData, data, sizeof(data), &length); |
yamaguch | 0:0232a97b3883 | 136 | mon.printf("Frametype:%02X, Length=%d, Data=", buf[INDEX(out + 2)] & 255, length); |
yamaguch | 0:0232a97b3883 | 137 | dump(data, min(sizeof(data), length)); |
yamaguch | 0:0232a97b3883 | 138 | } |
yamaguch | 0:0232a97b3883 | 139 | } |
yamaguch | 0:0232a97b3883 | 140 | } |
yamaguch | 0:0232a97b3883 | 141 | |
yamaguch | 0:0232a97b3883 | 142 | void XBee::dumpAll() { |
yamaguch | 0:0232a97b3883 | 143 | mon.printf("cur = %04X\n", cur); |
yamaguch | 0:0232a97b3883 | 144 | mon.printf("in = %04X\n", in); |
yamaguch | 0:0232a97b3883 | 145 | mon.printf("out = %04X\n", out); |
yamaguch | 0:0232a97b3883 | 146 | mon.printf("received = %04X\n", received); |
yamaguch | 0:0232a97b3883 | 147 | mon.printf("free = %d\n", free); |
yamaguch | 0:0232a97b3883 | 148 | for (int i = 0; i < BUFSIZE; i += 16) { |
yamaguch | 0:0232a97b3883 | 149 | mon.printf("%04X: ", i); |
yamaguch | 0:0232a97b3883 | 150 | dump(buf + i, 16); |
yamaguch | 0:0232a97b3883 | 151 | } |
yamaguch | 0:0232a97b3883 | 152 | } |
yamaguch | 0:0232a97b3883 | 153 | |
yamaguch | 0:0232a97b3883 | 154 | void XBee::dump(const char* data, int length) { |
yamaguch | 0:0232a97b3883 | 155 | for (int i = 0; i < length; i++) mon.printf("%02X", data[i]); |
yamaguch | 0:0232a97b3883 | 156 | mon.printf(" | "); |
yamaguch | 0:0232a97b3883 | 157 | for (int i = 0; i < length; i++) mon.printf("%c", isprint(data[i]) ? data[i] : '.'); |
yamaguch | 0:0232a97b3883 | 158 | mon.printf("\n"); |
yamaguch | 0:0232a97b3883 | 159 | } |
yamaguch | 0:0232a97b3883 | 160 | |
yamaguch | 0:0232a97b3883 | 161 | void XBee::dumpIOSample(const char* data, int length) { |
yamaguch | 0:0232a97b3883 | 162 | if (length > 0) { |
yamaguch | 0:0232a97b3883 | 163 | IOSample sample(data); |
yamaguch | 0:0232a97b3883 | 164 | mon.printf(sample); |
yamaguch | 1:482216f3f6ee | 165 | mon.printf("\n"); |
yamaguch | 0:0232a97b3883 | 166 | } |
yamaguch | 0:0232a97b3883 | 167 | } |