fp

Dependencies:   libmDot-mbed5 ISL29011

Revision:
8:e667f4a507b1
Parent:
7:724cb82a113e
Child:
10:4d0b765f7b9e
--- a/examples/src/dot_util.cpp	Fri Oct 07 12:45:23 2016 -0500
+++ b/examples/src/dot_util.cpp	Fri Oct 07 15:31:03 2016 -0500
@@ -25,11 +25,17 @@
     logInfo("\tpublic network:          %s", dot->getPublicNetwork() == true ? "on" : "off");
     logInfo("credentials configuration");
     logInfo("-------------------------");
-    logInfo("\tnetwork name:            %s", dot->getNetworkName().c_str());
-    logInfo("\tnetwork phrase:          %s", dot->getNetworkPassphrase().c_str());
-    logInfo("\tnetwork EUI:             %s", mts::Text::bin2hexString(dot->getNetworkId()).c_str());
-    logInfo("\tnetwork KEY:             %s", mts::Text::bin2hexString(dot->getNetworkKey()).c_str());
     logInfo("\tnetwork join mode:       %s", mDot::JoinModeStr(dot->getJoinMode()).c_str());
+    if (dot->getJoinMode() == mDot::MANUAL) {
+	logInfo("\tnetwork address:         %s", mts::Text::bin2hexString(dot->getNetworkAddress()).c_str());
+	logInfo("\tnetwork session key:     %s", mts::Text::bin2hexString(dot->getNetworkSessionKey()).c_str());
+	logInfo("\tdata session key:        %s", mts::Text::bin2hexString(dot->getDataSessionKey()).c_str());
+    } else {
+	logInfo("\tnetwork name:            %s", dot->getNetworkName().c_str());
+	logInfo("\tnetwork phrase:          %s", dot->getNetworkPassphrase().c_str());
+	logInfo("\tnetwork EUI:             %s", mts::Text::bin2hexString(dot->getNetworkId()).c_str());
+	logInfo("\tnetwork KEY:             %s", mts::Text::bin2hexString(dot->getNetworkKey()).c_str());
+    }
     logInfo("communication parameters");
     logInfo("------------------------");
     logInfo("\tacks:                    %s, %u attempts", dot->getAck() > 0 ? "on" : "off", dot->getAck());
@@ -127,6 +133,61 @@
     }
 }
 
+void update_manual_config(uint8_t *network_address, uint8_t *network_session_key, uint8_t *data_session_key, uint8_t frequency_sub_band, bool public_network, uint8_t ack) {
+    std::vector<uint8_t> current_network_address = dot->getNetworkAddress();
+    std::vector<uint8_t> current_network_session_key = dot->getNetworkSessionKey();
+    std::vector<uint8_t> current_data_session_key = dot->getDataSessionKey();
+    uint8_t current_frequency_sub_band = dot->getFrequencySubBand();
+    bool current_public_network = dot->getPublicNetwork();
+    uint8_t current_ack = dot->getAck();
+
+    std::vector<uint8_t> network_address_vector(network_address, network_address + 4);
+    std::vector<uint8_t> network_session_key_vector(network_session_key, network_session_key + 16);
+    std::vector<uint8_t> data_session_key_vector(data_session_key, data_session_key + 16);
+
+    if (current_network_address != network_address_vector) {
+        logInfo("changing network address from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_address).c_str(), mts::Text::bin2hexString(network_address_vector).c_str());
+        if (dot->setNetworkAddress(network_address_vector) != mDot::MDOT_OK) {
+            logError("failed to set network address to \"%s\"", mts::Text::bin2hexString(network_address_vector).c_str());
+        }
+    }
+    
+    if (current_network_session_key != network_session_key_vector) {
+        logInfo("changing network session key from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_network_session_key).c_str(), mts::Text::bin2hexString(network_session_key_vector).c_str());
+        if (dot->setNetworkSessionKey(network_session_key_vector) != mDot::MDOT_OK) {
+            logError("failed to set network session key to \"%s\"", mts::Text::bin2hexString(network_session_key_vector).c_str());
+        }
+    }
+    
+    if (current_data_session_key != data_session_key_vector) {
+        logInfo("changing data session key from \"%s\" to \"%s\"", mts::Text::bin2hexString(current_data_session_key).c_str(), mts::Text::bin2hexString(data_session_key_vector).c_str());
+        if (dot->setDataSessionKey(data_session_key_vector) != mDot::MDOT_OK) {
+            logError("failed to set data session key to \"%s\"", mts::Text::bin2hexString(data_session_key_vector).c_str());
+        }
+    }
+    
+    if (current_frequency_sub_band != frequency_sub_band) {
+        logInfo("changing frequency sub band from %u to %u", current_frequency_sub_band, frequency_sub_band);
+        if (dot->setFrequencySubBand(frequency_sub_band) != mDot::MDOT_OK) {
+            logError("failed to set frequency sub band to %u", frequency_sub_band);
+        }
+    }
+    
+    if (current_public_network != public_network) {
+        logInfo("changing public network from %s to %s", current_public_network ? "true" : "false", public_network ? "true" : "false");
+        if (dot->setPublicNetwork(public_network) != mDot::MDOT_OK) {
+            logError("failed to set public network to %s", public_network ? "true" : "false");
+        }
+    }
+    
+    if (current_ack != ack) {
+        logInfo("changing acks from %u to %u", current_ack, ack);
+        if (dot->setAck(ack) != mDot::MDOT_OK) {
+            logError("failed to set acks to %u", ack);
+        }
+    }
+}
+
 void join_network() {
     int32_t j_attempts = 0;
     int32_t ret = mDot::MDOT_ERROR;