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 WaspXBeeDM::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 data_length=0; 00036 it=0; 00037 start=0; 00038 finish=0; 00039 add_type=0; 00040 mode=0; 00041 frag_length=0; 00042 TIME1=0; 00043 00044 totalFragmentsReceived=0; 00045 pendingPackets=0; 00046 pos=0; 00047 discoveryOptions=0x00; 00048 00049 scanTime[0]=SCAN_TIME_DIGIMESH_H; 00050 scanTime[1]=SCAN_TIME_DIGIMESH_L; 00051 encryptMode=ENCRYPT_MODE_DIGIMESH; 00052 timeRSSI=TIME_RSSI_DIGIMESH; 00053 00054 if( protocol!=XBEE_900 ) 00055 { 00056 awakeTime[0]=AWAKE_TIME_DIGIMESH_H; 00057 awakeTime[1]=AWAKE_TIME_DIGIMESH_M; 00058 awakeTime[2]=AWAKE_TIME_DIGIMESH_L; 00059 sleepTime[0]=SLEEP_TIME_DIGIMESH_H; 00060 sleepTime[1]=SLEEP_TIME_DIGIMESH_M; 00061 sleepTime[2]=SLEEP_TIME_DIGIMESH_L; 00062 00063 sleepOptions=SLEEP_OPTIONS_DIGIMESH; 00064 powerLevel=POWER_LEVEL_DIGIMESH; 00065 00066 networkHops=7; 00067 netDelaySlots=3; 00068 netRouteRequest=3; 00069 meshNetRetries=1; 00070 } 00071 nextIndex1=0; 00072 frameNext=0; 00073 replacementPolicy=XBEE_OUT; 00074 indexNotModified=1; 00075 error_AT=2; 00076 error_RX=2; 00077 error_TX=2; 00078 clearFinishArray(); 00079 clearCommand(); 00080 } 00081 00082 /* 00083 Function: Read the number of times the RF receiver detected a CRC or length error 00084 Returns: Integer that determines if there has been any error 00085 error=2 --> The command has not been executed 00086 error=1 --> There has been an error while executing the command 00087 error=0 --> The command has been executed with no errors 00088 Values: Stores in global "errorsRF" variable number of times CRC or length error 00089 */ 00090 uint8_t WaspXBeeDM::getRFerrors() 00091 { 00092 int8_t error=2; 00093 00094 error_AT=2; 00095 gen_data(get_RF_errors_DM); 00096 error=gen_send(get_RF_errors_DM); 00097 00098 if(!error) 00099 { 00100 errorsRF[0]=data[0]; 00101 delay(20); 00102 errorsRF[1]=data[1]; 00103 delay(20); 00104 } 00105 return error; 00106 } 00107 00108 /* 00109 Function: Read the number of good frames with valid MAC headers that are received on the RF interface 00110 Returns: Integer that determines if there has been any error 00111 error=2 --> The command has not been executed 00112 error=1 --> There has been an error while executing the command 00113 error=0 --> The command has been executed with no errors 00114 Values: Stores in global "goodPackets" variable the number of good frames received 00115 */ 00116 uint8_t WaspXBeeDM::getGoodPackets() 00117 { 00118 int8_t error=2; 00119 00120 error_AT=2; 00121 gen_data(get_good_pack_DM); 00122 error=gen_send(get_good_pack_DM); 00123 00124 if(!error) 00125 { 00126 goodPackets[0]=data[0]; 00127 delay(20); 00128 goodPackets[1]=data[1]; 00129 delay(20); 00130 } 00131 return error; 00132 } 00133 00134 /* 00135 Function: Reads the DBM level of the designated channel 00136 Returns: Integer that determines if there has been any error 00137 error=2 --> The command has not been executed 00138 error=1 --> There has been an error while executing the command 00139 error=0 --> The command has been executed with no errors 00140 Values: Stores in global "channelRSSI" variable the DBM level of the designated channel 00141 Parameters: 00142 channel --> The channel to get the DBM value 00143 */ 00144 uint8_t WaspXBeeDM::getChannelRSSI(uint8_t channel) 00145 { 00146 int8_t error=2; 00147 00148 error_AT=2; 00149 gen_data(get_channel_RSSI_DM,channel); 00150 gen_checksum(get_channel_RSSI_DM); 00151 error=gen_send(get_channel_RSSI_DM); 00152 00153 if(!error) 00154 { 00155 channelRSSI=data[1]; 00156 delay(20); 00157 } 00158 return error; 00159 } 00160 00161 /* 00162 Function: Read the number of MAC frames that exhaust MAC retries without ever receiving a MAC acknowledgement message from the adjacent node 00163 Returns: Integer that determines if there has been any error 00164 error=2 --> The command has not been executed 00165 error=1 --> There has been an error while executing the command 00166 error=0 --> The command has been executed with no errors 00167 Values: Stores in global "transmisionErrors" variable the number of MAC frames that exhaust 00168 MAC retries 00169 */ 00170 uint8_t WaspXBeeDM::getTransmisionErrors() 00171 { 00172 int8_t error=2; 00173 00174 error_AT=2; 00175 gen_data(get_trans_errors_DM); 00176 error=gen_send(get_trans_errors_DM); 00177 00178 if(!error) 00179 { 00180 transmisionErrors[0]=data[0]; 00181 delay(20); 00182 transmisionErrors[1]=data[1]; 00183 delay(20); 00184 } 00185 return error; 00186 } 00187 00188 /* 00189 Function: Set the maximum number of hops expected to be seen in a network route 00190 Returns: Integer that determines if there has been any error 00191 error=2 --> The command has not been executed 00192 error=1 --> There has been an error while executing the command 00193 error=0 --> The command has been executed with no errors 00194 Values: Change the NH command 00195 Parameters: 00196 nhops: maximum number of hops (1-0xFF) 00197 */ 00198 uint8_t WaspXBeeDM::setNetworkHops(uint8_t nhops) 00199 { 00200 int8_t error=2; 00201 00202 if( protocol!=XBEE_900 ) 00203 { 00204 error_AT=2; 00205 gen_data(set_network_hops_DM,nhops); 00206 gen_checksum(set_network_hops_DM); 00207 error=gen_send(set_network_hops_DM); 00208 } 00209 else { 00210 error=-1; 00211 error_AT=-1; 00212 } 00213 if(!error) 00214 { 00215 networkHops=nhops; 00216 } 00217 return error; 00218 } 00219 00220 /* 00221 Function: Read the maximum number of hops expected to be seen in a network route 00222 Returns: Integer that determines if there has been any error 00223 error=2 --> The command has not been executed 00224 error=1 --> There has been an error while executing the command 00225 error=0 --> The command has been executed with no errors 00226 Values: Stores in global "networkHops" variable max number of hops 00227 */ 00228 uint8_t WaspXBeeDM::getNetworkHops() 00229 { 00230 int8_t error=2; 00231 00232 if( protocol!=XBEE_900 ) 00233 { 00234 error_AT=2; 00235 gen_data(get_network_hops_DM); 00236 error=gen_send(get_network_hops_DM); 00237 } 00238 else { 00239 error=-1; 00240 error_AT=-1; 00241 } 00242 if(error==0) 00243 { 00244 networkHops=data[0]; 00245 delay(20); 00246 } 00247 return error; 00248 } 00249 00250 /* 00251 Function: Set the maximum random number of network delay slots before rebroadcasting a network packet 00252 Returns: Integer that determines if there has been any error 00253 error=2 --> The command has not been executed 00254 error=1 --> There has been an error while executing the command 00255 error=0 --> The command has been executed with no errors 00256 Values: Change the NN command 00257 Parameters: 00258 dslots: maximum number of delay slots (0-0x0A) 00259 */ 00260 uint8_t WaspXBeeDM::setNetworkDelaySlots(uint8_t dslots) 00261 { 00262 int8_t error=2; 00263 00264 if( protocol!=XBEE_900 ) 00265 { 00266 error_AT=2; 00267 gen_data(set_network_delay_DM,dslots); 00268 gen_checksum(set_network_delay_DM); 00269 error=gen_send(set_network_delay_DM); 00270 } 00271 else { 00272 error=-1; 00273 error_AT=-1; 00274 } 00275 if(error==0) 00276 { 00277 netDelaySlots=dslots; 00278 } 00279 return error; 00280 } 00281 00282 /* 00283 Function: Read the maximum random number of network delay slots before rebroadcasting a network packet 00284 Returns: Integer that determines if there has been any error 00285 error=2 --> The command has not been executed 00286 error=1 --> There has been an error while executing the command 00287 error=0 --> The command has been executed with no errors 00288 Values: Stores in global "netDelaySlots" variable max random number of net delay slots 00289 */ 00290 uint8_t WaspXBeeDM::getNetworkDelaySlots() 00291 { 00292 int8_t error=2; 00293 00294 if( protocol!=XBEE_900 ) 00295 { 00296 error_AT=2; 00297 gen_data(get_network_delay_DM); 00298 error=gen_send(get_network_delay_DM); 00299 } 00300 else { 00301 error=-1; 00302 error_AT=-1; 00303 } 00304 if(error==0) 00305 { 00306 netDelaySlots=data[0]; 00307 delay(20); 00308 } 00309 return error; 00310 } 00311 00312 /* 00313 Function: Set the maximum number of route discovery retries allowed to find a path to the destination node 00314 Returns: Integer that determines if there has been any error 00315 error=2 --> The command has not been executed 00316 error=1 --> There has been an error while executing the command 00317 error=0 --> The command has been executed with no errors 00318 Values: Change the NQ command 00319 Parameters: 00320 route: maximum number of route discovery retries (0-0x0A) 00321 */ 00322 uint8_t WaspXBeeDM::setNetworkRouteRequests(uint8_t route) 00323 { 00324 int8_t error=2; 00325 00326 00327 if( protocol!=XBEE_900 ) 00328 { 00329 error_AT=2; 00330 gen_data(set_network_route_DM,route); 00331 gen_checksum(set_network_route_DM); 00332 error=gen_send(set_network_route_DM); 00333 } 00334 else { 00335 error=-1; 00336 error_AT=-1; 00337 } 00338 if(error==0) 00339 { 00340 netRouteRequest=route; 00341 } 00342 return error; 00343 } 00344 00345 /* 00346 Function: Read the maximum number of route discovery retries allowed to find a path to the destination node 00347 Returns: Integer that determines if there has been any error 00348 error=2 --> The command has not been executed 00349 error=1 --> There has been an error while executing the command 00350 error=0 --> The command has been executed with no errors 00351 Values: Stores in global "netRouteRequest" variable max number of route discovery retries 00352 */ 00353 uint8_t WaspXBeeDM::getNetworkRouteRequests() 00354 { 00355 int8_t error=2; 00356 00357 if( protocol!=XBEE_900 ) 00358 { 00359 error_AT=2; 00360 gen_data(get_network_route_DM); 00361 error=gen_send(get_network_route_DM); 00362 } 00363 else { 00364 error=-1; 00365 error_AT=-1; 00366 } 00367 if(error==0) 00368 { 00369 netRouteRequest=data[0]; 00370 delay(20); 00371 } 00372 return error; 00373 } 00374 00375 /* 00376 Function: Set the maximum number of network packet delivery attempts 00377 Returns: Integer that determines if there has been any error 00378 error=2 --> The command has not been executed 00379 error=1 --> There has been an error while executing the command 00380 error=0 --> The command has been executed with no errors 00381 Values: Change the MR command 00382 Parameters: 00383 mesh: maximum number of attempts (0-7) 00384 */ 00385 uint8_t WaspXBeeDM::setMeshNetworkRetries(uint8_t mesh) 00386 { 00387 int8_t error=2; 00388 00389 if( protocol!=XBEE_900 ) 00390 { 00391 error_AT=2; 00392 gen_data(set_network_retries_DM,mesh); 00393 gen_checksum(set_network_retries_DM); 00394 error=gen_send(set_network_retries_DM); 00395 } 00396 else { 00397 error=-1; 00398 error_AT=-1; 00399 } 00400 if(error==0) 00401 { 00402 meshNetRetries=mesh; 00403 } 00404 return error; 00405 } 00406 00407 /* 00408 Function: Read the maximum number of network packet delivery attempts 00409 Returns: Integer that determines if there has been any error 00410 error=2 --> The command has not been executed 00411 error=1 --> There has been an error while executing the command 00412 error=0 --> The command has been executed with no errors 00413 Values: Stores in global "meshNetRetries" variable max number of net packet delivery attempts 00414 */ 00415 uint8_t WaspXBeeDM::getMeshNetworkRetries() 00416 { 00417 int8_t error=2; 00418 00419 if( protocol!=XBEE_900 ) 00420 { 00421 error_AT=2; 00422 gen_data(get_network_retries_DM); 00423 error=gen_send(get_network_retries_DM); 00424 } 00425 else { 00426 error=-1; 00427 error_AT=-1; 00428 } 00429 if(error==0) 00430 { 00431 meshNetRetries=data[0]; 00432 delay(20); 00433 } 00434 return error; 00435 } 00436 00437 /* 00438 Function: Read module temperature in Celsius. Negatives temperatures can be returned 00439 Returns: Integer that determines if there has been any error 00440 error=2 --> The command has not been executed 00441 error=1 --> There has been an error while executing the command 00442 error=0 --> The command has been executed with no errors 00443 Values: Executes the TP command. Stores in global "temperature" variable the readed temp in Celsius 00444 */ 00445 uint8_t WaspXBeeDM::getTemperature() 00446 { 00447 int8_t error=2; 00448 00449 if( (protocol==XBEE_900) || ( (protocol==DIGIMESH) && (freq==FREQ900M) ) ) 00450 { 00451 error_AT=2; 00452 gen_data(get_temperature_DM); 00453 error=gen_send(get_temperature_DM); 00454 } 00455 else { 00456 error=-1; 00457 error_AT=-1; 00458 } 00459 if(error==0) 00460 { 00461 temperature[0]=data[0]; 00462 delay(20); 00463 temperature[1]=data[1]; 00464 delay(20); 00465 } 00466 return error; 00467 } 00468 00469 /* 00470 Function: Reads the voltage on the Vcc pin 00471 Returns: Integer that determines if there has been any error 00472 error=2 --> The command has not been executed 00473 error=1 --> There has been an error while executing the command 00474 error=0 --> The command has been executed with no errors 00475 Values: Executes the %V command. Stores in global "supplyVoltage" variable the VCC 00476 */ 00477 uint8_t WaspXBeeDM::getSupplyVoltage() 00478 { 00479 int8_t error=2; 00480 00481 if( (protocol==XBEE_900) || ( (protocol==DIGIMESH) && (freq==FREQ900M) ) ) 00482 { 00483 error_AT=2; 00484 gen_data(get_supply_Volt_DM); 00485 error=gen_send(get_supply_Volt_DM); 00486 } 00487 else { 00488 error=-1; 00489 error_AT=-1; 00490 } 00491 if(error==0) 00492 { 00493 supplyVoltage[0]=data[0]; 00494 delay(20); 00495 supplyVoltage[1]=data[1]; 00496 delay(20); 00497 } 00498 return error; 00499 } 00500 00501 /* 00502 Function: Restore module parameters to compiled defaults 00503 Returns: Integer that determines if there has been any error 00504 error=2 --> The command has not been executed 00505 error=1 --> There has been an error while executing the command 00506 error=0 --> The command has been executed with no errors 00507 Values: Executes the R1 command. 00508 */ 00509 uint8_t WaspXBeeDM::restoreCompiled() 00510 { 00511 int8_t error=2; 00512 00513 if( (protocol==XBEE_900) || ( (protocol==DIGIMESH) && (freq==FREQ900M) ) ) 00514 { 00515 error_AT=2; 00516 gen_data(restore_compiled_DM); 00517 error=gen_send(restore_compiled_DM); 00518 } 00519 else { 00520 error=-1; 00521 error_AT=-1; 00522 } 00523 return error; 00524 } 00525 00526 WaspXBeeDM xbeeDM = WaspXBeeDM();
1.5.6