/*FUNCTION NAME:
  * connectESP
  *
  * DESCRIPTION:
  * This sets up a TCP connection to the local version of data.sparkfun.com.
  * Also tells the ESP how much char of data to send.
  *
  *
  * PARAMETERS:
  * None.
  *
  * RETURN VALUES:
  * 1 - if able to connect
  * 0 - if not able to connect
  */
boolean connectESP(){
	//get rid on any more Rx data and clear the buffer
    clearESPBuffer();
	Serial.println("Setting TCP connection");  //log the info
	Serial1.print("AT+CIPSTART=\"TCP\",\"10.77.133.44\",8080\r\n");   //set TCP connection to the server.
    //check whether you got OK
	if(checkResponse(OK,sizeof(OK),5000)){
	   Serial.println("TCP connection set with ESP"); //log the info
	}else{
	   Serial.println("TCP connection failed with ESP");  //log the info
	   return 0;
	}
	//get rid on any more Rx data and clear the buffer
	clearESPBuffer();

	//send the no of character to send
	Serial.println("Sending no of chars to send");   //log the info
    Serial1.print("AT+CIPSEND=");
    Serial1.print(payloadSize);  //for debuggin
    //int debugSize = 159;
    //Serial1.print(debugSize);
    Serial1.print("\r\n");
    //check whether you got >
	if(checkResponse(CARROT,sizeof(CARROT),5000)){
	   Serial.println("Got > ready to send data"); //log the info
	}else{
	   Serial.println("Didn't got > :(");  //log the info
	   return 0;
	}
	//get rid on any more Rx data and clear the buffer
	clearESPBuffer();
	return 1;


}
Example #2
0
void Client::unregister(const std::string& urn)
  throw (Exception, net::Exception)
{
  std::string address("localhost");
  _socket = new net::Socket(address, _port);

  iostream::XdrInputStream& istream = _socket->getXdrInputStream();
  iostream::XdrOutputStream& ostream = _socket->getXdrOutputStream();

  ostream.write(net::ProtocolHeader::NAME_SERVICE);
  ostream.write(net::ProtocolHeader::VERSION_1);
  ostream.write(net::MessageProtocol::UNREGISTER);
  ostream.write(urn);
  ostream.flush();

  try {
    checkResponse();
  } catch (Exception& ex) {
    delete _socket;
    throw ex;
  } catch (net::Exception& ex) { 
    delete _socket;
    throw ex;   
  }

  //  istream.flush();

  delete _socket;
}
Example #3
0
std::string Client::registerTechnique(TechniqueRecord& record)
  throw (Exception, net::Exception)
{
  std::string address("localhost");
  _socket = new net::Socket(address, _port);

  iostream::XdrInputStream& istream = _socket->getXdrInputStream();
  iostream::XdrOutputStream& ostream = _socket->getXdrOutputStream();

  ostream.write(net::ProtocolHeader::NAME_SERVICE);
  ostream.write(net::ProtocolHeader::VERSION_1);
  ostream.write(net::MessageProtocol::REGISTER_TECHNIQUE);
  record.encode(ostream);
  ostream.flush();

  try {
    checkResponse();
  } catch (Exception& ex) {
    delete _socket;
    throw ex;
  } catch (net::Exception& ex) { 
    delete _socket;
    throw ex;   
  }

  std::string result;
  istream.read(result);
  //  istream.flush();

  delete _socket;

  return result;
}
Example #4
0
void Client::getDomain(const std::string& urn)
  throw (Exception, net::Exception)
{
  std::string address("localhost");
  _socket = new net::Socket(address, _port);

  iostream::XdrInputStream& istream = _socket->getXdrInputStream();
  iostream::XdrOutputStream& ostream = _socket->getXdrOutputStream();

  ostream.write(net::ProtocolHeader::NAME_SERVICE);
  ostream.write(net::ProtocolHeader::VERSION_1);
  ostream.write(net::MessageProtocol::GET_ONTOLOGY);
  ostream.write(urn);
  ostream.flush();

  try {
    checkResponse();
  } catch (Exception& ex) {
    delete _socket;
    throw ex;
  } catch (net::Exception& ex) { 
    delete _socket;
    throw ex;   
  }

  ontologydto::DomainDTO* result = new ontologydto::DomainDTO(istream);
  //  istream.flush();

  delete _socket;
}
Example #5
0
std::string Client::getNames(const std::string& criteria)
  throw (Exception, net::Exception)
{
  std::string address("localhost");
  _socket = new net::Socket(address, _port);

  iostream::XdrInputStream& istream = _socket->getXdrInputStream();
  iostream::XdrOutputStream& ostream = _socket->getXdrOutputStream();

  ostream.write(net::ProtocolHeader::NAME_SERVICE);
  ostream.write(net::ProtocolHeader::VERSION_1);
  ostream.write(net::MessageProtocol::GET_NAMES);
  ostream.write(criteria);
  ostream.flush();

  try {
    checkResponse();
  } catch (Exception& ex) {
    delete _socket;
    throw ex;
  } catch (net::Exception& ex) { 
    delete _socket;
    throw ex;   
  }

  std::string result;
  istream.read(result);
  //  istream.flush();

  delete _socket;

  return result;
}
Example #6
0
std::string Client::registerDomain(ontologydto::DomainDTO& domain)
    throw (Exception, net::Exception)
{
  std::string address("localhost");
  _socket = new net::Socket(address, _port);

  iostream::XdrInputStream& istream = _socket->getXdrInputStream();
  iostream::XdrOutputStream& ostream = _socket->getXdrOutputStream();

  ostream.write(net::ProtocolHeader::NAME_SERVICE);
  ostream.write(net::ProtocolHeader::VERSION_1);
  ostream.write(net::MessageProtocol::REGISTER_ONTOLOGY);
  domain.encode(ostream);
  ostream.flush();

  try {
    checkResponse();

  } catch (Exception& ex) {
    delete _socket;
    throw ex;

  } catch (net::Exception& ex) {
    delete _socket;
    throw ex;
  }

  std::string result;
  istream.read(result);

  delete _socket;

  return result;
}
Example #7
0
void DlgCreateGame::actOK()
{
    Command_CreateGame cmd;
    cmd.set_description(descriptionEdit->text().simplified().toStdString());
    cmd.set_password(passwordEdit->text().toStdString());
    cmd.set_max_players(maxPlayersEdit->value());
    cmd.set_only_buddies(onlyBuddiesCheckBox->isChecked());
    cmd.set_only_registered(onlyRegisteredCheckBox->isChecked());
    cmd.set_spectators_allowed(spectatorsAllowedCheckBox->isChecked());
    cmd.set_spectators_need_password(spectatorsNeedPasswordCheckBox->isChecked());
    cmd.set_spectators_can_talk(spectatorsCanTalkCheckBox->isChecked());
    cmd.set_spectators_see_everything(spectatorsSeeEverythingCheckBox->isChecked());

    QMapIterator<int, QCheckBox *> gameTypeCheckBoxIterator(gameTypeCheckBoxes);
    while (gameTypeCheckBoxIterator.hasNext()) {
        gameTypeCheckBoxIterator.next();
        if (gameTypeCheckBoxIterator.value()->isChecked())
            cmd.add_game_type_ids(gameTypeCheckBoxIterator.key());
    }

    PendingCommand *pend = room->prepareRoomCommand(cmd);
    connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(checkResponse(Response)));
    room->sendRoomCommand(pend);

    buttonBox->setEnabled(false);
}
RemoteBlockReader::RemoteBlockReader(const ExtendedBlock& eb,
                                     DatanodeInfo& datanode,
                                     PeerCache& peerCache, int64_t start,
                                     int64_t len, const Token& token,
                                     const char* clientName, bool verify,
                                     SessionConfig& conf)
    : sentStatus(false),
      verify(verify),
      binfo(eb),
      datanode(datanode),
      checksumSize(0),
      chunkSize(0),
      position(0),
      size(0),
      cursor(start),
      endOffset(len + start),
      lastSeqNo(-1),
      peerCache(peerCache) {

    assert(start >= 0);
    readTimeout = conf.getInputReadTimeout();
    writeTimeout = conf.getInputWriteTimeout();
    connTimeout = conf.getInputConnTimeout();
    sock = getNextPeer(datanode);
    in = shared_ptr<BufferedSocketReader>(new BufferedSocketReaderImpl(*sock));
    sender = shared_ptr<DataTransferProtocol>(new DataTransferProtocolSender(
        *sock, writeTimeout, datanode.formatAddress()));
    sender->readBlock(eb, token, clientName, start, len);
    checkResponse();
}
static opvp_result_t CStubQueryColorSpace(opvp_dc_t printerContext,
    opvp_int_t *pnum, opvp_cspace_t *pcspace)
{
    int seqNo;
    void *vp;
    int rnum;
    int r = OPVP_OK;

    if (pnum == NULL) {
	opvpErrorNo = OPVP_PARAMERROR;
	return -1;
    }
    if ((seqNo = oprpc_putPktStart(rpcHandle, -1, RPCNO_QUERYCOLORSPACE)) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (oprpc_put(rpcHandle,printerContext) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (pcspace == NULL) *pnum = 0;
    if (oprpc_put(rpcHandle,*pnum) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (oprpc_putPktEnd(rpcHandle) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }

    if (checkResponse(seqNo,RPCNO_QUERYCOLORSPACE) < 0) {
	return -1;
    }
    if (oprpc_getInt(rpcHandle,&rnum) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (rnum <= *pnum && pcspace != NULL && *pnum > 0) {
	if (oprpc_getPktPointer(rpcHandle,&vp,
	      rnum*sizeof(opvp_cspace_t)) < 0) {
	    opvpErrorNo = OPVP_FATALERROR;
	    return -1;
	}
	memcpy(pcspace,vp,rnum*sizeof(opvp_cspace_t));
    }
    if (oprpc_getPktEnd(rpcHandle) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (rnum > *pnum) {
	opvpErrorNo = OPVP_PARAMERROR;
	r = -1;
    }
    *pnum = rnum;
    return r;
}
Example #10
0
void Client::addLocation(int techniqueId, const std::string& location)
  throw (Exception, net::Exception)
{
  std::string address("127.0.0.1");
  net::Socket socket(address, _port);

  checkResponse(socket);

  iostream::XdrOutputStream& ostream = socket.getXdrOutputStream();

  ostream.write(net::MessageProtocol::ADD_LOCATION);
  ostream.flush();

  ostream.write(techniqueId);
  ostream.write(location);
  ostream.flush();

  checkResponse(socket);
}
Example #11
0
static opvp_result_t CStubGetLineDash(opvp_dc_t printerContext,
    opvp_int_t *pnum, opvp_fix_t *pdash)
{
    int seqNo;
    void *vp;
    int rnum;
    int r = OPVP_OK;

    if (pnum == NULL) {
	opvpErrorNo = OPVP_PARAMERROR;
	return -1;
    }
    if ((seqNo = oprpc_putPktStart(rpcHandle, -1, RPCNO_GETLINEDASH)) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (oprpc_put(rpcHandle,printerContext) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (pdash == NULL) *pnum = 0;
    if (oprpc_put(rpcHandle,*pnum) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (oprpc_putPktEnd(rpcHandle) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }

    if (checkResponse(seqNo,RPCNO_GETLINEDASH) < 0) {
	return -1;
    }
    if (oprpc_get(rpcHandle,rnum) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (rnum <= *pnum && pdash != NULL && *pnum > 0) {
	if (oprpc_getPktPointer(rpcHandle,&vp,
	      rnum*sizeof(opvp_fix_t)) < 0) {
	    opvpErrorNo = OPVP_FATALERROR;
	    return -1;
	}
	memcpy(pdash,vp,rnum*sizeof(opvp_fix_t));
    } else {
	opvpErrorNo = OPVP_PARAMERROR;
	r = -1;
    }
    if (oprpc_getPktEnd(rpcHandle) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    *pnum = rnum;
    return r;
}
unsigned int modbus_update(Packet* packets) 
{
	// Initialize the connection_status variable to the
	// total_no_of_packets. This value cannot be used as 
	// an index (and normally you won't). Returning this 
	// value to the main skecth informs the user that the 
	// previously scanned packet has no connection error.
	
	unsigned int connection_status = total_no_of_packets;

  if (transmission_ready_Flag) 
	{
	
		static unsigned int packet_index;	
	
		unsigned int failed_connections = 0;
	
		unsigned char current_connection;
	
		do
		{		
		
			if (packet_index == total_no_of_packets) // wrap around to the beginning
				packet_index = 0;
		
			// proceed to the next packet
			packet = &packets[packet_index];
		
			// get the current connection status
			current_connection = packet->connection;
		
			if (!current_connection)
			{
				connection_status = packet_index;
			
				// If all the connection attributes are false return
				// immediately to the main sketch
				if (++failed_connections == total_no_of_packets)
					return connection_status;
			}
		
			packet_index++;
			
		}while (!current_connection); // while a packet has no connection get the next one
		
		constructPacket();
	}
    
	checkResponse();
	
  check_packet_status();	
	
	return connection_status; 
}
Example #13
0
std::string Client::nextLocation(int techniqueId)
{
  std::string address("127.0.0.1");
  net::Socket socket(address, _port);

  checkResponse(socket);

  iostream::XdrInputStream& istream = socket.getXdrInputStream();
  iostream::XdrOutputStream& ostream = socket.getXdrOutputStream();

  ostream.write(net::MessageProtocol::NEXT_LOCATION);
  ostream.flush();

  ostream.write(techniqueId);
  ostream.flush();

  checkResponse(socket);

  std::string result;
  istream.read(result);

  return result;
}
Example #14
0
static opvp_result_t CStubEndPage(opvp_dc_t printerContext)
{
    int seqNo;

    if ((seqNo = CStubDoSimple1(RPCNO_ENDPAGE,printerContext)) < 0) {
	return -1;
    }

    if (checkResponse(seqNo,RPCNO_ENDPAGE) < 0) {
	return -1;
    }
    if (oprpc_getPktEnd(rpcHandle) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    return OPVP_OK;
}
Example #15
0
void DlgCreateGame::actOK()
{
	Command_CreateGame *createCommand = new Command_CreateGame(
		roomId,
		descriptionEdit->text(),
		passwordEdit->text(),
		maxPlayersEdit->value(),
		spectatorsAllowedCheckBox->isChecked(),
		spectatorsNeedPasswordCheckBox->isChecked(),
		spectatorsCanTalkCheckBox->isChecked(),
		spectatorsSeeEverythingCheckBox->isChecked()
	);
	connect(createCommand, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
	client->sendCommand(createCommand);
	
	okButton->setEnabled(false);
	cancelButton->setEnabled(false);
}
Example #16
0
bool remove(net::MessageProtocol::Type messageType, int& id, int& port)
{
  std::string address("127.0.0.1");
  net::Socket socket(address, port);

  iostream::XdrOutputStream& ostream = socket.getXdrOutputStream();

  ostream.write(messageType);
  ostream.flush();

  ostream.write(id);
  ostream.flush();

  checkResponse(socket);

  // TODO: Implement better
  return true;
}
Example #17
0
template <class Param> int add(Param& instance, net::MessageProtocol::Type messageType, int& port)
{
  std::string address("127.0.0.1");
  net::Socket socket(address, port);

  iostream::XdrOutputStream& ostream = socket.getXdrOutputStream();

  ostream.write(messageType);
  ostream.flush();

  instance.encode(ostream);
  ostream.flush();

  checkResponse(socket);

  int resultId = 0;
  socket.getXdrInputStream().read(resultId);

  return resultId;
}
Example #18
0
static opvp_result_t CStubClosePrinter(opvp_dc_t printerContext)
{
    int seqNo;

    if ((seqNo = CStubDoSimple1(RPCNO_CLOSEPRINTER,printerContext)) < 0) {
	return -1;
    }

    if (checkResponse(seqNo,RPCNO_CLOSEPRINTER) < 0) {
	return -1;
    }
    if (oprpc_getPktEnd(rpcHandle) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (serverPid > 0) {
	kill(serverPid,SIGTERM);
	waitpid(serverPid,NULL,0);
    }
    return OPVP_OK;
}
Example #19
0
int KApiFetchObject::writeClient(const char *str, int len) {
	if (!headSended) {
		if (!TEST(rq->workModel, WORK_MODEL_MANAGE|WORK_MODEL_INTERNAL) 
			&& checkResponse(rq,sa.tr.obj) == JUMP_DENY) {
				responseDenied = true;
		}
	}
#ifdef ENABLE_TF_EXCHANGE
	if (!headSended && sa.tr.rq->tf) {
		sa.tr.rq->tf->init(-1);
	}
#endif
	headSended = true;
	if (responseDenied) {
		return 0;
	}
	if(sa.tr.getWStream()->write_all(str,len)){
		return len;
	}
	return 0;	
}
Example #20
0
static opvp_result_t CStubGetLineWidth(opvp_dc_t printerContext,
    opvp_fix_t *pwidth)
{
    int seqNo;

    if ((seqNo = CStubDoSimple1(RPCNO_GETLINEWIDTH,printerContext)) < 0) {
	return -1;
    }

    if (checkResponse(seqNo,RPCNO_GETLINEWIDTH) < 0) {
	return -1;
    }
    if (oprpc_get(rpcHandle,*pwidth) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (oprpc_getPktEnd(rpcHandle) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    return OPVP_OK;
}
Example #21
0
static opvp_result_t CStubGetAlphaConstant(opvp_dc_t printerContext,
    opvp_float_t *palpha)
{
    int seqNo;

    if ((seqNo = CStubDoSimple1(RPCNO_GETALPHACONSTANT,printerContext)) < 0) {
	return -1;
    }

    if (checkResponse(seqNo,RPCNO_GETALPHACONSTANT) < 0) {
	return -1;
    }
    if (oprpc_get(rpcHandle,*palpha) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (oprpc_getPktEnd(rpcHandle) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    return OPVP_OK;
}
Example #22
0
std::string Client::nextLocation(const std::string& urn)
{
  std::string address("localhost");
  _socket = new net::Socket(address, _port);

  iostream::XdrInputStream& istream = _socket->getXdrInputStream();
  iostream::XdrOutputStream& ostream = _socket->getXdrOutputStream();

  ostream.write(net::ProtocolHeader::NAME_SERVICE);
  ostream.write(net::ProtocolHeader::VERSION_1);
  ostream.write(net::MessageProtocol::NEXT_LOCATION);
  ostream.write(urn);
  ostream.flush();

  try {
    checkResponse();

  } catch (Exception& ex) {
    std::cout << "name exception" << std::endl;
    delete _socket;
    throw ex;

  } catch (net::Exception& ex) { 
    delete _socket;
    throw ex;   

  } catch (iostream::Exception& ex) {
    delete _socket;
    std::cout << "unknown" << std::endl;
  }

  std::string result;
  istream.read(result);
  //  istream.flush();

  delete _socket;

  return result;
}
Example #23
0
static opvp_result_t CStubDoSimpleGet(int reqNo, opvp_dc_t printerContext,
  void *parg, int arglen)
{
    int seqNo;

    if ((seqNo = CStubDoSimple1(reqNo,printerContext)) < 0) {
	return -1;
    }

    if (checkResponse(seqNo,reqNo) < 0) {
	return -1;
    }
    if (oprpc_getPkt(rpcHandle,parg,arglen) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (oprpc_getPktEnd(rpcHandle) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    return OPVP_OK;
}
Example #24
0
static opvp_result_t CStubGetMiterLimit(opvp_dc_t printerContext,
    opvp_fix_t *pmiterlimit)
{
    int seqNo;

    if ((seqNo = CStubDoSimple1(RPCNO_GETMITERLIMIT,printerContext)) < 0) {
	return -1;
    }

    if (checkResponse(seqNo,RPCNO_GETMITERLIMIT) < 0) {
	return -1;
    }
    if (oprpc_get(rpcHandle,*pmiterlimit) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (oprpc_getPktEnd(rpcHandle) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    return OPVP_OK;
}
Example #25
0
static opvp_result_t CStubGetLineDashOffset(opvp_dc_t printerContext,
    opvp_fix_t *poffset)
{
    int seqNo;

    if ((seqNo = CStubDoSimple1(RPCNO_GETLINEDASHOFFSET,printerContext)) < 0) {
	return -1;
    }

    if (checkResponse(seqNo,RPCNO_GETLINEDASHOFFSET) < 0) {
	return -1;
    }
    if (oprpc_get(rpcHandle,*poffset) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    if (oprpc_getPktEnd(rpcHandle) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    return OPVP_OK;
}
Example #26
0
void GameSelector::actJoin()
{
	bool spectator = sender() == spectateButton;
	
	QModelIndex ind = gameListView->currentIndex();
	if (!ind.isValid())
		return;
	const ServerInfo_Game &game = gameListModel->getGame(ind.data(Qt::UserRole).toInt());
	bool overrideRestrictions = !tabSupervisor->getAdminLocked();
	QString password;
	if (game.with_password() && !(spectator && !game.spectators_need_password()) && !overrideRestrictions) {
		bool ok;
		password = QInputDialog::getText(this, tr("Join game"), tr("Password:"******"Error"), tr("Please join the respective room first."));
		return;
	}
	
	PendingCommand *pend = r->prepareRoomCommand(cmd);
	connect(pend, SIGNAL(finished(Response, CommandContainer, QVariant)), this, SLOT(checkResponse(Response)));
	r->sendRoomCommand(pend);

	if (createButton)
		createButton->setEnabled(false);
	joinButton->setEnabled(false);
	spectateButton->setEnabled(false);
}
Example #27
0
static opvp_result_t CStubGetCTM(opvp_dc_t printerContext, opvp_ctm_t *pCTM)
{
    int seqNo;
    void *vp;

    if ((seqNo = CStubDoSimple1(RPCNO_GETCTM,printerContext)) < 0) {
	return -1;
    }

    if (checkResponse(seqNo,RPCNO_GETCTM) < 0) {
	return -1;
    }
    if (oprpc_getPktPointer(rpcHandle,&vp,sizeof(opvp_ctm_t)) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    memcpy(pCTM,vp,sizeof(opvp_ctm_t));
    if (oprpc_getPktEnd(rpcHandle) < 0) {
	opvpErrorNo = OPVP_FATALERROR;
	return -1;
    }
    return OPVP_OK;
}
Example #28
0
void GameSelector::actJoin()
{
	bool spectator = sender() == spectateButton;
	
	QModelIndex ind = gameListView->currentIndex();
	if (!ind.isValid())
		return;
	ServerInfo_Game *game = gameListModel->getGame(ind.data(Qt::UserRole).toInt());
	QString password;
	if (game->getHasPassword() && !(spectator && !game->getSpectatorsNeedPassword())) {
		bool ok;
		password = QInputDialog::getText(this, tr("Join game"), tr("Password:"), QLineEdit::Password, QString(), &ok);
		if (!ok)
			return;
	}

	Command_JoinGame *commandJoinGame = new Command_JoinGame(roomId, game->getGameId(), password, spectator);
	connect(commandJoinGame, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
	client->sendCommand(commandJoinGame);

	createButton->setEnabled(false);
	joinButton->setEnabled(false);
	spectateButton->setEnabled(false);
}
Example #29
0
bool retrieve(Param& instance, int& id, net::MessageProtocol::Type type, int& port)
{
  instance.clear();

  std::string address("127.0.0.1");
  net::Socket socket(address, port);

  iostream::XdrOutputStream& ostream = socket.getXdrOutputStream();

  ostream.write(type);
  ostream.flush();

  ostream.write(id);
  ostream.flush();

  checkResponse(socket);

  instance.clear();
  iostream::XdrInputStream& istream = socket.getXdrInputStream();
  instance.decode(istream);

  // TODO: Change this
  return true;
}
/*FUNCTION NAME:
  * sendData
  *
  * DESCRIPTION:
  * This is used to send data to the data.sparkfun.com(local version).
  * The data is sent from ESP.
  *
  *
  * PARAMETERS:
  * None.
  *
  * RETURN VALUES:
  * None
  */
void sendData(){
	counter=0;//keeps track of the payload size
	payloadSize=0;
	for(int i=0; i<(sizeof(thingsSpeakURL)-1); i++){
	   payload[payloadSize+i] = thingsSpeakURL[i];//build up the payload
	   counter++;
	}
	payloadSize = counter+payloadSize;

	//connect the ESP to server and proceed if successful
	if(connectESP()){
	//send the data
		Serial.println("Sending data of size: ");  //log the info
		Serial.print(payloadSize);                  //log the info
	//send data to the server
/*		for(int i=0; i<payloadSize; i++){
		   Serial1.print(payload[i]);
		   Serial.print(payload[i]);    //log the info
		}*/
/*		for(int i=0; i<150; i++){
				   Serial1.print(payload[i]);
				   Serial.print(payload[i]);    //log the info
				}
		Serial1.print("1.0\r\n\r\n");
		Serial.print("1.0\r\n\r\n");
*/
	//now I have f****d up this code and I am going vahiyaat se bhi vahiyyat jugaad.
	//see the tag no. and decide what you want to send.
	//doing juggad for the app again , don't know why the f*****g changes in the app are not working.
		// My mapping is
		// Levi's Jeans - oreo1
		// Wrogn shirt -  jam11
		// Arrow shirt - sauce
		// Leee shirt  - milk1
		//tag 1 Levi's Jeans.
		if(tagNo ==1){
		Serial.println("Sending Levi's Jeans");
		Serial.println("GET /input/L87zZE13dQu1wB3e3aoeH73rM4ZR?private_key=QQNPMndZ5rIyLaNWNZ4WuLGdY3Z0&kaand=green&phonenumber=12345&productname=oreo1&productprice=1999 HTTP/1.0\r\n\r\n");
		Serial1.println("GET /input/L87zZE13dQu1wB3e3aoeH73rM4ZR?private_key=QQNPMndZ5rIyLaNWNZ4WuLGdY3Z0&kaand=green&phonenumber=12345&productname=oreo1&productprice=1999 HTTP/1.0\r\n\r\n");
		}

		//tag 2 Wrogn Shirt
		if(tagNo ==2){
		Serial.println("Sending Wrogn shirt");
		Serial.println("GET /input/L87zZE13dQu1wB3e3aoeH73rM4ZR?private_key=QQNPMndZ5rIyLaNWNZ4WuLGdY3Z0&kaand=green&phonenumber=12345&productname=jam11&productprice=2499 HTTP/1.0\r\n\r\n");
	    Serial1.println("GET /input/L87zZE13dQu1wB3e3aoeH73rM4ZR?private_key=QQNPMndZ5rIyLaNWNZ4WuLGdY3Z0&kaand=green&phonenumber=12345&productname=jam11&productprice=2499 HTTP/1.0\r\n\r\n");
		}


	    //tag 3 Arrow Shirt
		if(tagNo ==3){
	    Serial.println("Sending Arrow shirt");
	    Serial.println("GET /input/L87zZE13dQu1wB3e3aoeH73rM4ZR?private_key=QQNPMndZ5rIyLaNWNZ4WuLGdY3Z0&kaand=green&phonenumber=12345&productname=sauce&productprice=3999 HTTP/1.0\r\n\r\n");
	    Serial1.println("GET /input/L87zZE13dQu1wB3e3aoeH73rM4ZR?private_key=QQNPMndZ5rIyLaNWNZ4WuLGdY3Z0&kaand=green&phonenumber=12345&productname=sauce&productprice=3999 HTTP/1.0\r\n\r\n");
		}


	    //tag 4 Leee Shirt
		if(tagNo ==4){
	    Serial.println("Sending Leeee shirt");
	    Serial.println("GET /input/L87zZE13dQu1wB3e3aoeH73rM4ZR?private_key=QQNPMndZ5rIyLaNWNZ4WuLGdY3Z0&kaand=green&phonenumber=12345&productname=milk1&productprice=1499 HTTP/1.0\r\n\r\n");
	    Serial1.println("GET /input/L87zZE13dQu1wB3e3aoeH73rM4ZR?private_key=QQNPMndZ5rIyLaNWNZ4WuLGdY3Z0&kaand=green&phonenumber=12345&productname=milk1&productprice=1499 HTTP/1.0\r\n\r\n");
		}
	    //debugging for now
	    //check whether you got success
		if(checkResponse(SUCCESS,sizeof(SUCCESS),15000)){
		   Serial.println("Data sent to server"); //log the info
		}else{
		   Serial.println("Data not sent to server");  //log the info
		}
		//get rid on any more Rx data and clear the buffer
		clearESPBuffer();

	//	delay(15000);
		//reducing the delay now to 1 sec.
		delay(1000);
		printESPBuffer(); //print all what you are getting

	}

}