void pinInt() { unsigned char pinClock = PINB & _BV(DAT); if (pinClock != pinClockLast && pinClock != 0) { readData(); if (msgIdx == 8) { setProgram(); TOC = BRIGHTMAX - 1; clearMsg(); } } pinClockLast = pinClock; }
void RMessagePassing::release(void) { // stop connecting thread setAlive(0); wait(10); kill(); // release node map m_nodeMap.release(); // close socket m_socket.close(); // clear message queue clearMsg(); // clear nodes m_nodeMe = NULL; m_nodeMaster = NULL; }
/* * @returns: the number of bytes sent, if succeeds * -1, if fails */ int _condorOutMsg::sendMsg(const int sock, const condor_sockaddr& who, _condorMsgID msgID, unsigned char * mac) { _condorPacket* tempPkt; int seqNo = 0, msgLen = 0, sent; int total = 0; unsigned char * md = mac; //char str[10000]; if(headPacket->empty()) // empty message return 0; while(headPacket != lastPacket) { tempPkt = headPacket; headPacket = headPacket->next; tempPkt->makeHeader(false, seqNo++, msgID, md); msgLen += tempPkt->length; sent = condor_sendto(sock, tempPkt->dataGram, tempPkt->length + SAFE_MSG_HEADER_SIZE, 0, who); if(sent != tempPkt->length + SAFE_MSG_HEADER_SIZE) { dprintf(D_ALWAYS, "sendMsg:sendto failed - errno: %d\n", errno); headPacket = tempPkt; clearMsg(); return -1; } //int i; //str[0] = 0; //for (i=0; i<tempPkt->length + SAFE_MSG_HEADER_SIZE; i++) { // sprintf(&str[strlen(str)], "%02x,", tempPkt->dataGram[i]); //} //dprintf(D_NETWORK, "--->packet [%d bytes]: %s\n", sent, str); dprintf( D_NETWORK, "SEND [%d] %s ", sent, sock_to_string(sock) ); dprintf( D_NETWORK|D_NOHEADER, "%s\n", who.to_sinful().Value()); total += sent; delete tempPkt; md = 0; } // headPacket = lastPacket if(seqNo == 0) { // a short message msgLen = lastPacket->length; lastPacket->makeHeader(true, 0, msgID, md); // Short messages are sent without initial "magic" header, // because we don't need to specify sequence number, // and presumably for backwards compatibility with ancient // versions of Condor. The crypto header may still // be there, since that is in the buffer starting at // the position pointed to by "data". sent = condor_sendto(sock, lastPacket->data, lastPacket->length, 0, who); if(sent != lastPacket->length) { dprintf( D_ALWAYS, "SafeMsg: sending small msg failed. errno: %d\n", errno ); headPacket->reset(); return -1; } //str[0] = 0; //for (i=0; i<lastPacket->length + SAFE_MSG_HEADER_SIZE; i++) { // sprintf(&str[strlen(str)], "%02x,", lastPacket->dataGram[i]); //} //dprintf(D_NETWORK, "--->packet [%d bytes]: %s\n", sent, str); dprintf( D_NETWORK, "SEND [%d] %s ", sent, sock_to_string(sock) ); dprintf( D_NETWORK|D_NOHEADER, "%s\n", who.to_sinful().Value()); total = sent; } else { lastPacket->makeHeader(true, seqNo, msgID, md); msgLen += lastPacket->length; sent = condor_sendto(sock, lastPacket->dataGram, lastPacket->length + SAFE_MSG_HEADER_SIZE, 0, who); if(sent != lastPacket->length + SAFE_MSG_HEADER_SIZE) { dprintf( D_ALWAYS, "SafeMsg: sending last packet failed. errno: %d\n", errno ); headPacket->reset(); return -1; } //str[0] = 0; //for (i=0; i<lastPacket->length + SAFE_MSG_HEADER_SIZE; i++) { // sprintf(&str[strlen(str)], "%02x,", lastPacket->dataGram[i]); //} //dprintf(D_NETWORK, "--->packet [%d bytes]: %s\n", sent, str); dprintf( D_NETWORK, "SEND [%d] %s ", sent, sock_to_string(sock) ); dprintf( D_NETWORK|D_NOHEADER, "%s\n", who.to_sinful().Value()); total += sent; } headPacket->reset(); noMsgSent++; if(noMsgSent == 1) avgMsgSize = msgLen; else avgMsgSize = ((noMsgSent - 1) * avgMsgSize + msgLen) / noMsgSent; return total; }
main() { char touche; // Variable où sera stocké la touche int y = OFFSET_Y, x = OFFSET_X; // Variable de la position du pointeur de l'utilisateur double bestScore = -1, score = -1, lastScore = -1; time_t depart, arrivee; // Variables de temps // Activation de rand() srand(time(NULL)); // Génération du menu showBorder(); // Génération du menu showMenu(); // Nouvelle partie newGame(); // On démarre le chrono time(&depart); // Gestion des touches do{ // Définition de la couleur du texte textbackground(B_TEXT); textcolor(C_TEXT); // On affiche le nombre de bombes restantes gotoxy(mapX+OFFSET_X+(BORDER*2), OFFSET_Y+8); printf("Bombs : %d ", NB_BOMBS-nbFlags); if(lastScore != -1) { // On affiche le meilleur score gotoxy(mapX+OFFSET_X+(BORDER*2), OFFSET_Y+12); printf("Last Score : %.0f ", lastScore); } if(bestScore != -1) { // On affiche le meilleur score gotoxy(mapX+OFFSET_X+(BORDER*2), OFFSET_Y+13); printf("Best Score : %.0f ", bestScore); } if(gameOver == TRUE) { // Affichage des bombes showBombs(); // On affiche le message msgZone(C_ERROR, B_ERROR); printf("BOOOOOM !"); gotoxy(mapX+OFFSET_X+(BORDER*2), OFFSET_Y+18); printf("Retry ? Press \"r\""); // Pour l'esthétique, on remet le curseur à sa place gotoxy(x, y); do{ touche = getch(); }while(touche != 114); } else if(nbMined == NB_CASES-NB_BOMBS) { // On calcul le temps mis pour gagner time(&arrivee); score = difftime(arrivee, depart); if(score < bestScore || bestScore == -1) bestScore = score; lastScore = score; // On affiche qu'il a gagner msgZone(C_SUCESS, B_SUCESS); printf("YOU WIN !"); gotoxy(mapX+OFFSET_X+(BORDER*2), OFFSET_Y+18); printf("Score : %.0f", score); // Pour l'esthétique, on remet le curseur à sa place gotoxy(x, y); do{ touche = getch(); }while(touche != 114); } else { // On remet le curseur là où le joueur joue gotoxy(x, y); //On récupère la touche appuyer touche = getch(); } //printf("\n%c %d", touche, touche); // DEBUG : permet de voir le code de la touche if(needToClear == TRUE) { clearMsg(); // On efface le message précédent gotoxy(x, y); // On remet le curseur là où le joueur joue } // Si c'est un mouvement, on se déplace if(touche == -32) { // On récupère le sens touche = getch(); switch(touche) { case 75:if(x != 0+OFFSET_X) x--; break; // gauche case 77:if(x != mapX-1+OFFSET_X) x++;break; // droite case 80:if(y != mapY-1+OFFSET_Y) y++;break; // bas case 72:if(y != 0+OFFSET_Y) y--; break; // haut } // On déplace le curseur gotoxy(x, y); } else if(touche == 32) // S'il selectionne la case (espace) { mineCase(x, y); } else if(touche == 102) // S'il pose un drapeau (touche "F") { putFlag(x, y); } else if(touche == 114) // Touche pour commencer une nouvelle partie { newGame(); x = OFFSET_X; y = OFFSET_Y; gotoxy(OFFSET_X, OFFSET_Y); // On remet à zéro le chrono time(&depart); } else if(touche == 113) // Touche pour quitter { return 1; } else if(touche == 51) // Touche de debug pour voir les bombes (touche B) { showBombs(); } } while(touche != '0'); }