Newer
Older
#include "GeoNetworkingLayer.hh"
#include "GeoNetworkingTypes.hh"
#include "loggers.hh"
GeoNetworkingLayer::GeoNetworkingLayer(const std::string & p_type, const std::string & param) : TLayer<LibItsGeoNetworking__TestSystem::GeoNetworkingPort>(p_type), _params(), _codec() {
loggers::get_instance().log(">>> GeoNetworkingLayer::GeoNetworkingLayer: %s, %s", to_string().c_str(), param.c_str());
void GeoNetworkingLayer::sendMsg(const LibItsGeoNetworking__TestSystem::GeoNetworkingReq& p, const Params& params) {
// Update parameters
Params par(params); // FIXME Review all const Param& in method declarations
par.insert(std::pair<std::string, std::string>(Params::mac_dst, std::string(static_cast<const char *>(oct2str(p.macDestinationAddress())))));
par.insert(std::pair<std::string, std::string>(Params::its_aid, std::string(static_cast<const char *>(int2str(p.its__aid())))));
void GeoNetworkingLayer::sendData(OCTETSTRING& data, Params& params) {
loggers::get_instance().log_msg(">>> GeoNetworkingLayer::sendData: ", data);
void GeoNetworkingLayer::receiveData(OCTETSTRING& data, Params& params) {
loggers::get_instance().log_msg(">>> GeoNetworkingLayer::receiveData: ", data);
// Decode the payload
LibItsGeoNetworking__TestSystem::GeoNetworkingInd p;
_codec.decode(data, p.msgIn());
// Add lower layers parameters
std::map<std::string, std::string>::const_iterator it = params.find(Params::mac_dst);
loggers::get_instance().log("GeoNetworkingLayer::receiveData: dst=", it->second.c_str());
p.macDestinationAddress() = str2oct(CHARSTRING(it->second.c_str()));
} else {
p.macDestinationAddress() = OCTETSTRING(Params::mac_address.size(), Params::mac_address.data());
}
// 2. ssp
it = params.find(Params::ssp);
if (it != params.cend()) {
loggers::get_instance().log("GeoNetworkingLayer::receiveData: ssp=", it->second.c_str());
p.ssp() = str2bit(CHARSTRING(it->second.c_str()));
} else {
p.ssp().set_to_omit();
// 3. its_aid
it = params.find(Params::its_aid);
if (it != params.cend()) {
loggers::get_instance().log("GeoNetworkingLayer::receiveData: its_aid=", it->second.c_str());
p.its__aid() = std::stoi(it->second.c_str());
} else {
p.its__aid().set_to_omit();
}
}
class GeoNetworkingFactory: public LayerFactory {
GeoNetworkingFactory();
virtual Layer * createLayer(const std::string & type,
const std::string & param);
};
GeoNetworkingFactory::GeoNetworkingFactory() {
// Register factory
loggers::get_instance().log(">>> GeoNetworkingFactory::GeoNetworkingFactory");
LayerStackBuilder::RegisterLayerFactory("GN", this);
}
Layer * GeoNetworkingFactory::createLayer(const std::string & type, const std::string & param) {
}
GeoNetworkingFactory GeoNetworkingFactory::_f;