00001 /* 00002 * Copyright (C) 2009 Libelium Comunicaciones Distribuidas S.L. 00003 * http://www.libelium.com 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as published by 00007 * the Free Software Foundation, either version 2.1 of the License, or 00008 * (at your option) any later version. 00009 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU Lesser General Public License for more details. 00014 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 * 00018 * Version: 0.2 00019 * Design: David Gascón 00020 * Implementation: Alberto Bielsa 00021 */ 00022 00023 00024 #ifndef __WPROGRAM_H__ 00025 // #include <WProgram.h> 00026 #include <WaspClasses.h> 00027 #endif 00028 00029 void WaspXBee868::init(uint8_t protocol_used, uint8_t frequency, uint8_t model_used) 00030 { 00031 protocol=protocol_used; 00032 freq=frequency; 00033 model=model_used; 00034 00035 totalFragmentsReceived=0; 00036 pendingPackets=0; 00037 pos=0; 00038 discoveryOptions=0x00; 00039 00040 scanTime[0]=0x00; 00041 scanTime[1]=0x82; 00042 encryptMode=0; 00043 powerLevel=4; 00044 timeRSSI=0x20; 00045 00046 ACKerrors[0]=0x00; 00047 ACKerrors[1]=0x00; 00048 errorsRF[0]=0x00; 00049 errorsRF[1]=0x00; 00050 goodPackets[0]=0x00; 00051 goodPackets[1]=0x00; 00052 transmisionErrors[0]=0x00; 00053 transmisionErrors[1]=0x00; 00054 maxPayloadBytes[0]=0x01; 00055 maxPayloadBytes[1]=0x00; 00056 multipleBroadcast=0x03; 00057 macRetries=0x0A; 00058 resetReason=0x00; 00059 00060 data_length=0; 00061 it=0; 00062 start=0; 00063 finish=0; 00064 add_type=0; 00065 mode=0; 00066 frag_length=0; 00067 TIME1=0; 00068 nextIndex1=0; 00069 frameNext=0; 00070 replacementPolicy=XBEE_OUT; 00071 indexNotModified=1; 00072 error_AT=2; 00073 error_RX=2; 00074 error_TX=2; 00075 clearFinishArray(); 00076 clearCommand(); 00077 } 00078 00079 /* 00080 Function: Read the number of times the RF receiver detected a CRC or length error 00081 Returns: Integer that determines if there has been any error 00082 error=2 --> The command has not been executed 00083 error=1 --> There has been an error while executing the command 00084 error=0 --> The command has been executed with no errors 00085 Values: Stores in global "errorsRF" variable number of times CRC or length error 00086 */ 00087 uint8_t WaspXBee868::getRFerrors() 00088 { 00089 int8_t error=2; 00090 00091 error_AT=2; 00092 gen_data(get_RF_errors_868); 00093 error=gen_send(get_RF_errors_868); 00094 00095 if(!error) 00096 { 00097 errorsRF[0]=data[0]; 00098 delay(20); 00099 errorsRF[1]=data[1]; 00100 delay(20); 00101 } 00102 return error; 00103 } 00104 00105 /* 00106 Function: Read the number of good frames with valid MAC headers that are received on the RF interface 00107 Returns: Integer that determines if there has been any error 00108 error=2 --> The command has not been executed 00109 error=1 --> There has been an error while executing the command 00110 error=0 --> The command has been executed with no errors 00111 Values: Stores in global "goodPackets" variable the number of good frames received 00112 */ 00113 uint8_t WaspXBee868::getGoodPackets() 00114 { 00115 int8_t error=2; 00116 00117 error_AT=2; 00118 gen_data(get_good_pack_868); 00119 error=gen_send(get_good_pack_868); 00120 00121 if(!error) 00122 { 00123 goodPackets[0]=data[0]; 00124 delay(20); 00125 goodPackets[1]=data[1]; 00126 delay(20); 00127 } 00128 return error; 00129 } 00130 00131 /* 00132 Function: Reads the DBM level of the designated channel 00133 Returns: Integer that determines if there has been any error 00134 error=2 --> The command has not been executed 00135 error=1 --> There has been an error while executing the command 00136 error=0 --> The command has been executed with no errors 00137 Values: Stores in global "channelRSSI" variable the DBM level of the designated channel 00138 Parameters: 00139 channel --> The channel to get the DBM value 00140 */ 00141 uint8_t WaspXBee868::getChannelRSSI(uint8_t channel) 00142 { 00143 int8_t error=2; 00144 00145 error_AT=2; 00146 gen_data(get_channel_RSSI_868,channel); 00147 gen_checksum(get_channel_RSSI_868); 00148 error=gen_send(get_channel_RSSI_868); 00149 00150 if(error==0) 00151 { 00152 channelRSSI=data[1]; 00153 delay(20); 00154 } 00155 return error; 00156 } 00157 00158 /* 00159 Function: Read the number of MAC frames that exhaust MAC retries without ever receiving a MAC acknowledgement message from the adjacent node 00160 Returns: Integer that determines if there has been any error 00161 error=2 --> The command has not been executed 00162 error=1 --> There has been an error while executing the command 00163 error=0 --> The command has been executed with no errors 00164 Values: Stores in global "transmisionErrors" variable the number of MAC frames that exhaust 00165 MAC retries 00166 */ 00167 uint8_t WaspXBee868::getTransmisionErrors() 00168 { 00169 int8_t error=2; 00170 00171 error_AT=2; 00172 gen_data(get_trans_errors_868); 00173 error=gen_send(get_trans_errors_868); 00174 00175 if(!error) 00176 { 00177 transmisionErrors[0]=data[0]; 00178 delay(20); 00179 transmisionErrors[1]=data[1]; 00180 delay(20); 00181 } 00182 return error; 00183 } 00184 00185 /* 00186 Function: Read module temperature in Celsius. Negatives temperatures can be returned 00187 Returns: Integer that determines if there has been any error 00188 error=2 --> The command has not been executed 00189 error=1 --> There has been an error while executing the command 00190 error=0 --> The command has been executed with no errors 00191 Values: Executes the TP command. Stores in global "temperature" variable the read temp in Celsius 00192 */ 00193 uint8_t WaspXBee868::getTemperature() 00194 { 00195 int8_t error=2; 00196 00197 error_AT=2; 00198 gen_data(get_temperature_868); 00199 error=gen_send(get_temperature_868); 00200 00201 if(error==0) 00202 { 00203 temperature[0]=data[0]; 00204 delay(20); 00205 temperature[1]=data[1]; 00206 delay(20); 00207 } 00208 return error; 00209 } 00210 00211 /* 00212 Function: Reads the voltage on the Vcc pin 00213 Returns: Integer that determines if there has been any error 00214 error=2 --> The command has not been executed 00215 error=1 --> There has been an error while executing the command 00216 error=0 --> The command has been executed with no errors 00217 Values: Executes the %V command. Stores in global "supplyVoltage" variable the VCC 00218 */ 00219 uint8_t WaspXBee868::getSupplyVoltage() 00220 { 00221 int8_t error=2; 00222 00223 error_AT=2; 00224 gen_data(get_supply_Volt_868); 00225 error=gen_send(get_supply_Volt_868); 00226 00227 if(error==0) 00228 { 00229 supplyVoltage[0]=data[0]; 00230 delay(20); 00231 supplyVoltage[1]=data[1]; 00232 delay(20); 00233 } 00234 return error; 00235 } 00236 00237 /* 00238 Function: Get the current device type 00239 Returns: Integer that determines if there has been any error 00240 error=2 --> The command has not been executed 00241 error=1 --> There has been an error while executing the command 00242 error=0 --> The command has been executed with no errors 00243 Values: Executes the DD command. Stores in global "deviceType" variable the current device type 00244 */ 00245 uint8_t WaspXBee868::getDeviceType() 00246 { 00247 int8_t error=2; 00248 00249 error_AT=2; 00250 gen_data(get_device_type_868); 00251 error=gen_send(get_device_type_868); 00252 00253 if(error==0) 00254 { 00255 for(it=0;it<4;it++) 00256 { 00257 deviceType[it]=data[it]; 00258 delay(20); 00259 } 00260 } 00261 return error; 00262 } 00263 00264 /* 00265 Function: Get the bytes that can be used in the payload 00266 Returns: Integer that determines if there has been any error 00267 error=2 --> The command has not been executed 00268 error=1 --> There has been an error while executing the command 00269 error=0 --> The command has been executed with no errors 00270 Values: Executes the NP command. Stores in global "maxPayloadBytes" variable the max Payload 00271 */ 00272 uint8_t WaspXBee868::getPayloadBytes() 00273 { 00274 int8_t error=2; 00275 00276 error_AT=2; 00277 gen_data(get_payload_bytes_868); 00278 error=gen_send(get_payload_bytes_868); 00279 00280 if(error==0) 00281 { 00282 maxPayloadBytes[0]=data[0]; 00283 maxPayloadBytes[1]=data[1]; 00284 } 00285 return error; 00286 } 00287 00288 /* 00289 Function: Specifies the number of additional broadcast retransmissions 00290 Returns: Integer that determines if there has been any error 00291 error=2 --> The command has not been executed 00292 error=1 --> There has been an error while executing the command 00293 error=0 --> The command has been executed with no errors 00294 Values: Change the MT command 00295 Parameters: 00296 mtrans: number of additional broadcast retransmissions (0x00-0x0F) 00297 */ 00298 uint8_t WaspXBee868::setMultipleBroadcast(uint8_t mtrans) 00299 { 00300 int8_t error=2; 00301 00302 error_AT=2; 00303 gen_data(set_mult_broadcast_868,mtrans); 00304 gen_checksum(set_mult_broadcast_868); 00305 error=gen_send(set_mult_broadcast_868); 00306 00307 if(error==0) 00308 { 00309 multipleBroadcast=mtrans; 00310 } 00311 return error; 00312 } 00313 00314 /* 00315 Function: Gets the number of additional broadcast retransmissions 00316 Returns: Integer that determines if there has been any error 00317 error=2 --> The command has not been executed 00318 error=1 --> There has been an error while executing the command 00319 error=0 --> The command has been executed with no errors 00320 Values: Executes the MT command 00321 */ 00322 uint8_t WaspXBee868::getMultipleBroadcast() 00323 { 00324 int8_t error=2; 00325 00326 error_AT=2; 00327 gen_data(get_mult_broadcast_868); 00328 error=gen_send(get_mult_broadcast_868); 00329 00330 if(error==0) 00331 { 00332 multipleBroadcast=data[0]; 00333 } 00334 return error; 00335 } 00336 00337 /* 00338 Function: Specifies the number of retries than can be sent for a given unicast RF packet 00339 Returns: Integer that determines if there has been any error 00340 error=2 --> The command has not been executed 00341 error=1 --> There has been an error while executing the command 00342 error=0 --> The command has been executed with no errors 00343 Values: Change the RR command 00344 Parameters: 00345 macretries: number of retries than can be sent for a given unicast RF packet (0x00-0x0F) 00346 */ 00347 uint8_t WaspXBee868::setMacRetries(uint8_t macretries) 00348 { 00349 int8_t error=2; 00350 00351 error_AT=2; 00352 gen_data(set_retries_868,macretries); 00353 gen_checksum(set_retries_868); 00354 error=gen_send(set_retries_868); 00355 00356 if(error==0) 00357 { 00358 macRetries=macretries; 00359 } 00360 return error; 00361 } 00362 00363 /* 00364 Function: Gets the number of retries than can be sent for a given unicast RF packet 00365 Returns: Integer that determines if there has been any error 00366 error=2 --> The command has not been executed 00367 error=1 --> There has been an error while executing the command 00368 error=0 --> The command has been executed with no errors 00369 Values: Executes the RR command 00370 */ 00371 uint8_t WaspXBee868::getMacRetries() 00372 { 00373 int8_t error=2; 00374 00375 error_AT=2; 00376 gen_data(get_retries_868); 00377 error=gen_send(get_retries_868); 00378 00379 if(error==0) 00380 { 00381 macRetries=data[0]; 00382 } 00383 return error; 00384 } 00385 00386 /* 00387 Function: Get the % it has been used of available Duty Cicle 00388 Returns: Integer that determines if there has been any error 00389 error=2 --> The command has not been executed 00390 error=1 --> There has been an error while executing the command 00391 error=0 --> The command has been executed with no errors 00392 Values: Executes the DC command 00393 */ 00394 uint8_t WaspXBee868::getDutyCicle() 00395 { 00396 int8_t error=2; 00397 00398 error_AT=2; 00399 gen_data(get_duty_cicle_868); 00400 error=gen_send(get_duty_cicle_868); 00401 00402 if(error==0) 00403 { 00404 dutyCicle=data[0]; 00405 } 00406 return error; 00407 } 00408 00409 /* 00410 Function: Tells the reason for the last module reset 00411 Returns: Integer that determines if there has been any error 00412 error=2 --> The command has not been executed 00413 error=1 --> There has been an error while executing the command 00414 error=0 --> The command has been executed with no errors 00415 Values: Executes the R# command 00416 */ 00417 uint8_t WaspXBee868::getResetReason() 00418 { 00419 int8_t error=2; 00420 00421 error_AT=2; 00422 gen_data(get_reset_reason_868); 00423 error=gen_send(get_reset_reason_868); 00424 00425 if(error==0) 00426 { 00427 resetReason=data[0]; 00428 } 00429 return error; 00430 } 00431 00432 /* 00433 Function: Specifies the number of failed ACK retries 00434 Returns: Integer that determines if there has been any error 00435 error=2 --> The command has not been executed 00436 error=1 --> There has been an error while executing the command 00437 error=0 --> The command has been executed with no errors 00438 Values: Executes the TA command 00439 */ 00440 uint8_t WaspXBee868::getACKerrors() 00441 { 00442 int8_t error=2; 00443 00444 error_AT=2; 00445 gen_data(get_ACK_errors_868); 00446 error=gen_send(get_ACK_errors_868); 00447 00448 if(error==0) 00449 { 00450 ACKerrors[0]=data[0]; 00451 ACKerrors[1]=data[1]; 00452 } 00453 return error; 00454 } 00455 00456 WaspXBee868 xbee868 = WaspXBee868();
1.5.6