00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __WPROGRAM_H__
00025
00026 #include <WaspClasses.h>
00027 #endif
00028
00029 void WaspXBeeZB::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 awakeTime[0]=AWAKE_TIME_ZIGBEE_H;
00040 awakeTime[1]=AWAKE_TIME_ZIGBEE_L;
00041 sleepTime[0]=SLEEP_TIME_ZIGBEE_H;
00042 sleepTime[1]=SLEEP_TIME_ZIGBEE_L;
00043 scanTime[0]=SCAN_TIME_ZIGBEE;
00044 scanChannels[0]=SCAN_CHANNELS_ZIGBEE_H;
00045 scanChannels[1]=SCAN_CHANNELS_ZIGBEE_L;
00046 timeEnergyChannel=TIME_ENERGY_CHANNEL_ZIGBEE;
00047 encryptMode=ENCRYPT_MODE_ZIGBEE;
00048 powerLevel=POWER_LEVEL_ZIGBEE;
00049 timeRSSI=TIME_RSSI_ZIGBEE;
00050 sleepOptions=SLEEP_OPTIONS_ZIGBEE;
00051
00052 parentNA[0]=0xFF;
00053 parentNA[1]=0xFE;
00054 deviceType[0]=0x00;
00055 deviceType[1]=0x03;
00056 deviceType[2]=0x00;
00057 deviceType[3]=0x00;
00058 for(it=0;it<8;it++)
00059 {
00060 extendedPAN[it]=0x00;
00061 }
00062 maxUnicastHops=0x1E;
00063 maxBroadcastHops=0x00;
00064 stackProfile=0;
00065 joinTime=0xFF;
00066 channelVerification=0x00;
00067 joinNotification=0x00;
00068 aggregateNotification=0xFF;
00069 encryptOptions=0;
00070 for(it=0;it<16;it++)
00071 {
00072 networkKey[it]=0x00;
00073 }
00074 powerMode=4;
00075
00076 data_length=0;
00077 it=0;
00078 start=0;
00079 finish=0;
00080 add_type=0;
00081 mode=0;
00082 frag_length=0;
00083 TIME1=0;
00084 nextIndex1=0;
00085 frameNext=0;
00086 replacementPolicy=XBEE_OUT;
00087 indexNotModified=1;
00088 error_AT=2;
00089 error_RX=2;
00090 error_TX=2;
00091 clearFinishArray();
00092 clearCommand();
00093 apsEncryption=0;
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 uint8_t WaspXBeeZB::resetNetwork(uint8_t reset)
00109 {
00110 int8_t error=2;
00111
00112 error_AT=2;
00113 gen_data(reset_network_ZB,reset);
00114 gen_checksum(reset_network_ZB);
00115 error=gen_send(reset_network_ZB);
00116
00117 return error;
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129 uint8_t WaspXBeeZB::getParentNetworkAddress()
00130 {
00131 int8_t error=2;
00132
00133 error_AT=2;
00134 gen_data(get_parent_NA_ZB);
00135 error=gen_send(get_parent_NA_ZB);
00136
00137 if(error==0)
00138 {
00139 parentNA[0]=data[0];
00140 parentNA[1]=data[1];
00141 }
00142 return error;
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 uint8_t WaspXBeeZB::getRemainingChildren()
00155 {
00156 int8_t error=2;
00157
00158 error_AT=2;
00159 gen_data(get_rem_children_ZB);
00160 error=gen_send(get_rem_children_ZB);
00161
00162 if(error==0)
00163 {
00164 remainingChildren=data[0];
00165 }
00166 return error;
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179 uint8_t WaspXBeeZB::setDeviceType(uint8_t* type)
00180 {
00181 int8_t error=2;
00182
00183 error_AT=2;
00184 gen_data(set_device_type_ZB,type);
00185 gen_checksum(set_device_type_ZB);
00186 error=gen_send(set_device_type_ZB);
00187
00188 if(error==0)
00189 {
00190 for(it=0;it<4;it++)
00191 {
00192 deviceType[it]=type[it];
00193 }
00194 }
00195 return error;
00196 }
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 uint8_t WaspXBeeZB::getDeviceType()
00207 {
00208 int8_t error=2;
00209
00210 error_AT=2;
00211 gen_data(get_device_type_ZB);
00212 error=gen_send(get_device_type_ZB);
00213
00214 if(error==0)
00215 {
00216 for(it=0;it<4;it++)
00217 {
00218 deviceType[it]=data[it];
00219 delay(20);
00220 }
00221 }
00222 return error;
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 uint8_t WaspXBeeZB::getPayloadBytes()
00234 {
00235 int8_t error=2;
00236
00237 error_AT=2;
00238 gen_data(get_payload_ZB);
00239 error=gen_send(get_payload_ZB);
00240
00241 if(error==0)
00242 {
00243 maxPayloadBytes[0]=data[0];
00244 maxPayloadBytes[1]=data[1];
00245 }
00246 return error;
00247 }
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257 uint8_t WaspXBeeZB::getExtendedPAN()
00258 {
00259 int8_t error=2;
00260
00261 error_AT=2;
00262 gen_data(get_ext_PAN_ZB);
00263 error=gen_send(get_ext_PAN_ZB);
00264
00265 if(error==0)
00266 {
00267 for(it=0;it<8;it++)
00268 {
00269 extendedPAN[it]=data[it];
00270 delay(25);
00271 }
00272 }
00273 return error;
00274 }
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284 uint8_t WaspXBeeZB::getOperatingPAN()
00285 {
00286 int8_t error=2;
00287
00288 error_AT=2;
00289 gen_data(get_opt_PAN_ZB);
00290 error=gen_send(get_opt_PAN_ZB);
00291
00292 if(error==0)
00293 {
00294 for(it=0;it<2;it++)
00295 {
00296 operatingPAN[it]=data[it];
00297 delay(25);
00298 }
00299 }
00300 return error;
00301 }
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 uint8_t WaspXBeeZB::setMaxUnicastHops(uint8_t hops)
00314 {
00315 int8_t error=2;
00316
00317 error_AT=2;
00318 gen_data(set_max_uni_hops_ZB,hops);
00319 gen_checksum(set_max_uni_hops_ZB);
00320 error=gen_send(set_max_uni_hops_ZB);
00321
00322 if(error==0)
00323 {
00324 maxUnicastHops=hops;
00325 }
00326 return error;
00327 }
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 uint8_t WaspXBeeZB::getMaxUnicastHops()
00339 {
00340 int8_t error=2;
00341
00342 error_AT=2;
00343 gen_data(get_max_uni_hops_ZB);
00344 error=gen_send(get_max_uni_hops_ZB);
00345
00346 if(error==0)
00347 {
00348 maxUnicastHops=data[0];
00349 }
00350 return error;
00351 }
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363 uint8_t WaspXBeeZB::setMaxBroadcastHops(uint8_t bhops)
00364 {
00365 int8_t error=2;
00366
00367 error_AT=2;
00368 gen_data(set_max_brd_hops_ZB,bhops);
00369 gen_checksum(set_max_brd_hops_ZB);
00370 error=gen_send(set_max_brd_hops_ZB);
00371
00372 if(error==0)
00373 {
00374 maxBroadcastHops=bhops;
00375 }
00376 return error;
00377 }
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 uint8_t WaspXBeeZB::getMaxBroadcastHops()
00389 {
00390 int8_t error=2;
00391
00392 error_AT=2;
00393 gen_data(get_max_brd_hops_ZB);
00394 error=gen_send(get_max_brd_hops_ZB);
00395
00396 if(error==0)
00397 {
00398 maxBroadcastHops=data[0];
00399 }
00400 return error;
00401 }
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 uint8_t WaspXBeeZB::setStackProfile(uint8_t profile)
00414 {
00415 int8_t error=2;
00416
00417 error_AT=2;
00418 gen_data(set_stack_profile_ZB,profile);
00419 gen_checksum(set_stack_profile_ZB);
00420 error=gen_send(set_stack_profile_ZB);
00421
00422 if(error==0)
00423 {
00424 stackProfile=profile;
00425 }
00426 return error;
00427 }
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437 uint8_t WaspXBeeZB::getStackProfile()
00438 {
00439 int8_t error=2;
00440
00441 error_AT=2;
00442 gen_data(get_stack_profile_ZB);
00443 error=gen_send(get_stack_profile_ZB);
00444
00445 if(error==0)
00446 {
00447 stackProfile=data[0];
00448 }
00449 return error;
00450 }
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462 uint8_t WaspXBeeZB::setPeriodSleep(uint8_t* periods)
00463 {
00464 int8_t error=2;
00465
00466 error_AT=2;
00467 gen_data(set_period_sleep_ZB,periods);
00468 gen_checksum(set_period_sleep_ZB);
00469 error=gen_send(set_period_sleep_ZB);
00470
00471 if(error==0)
00472 {
00473 periodSleep[0]=periods[0];
00474 periodSleep[1]=periods[1];
00475 }
00476 return error;
00477 }
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490 uint8_t WaspXBeeZB::setJoinTime(uint8_t time)
00491 {
00492 int8_t error=2;
00493
00494 error_AT=2;
00495 gen_data(set_join_time_ZB,time);
00496 gen_checksum(set_join_time_ZB);
00497 error=gen_send(set_join_time_ZB);
00498
00499 if(error==0)
00500 {
00501 joinTime=time;
00502 }
00503 return error;
00504 }
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514 uint8_t WaspXBeeZB::getJoinTime()
00515 {
00516 int8_t error=2;
00517
00518 error_AT=2;
00519 gen_data(get_join_time_ZB);
00520 error=gen_send(get_join_time_ZB);
00521
00522 if(error==0)
00523 {
00524 joinTime=data[0];
00525 }
00526 return error;
00527 }
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539 uint8_t WaspXBeeZB::setChannelVerification(uint8_t verif)
00540 {
00541 int8_t error=2;
00542
00543 error_AT=2;
00544 gen_data(set_channel_verif_ZB,verif);
00545 gen_checksum(set_channel_verif_ZB);
00546 error=gen_send(set_channel_verif_ZB);
00547
00548 if(error==0)
00549 {
00550 channelVerification=verif;
00551 }
00552 return error;
00553 }
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564 uint8_t WaspXBeeZB::getChannelVerification()
00565 {
00566 int8_t error=2;
00567
00568 error_AT=2;
00569 gen_data(get_channel_verif_ZB);
00570 error=gen_send(get_channel_verif_ZB);
00571
00572 if(error==0)
00573 {
00574 channelVerification=data[0];
00575 }
00576 return error;
00577 }
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589 uint8_t WaspXBeeZB::setJoinNotification(uint8_t notif)
00590 {
00591 int8_t error=2;
00592
00593 error_AT=2;
00594 gen_data(set_join_notif_ZB,notif);
00595 gen_checksum(set_join_notif_ZB);
00596 error=gen_send(set_join_notif_ZB);
00597
00598 if(error==0)
00599 {
00600 joinNotification=notif;
00601 }
00602 return error;
00603 }
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614 uint8_t WaspXBeeZB::getJoinNotification()
00615 {
00616 int8_t error=2;
00617
00618 error_AT=2;
00619 gen_data(get_join_notif_ZB);
00620 error=gen_send(get_join_notif_ZB);
00621
00622 if(error==0)
00623 {
00624 joinNotification=data[0];
00625 }
00626 return error;
00627 }
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639 uint8_t WaspXBeeZB::setAggregateNotification(uint8_t anotif)
00640 {
00641 int8_t error=2;
00642
00643 error_AT=2;
00644 gen_data(set_aggreg_notif_ZB,anotif);
00645 gen_checksum(set_aggreg_notif_ZB);
00646 error=gen_send(set_aggreg_notif_ZB);
00647
00648 if(error==0)
00649 {
00650 aggregateNotification=anotif;
00651 }
00652 return error;
00653 }
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663 uint8_t WaspXBeeZB::getAggregateNotification()
00664 {
00665 int8_t error=2;
00666
00667 error_AT=2;
00668 gen_data(get_aggreg_notif_ZB);
00669 error=gen_send(get_aggreg_notif_ZB);
00670
00671 if(error==0)
00672 {
00673 aggregateNotification=data[0];
00674 }
00675 return error;;
00676 }
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687 uint8_t WaspXBeeZB::getAssociationIndication()
00688 {
00689 int8_t error=2;
00690
00691 error_AT=2;
00692 gen_data(get_assoc_indic_ZB);
00693 error=gen_send(get_assoc_indic_ZB);
00694
00695 if(error==0)
00696 {
00697 associationIndication=data[0];
00698 }
00699 return error;
00700 }
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712 uint8_t WaspXBeeZB::setEncryptionOptions(uint8_t eoptions)
00713 {
00714 int8_t error=2;
00715
00716 error_AT=2;
00717 gen_data(set_encryp_options_ZB,eoptions);
00718 gen_checksum(set_encryp_options_ZB);
00719 error=gen_send(set_encryp_options_ZB);
00720
00721 if(error==0)
00722 {
00723 encryptOptions=eoptions;
00724 }
00725 return error;
00726 }
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737 uint8_t WaspXBeeZB::getEncryptionOptions()
00738 {
00739 int8_t error=2;
00740
00741 error_AT=2;
00742 gen_data(get_encryp_options_ZB);
00743 error=gen_send(get_encryp_options_ZB);
00744
00745 if(error==0)
00746 {
00747 encryptOptions=data[0];
00748 }
00749 return error;
00750 }
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762 uint8_t WaspXBeeZB::setNetworkKey(char* key)
00763 {
00764 int8_t error=2;
00765
00766 error_AT=2;
00767 gen_data(set_netwk_key_ZB,key);
00768 gen_checksum(set_netwk_key_ZB);
00769 error=gen_send(set_netwk_key_ZB);
00770
00771 if(error==0)
00772 {
00773 for(it=0;it<16;it++)
00774 {
00775 networkKey[it]=key[it];
00776 }
00777 }
00778 return error;
00779 }
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791 uint8_t WaspXBeeZB::setPowerMode(uint8_t power)
00792 {
00793 int8_t error=2;
00794
00795 error_AT=2;
00796 gen_data(set_power_mode_ZB,power);
00797 gen_checksum(set_power_mode_ZB);
00798 error=gen_send(set_power_mode_ZB);
00799
00800 if(error==0)
00801 {
00802 powerMode=power;
00803 }
00804 return error;
00805 }
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815 uint8_t WaspXBeeZB::getPowerMode()
00816 {
00817 int8_t error=2;
00818
00819 error_AT=2;
00820 gen_data(get_power_mode_ZB);
00821 error=gen_send(get_power_mode_ZB);
00822
00823 if(error==0)
00824 {
00825 powerMode=data[0];
00826 }
00827 return error;
00828 }
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838 uint8_t WaspXBeeZB::getSupplyVoltage()
00839 {
00840 int8_t error=2;
00841
00842 error_AT=2;
00843 gen_data(get_supply_Volt_ZB);
00844 error=gen_send(get_supply_Volt_ZB);
00845
00846 if(error==0)
00847 {
00848 supplyVoltage[0]=data[0];
00849 delay(20);
00850 supplyVoltage[1]=data[1];
00851 delay(20);
00852 }
00853 return error;
00854 }
00855
00856
00857
00858
00859
00860
00861
00862
00863 uint8_t WaspXBeeZB::setAPSencryption(uint8_t mode)
00864 {
00865 int8_t error=0;
00866
00867 if(mode==XBEE_ON) apsEncryption=1;
00868 else if(mode==XBEE_OFF) apsEncryption=0;
00869
00870 error_AT=0;
00871
00872 return error;
00873 }
00874
00875
00876 WaspXBeeZB xbeeZB = WaspXBeeZB();