void Interface::prepareNumLines() { _numVertic = new char[_h*2]; _numHoriz = new char[_w*2]; for(unsigned int i=0; i<_h; i++) { char * value = convertIntToChar(i,10); if(i<10) { _numVertic[i*2] = ' '; _numVertic[i*2+1] = value[0]; } else { _numVertic[i*2] = value[0]; _numVertic[i*2+1] = value[1]; } delete [] value; } for(unsigned int i=0; i<_w; i++) { char * value = convertIntToChar(i,10); if(i<10) { _numHoriz[i] = ' '; _numHoriz[_w+i] = value[0]; } else { _numHoriz[i] = value[0]; _numHoriz[_w+i] = value[1]; } delete [] value; } }
BigInteger BigInteger::sumDigit (BigInteger const &A, BigInteger const &B) { int t = 0, sum = 0; Node *a; Node *b; Node *c; BigInteger S; a = A.pTail; b = B.pTail; while( a != NULL && b != NULL) { sum = t + convertCharToInt(a->getValue()) + convertCharToInt(b->getValue()); // plus two node of A, B S.addHead(Node::getNode(convertIntToChar(sum % 10))); // get the unit number eg 18 -> 8 -> node t = sum / 10; // get the left number 18 -> 1; a = a->getpPrev(); b = b->getpPrev(); } if( a == NULL){ while( b != NULL) { // scan the redundancy of b sum = t + convertCharToInt(b->getValue()); S.addHead(Node::getNode(convertIntToChar(sum % 10))); t = sum/10; b = b->getpPrev(); } S.digit = B.digit; } else if( b == NULL) { while( a != NULL) { // scan the element of redundancy of a sum = t + convertCharToInt(a->getValue()); S.addHead(Node::getNode(convertIntToChar(sum % 10))); t = sum/10; a = a->getpPrev(); } S.digit = A.digit; } if( t== 1) { S.addHead(Node::getNode(convertIntToChar(t))); S.digit++; } S.setFlag(true); return S; }
BigInteger BigInteger::subtractDigit (BigInteger const &A, BigInteger const &B) { int t = 0, sum = 0; int x, y; Node *a; Node *b; Node *c; BigInteger S; a = A.pTail; b = B.pTail; while( a != NULL && b != NULL) { x = convertCharToInt(a->getValue()); y = convertCharToInt(b->getValue()); if(t + x - y >= 0) { sum = t + x - y ; // subtract two node of A, B t = 0; } else { sum = 10 + t + x - y ; t = -1; // borrow the previous unit } S.addHead(Node::getNode(convertIntToChar(sum))); // get the unit number eg 18 -> 8 -> node S.digit++; a = a->getpPrev(); b = b->getpPrev(); } if( a == NULL){ while( b != NULL) { // scan the redundancy of b y = convertCharToInt(b->getValue()); if(t - y >= 0) { sum = t - y ; // subtract two node of A, B t = 0; } else { sum = 10 + t - y ; t = -1; // borrow the previous unit } S.addHead(Node::getNode(convertIntToChar(sum))); // get the unit number eg 18 -> 8 -> node S.digit++; b = b->getpPrev(); } } else if( b == NULL) { while( a != NULL) { // scan the element of redundancy of a x = convertCharToInt(a->getValue()); if(t + x >= 0) { sum = t + x ; // subtract two node of A, B t = 0; } else { sum = 10 + t + x; t = -1; // borrow the previous unit } S.addHead(Node::getNode(convertIntToChar(sum))); // get the unit number eg 18 -> 8 -> node S.digit++; a = a->getpPrev(); } } S.setFlag(true); S.removePrefixZero(); return S; // error automatically destructor and lost all of information }
void *thread_runtime (void * arg) { int * clients=(int *)arg; // On precise la nature de la variable arg int tailleTrameClient = TAILLE_INFO_TRAME + TAILLE_INFO_TRAME_CAN + TAILLE_TRAME + TAILLE_TRAME_CAN; // Declaration et allocation de la trame client char trameClient[TAILLE_INFO_TRAME + TAILLE_INFO_TRAME_CAN + TAILLE_TRAME + TAILLE_TRAME_CAN]; // Placement des pointeurs vers les differentes parties de la trame client char* tailleTrameSerieLue_char = trameClient; char* tailleTrameCanLue_char = tailleTrameSerieLue_char + TAILLE_INFO_TRAME; char* buffer = tailleTrameCanLue_char + TAILLE_INFO_TRAME_CAN; char* bufferCan = buffer + TAILLE_TRAME; //char* bufferTest="Testbuffer"; int fdSerie; int fdCan; int i, idClient; int ecrits=0; /* // TESTS int tailleTrameCanLue_int = 8; for(i=0 ; i<8 ; i++) { bufferCan[i] = (char)i+70; } */ int tailleTrameCanLue_int = 0; int tailleTrameSerieLue_int = 0; int lectureTramesFaite = 0; printf("thread cree\n"); // Ouverture des fichiers de sauvgegarde FILE* logSerie = fopen("data.csv", "w"); FILE* logCan = fopen("dataCAN.csv", "w"); fdSerie = initLiaisonSerie(); fdCan = initLiaisonCan(); printf("keepRunning %d\n", keepRunning); while ( keepRunning ) { lectureTramesFaite = 0; for(idClient=0 ; idClient < CLIENT_MAX ; idClient++) { //printf("check client %d\n", idClient); if(clients[idClient]==-1) { //printf("Pas de client a %d\n", idClient); continue; // on passe au client suivant } // On ne fait la lecture que si on a au moins 1 client // Si il ya plusieurs clients dans le tableau, la lecture des trames n'est faite qu'une fois if(!lectureTramesFaite) { // LECTURE TRAME CAN tailleTrameCanLue_int = lectureTrameCan(fdCan, bufferCan, TAILLE_TRAME_CAN); if( tailleTrameCanLue_int == 0 ) { // error } convertIntToChar(tailleTrameCanLue_int, tailleTrameCanLue_char, TAILLE_INFO_TRAME_CAN); // LECTURE TRAME SERIE tailleTrameSerieLue_int = lectureTrame(fdSerie, buffer, TAILLE_TRAME); if( tailleTrameSerieLue_int == 0 ) { // error } convertIntToChar(tailleTrameSerieLue_int, tailleTrameSerieLue_char, TAILLE_INFO_TRAME); lectureTramesFaite = 1; } printf("tentative decriture sur le client %d \n", idClient); ecrits = write(clients[idClient], trameClient, tailleTrameClient); printf("code de retour du write : %d \n", ecrits); if(ecrits == -1) { printf("Error writing from socket ! \n"); printf("errno = %d \n", errno); if(errno == EPIPE || errno == ECONNRESET) { printf("deconnexion client\n"); close(clients[idClient]); clients[idClient]=-1; } else { printf("Erreur inconnue \n"); exit(errno); } } else // Si le write s'est bien passe { printf("Trame envoyee au client %d : ", idClient); for(i=0 ; i < tailleTrameClient ; i++) { if(i < TAILLE_TRAME+TAILLE_INFO_TRAME_CAN+TAILLE_INFO_TRAME) printf("%c", trameClient[i]); else printf("%d", trameClient[i]); } printf("(%d octets)\n", ecrits); if( saveTrameCan(logCan, bufferCan, TAILLE_TRAME_CAN) ) printf("la sauvegarde CAN a bien ete faite \n"); if( saveTrame(logSerie, buffer, TAILLE_TRAME) ) printf("la sauvegarde SERIE a bien ete faite \n"); } } } // Ce code est atteint si keepRunning == 0 close(fdSerie); // Fermeture de la liaison Serie close(fdCan); // Fermeture de la liaison CAN printf("fin du thread\n"); return 0; }