Changeset 445 in flair-src for trunk/lib/FlairCore/src/ui_com.cpp
- Timestamp:
- Sep 10, 2021, 3:14:17 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairCore/src/ui_com.cpp
r444 r445 39 39 using namespace flair::gui; 40 40 41 ui_com::ui_com(const Object *parent, UDTSOCKET sock) 42 : Thread(parent, "send", 2,16384*2) { 43 // buffer envoi 44 send_buffer = (char *)malloc(3); 45 send_size = 3; // id(1)+period(2) 46 41 ui_com::ui_com(const Object *parent, UDTSOCKET sock) : Thread(parent, "send", 2,16384*2) { 47 42 // mutex 48 send_mutex = NULL;49 43 send_mutex = new Mutex(this, ObjectName()); 50 44 … … 150 144 Send(&buf,1); 151 145 152 if (send_buffer != NULL) 153 free(send_buffer); 154 send_buffer = NULL; 155 146 for (size_t i = 0; i < pushedDatas.size(); i++) { 147 free(pushedDatas.at(i).buf); 148 } 156 149 //Printf("destruction ui_com ok\n"); 157 150 } … … 264 257 //-> enelver l'alloc du buffer au startup (UpdateDataToSendSize) 265 258 void ui_com::Run(void) { 266 // check endianness267 char header;268 if (IsBigEndian()) {269 header = DATA_BIG_ENDIAN;270 Printf("System is big endian\n");271 } else {272 header = DATA_LITTLE_ENDIAN;273 Printf("System is little endian\n");274 }275 276 259 #ifdef __XENO__ 277 260 WarnUponSwitches(true); … … 305 288 306 289 // envoi des donnees 307 int offset = 3;308 send_buffer[0] = header;309 290 send_mutex->GetMutex(); 310 291 311 for (size_t i = 0; i < datasToSend.size(); i++) { 312 if (datasToSend.at(i)->SendPeriod() == resume_period && datasToSend.at(i)->IsEnabled() == true) { 313 datasToSend.at(i)->CopyDatas(send_buffer + offset); 314 offset += datasToSend.at(i)->SendSize(); 315 } 316 } 317 if (offset != 3) { 318 memcpy(&send_buffer[1], &resume_period, sizeof(uint16_t)); 319 //printf("send %i %i %i %x %x\n",resume_period,offset,sizeof(uint16_t),send_buffer,&send_buffer[1]); 320 // for(int i=0;i<offset;i++) printf("%x ",send_buffer[i]); 321 // printf("\n"); 322 //Send(send_buffer, offset,resume_period); 323 } 324 325 //test to push datas 292 //mulit buffering 326 293 for (size_t i = 0; i < datasToSend.size(); i++) { 327 294 if (datasToSend.at(i)->SendPeriod() == resume_period && datasToSend.at(i)->IsEnabled() == true) { … … 329 296 } 330 297 } 331 //end test332 298 333 299 // on planifie la prochaine execution … … 375 341 376 342 if(ptr->actual_size==0) { 377 if (IsBigEndian()) { 378 ptr->buf[0] = MULTIPLE_DATA_BIG_ENDIAN; 343 if(ptr->nb_buffering>1) { 344 if (IsBigEndian()) { 345 ptr->buf[0] = MULTIPLE_DATA_BIG_ENDIAN; 346 } else { 347 ptr->buf[0] = MULTIPLE_DATA_LITTLE_ENDIAN; 348 } 349 ptr->actual_size+=sizeof(char); 350 memcpy(ptr->buf+ptr->actual_size,&(ptr->period),sizeof(uint16_t)); 351 ptr->actual_size+=sizeof(uint16_t); 352 memcpy(ptr->buf+ptr->actual_size,&(ptr->nb_buffering),sizeof(uint16_t)); 353 ptr->actual_size+=sizeof(uint16_t); 379 354 } else { 380 ptr->buf[0] = MULTIPLE_DATA_LITTLE_ENDIAN; 355 if (IsBigEndian()) { 356 ptr->buf[0] = DATA_BIG_ENDIAN; 357 } else { 358 ptr->buf[0] = DATA_LITTLE_ENDIAN; 359 } 360 ptr->actual_size+=sizeof(char); 361 memcpy(ptr->buf+ptr->actual_size,&(ptr->period),sizeof(uint16_t)); 362 ptr->actual_size+=sizeof(uint16_t); 381 363 } 382 ptr->actual_size+=sizeof(char);383 memcpy(ptr->buf+ptr->actual_size,&(ptr->period),sizeof(uint16_t));384 ptr->actual_size+=sizeof(uint16_t);385 memcpy(ptr->buf+ptr->actual_size,&(ptr->nb_buffering),sizeof(uint16_t));386 ptr->actual_size+=sizeof(uint16_t);387 364 } 388 365 … … 613 590 } 614 591 bufSize*=(*pushedDatasIterator).nb_buffering; 615 if(bufSize!=0) bufSize+=sizeof(char)+sizeof(uint16_t)+sizeof(uint16_t);//header+period+nb_buffering 592 if(bufSize!=0) { 593 bufSize+=sizeof(char)+sizeof(uint16_t);//header+period 594 if((*pushedDatasIterator).nb_buffering>1) bufSize+=sizeof(uint16_t);//+nb_buffering 595 } 616 596 if(bufSize!=(*pushedDatasIterator).final_size && bufSize!=0) { 617 597 //Printf("change buf size %i->%i\n",(*pushedDatasIterator).final_size,bufSize); … … 655 635 } 656 636 tmp.final_size*=obj->NbBuffering(); 657 tmp.final_size+=sizeof(char)+sizeof(uint16_t)+sizeof(uint16_t);//header+period+nb_buffering 637 tmp.final_size+=sizeof(char)+sizeof(uint16_t);//header+period 638 if(tmp.nb_buffering>1) tmp.final_size+=sizeof(uint16_t);//+nb_buffering 658 639 //printf("final size %i\n",tmp.final_size); 659 640 tmp.buf=(char*)malloc(tmp.final_size); … … 667 648 //Printf("nb buf %i\n",pushedDatas.size()); 668 649 return; 669 }670 671 //allocate a buffer at startup for the worst case672 //(every data send with same pedriod)673 //TODO: dynamic size depending on what gcs asks?674 void ui_com::UpdateDataToSendSize(void) {675 send_mutex->GetMutex();676 send_size = 3; // id(1)+period(2)677 for (size_t i = 0; i < datasToSend.size(); i++) {678 if (datasToSend[i] != NULL)679 send_size += datasToSend[i]->SendSize();680 }681 682 // send_buffer=(char*)realloc((void*)send_buffer,send_size*sizeof(char));683 if (send_buffer != NULL)684 free(send_buffer);685 send_buffer = (char *)malloc(send_size * sizeof(char));686 send_mutex->ReleaseMutex();687 650 } 688 651 … … 704 667 } 705 668 706 ptr->final_size=sizeof(char)+sizeof(uint16_t)+sizeof(uint16_t);//header+period+nb_buffering 669 ptr->final_size=sizeof(char)+sizeof(uint16_t);//header+period 670 if(ptr->nb_buffering>1) ptr->final_size+=sizeof(uint16_t);//+nb_buffering 707 671 ptr->final_size+=obj->SendSize()*obj->NbBuffering(); 708 Printf("final %i\n",ptr->final_size);672 //Printf("final %i\n",ptr->final_size); 709 673 free(ptr->buf); 710 674 ptr->buf=(char*)malloc(ptr->final_size);
Note:
See TracChangeset
for help on using the changeset viewer.