Basic introspection for device supported networks

This commit is contained in:
Paul Hollinsky
2019-01-03 17:00:15 -05:00
parent efd5547e5c
commit 7e9fbc4959
17 changed files with 317 additions and 38 deletions
+24
View File
@@ -203,6 +203,9 @@ bool Device::goOffline() {
}
bool Device::transmit(std::shared_ptr<Message> message) {
if(!isSupportedTXNetwork(message->network))
return false;
std::vector<uint8_t> packet;
if(!com->encoder->encode(packet, message))
return false;
@@ -218,6 +221,27 @@ bool Device::transmit(std::vector<std::shared_ptr<Message>> messages) {
return true;
}
size_t Device::getNetworkCountByType(Network::Type type) const {
size_t count = 0;
for(const auto& net : getSupportedRXNetworks())
if(net.getType() == type)
count++;
return count;
}
// Indexed starting at one
Network Device::getNetworkByNumber(Network::Type type, size_t index) const {
size_t count = 0;
for(const auto& net : getSupportedRXNetworks()) {
if(net.getType() == type) {
count++;
if(count == index)
return net;
}
}
return Network::NetID::Invalid;
}
void Device::handleInternalMessage(std::shared_ptr<Message> message) {
switch(message->network.getNetID()) {
case Network::NetID::Reset_Status: