Skip to content
ConfigRsuSimulatorLayer.cc 1.97 KiB
Newer Older
#include "ConfigRsuSimulatorLayerFactory.hh"

#include "loggers.hh"

#include "ItsRSUsSimulator_TestSystem.hh"

garciay's avatar
garciay committed
ConfigRsuSimulatorLayer::ConfigRsuSimulatorLayer(const std::string & p_type, const std::string & param) : t_layer<ItsRSUsSimulator__TestSystem::ConfigRsuSimulatorPort>(p_type), _params(), _codec() {
  loggers::get_instance().log(">>> ConfigRsuSimulatorLayer::ConfigRsuSimulatorLayer: %s, %s", to_string().c_str(), param.c_str());
  // Setup parameters
  Params::convert(_params, param);
}

void ConfigRsuSimulatorLayer::sendMsg(const ItsRSUsSimulator__TestSystem::CfInitialize& send_par, Params& params){
  loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::sendMsg: ", send_par);
  
  // Encode ConfigRsuSimulator PDU
  OCTETSTRING data;
  if (_codec.encode(static_cast<const Record_Type&>(send_par), data) == -1) {
    loggers::get_instance().warning("ConfigRsuSimulatorLayer::sendMsg: Encoding failure");
    return;
  }

garciay's avatar
garciay committed
  send_data(data, _params);
garciay's avatar
garciay committed
void ConfigRsuSimulatorLayer::send_data(OCTETSTRING& data, Params& params) {
  loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::send_data: ", data);
garciay's avatar
garciay committed
  send_to_all_layers(data, params);
garciay's avatar
garciay committed
void ConfigRsuSimulatorLayer::receive_data(OCTETSTRING& data, Params& params)
garciay's avatar
garciay committed
  loggers::get_instance().log_msg(">>> ConfigRsuSimulatorLayer::receive_data: ", data);
  
  // Sanity check
  if (*(static_cast<const unsigned char*>(data)+ 1) != 0x02) { // Check that received packet has CA message id - See ETSI TS 102 894
    // Not a ConfigRsuSimulator message, discard it
garciay's avatar
garciay committed
    loggers::get_instance().warning("ConfigRsuSimulatorLayer::receive_data: Wrong message id: 0x%02x", *(static_cast<const unsigned char*>(data)+ 1));
    return;
  }
  
  // Decode the payload
  BOOLEAN p;
  /*_codec.decode(data, p);
  if (!p.msgIn().is_bound()) {
    // Discard it
    return;
    }*/ // else, continue
  
  // Pass it to the ports if amy
garciay's avatar
garciay committed
  to_all_upper_ports(p, params);
}

ConfigRsuSimulatorLayerFactory ConfigRsuSimulatorLayerFactory::_f;