int addCity(char *extendedArgs, int pid, char *password) { pOutbound request = malloc(sizeof(Outbound)); pInbound response; unsigned long len; len = strlen(extendedArgs)+1; request->len = len; request->pid = pid; request->userLevel = 1; request->jobRef = 3; request->nArgs = 1; strcpy(request->pw,password); request->args = extendedArgs; response = startCommunication(request,pid); free(request); request = NULL; if(response->valid == 1) { printf("City added: %s.\n", request->args); return 1; } else { printf("Error: adding city. Check if the city you specified is already in the system.\n"); } return 0; }
int addFlight(char *extendedArgs, int pid, char *password) { pOutbound request = malloc(sizeof(Outbound)); pInbound response; unsigned long len; len = strlen(extendedArgs)+1; request->len = len; request->pid = pid; request->userLevel = 1; request->jobRef = 6; request->nArgs = 4; strcpy(request->pw,password); request->args = extendedArgs; response = startCommunication(request,pid); free(request); request = NULL; if(response->valid == 1) { printf("Flight added!\n"); return 1; } else { printf("Error: adding flight. Invalid cities, wrong ID or invalid date\n"); } return 0; }
int delCity(char *extendedArgs, int pid, char *password) { pOutbound request = malloc(sizeof(Outbound)); pInbound response; unsigned long len; len = strlen(extendedArgs)+1; request->len = len; request->pid = pid; request->userLevel = 1; request->jobRef = 4; request->nArgs = 1; strcpy(request->pw,password); request->args = extendedArgs; response = startCommunication(request,pid); free(request); request = NULL; if(response->valid == 1) { printf("City removed: %s.\n", request->args); return 1; } else { printf("Error: removing city. City does not exists or Check if there is some flight using this city as departure or arrival.\n"); } return 0; }
int addUser(char *extendedArgs, int pid, char *password) { pOutbound request = malloc(sizeof(Outbound)); pInbound response; unsigned long len; len = strlen(extendedArgs)+1; request->len = len; request->pid = pid; request->userLevel = 1; request->jobRef = 11; request->nArgs = 2; strcpy(request->pw,password); request->args = extendedArgs; free(request); request = NULL; response = startCommunication(request,pid); if(response->valid == 1) { printf("User added!\n"); return 1; } else { printf("Error: inserting user. Check if the username you specified is already in use\n"); } return 0; }
int changeDate(char *extendedArgs, int pid, char *password) { pOutbound request = malloc(sizeof(Outbound)); pInbound response; unsigned long len; len = strlen(extendedArgs)+1; request->len = len; request->pid = pid; request->userLevel = 1; request->jobRef = 8; request->nArgs = 1; strcpy(request->pw,password); request->args = extendedArgs; response = startCommunication(request,pid); free(request); request = NULL; if(response->valid == 1) { printf("Date: updated!\n"); return 1; } else { printf("Error: changing date. Invalid date or permission file problem\n"); } return 0; }
int delFlight(char *extendedArgs, int pid, char *password) { pOutbound request = malloc(sizeof(Outbound)); pInbound response; unsigned long len; len = strlen(extendedArgs)+1; request->len = len; request->pid = pid; request->userLevel = 1; request->jobRef = 7; request->nArgs = 1; strcpy(request->pw,password); request->args = extendedArgs; response = startCommunication(request,pid); free(request); request = NULL; if(response->valid == 1) { printf("Flight removed!\n"); return 1; } else { printf("Error: removing flight. Check if the Flight ID you specified is valid.\n"); } return 0; }
void SerialPortHandler::createSerialPortCommunicator() { try{ this->serial = new LagTestSerialPortComm( this->port, 115200, this->tm, this->clock_storage, this->adc_storage ); // Setup period query for arduino clock this->timer = new QTimer(this); connect(timer, SIGNAL(timeout()), serial, SLOT(sendClockRequest())); timer->setInterval(requestPeriod); this->thread = new QThread(); serial->moveToThread(thread); connect(thread, SIGNAL(started()), serial, SLOT(startCommunication())); connect(serial, SIGNAL(finished()), this, SLOT(onThreadQuit())); connect(serial, SIGNAL(finished()), serial, SLOT(deleteLater())); //Forward signals connect(serial, SIGNAL(sendDebugMsg(QString)), this, SIGNAL(sendDebugMsg(QString)) ); connect(serial, SIGNAL(sendErrorMsg(QString)), this, SIGNAL(sendErrorMsg(QString)) ); connect(serial, SIGNAL(sendFirmwareVersion(int)), this, SIGNAL(sendFirmwareVersion(int)) ); connect(serial, SIGNAL(sendArduinoTimeout()), this, SIGNAL(sendArduinoTimeout()) ); connect(serial, SIGNAL(sendArduinoDetectionFailed()), this, SIGNAL(sendArduinoDetectionFailed()) ); //This is not working, dont know why, cant get signal through to the slot // connect(this, SIGNAL(sendVersionCheck()), serial, SLOT(doVersionCheck()) ); // connect(this, SIGNAL(sendVersionCheck()), serial, SLOT(doSomethingElse()) ); // connect(this, SIGNAL(sendVersionCheck()), qApp, SLOT(aboutQt())); } catch (exception &e){ //qCritical("Connecting to the lagtest serial board failed!"); this->sendErrorMsg("Connecting to the lagtest serial board failed!"); throw e; } }
void MainWindow::eventStartStop() { if (isStart == false && mSerialPort->currentText()!="") { qDebug()<<"MainWindow::eventStartStop start"; if (startCommunication()==false) { return; } setStartStopButton(tr("Stop communication"), *iconStop); isStart = true; } else { qDebug()<<"MainWindow::eventStartStop stop"; setStartStopButton(tr("Start communication"), *iconStart); stopCommunication(); isStart = false; } }
void main() { startServer("Server.exe", NULL); startCommunication(); startClients(); printf("LOADER: Loader Exiting.\n"); }
void NetServerCom::startListening() { QString ip = Sett::ings().getString("net/myip"); int port = Sett::ings().getInt("net/mynextfreeport"); Sett::ings().setInt("net/mynextfreeport", port+1); server = new QTcpServer(this); connect(server, SIGNAL(newConnection()), this, SLOT(startCommunication())); if (!server->listen(QHostAddress(ip),port)) { return; } }
void mainApp::start() { //Start a thread and execute doProcessing() QThread* thread = new QThread(); LagTestSerialPortComm* serial = new LagTestSerialPortComm( 115200 ); serial->moveToThread(thread); //connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString))); connect(thread, SIGNAL(started()), serial, SLOT(startCommunication())); connect(serial, SIGNAL(finished()), this, SLOT(onThreadQuit())); connect(serial, SIGNAL(finished()), serial, SLOT(deleteLater())); //connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start(); }
int shutdown(int pid, char *password) { pOutbound request = malloc(sizeof(Outbound)); pInbound response; request->len = 0; request->pid = pid; request->userLevel = 1; request->jobRef = 2; strcpy(request->pw,password); response = startCommunication(request,pid); free(request); request = NULL; return 0; }
YarsControlWidget::YarsControlWidget(QWidget *parent) : QWidget(parent) { QGroupBox *buttonGroup = new QGroupBox("yars control", this); QVBoxLayout *layout = new QVBoxLayout; QPushButton *start = new QPushButton("start"); QPushButton *stop = new QPushButton("stop"); QPushButton *quit = new QPushButton("quit"); layout->addWidget(start); layout->addWidget(stop); layout->addWidget(quit); buttonGroup->setLayout(layout); YarsClientControl *ycc = YarsClientControl::instance(); connect(start, SIGNAL(clicked()), ycc, SLOT(startCommunication())); connect(stop, SIGNAL(clicked()), ycc, SLOT(stopCommunication())); connect(quit, SIGNAL(clicked()), ycc, SLOT(quitYars())); }
int logout(int *validLogin, int pid, char *password) { pOutbound request = malloc(sizeof(Outbound)); pInbound response; request->len = 0; request->pid = pid; request->userLevel = 1; request->jobRef = 12; strcpy(request->pw,password); response = startCommunication(request,pid); free(request); request = NULL; if(response->valid == 1) { validLogin = 0; return 1; } return 0; }
int getDate(int pid, char *password) { pOutbound request = malloc(sizeof(Outbound)); pInbound response; request->len = 0; request->pid = pid; request->userLevel = 1; request->jobRef = 9; strcpy(request->pw,password); response = startCommunication(request,pid); free(request); request = NULL; if(response->valid > 0) { printf("Date: %d\n", response->valid); return 1; } else return 0; }
int logIn(int sockFd) { /** Asks client to provide credentials to log in with. Return: 1, if log in is successful -1, if there's some error **/ //printf("In logIn\n"); char sendMsg[MAXLINE], recvMsg[MAXLINE]; char welcome[MAXLINE] = "WELCOME "; int n, i, k, count = 0, wrong = 0; int logout; bzero(&recvMsg, MAXLINE); bzero(&sendMsg, MAXLINE); // server asking for credentials to log in //printf("server asking for credentials to log in\n"); if((n = read(sockFd, recvMsg, MAXLINE)) < 0) printError('w'); if(n == 0) printError('t'); if(strlen(recvMsg) == 0) { fputs("Server not responding. Closing connection.", stdout); exit(1); } printf("\nServer :\n%s\n", recvMsg); printf("\nClient : \n"); fgets(sendMsg, MAXLINE, stdin); // providing log in credentials if((n = write(sockFd, sendMsg, MAXLINE)) < 0) printError('w'); if(n == 0) printError('t'); bzero(&recvMsg, MAXLINE); if((n = read(sockFd, recvMsg, MAXLINE)) < 0) printError('r'); if(n == 0) printError('t'); printf("\n%s\n\n", recvMsg); // matching the welcome message and id k = strlen(welcome); for(i = 0; sendMsg[i] != ' '; ++i, ++k) welcome[k] = sendMsg[i]; welcome[k] = '\0'; if(strcmp(welcome, recvMsg) != 0) wrong = 1; // begin operation if(!wrong) logout = startCommunication(sockFd); else logout = -1; return logout; }