void ClientSocket::readClient() { QDataStream in(this); in.setVersion(QDataStream::Qt_4_7); if (nextBlockSize == 0) { if (bytesAvailable() < sizeof(quint16)) return; in >> nextBlockSize; } if (bytesAvailable() < nextBlockSize) return; quint8 requestType = 0; in >> requestType; if (requestType == 'O') { readOrder(in); } /* else if (requestType == 'R') { qDebug() << "register"; readRegistration(in); }*/ close(); }
void sendOrder(int fdw,porder po) { data sbuf; memset(&sbuf,0,sizeof(sbuf)); po->infolen = strlen(po->info); readOrder(po->info,po->infolen,po); //send order to server sbuf.len = sizeof(*po); memcpy(sbuf.buf,(char*)po,sbuf.len); sendN(fdw,(char*)&sbuf,sbuf.len+sizeof(sbuf.len)); // printf("len = %d\nbuf = %s\n",sbuf.len,sbuf.buf); }
void ClientInvade::readOrder(QTcpSocket * clientConnection) { QDataStream in(clientConnection); in.setVersion(QDataStream::Qt_4_0); if (blockSize_ == 0) { if (clientConnection->bytesAvailable() < (int)sizeof(quint16)) { return; } in >> blockSize_; } if (clientConnection->bytesAvailable() < blockSize_) { return; } blockSize_ = 0; QByteArray block; in >> block; QJsonParseError error; QJsonDocument d = QJsonDocument::fromJson(block, &error); if( error.error != QJsonParseError::ParseError::NoError ) { qDebug() << error.errorString(); return; } if( !d.isObject() ) { qDebug() << "Le json recu n'est pas valide"; return; } receiveOrder( d.object() ); readOrder(clientConnection); }
void CommunicationManager::update() { // On regarde si un socket envoie des données if (m_selector.wait()) { // On regarde si c'est une nouvelle connection if (m_selector.isReady(m_listener)) { Client *client = new Client(""); if (m_listener.accept(client->socket()) == sf::Socket::Done) { m_clients.push_back(client); clientJoined(client); //On ajoute le nouveau client au selector m_selector.add(client->socket()); sf::Packet packet; packet << "whoAreYou"; client->socket().send(packet); } } else { // On test chaque socket pour récupérer les données for (std::list<Client*>::iterator it = m_clients.begin(); it != m_clients.end(); ++it) { if (m_selector.isReady((*it)->socket())) { sf::Packet packet; if ((*it)->socket().receive(packet) == sf::Socket::Done) readOrder((*it), packet); } } } } }
int main(void) { int cam_mode,cam_x1,cam_y1,cam_width,cam_heigth,cam_zx,cam_zy; if(getSelector() == 0) return; char c; int i;//buff_length; //int wait_cam; //defining the position of the several inputs and outputs (motors are outputs) in the respective SFR //the SFR are programed as structures, so accessing to an input/output implies only acessing to the field of the structure corresponding to the SFR that was //assigned to that input/output (see epuck_ports.h and p30f6014.h to understand the SFR assignment) e_init_port(); e_init_motors(); //important to enable uart interface e_init_uart1(); e_init_ad_scan(ALL_ADC); e_calibrate_ir(); //initial configuration of the camera cam_x1=(ARRAY_WIDTH/Z_WIDTH-WIDTH)/2; cam_y1=(ARRAY_HEIGHT/Z_HEIGHT-HEIGHT)/2; cam_width=WIDTH; cam_heigth=HEIGHT; cam_zx=Z_WIDTH; cam_zy=Z_HEIGHT; cam_mode=MODE; if(cam_mode==GREY_SCALE_MODE) cam_size=cam_width*cam_heigth; else cam_size=cam_width*cam_heigth*2; //not waiting for camera wait_cam=0; e_activate_agenda(updateFlag, 500);//500//1000 e_activate_agenda(readValues, 10); e_start_agendas_processing(); keepFinding = 0; e_set_led(4,1); keepFinding = 1; int s = getSelector(); while(s==getSelector()); /*while(1){ sprintf(b1,"%i\n",e_get_calibrated_prox(S_FRONT_LEFT)); e_send_uart1_char(b1,10); while(e_uart1_sending()); }*/ while(1){ while(keepFinding) { if(!cameraOn) { startCamera(); correctRobot(); } while(!captura()); //e_send_uart1_char(buffer,buff_length); //while(e_uart1_sending()); if(cameraOn > 5) processaImagem(); cameraOn++; } if(cameraOn) stopCamera(); while(!flag); flag = 0; sendInputs(); readOrder(); readOrder(); e_set_speed_left(speedLeft); e_set_speed_right(speedRight); e_set_led(4,0); } return 0; }
void ClientInvade::readyRead() { readOrder(qobject_cast<QTcpSocket *>(sender())); }