Example #1
0
unsigned long OMAxis::getStepsMoved() {
    int res = command(m_slaveAddr, OM_PCODE_PC, CMD_PC_STATUS_REQ, OM_STAT_MOVED);
    
    unsigned long ret = 0;
    
    if( res && responseType() != -1 && responseLen() > 3 ) {
        uint8_t* data = (uint8_t*) responseData();
        ret = ntoul(data);
    }
    
    return ret;    
}
Example #2
0
long OMAxis::getHomeDistance() {
    int res = command(m_slaveAddr, OM_PCODE_PC, CMD_PC_STATUS_REQ, OM_STAT_HOMEDIST);
    
    long ret = 0;
    
    if( res && responseType() != -1 && responseLen() > 3 ) {
        uint8_t* data = (uint8_t*) responseData();
        ret = ntol(data);
    }
    
    return ret;      
}
Example #3
0
/** Status: Timing Master
 
 @return
 Timing master value
 */
bool OMAxis::getMaster() {
    int res = command(m_slaveAddr, OM_PCODE_PC, CMD_PC_STATUS_REQ, OM_STAT_MASTER);
    
    bool ret = 0;
    
    if( res && responseType() != -1 && responseLen() > 0 ) {
        uint8_t* data = (uint8_t*) responseData();
        ret = data[0];
    }
    
    return ret;    
}
Example #4
0
/** Status: Firmware Version
 
 Retrieve the firmware version.
 
 @return
 The firmware version #
 */
