void UserWin::receiveCall(QString _contact) { QLabel _logo; QLabel _text; QPushButton _accept; QPushButton _cancel; QVBoxLayout _mainLayout; QHBoxLayout _logoLayout; QHBoxLayout _buttonLayout; QHBoxLayout _textLayout; this->_connectedContact = _contact; this->_receiveWin.setFixedSize(300, 350); _accept.setText("Accepter"); _cancel.setText("Annuler"); _logo.setPixmap(QPixmap(QCoreApplication::applicationDirPath() + "/ressources/Lreceive.png")); _logoLayout.setAlignment(Qt::AlignCenter); _logoLayout.addWidget(&_logo); _contact.append(" cherche à vous joindre ..."); _text.setText(_contact); _text.setAlignment(Qt::AlignCenter); _textLayout.addWidget(&_text); _cancel.setCursor(Qt::PointingHandCursor); _buttonLayout.setAlignment(Qt::AlignBottom); _buttonLayout.addWidget(&_accept); _buttonLayout.addWidget(&_cancel); _mainLayout.addLayout(&_logoLayout); _mainLayout.addLayout(&_textLayout); _mainLayout.addLayout(&_buttonLayout); this->_receiveWin.setLayout(&_mainLayout); this->_receiveWin.setWindowTitle("Appel en cours ..."); this->_receiveWin.setWindowIcon(QIcon(QCoreApplication::applicationDirPath() + "/ressources/babybel.png")); connect(&_accept, SIGNAL(clicked()), this, SLOT(acceptCall())); connect(&_cancel, SIGNAL(clicked()), this, SLOT(deniedCall())); this->_receiveWin.exec(); }
int main() { RCC_Config(); // to read and write to AFIO_remap AFIO_clock must first be eanble NVIC_Config(); TIM_Config(); GPIO_Config(); EXTI_Configuration(); initUsart(); //initBT(); // Only for debug the clock tree *********************************************** // Put the clock configuration into RCC_APB2PeriphClockCmd RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); /* Output clock on MCO pin ---------------------------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); // RCC_MCOConfig(RCC_MCO_HSE); // Put on MCO pin the: freq. of external crystal RCC_MCOConfig(RCC_MCO_SYSCLK); // Put on MCO pin the: System clock selected // //RTCInit(); RCC_GetClocksFreq(&RCC_Clocks); writeStringUSART2("\033[2J"); //clear usart 2 screen writeStringUSART1("\033[2J"); //clear usart 1 screen writeStringUSART1(" <<<<- Welcome To Hinkens Cobra Bluetooth ->>>>\n\n\r"); while(1) { if(GPIO_ReadInputDataBit(GPIOB, COBRA_BOARDSWITCH)== false) writeStringUSART1("On Hook\n\r"); else //Luren är lyft { writeStringUSART1("Phone is off hook!\n\r Dial: \n\r"); acceptCall(); //accept incoming call Delay(Delay_10ms); //for(counter = 0 ; counter < 10 ; counter++) while(TIM_GetITStatus(TIM2, TIM_IT_Update) == RESET) // { dialed_number = 0; while(GPIO_ReadInputDataBit(GPIOB, COBRA_DIALING)== true && GPIO_ReadInputDataBit(GPIOB, COBRA_BOARDSWITCH)== true)//Wait for user to start dialing { //writeStringUSART1("Timer Counter: %d\r\n",TIM_GetCounter(TIM2)); if(state == 1 && dialingFlag == true) //check if timer has run out and user has started a call { writeStringUSART1("time is up dialing number: "); for (int x = 0; x < counter; x++) { //printf("%d", number[x] ); } sendPhoneNumber(number, counter); writeStringUSART1("\r\n"); dialingFlag = false; state = 0; counter = 0; } } Delay(Delay_100ms); //Wait for switch to debounce while(GPIO_ReadInputDataBit(GPIOB, COBRA_DIALING) == false) { dialingFlag = true; state = 0; TIM_SetCounter(TIM2, 0); TIM_Cmd(TIM2, ENABLE); //Start timer //RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); Delay(Delay_10ms); Delay(Delay_10ms); //Now count how many times the mechnical switch toggles if(GPIO_ReadInputDataBit(GPIOB, COBRA_PULSE)== false && pulseFlag == 1) { pulseFlag = 0; dialed_number ++; } else if(GPIO_ReadInputDataBit(GPIOB, COBRA_PULSE) == true && pulseFlag == 0) { pulseFlag = 1; //Do notthing just idle.. } Delay(Delay_10ms); } Delay(Delay_100ms); if(dialed_number != 0) // to handle the error of a extra loop after dialed number { dialed_number--; //Rotary always has one extra closure that must be taken off number[counter] = dialed_number; counter ++; } if(GPIO_ReadInputDataBit(GPIOB, COBRA_BOARDSWITCH)== false) //Hunng upp { hangUp(); //hang-up command to bluettooh writeStringUSART1("Hung up!\n\r"); counter = 0; break; } //printf("%d\n\r", dialed_number); }//end for loop } Delay(Delay_100ms); }//end while(1) }//end main()
int main(int argc, char** argv) { #ifdef printauthor printf("artur goncalves, 69271\n"); #endif // printauthor if (argc < 3 || argc % 2 != 1) { printf("Usage: %s name.surname IP [-t talkport] [-d dnsport] [-i saIP] [-p saport]\n", argv[0]); exit(-2); } // Set default values for arguments myTalkPort = 30000; myDnsPort = 30000; saPort = 58000; saIP.s_addr = 0; myName = argv[1]; if (strstr(myName, ".") == NULL) { printf("Error on argument 'name.surname'. Must be separated by '.'\n"); exit(-2); } if (inet_aton(argv[2], &myIP) == 0) { perror("Error parsing argument IP. Should be on dot-decimal notation.\n"); exit(-2); } // Parse optional arguments int i; for (i = 3; i < argc - 1; i += 2) { if (strcmp(argv[i], "-t") == 0) myTalkPort = atoi(argv[i+1]); if (strcmp(argv[i], "-d") == 0) myDnsPort = atoi(argv[i+1]); if (strcmp(argv[i], "-i") == 0) { if (inet_aton(argv[i+1], &saIP) == 0) { perror("Error parsing saIP"); exit(-2); } } if (strcmp(argv[i], "-p") == 0) saPort = atoi(argv[i+1]); } // Get default IP if it has not been set if (saIP.s_addr == 0) getDefaultSS(&saIP); fd_set rfds; int ret; char buffer[2048]; buffer[2047] = '\0'; // Ensure buffer is always null-terminated. int max = 0; contacts = newList(); talkServerSocket = prepareTalkServer(); // Set handler the SIGINT (Ctrl+C) signal, which automatically leaves before terminating signal(SIGINT, sigintHandler); printPrompt(); // Run while in normal conditions, or while we're in the process of leaving and exiting while (isRunning || joinStatus != NotJoined) { FD_ZERO(&rfds); FD_SET(STDIN_FILENO, &rfds); max = (STDIN_FILENO > max) ? STDIN_FILENO : max; // Add different sockets to rfds if they are ready to be used /* Always add the TCP server socket for starting chats There's no problem if we're not even joined yet, the chats only depend on the rest of the program to find the IP+port. */ FD_SET(talkServerSocket, &rfds); max = (talkServerSocket > max) ? talkServerSocket : max; // Chat socket, possibly open with a contact if (talkSocket != -1) { FD_SET(talkSocket, &rfds); max = (talkSocket > max) ? talkSocket : max; } // DNS socket, used to trade behind-the-scenes messages like queries, etc if (dnsSocket != -1) { FD_SET(dnsSocket, &rfds); max = (dnsSocket > max) ? dnsSocket : max; } // Set timeout if state is not stable (if we are waiting for OKs, etc) struct timeval timeout; struct timeval* pTimeout = NULL; if ((joinStatus != Joined && joinStatus != NotJoined) || (findStatus != NotFinding)) { pTimeout = &timeout; timeout.tv_sec = 10; timeout.tv_usec = 0; } // Multiplex all possible inputs ret = select(max + 1, &rfds, NULL, NULL, pTimeout); if (ret < 0) { // If user pressed Ctrl+C (INTerRuption), don't leave the loop yet // We must wait the 'leave' messages and OKs to be sent // ...unless we are not joined to begin with if (errno == EINTR) { if (joinStatus == NotJoined) break; else continue; } perror("Error on select()"); exit(-1); } // Handle a timeout if (ret == 0) { if (joinStatus != Joined) { if (joinStatus < Joined) printf("Join timed out. Aborted join. Please try again.\n"); else printf("Leave timed out. Forced leave.\n"); logm(1, "Other members' state may be inconsistent. Sent UNR to Surname Server just in case.\n"); abortJoin(); } if (findStatus != NotFinding) { findStatus = NotFinding; printf("Find timed out. Find cancelled.\n"); } } // Read user commands from stdin if (FD_ISSET(STDIN_FILENO, &rfds)) { fgets(buffer, 2047, stdin); parseCommand(buffer, &isRunning); printPrompt(); } // Read messages from current call if (talkSocket != -1 && FD_ISSET(talkSocket, &rfds)) { receiveMessage(buffer); } // Accept an imcoming call from the Call Server if (talkServerSocket != -1 && FD_ISSET(talkServerSocket, &rfds)) { acceptCall(); } // Handle a query or reply on the DNS if (dnsSocket != -1 && FD_ISSET(dnsSocket, &rfds)) { parseServerCommand(&isRunning); } } // Loop ends when user wants to close program // Free memory emptyList(contacts); free(contacts); logm(1, "Exiting gracefully.\n"); exit(0); }