コード例 #1
0
ファイル: systemerror.cpp プロジェクト: jouven/cxxtools
SymbolNotFound::SymbolNotFound(const std::string& sym)
: SystemError(0, "symbol not found: " + sym),
  _symbol(sym)
{
  log_finer("symbol " << sym << " not found; " << what());
}
コード例 #2
0
ファイル: systemerror.cpp プロジェクト: jouven/cxxtools
OpenLibraryFailed::OpenLibraryFailed(const std::string& msg)
: SystemError(msg)
{
  log_finer("open library failed: " << what());
}
コード例 #3
0
ファイル: systemerror.cpp プロジェクト: jouven/cxxtools
SystemError::SystemError(const char* fn, const std::string& what)
: std::runtime_error(fn && fn[0] ? (std::string("function ") + fn + " failed: " + what) : what),
  m_errno(0)
{
  log_finer("system error: " << std::exception::what());
}
コード例 #4
0
ファイル: systemerror.cpp プロジェクト: jouven/cxxtools
SystemError::SystemError(const char* fn)
: std::runtime_error(getErrnoString(fn)),
  m_errno(errno)
{
  log_finer("system error: " << what());
}
コード例 #5
0
ファイル: systemerror.cpp プロジェクト: jouven/cxxtools
SystemError::SystemError(const std::string& msg)
: std::runtime_error(msg),
  m_errno(0)
{
  log_finer("system error: " << what());
}
コード例 #6
0
/**
 * Decode a header version 1.
 * Reads parts of the message from the medium using recv_int().
 */
int decode_header(int first) {
	log_finer("decoding message header ...");

	// set type as specified in protocol version 1
	first = fmod(first, pow(2, 24));
	int type = floor(first / pow(2, 20));

	log_finest("message type: %d", type);

	// set id as specified in protocol version 1
	first = fmod(first, pow(2, 20));
	int id = floor(first / pow(2, 16));

	log_finest("target id   : %d", id);

	// the last two bytes mark the size of this frame
	int size = fmod(first, pow(2, 16));
	log_finest("payload size: %d", size);

	// 8 bit protocol version
	// 4 bit message type
	// 4 bit component identifier
	// 16 bit size or value, depending on type
	// <size> bytes data, depending on type

	// perform actions, depending on the message type
	switch(type) {
	case  reset: // This is a soft reset.
		     // Clear all queues and propagate a hardware reset.
		     // Afterwards, answer with a reset type message to acknowledge successful reset.
		break;
		// 1-6 are not assigned
	case  debug: // This is an error message.
		     // By design, error messages should only be sent by the server.
		     // Consequently, receiving such a message is an error ;)
		break;
	case  data: // This is a blocking data package.
		if(size > 0) {
			// the size is given in byte
			int payload[size];

			log_finer("reading payload ...");

			// read <size> bytes
			int i;
			for(i = 0; i < size; i++) {
				payload[i] = medium_recv_int();
				log_finest("value %d: %d", i, payload[i]);
			}

			recv_message(id, payload, size);
		}
		break;
	case poll: // This is a poll. Receiving a poll from the client means reading <size> values from out-going port <id>.
        pollCount[id] += size;
		break;
	case gpio: // This marks a GPIO message. We need to switch over the target component.
#if gpi_count > 0 || gpo_count > 0
	    gpio_write(id, size);
#endif
	case ack: // This is an acknowledgement.
		      // By design, acks should only be sent by the server.
		      // Consequently, receiving such a message is an error ;)
		break;
	default:
		log_warn("WARNING: unknown type %d for protocol version 1. The frame will be ignored.", type);
		return 1;
	}

	log_finer("finished message interpretation");

	return 0;
}