uint8_t OMAxis::getFWVersion() {
    int res = command(m_slaveAddr, OM_PCODE_PC, CMD_PC_STATUS_REQ, OM_STAT_FWVER);
    
    uint8_t ret = 0;
    
    if( res && responseType() != -1 && responseLen() > 0 ) {
        uint8_t* data = (uint8_t*) responseData();
        ret = data[0];
    }
    
    return ret;
}
int OMMoCoMaster::getVersion(uint8_t p_addr) {

	if (command(p_addr, (uint8_t) OM_SER_BASECOM, (uint8_t) OM_SER_COREVER)	!= 1)
		return (-1);

	if (responseLen() > 0) {
		int ver = ntoi((uint8_t*) responseData());
		return (ver);
	}

	return (0);

}
Example #6
0
unsigned int OMAxis::getSteps() {
    int res = command(m_slaveAddr, OM_PCODE_PC, CMD_PC_STATUS_REQ, OM_STAT_STEPS);
    
    unsigned int ret = 0;
    
    if( res && responseType() != -1 && responseLen() > 1 ) {
        uint8_t* data = (uint8_t*) responseData();
        ret = ntoui(data);
    }
    
    return ret;        
 
}
Example #7
0
uint8_t OMAxis::getBacklash() {
    int res = command(m_slaveAddr, OM_PCODE_PC, CMD_PC_STATUS_REQ, OM_STAT_BACKLASH);
    
    bool ret = 0;
    
    if( res && responseType() != -1 && responseLen() > 0 ) {
        uint8_t* data = (uint8_t*) responseData();
        ret = data[0];
    }
    
    return ret;
   
}
Example #8
0
void
ManagerBase::sendNack(const Name& name)
{
  NFD_LOG_DEBUG("responding NACK to " << name);

  ndn::MetaInfo meta;
  meta.setType(tlv::ContentType_Nack);

  shared_ptr<Data> responseData(make_shared<Data>(name));
  responseData->setMetaInfo(meta);

  m_keyChain.sign(*responseData);
  m_face->putData(*responseData);
}
void VBentoMessageInputThread::_handleNoMessageHandler(VMessagePtr message) {
    VBentoNode responseData("response");
    responseData.addInt("result", -1);
    responseData.addString("error-message", VSTRING_FORMAT("Invalid message ID %d. No handler defined.", (int) message->getMessageID()));

    VString bentoText;
    responseData.writeToBentoTextString(bentoText);
    VLOGGER_NAMED_ERROR(mLoggerName, VSTRING_FORMAT("[%s] Error Reply: %s", mName.chars(), bentoText.chars()));

    VMessagePtr response = mMessageFactory->instantiateNewMessage();
    responseData.writeToStream(*response);
    VBinaryIOStream io(mSocketStream);
    response->send(mName, io);
}
char* OMMoCoMaster::getId(uint8_t p_addr) {

	char* dat = 0;

	if (command(p_addr, (uint8_t) OM_SER_BASECOM, (uint8_t) OM_SER_COREID) != 1)
		return (dat);

	if (responseLen() > 0) {
		char* dat = responseData();
		return (dat);
	}

	return (dat);

}
Example #11
0
void MQTT::messageReceived(std::vector<char>& message)
{
	try
	{
		BaseLib::PVariable result = _jsonDecoder->decode(message);
		std::string methodName;
		std::string clientId;
		int32_t messageId = 0;
		BaseLib::PVariable parameters;
		if(result->type == BaseLib::VariableType::tStruct)
		{
			if(result->structValue->find("method") == result->structValue->end())
			{
				_out.printWarning("Warning: Could not decode JSON RPC packet from MQTT payload.");
				return;
			}
			methodName = result->structValue->at("method")->stringValue;
			if(result->structValue->find("id") != result->structValue->end()) messageId = result->structValue->at("id")->integerValue;
			if(result->structValue->find("clientid") != result->structValue->end()) clientId = result->structValue->at("clientid")->stringValue;
			if(result->structValue->find("params") != result->structValue->end()) parameters = result->structValue->at("params");
			else parameters.reset(new BaseLib::Variable());
		}
		else
		{
			_out.printWarning("Warning: Could not decode MQTT RPC packet.");
			return;
		}
		GD::out.printInfo("Info: MQTT RPC call received. Method: " + methodName);
		BaseLib::PVariable response = GD::rpcServers.begin()->second.callMethod(methodName, parameters);
		std::shared_ptr<std::pair<std::string, std::vector<char>>> responseData(new std::pair<std::string, std::vector<char>>());
		_jsonEncoder->encodeMQTTResponse(methodName, response, messageId, responseData->second);
		responseData->first = (!clientId.empty()) ? clientId + "/rpcResult" : "rpcResult";
		queueMessage(responseData);
	}
	catch(const std::exception& ex)
	{
		_out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
	}
	catch(BaseLib::Exception& ex)
	{
		_out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
	}
	catch(...)
	{
		_out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
	}
}
Example #12
0
void
ManagerBase::sendResponse(const Name& name,
                          const ControlResponse& response)
{
  NFD_LOG_DEBUG("responding"
                << " name: " << name
                << " code: " << response.getCode()
                << " text: " << response.getText());

  const Block& encodedControl = response.wireEncode();

  shared_ptr<Data> responseData(make_shared<Data>(name));
  responseData->setContent(encodedControl);

  m_keyChain.sign(*responseData);
  m_face->putData(*responseData);
}
void VBentoMessageInputThread::_callProcessMessage(VMessageHandler* handler) {
    try {
        VMessageInputThread::_callProcessMessage(handler);
    } catch (const std::exception& ex) {
        VBentoNode responseData("response");
        responseData.addInt("result", -1);
        responseData.addString("error-message", VSTRING_FORMAT("An error occurred processing the message: %s", ex.what()));

        VString bentoText;
        responseData.writeToBentoTextString(bentoText);
        VLOGGER_NAMED_ERROR(mLoggerName, VSTRING_FORMAT("[%s] Error Reply: %s", mName.chars(), bentoText.chars()));

        VMessagePtr response = mMessageFactory->instantiateNewMessage();
        responseData.writeToStream(*response);
        VBinaryIOStream io(mSocketStream);
        response->send(mName, io);
    }
}
Example #14
0
int
do_lq_request(struct lq_info *info, const char *vm_name,
	      const char *action)
{
	std::string vm_state;
	const char *property = "name";
	if (is_uuid(vm_name) == 1) {
		property = "uuid";
	}
	
	qmf::ConsoleSession session(lq_open_session(info));
	if (!session.isValid()) {
		std::cout << "Invalid session." << std::endl;
		return 1;
	}

	qmf::Agent agent;
	qmf::Data domain;
	int result;

	unsigned tries = 0;
	bool found = false;
	while (++tries < 10 && !found) {
		sleep(1);

		uint32_t numAgents = session.getAgentCount();
		for (unsigned a = 0; !found && a < numAgents; a++) {
			agent = session.getAgent(a);

			qmf::ConsoleEvent event(queryDomain(agent));
			uint32_t numDomains = event.getDataCount();
			for (unsigned d = 0; !found && d < numDomains; d++) {
				domain = event.getData(d);
				qpid::types::Variant prop;
				try {
					prop = domain.getProperty(property);
				} catch (qmf::KeyNotFound e) {
					std::cout << e.what() << " - skipping" << std::endl;
					continue;
				}

				if (prop.asString() != vm_name) {
					continue;
				}

				found = true;
			}
		}
	}

	if (!found) {
		result = 1;
		goto out;
	}

	vm_state = domain.getProperty("state").asString();

	std::cout << vm_name << " " << vm_state << std::endl;

	int r;
	if (vm_state == "running" ||
	    vm_state == "idle" ||
	    vm_state == "paused" ||
	    vm_state == "no state") {
		r = RESP_OFF;
	} else {
		r = 0;
	}

	if (strcasecmp(action, "state") == 0) {
		result = r;
		goto out;
	}

	result = 1;
	if (!r && strcasecmp(action, "destroy") == 0) {
		std::cout << "Domain is inactive; nothing to do" << std::endl;
		result = 0;
		goto out;
	}
	if (r && strcasecmp(action, "create") == 0) {
		std::cout << "Domain is active; nothing to do" << std::endl;
		result = 0;
		goto out;
	}

	{
		qmf::ConsoleEvent response;
		response = agent.callMethod(action,
				qpid::types::Variant::Map(),
				domain.getAddr());

		if (response.getType() == qmf::CONSOLE_EXCEPTION) {
			std::string errorText;
			if (response.getDataCount()) {
				qmf::Data responseData(response.getData(0));

				qpid::types::Variant code(responseData.getProperty("error_code"));
				if (code.getType() == qpid::types::VAR_INT32) {
					result = responseData.getProperty("error_code").asInt32();
				} else {
					result = 7; // Exception
				}
				qpid::types::Variant text(responseData.getProperty("error_text"));
				if (text.getType() != qpid::types::VAR_VOID) {
					errorText = text.asString();
				}
			} else {
				result = 7; // Exception
			}

			std::cout << "Response: " << result;
			if (errorText.length()) {
				std::cout << " (" << errorText << ")";
			}
			std::cout << std::endl;
		} else { // Success
			result = 0;
		}
	}

out:
	session.close();

	return result;
}