00001
00010 #include <stdint.h>
00011 #include <string.h>
00012 #include "ScatterWeb.System.h"
00013 #include "ScatterWeb.CC1020.h"
00014 #include "_dsr.h"
00015
00016
00017
00018
00019 void Net_sendArgsInit_1(netpacket_send_args_t* args)
00020 {
00021 memset(args, 0, sizeof(netpacket_send_args_t));
00022 args->netheader.from = Configuration.id;
00023 args->netheader.flags = NET_TLFLAG_ACKREQ;
00024 }
00025
00026
00027
00028
00029 enum netaddr_compareresult
00030 Net_compareAddress_1(const netaddr_t (*const adr), const bool directConnection)
00031 {
00032 if (*adr == Configuration.id)
00033 return ADRCOMP_THIS;
00034
00035 if (directConnection) {
00036 if( (*adr == 0) )
00037 return ADRCOMP_THIS;
00038 } else if( *adr == 0 )
00039 return ADRCOMP_ERROR;
00040 if( *adr == MY_BROADCAST )
00041 return ADRCOMP_BROADCAST;
00042 else
00043 return ADRCOMP_OTHER;
00044
00045 }
00046
00047
00048
00049
00050
00055
00056 bool Route_discovery(netaddr_t dest) {
00057
00058
00059 Net_sendRequest(dest);
00060
00061 }
00066
00067 bool Net_sendDecides(netaddr_t dest,uint8_t counter,uint8_t feld []) {
00068
00069 bool wahr =true;
00070 bool weiter =true;
00071 uint8_t *pointer;
00072 pointer=feld;
00073
00074 if(dest == Configuration.id)
00075 {
00076 Net_sendReply(dest,counter,feld);
00077
00078 }else{
00079
00080 while(wahr){
00081 if(*pointer!=0){
00082 if(*pointer == Configuration.id){
00083 printf("My id is in Array %d\n");
00084 wahr=false;
00085 weiter = false;
00086 }
00087 *pointer++;
00088 }
00089 wahr =false;
00090 }
00091 while(weiter){
00092 handle_Request(dest,counter,feld);
00093 weiter = false;
00094 }
00095 }
00096 }
00097
00098
00099
00104
00105 bool Net_sendRequest(netaddr_t dest) {
00106 netpacket_send_args_t npsargs;
00107
00108
00109
00110 Net_sendArgsInit_1( &npsargs );
00111
00112
00113
00114
00115 uint8_t i;
00116 for(i=0;i<=ARRAYLAENGE;i++){
00117
00118 npsargs.netheader.away[i]=0;
00119
00120 }
00121
00122
00123 uint8_t counter1 = 0;
00124
00125 npsargs.netheader.away[0]=Configuration.id;
00126 counter1++;
00127
00128
00129
00130 npsargs.netheader.counter = counter1;
00131
00132
00133 npsargs.netheader.destination = dest;
00134
00135 npsargs.netheader.to = ((netaddr_t)MY_BROADCAST);
00136 npsargs.netheader.type = DSR_REQUEST_PACKET;
00137 npsargs.netheader.flags = 0;
00138
00139
00140
00141
00142
00143 return Net_send( &npsargs );
00144 }
00145
00146
00151
00153 bool handle_Request (netaddr_t dest,uint8_t counter,uint8_t feld[]){
00154 netpacket_send_args_t npsargs;
00155
00156
00157 Net_sendArgsInit_1( &npsargs );
00158
00159
00160 uint8_t *pointer;
00161 pointer= feld;
00162
00163
00164 uint8_t j;
00165 for(j=0;j<=ARRAYLAENGE;j++){
00166 if(npsargs.netheader.away[j]==0){
00167 npsargs.netheader.away[j]=*pointer;
00168 break;
00169 }
00170 }
00171
00172
00173 uint8_t counter1;
00174 counter1=counter;
00175
00176 npsargs.netheader.destination = dest;
00177
00178
00179
00180 bool again = true;
00181
00182 while(again){
00183 if(*pointer==0){
00184 *pointer = Configuration.id;
00185 npsargs.netheader.away[*pointer];
00186 again=false;
00187 break;
00188 }
00189 else {
00190 *pointer++;
00191 }
00192 }
00193
00194
00195
00196 uint8_t k;
00197
00198
00199 for(k=counter;k<=ARRAYLAENGE;k++){
00200 if(*pointer != 0){
00201
00202 npsargs.netheader.away[k]=*pointer;
00203
00204 }
00205
00206 *pointer++;
00207
00208 }
00209
00210 counter1++;
00211 npsargs.netheader.counter=counter1;
00212
00213
00214
00215 npsargs.netheader.to =((netaddr_t)MY_BROADCAST);
00216
00217
00218
00219 npsargs.netheader.type = DSR_REQUEST_PACKET;
00220 npsargs.netheader.flags = 0;
00221
00222 return Net_send( &npsargs );
00223
00224 }
00225
00226
00231
00233 bool Net_sendReply(netaddr_t dest,uint8_t counter,uint8_t feld[]) {
00234 netpacket_send_args_t npsargs;
00235
00236
00237
00238
00239 Net_sendArgsInit_1( &npsargs );
00240
00241 uint8_t *pointer;
00242 pointer= feld;
00243
00244 uint8_t counter1;
00245 counter1=counter;
00246
00247
00248
00249 npsargs.netheader.destination = dest;
00250
00251
00252
00253 uint8_t x;
00254 for(x=0;x<=ARRAYLAENGE;x++){
00255 if(feld[x]==0){
00256 feld[x] = Configuration.id;
00257 break;
00258 }
00259
00260 }
00261
00262 uint8_t s=0;
00263 uint8_t k;
00264 for(k=0; k<=ARRAYLAENGE; k++){
00265 npsargs.netheader.away[s]=feld[k];
00266 s++;
00267 }
00268
00269
00270 bool wahr = true;
00271
00272 while(wahr){
00273 if(*pointer == Configuration.id){
00274 *pointer--;
00275 npsargs.netheader.to =((netaddr_t)*pointer);
00276 wahr=false;
00277
00278 }
00279 else {
00280 *pointer++;
00281 }
00282 }
00283
00284 counter1++;
00285 npsargs.netheader.counter=counter1;
00286
00287 npsargs.netheader.type = DSR_REPLY_PACKET;
00288 npsargs.netheader.flags = 0;
00289
00290
00291 return Net_send( &npsargs );
00292
00293 }
00294
00295
00300
00302 void handle_Reply(netaddr_t dest,uint8_t counter,uint8_t feld[]) {
00303 netpacket_send_args_t npsargs;
00304
00305
00306
00307 uint8_t i=0;
00308 uint8_t j;
00309
00310
00311
00312
00313 if(feld[0] == Configuration.id){
00314
00315 for(j=0; j<=ARRAYLAENGE; j++){
00316 help_array[i]=feld[j];
00317 i++;
00318 }
00319
00320 uint8_t l;
00321 for(l=0;l<=counter;l++){
00322
00323 printf("The_way: %d\n", feld[l]);
00324
00325 }
00326 printf("Die Anzahl der Knoten ist : %d\n",counter);
00327 copy_dest = dest;
00328
00329 Net_sendData();
00330
00331 }
00332
00333
00334 else{
00335
00336
00337
00338 Net_sendArgsInit_1( &npsargs );
00339
00340
00341 uint8_t *pointer;
00342 pointer= feld;
00343
00344
00345
00346 uint8_t s=0;
00347 uint8_t k;
00348 for(k=0; k<=ARRAYLAENGE; k++){
00349 npsargs.netheader.away[s]=feld[k];
00350 s++;
00351 }
00352
00353
00354
00355
00356 bool wahr = true;
00357
00358 while(wahr){
00359 if(*pointer == Configuration.id){
00360
00361 *pointer--;
00362 npsargs.netheader.to =((netaddr_t)*pointer);
00363 wahr=false;
00364
00365 }
00366 else {
00367 *pointer++;
00368
00369 }
00370
00371 }
00372
00373
00374 npsargs.netheader.destination = dest;
00375 npsargs.netheader.counter=counter;
00376
00377
00378 npsargs.netheader.type = DSR_REPLY_PACKET;
00379 npsargs.netheader.flags = 0;
00380
00381
00382
00383 return Net_send( &npsargs );
00384
00385 }
00386
00387 }
00388
00389
00393 bool Decides_data(netaddr_t dest,uint8_t* data,uint8_t feld[]) {
00394
00395
00396
00397 if(dest == Configuration.id)
00398 {
00399 Net_sendAck(feld);
00400 printf("bis decide ack %d\n");
00401
00402 }else{
00403 handle_Data(dest,data,feld);
00404 printf("bis decide data %d\n");
00405 }
00406
00407 }
00408
00412
00413
00414 bool Net_sendData(){
00415 netpacket_send_args_t npsargs;
00416
00417 Net_sendArgsInit_1( &npsargs );
00418
00419 printf("kopierte %d\n");
00420
00421
00422 uint8_t s=0;
00423 uint8_t k;
00424 for(k=0; k<=ARRAYLAENGE; k++){
00425 npsargs.netheader.away[s]=help_array[k];
00426 s++;
00427 }
00428
00429
00430
00431 uint8_t l;
00432 for(l=0;l<=ARRAYLAENGE;l++){
00433 if(help_array[l] == Configuration.id){
00434 l++;
00435 npsargs.netheader.to =((netaddr_t)help_array[l]);
00436 break;
00437 }
00438
00439 }
00440
00441
00442 npsargs.netheader.destination = copy_dest;
00443 npsargs.netheader.type = DATA_PACKET;
00444 npsargs.netheader.flags = 0;
00445
00446
00447
00448
00449 uint8_t* data = "Hello world!";
00450
00451
00452 npsargs.payload[0].buffer = (uint8_t*) data;
00453 npsargs.payload[0].size = strlen(data);
00454
00455
00456
00457
00458
00459 return Net_send( &npsargs );
00460
00461
00462
00463 }
00464
00468
00469 bool handle_Data(netaddr_t dest,uint8_t* data,uint8_t feld[]){
00470
00471 netpacket_send_args_t npsargs;
00472
00473
00474 Net_sendArgsInit_1( &npsargs );
00475
00476
00477
00478
00479 uint8_t s=0;
00480 uint8_t k;
00481 for(k=0; k<=ARRAYLAENGE; k++){
00482 npsargs.netheader.away[s]=feld[k];
00483 s++;
00484 }
00485
00486
00487
00488
00489 uint8_t l;
00490 for(l=0;l<=ARRAYLAENGE;l++){
00491 if(feld[l] == Configuration.id){
00492 l++;
00493 npsargs.netheader.to =((netaddr_t)feld[l]);
00494 break;
00495 }
00496
00497
00498 }
00499
00500
00501 npsargs.netheader.destination=dest;
00502 npsargs.netheader.type = DATA_PACKET;
00503 npsargs.netheader.flags = 0;
00504
00505
00506
00507 uint8_t* data = *data;
00508
00509
00510 npsargs.payload[0].buffer = (uint8_t*) data;
00511 npsargs.payload[0].size = strlen(data);
00512
00513
00514
00515 return Net_send( &npsargs );
00516
00517
00518
00519 }
00520
00521
00522
00526
00527 bool Net_sendAck(uint8_t feld[]){
00528
00529 netpacket_send_args_t npsargs;
00530
00531
00532 Net_sendArgsInit_1( &npsargs );
00533
00534
00535
00536
00537 if(feld[0]==Configuration.id){
00538
00539 printf("Bestaetigung %d\n");
00540 printf("Ich habe die Daten erhalten %d\n");
00541
00542 }
00543
00544 uint8_t s=0;
00545 uint8_t k;
00546 for(k=0; k<=ARRAYLAENGE; k++){
00547 npsargs.netheader.away[s]=feld[k];
00548 s++;
00549 }
00550
00551
00552
00553
00554 uint8_t l;
00555 for(l=0;l<=ARRAYLAENGE;l++){
00556 if(feld[l] == Configuration.id){
00557 l--;
00558 npsargs.netheader.to =((netaddr_t)feld[l]);
00559 break;
00560 }
00561
00562 }
00563
00564
00565 npsargs.netheader.type = ACK_PACKET;
00566 npsargs.netheader.flags = 0;
00567
00568
00569
00570 return Net_send( &npsargs );
00571
00572
00573
00574 }