mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-21 19:30:03 +02:00
UDP struct uses IpAddr and MacAddr
This commit is contained in:
parent
9d744deb4a
commit
ba52bfb65e
@ -1388,34 +1388,34 @@ UdpDestination CmdProxy::getUdpEntry() {
|
||||
std::string key = it.substr(0, pos);
|
||||
std::string value = it.substr(pos + 1);
|
||||
if (key == "entry") {
|
||||
udpDestination.setEntry(StringTo<int>(value));
|
||||
udpDestination.entry = StringTo<int>(value);
|
||||
hasEntry = true;
|
||||
} else if (key == "ip") {
|
||||
if (value == "auto") {
|
||||
auto val = getIpFromAuto();
|
||||
LOG(logINFO) << "Setting udp_dstip of detector " << det_id
|
||||
<< " to " << val;
|
||||
udpDestination.setIp(val);
|
||||
udpDestination.ip = val;
|
||||
} else {
|
||||
udpDestination.setIp(IpAddr(value));
|
||||
udpDestination.ip = IpAddr(value);
|
||||
}
|
||||
} else if (key == "ip2") {
|
||||
if (value == "auto") {
|
||||
auto val = getIpFromAuto();
|
||||
LOG(logINFO) << "Setting udp_dstip2 of detector " << det_id
|
||||
<< " to " << val;
|
||||
udpDestination.setIp2(val);
|
||||
udpDestination.ip2 = val;
|
||||
} else {
|
||||
udpDestination.setIp2(IpAddr(value));
|
||||
udpDestination.ip2 = IpAddr(value);
|
||||
}
|
||||
} else if (key == "mac") {
|
||||
udpDestination.setMac(MacAddr(value));
|
||||
udpDestination.mac = MacAddr(value);
|
||||
} else if (key == "mac2") {
|
||||
udpDestination.setMac2(MacAddr(value));
|
||||
udpDestination.mac2 = MacAddr(value);
|
||||
} else if (key == "port") {
|
||||
udpDestination.setPort(StringTo<uint32_t>(value));
|
||||
udpDestination.port = StringTo<uint32_t>(value);
|
||||
} else if (key == "port2") {
|
||||
udpDestination.setPort2(StringTo<uint32_t>(value));
|
||||
udpDestination.port2 = StringTo<uint32_t>(value);
|
||||
}
|
||||
}
|
||||
if (!hasEntry) {
|
||||
|
@ -945,24 +945,24 @@ sls::UdpDestination Module::getDestinationUDPList(const uint32_t entry) const {
|
||||
|
||||
void Module::setDestinationUDPList(const sls::UdpDestination dest) {
|
||||
// set them in the default way so the receivers are also set up
|
||||
if (dest.getEntry() == 0) {
|
||||
if (dest.getPort() != 0) {
|
||||
setDestinationUDPPort(dest.getPort());
|
||||
if (dest.entry == 0) {
|
||||
if (dest.port != 0) {
|
||||
setDestinationUDPPort(dest.port);
|
||||
}
|
||||
if (dest.getIp() != 0) {
|
||||
setDestinationUDPIP(IpAddr(dest.getIp()));
|
||||
if (dest.ip != 0) {
|
||||
setDestinationUDPIP(dest.ip);
|
||||
}
|
||||
if (dest.getMac() != 0) {
|
||||
setDestinationUDPMAC(MacAddr(dest.getMac()));
|
||||
if (dest.mac != 0) {
|
||||
setDestinationUDPMAC(dest.mac);
|
||||
}
|
||||
if (dest.getPort2() != 0) {
|
||||
setDestinationUDPPort2(dest.getPort2());
|
||||
if (dest.port2 != 0) {
|
||||
setDestinationUDPPort2(dest.port2);
|
||||
}
|
||||
if (dest.getIp2() != 0) {
|
||||
setDestinationUDPIP2(IpAddr(dest.getIp2()));
|
||||
if (dest.ip2 != 0) {
|
||||
setDestinationUDPIP2(dest.ip2);
|
||||
}
|
||||
if (dest.getMac2() != 0) {
|
||||
setDestinationUDPMAC2(MacAddr(dest.getMac2()));
|
||||
if (dest.mac2 != 0) {
|
||||
setDestinationUDPMAC2(dest.mac2);
|
||||
}
|
||||
} else {
|
||||
sendToDetector(F_SET_DEST_UDP_LIST, dest, nullptr);
|
||||
|
@ -30,7 +30,7 @@ class IpAddr {
|
||||
return addr_ != other;
|
||||
}
|
||||
constexpr uint32_t uint32() const noexcept { return addr_; }
|
||||
};
|
||||
} __attribute__((packed));
|
||||
|
||||
class MacAddr {
|
||||
private:
|
||||
@ -57,62 +57,23 @@ class MacAddr {
|
||||
return addr_ != other;
|
||||
}
|
||||
constexpr uint64_t uint64() const noexcept { return addr_; }
|
||||
};
|
||||
|
||||
class UdpDestination {
|
||||
private:
|
||||
uint32_t entry_{};
|
||||
uint32_t port_{};
|
||||
uint32_t port2_{};
|
||||
uint32_t ip_{};
|
||||
uint32_t ip2_{};
|
||||
uint64_t mac_{};
|
||||
uint64_t mac2_{};
|
||||
|
||||
public:
|
||||
constexpr UdpDestination() noexcept = default;
|
||||
explicit constexpr UdpDestination(uint32_t entry, uint32_t port = 0,
|
||||
IpAddr ip = {}, MacAddr mac = {},
|
||||
uint32_t port2 = 0, IpAddr ip2 = {},
|
||||
MacAddr mac2 = {})
|
||||
: entry_(entry), port_(port), port2_(port2), ip_(ip.uint32()),
|
||||
ip2_(ip2.uint32()), mac_(mac.uint64()), mac2_(mac2.uint64()) {}
|
||||
|
||||
uint32_t getEntry() const noexcept { return entry_; }
|
||||
|
||||
void setEntry(const uint32_t value) { entry_ = value; }
|
||||
|
||||
uint32_t getPort() const noexcept { return port_; }
|
||||
|
||||
void setPort(const uint32_t value) { port_ = value; }
|
||||
|
||||
uint32_t getPort2() const noexcept { return port2_; }
|
||||
|
||||
void setPort2(const uint32_t value) { port2_ = value; }
|
||||
|
||||
IpAddr getIp() const noexcept { return IpAddr(ip_); }
|
||||
|
||||
void setIp(const IpAddr value) { ip_ = value.uint32(); }
|
||||
|
||||
IpAddr getIp2() const noexcept { return IpAddr(ip2_); }
|
||||
|
||||
void setIp2(const IpAddr value) { ip2_ = value.uint32(); }
|
||||
|
||||
MacAddr getMac() const noexcept { return MacAddr(mac_); }
|
||||
|
||||
void setMac(const MacAddr value) { mac_ = value.uint64(); }
|
||||
|
||||
MacAddr getMac2() const noexcept { return MacAddr(mac2_); }
|
||||
|
||||
void setMac2(const MacAddr value) { mac2_ = value.uint64(); }
|
||||
} __attribute__((packed));
|
||||
|
||||
struct UdpDestination {
|
||||
uint32_t entry{};
|
||||
uint32_t port{};
|
||||
uint32_t port2{};
|
||||
IpAddr ip;
|
||||
IpAddr ip2;
|
||||
MacAddr mac;
|
||||
MacAddr mac2;
|
||||
std::string str() const;
|
||||
|
||||
constexpr bool operator==(const UdpDestination &other) const {
|
||||
return ((entry_ == other.entry_) && (port_ == other.port_) &&
|
||||
(port2_ == other.port2_) && (ip_ == other.ip_) &&
|
||||
(ip2_ == other.ip2_) && (mac_ == other.mac_) &&
|
||||
(mac2_ == other.mac2_));
|
||||
return ((entry == other.entry) && (port == other.port) &&
|
||||
(port2 == other.port2) && (ip== other.ip) &&
|
||||
(ip2 == other.ip2) && (mac == other.mac) &&
|
||||
(mac2 == other.mac2));
|
||||
}
|
||||
} __attribute__((packed));
|
||||
|
||||
|
@ -72,18 +72,18 @@ std::string MacAddr::hex() const { return to_hex(); }
|
||||
std::string UdpDestination::str() const {
|
||||
std::ostringstream oss;
|
||||
oss << '[' << std::endl
|
||||
<< "entry " << entry_ << std::endl
|
||||
<< "ip " << ip_ << std::endl
|
||||
<< "mac " << mac_ << std::endl
|
||||
<< "port " << port_ << std::endl;
|
||||
if (port2_ != 0) {
|
||||
oss << "port2 " << port2_ << std::endl;
|
||||
<< "entry " << entry << std::endl
|
||||
<< "ip " << ip << std::endl
|
||||
<< "mac " << mac << std::endl
|
||||
<< "port " << port << std::endl;
|
||||
if (port2 != 0) {
|
||||
oss << "port2 " << port2 << std::endl;
|
||||
}
|
||||
if (ip2_ != 0) {
|
||||
oss << "ip2 " << ip2_ << std::endl;
|
||||
if (ip2 != 0) {
|
||||
oss << "ip2 " << ip2 << std::endl;
|
||||
}
|
||||
if (mac2_ != 0) {
|
||||
oss << "mac2 " << mac2_ << std::endl;
|
||||
if (mac2 != 0) {
|
||||
oss << "mac2 " << mac2 << std::endl;
|
||||
}
|
||||
oss << ']';
|
||||
return oss.str();
|
||||
|
@ -9,7 +9,7 @@ TEST_CASE("Get size of empty file") {
|
||||
char fname[] = "temfile_XXXXXX";
|
||||
std::ifstream ifs(fname);
|
||||
auto size = sls::getFileSize(ifs);
|
||||
REQUIRE(size == 0);
|
||||
REQUIRE(size <= 0); // -1 or zero
|
||||
}
|
||||
|
||||
TEST_CASE("Get size of file with data") {
|
||||
|
@ -112,4 +112,12 @@ TEST_CASE("Copy construct a MacAddr") {
|
||||
CHECK(addr == addr2);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("udp dst struct"){
|
||||
static_assert(sizeof(UdpDestination) == 36);
|
||||
UdpDestination dst{};
|
||||
REQUIRE(dst.ip == 0);
|
||||
}
|
||||
|
||||
|
||||
// TODO!(Erik) Look up a real hostname and verify the IP
|
||||
|
Loading…
x
Reference in New Issue
Block a user