Exemplo n.º 1
0
CopyableBuffer::CopyableBuffer(const openpal::RSlice& buffer) :
	mpBuff(new uint8_t[buffer.Size()]),
	mSize(buffer.Size())
{
	openpal::WSlice dest(mpBuff, mSize);
	buffer.CopyTo(dest);
}
Exemplo n.º 2
0
APDUHeaderParser::Result<APDUHeader> APDUHeaderParser::ParseRequest(const openpal::RSlice& apdu,
                                                                    openpal::Logger* logger)
{
    if (apdu.Size() < APDUHeader::REQUEST_SIZE)
    {
        FORMAT_LOGGER_BLOCK(logger, flags::WARN, "Request fragment  with insufficient size of %u bytes", apdu.Size());
        return Result<APDUHeader>::Error();
    }

    return Result<APDUHeader>::Ok(APDUHeader(AppControlField(apdu[0]), FunctionCodeFromType(apdu[1])),
                                  apdu.Skip(APDUHeader::REQUEST_SIZE));
}
Exemplo n.º 3
0
void SocketChannel::BeginWriteImpl(const openpal::RSlice& buffer)
{
	auto callback = [this](const std::error_code & ec, size_t num)
	{
		this->OnWriteCallback(ec, num);
	};

	asio::async_write(socket, asio::buffer(buffer, buffer.Size()), this->executor->strand.wrap(callback));
}
Exemplo n.º 4
0
bool NumParser::Read(uint16_t& num, openpal::RSlice& buffer) const
{
	if (buffer.Size() < size)
	{
		return false;
	}
	else
	{
		num = pReadFun(buffer);
		return true;
	}
}
Exemplo n.º 5
0
bool IMasterTask::ValidateNoObjects(const openpal::RSlice& objects)
{
	if (objects.IsEmpty())
	{
		return true;
	}
	else
	{
		FORMAT_LOG_BLOCK(logger, flags::WARN, "Received unexpected response object headers for task: %s", this->Name());
		return false;
	}
}
Exemplo n.º 6
0
IMasterTask::ResponseResult RestartOperationTask::ProcessResponse(const opendnp3::APDUResponseHeader& header, const openpal::RSlice& objects)
{
	if (!(ValidateSingleResponse(header) && ValidateInternalIndications(header)))
	{
		return ResponseResult::ERROR_BAD_RESPONSE;
	}

	if (objects.IsEmpty())
	{
		return ResponseResult::ERROR_BAD_RESPONSE;
	}

	auto result = APDUParser::Parse(objects, *this, &logger);

	return (result == ParseResult::OK) ? ResponseResult::OK_FINAL : ResponseResult::ERROR_BAD_RESPONSE;
}
Exemplo n.º 7
0
bool DecoderImpl::IsResponse(const openpal::RSlice& data)
{
    if (data.Size() < 2)
    {
        return false;
    }

    switch (FunctionCodeFromType(data[1]))
    {
    case (FunctionCode::RESPONSE):
    case (FunctionCode::UNSOLICITED_RESPONSE):
    case (FunctionCode::AUTH_RESPONSE):
        return true;
    default:
        return false;
    }
}
Exemplo n.º 8
0
ParseResult NumParser::ParseRange(openpal::RSlice& buffer, Range& range, openpal::Logger* pLogger) const
{
	if (buffer.Size() < (2 * static_cast<uint32_t>(size)))
	{
		SIMPLE_LOGGER_BLOCK(pLogger, flags::WARN, "Not enough data for start / stop");
		return ParseResult::NOT_ENOUGH_DATA_FOR_RANGE;
	}
	else
	{
		range.start = this->ReadNum(buffer);
		range.stop = this->ReadNum(buffer);

		if (range.IsValid())
		{
			return ParseResult::OK;
		}
		else
		{
			FORMAT_LOGGER_BLOCK(pLogger, flags::WARN, "start (%u) > stop (%u)", range.start, range.stop);
			return ParseResult::BAD_START_STOP;
		}
	}
}
Exemplo n.º 9
0
uint16_t CRC::CalcCrc(const openpal::RSlice& view)
{
    return CalcCrc(view, view.Size());
}