Ejemplo n.º 1
0
/*
 * Calculate the checksum for a packet, and verify
 */
void RDMCommandTest::PackAndVerify(const RDMCommand &command,
                                   const uint8_t *expected,
                                   unsigned int expected_length) {
  // now check packing
  unsigned int buffer_size = command.Size();
  uint8_t *buffer = new uint8_t[buffer_size];
  CPPUNIT_ASSERT(command.Pack(buffer, &buffer_size));

  for (unsigned int i = 0 ; i < expected_length; i++) {
    std::stringstream str;
    str << "Offset " << i << ", expected " << static_cast<int>(expected[i]) <<
      ", got " << static_cast<int>(buffer[i]);
    CPPUNIT_ASSERT_MESSAGE(str.str(), buffer[i] == expected[i]);
  }
  delete[] buffer;

  // now check string packing
  string str_buffer;
  CPPUNIT_ASSERT(command.Pack(&str_buffer));
  CPPUNIT_ASSERT_EQUAL((size_t) expected_length, str_buffer.size());

  for (unsigned int i = 0 ; i < expected_length; i++) {
    std::stringstream str;
    uint8_t c = str_buffer[i];
    str << "Offset " << i << ", expected " << std::hex <<
      static_cast<int>(expected[i]) << ", got " << std::hex <<
      static_cast<int>(c);
    CPPUNIT_ASSERT_MESSAGE(str.str(), c == expected[i]);
  }
}
Ejemplo n.º 2
0
bool RDMCommand::operator==(const RDMCommand &other) const {
  if (SourceUID() == other.SourceUID() &&
      DestinationUID() == other.DestinationUID() &&
      TransactionNumber() == other.TransactionNumber() &&
      MessageCount() == other.MessageCount() &&
      SubDevice() == other.SubDevice() &&
      CommandClass() == other.CommandClass() &&
      ParamId() == other.ParamId() &&
      ParamDataSize() == other.ParamDataSize()) {
    return 0 == memcmp(ParamData(), other.ParamData(), ParamDataSize());
  }
  return false;
}
Ejemplo n.º 3
0
/**
 * Populate the RDMCommandHeader struct.
 * @param header a pointer to the RDMCommandHeader to populate
 * @param command the RDMCommand to use
 * @param the length of the packet excluding the start code.
 * @param source the source UID.
 * @param transaction_number the RDM transaction number
 * @param port_id the RDM port id
 */
void RDMCommandSerializer::PopulateHeader(RDMCommandHeader *header,
                                          const RDMCommand &command,
                                          unsigned int packet_length,
                                          const UID &source,
                                          uint8_t transaction_number,
                                          uint8_t port_id) {
  // ignore the checksum length for now
  packet_length -= CHECKSUM_LENGTH;

  header->sub_start_code = SUB_START_CODE;
  header->message_length = packet_length + 1;  // add in start code as well
  command.DestinationUID().Pack(header->destination_uid, UID::UID_SIZE);
  source.Pack(header->source_uid, UID::UID_SIZE);
  header->transaction_number = transaction_number;
  header->port_id = port_id;
  header->message_count = command.MessageCount();
  header->sub_device[0] = command.SubDevice() >> 8;
  header->sub_device[1] = command.SubDevice() & 0xff;
  header->command_class = command.CommandClass();
  header->param_id[0] = command.ParamId() >> 8;
  header->param_id[1] = command.ParamId() & 0xff;
  header->param_data_length = command.ParamDataSize();
}