Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/common/lora_interface/LoRaInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ delay(1500);
LoRa.setTxPower(power);

INFO("LoRa init succeeded.");
TRACE("LoRa bandwidth is " + std::to_string(Utilities::OS::round(_bitrate/1000.0, 2)) + " Kbps");
TRACEF("LoRa bandwidth is %s Kbps", std::to_string(Utilities::OS::round(_bitrate/1000.0, 2)).c_str());
#endif

_online = true;
Expand Down Expand Up @@ -111,10 +111,10 @@ void LoRaInterface::loop() {
}

/*virtual*/ void LoRaInterface::send_outgoing(const Bytes& data) {
DEBUG(toString() + ".on_outgoing: data: " + data.toHex());
DEBUGF("%s.on_outgoing: data: %s", toString().c_str(), data.toHex().c_str());
try {
if (_online) {
TRACE("LoRaInterface: sending " + std::to_string(data.size()) + " bytes...");
TRACEF("LoRaInterface: sending %zu bytes...", data.size());
// Send packet
#ifdef ARDUINO

Expand Down Expand Up @@ -142,12 +142,12 @@ void LoRaInterface::loop() {
InterfaceImpl::handle_outgoing(data);
}
catch (std::exception& e) {
ERROR("Could not transmit on " + toString() + ". The contained exception was: " + e.what());
ERRORF("Could not transmit on %s. The contained exception was: %s", toString().c_str(), e.what());
}
}

/*virtual*/ void LoRaInterface::on_incoming(const Bytes& data) {
DEBUG(toString() + ".on_incoming: data: " + data.toHex());
DEBUGF("%s.on_incoming: data: %s", toString().c_str(), data.toHex().c_str());
// Pass received data on to transport
InterfaceImpl::handle_incoming(data);
}
32 changes: 16 additions & 16 deletions examples/common/udp_interface/UDPInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa
}
_local_port = port;
_remote_port = port;
TRACE("UDPInterface: local host: " + _local_host);
TRACE("UDPInterface: local port: " + std::to_string(_local_port));
TRACE("UDPInterface: remote host: " + _remote_host);
TRACE("UDPInterface: remote port: " + std::to_string(_remote_port));
TRACEF("UDPInterface: local host: %s", _local_host.c_str());
TRACEF("UDPInterface: local port: %d", _local_port);
TRACEF("UDPInterface: remote host: %s", _remote_host.c_str());
TRACEF("UDPInterface: remote port: %d", _remote_port);

#ifdef ARDUINO
TRACE("UDPInterface: wifi ssid: " + _wifi_ssid);
TRACE("UDPInterface: wifi password: " + _wifi_password);
TRACEF("UDPInterface: wifi ssid: %s", _wifi_ssid.c_str());
TRACEF("UDPInterface: wifi password: %s", _wifi_password.c_str());

// Connect to the WiFi network
WiFi.begin(_wifi_ssid.c_str(), _wifi_password.c_str());
Expand Down Expand Up @@ -133,7 +133,7 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa
if (inet_aton(_local_host.c_str(), &local_addr) == 0) {
struct hostent* host_ent = gethostbyname(_local_host.c_str());
if (host_ent == nullptr || host_ent->h_addr_list[0] == nullptr) {
ERROR("Unable to resolve local host " + std::string(_local_host));
ERRORF("Unable to resolve local host %s", _local_host.c_str());
return false;
}
_local_address = *((in_addr_t*)(host_ent->h_addr_list[0]));
Expand All @@ -147,7 +147,7 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa
if (inet_aton(_remote_host.c_str(), &remote_addr) == 0) {
struct hostent* host_ent = gethostbyname(_remote_host.c_str());
if (host_ent == nullptr || host_ent->h_addr_list[0] == nullptr) {
ERROR("Unable to resolve remote host " + std::string(_remote_host));
ERRORF("Unable to resolve remote host %s", _remote_host.c_str());
return false;
}
_remote_address = *((in_addr_t*)(host_ent->h_addr_list[0]));
Expand All @@ -160,7 +160,7 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa
TRACE("Opening UDP socket");
_socket = socket( PF_INET, SOCK_DGRAM, 0 );
if (_socket < 0) {
ERROR("Unable to create socket with error " + std::to_string(errno));
ERRORF("Unable to create socket with error %d", errno);
return false;
}

Expand All @@ -176,15 +176,15 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa
#endif

// bind to interface for listening
INFO("Binding UDP socket " + std::to_string(_socket) + " to " + std::string(_local_host) + ":" + std::to_string(_local_port));
INFOF("Binding UDP socket %d to %s:%d", _socket, _local_host.c_str(), _local_port);
sockaddr_in bind_addr;
bind_addr.sin_family = AF_INET;
bind_addr.sin_addr.s_addr = _local_address;
bind_addr.sin_port = htons(_local_port);
if (bind(_socket, (struct sockaddr*)&bind_addr, sizeof(bind_addr)) == -1) {
close(_socket);
_socket = -1;
ERROR("Unable to bind socket with error " + std::to_string(errno));
ERRORF("Unable to bind socket with error %d", errno);
return false;
}
#endif
Expand Down Expand Up @@ -234,7 +234,7 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa
}

/*virtual*/ void UDPInterface::send_outgoing(const Bytes& data) {
DEBUG(toString() + ".on_outgoing: data: " + data.toHex());
DEBUGF("%s.on_outgoing: data: %s", toString().c_str(), data.toHex().c_str());
try {
if (_online) {
// Send packet
Expand All @@ -243,26 +243,26 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : RNS::Interfa
udp.write(data.data(), data.size());
udp.endPacket();
#else
TRACE("Sending UDP packet to " + std::string(_remote_host) + ":" + std::to_string(_remote_port));
TRACEF("Sending UDP packet to %s:%d", _remote_host.c_str(), _remote_port);
sockaddr_in sock_addr;
sock_addr.sin_family = AF_INET;
sock_addr.sin_addr.s_addr = _remote_address;
sock_addr.sin_port = htons(_remote_port);
int sent = sendto(_socket, data.data(), data.size(), 0, (struct sockaddr*)&sock_addr, sizeof(sock_addr));
TRACE("Sent " + std::to_string(sent) + " bytes to " + std::string(_remote_host) + ":" + std::to_string(_remote_port));
TRACEF("Sent %d bytes to %s:%d", sent, _remote_host.c_str(), _remote_port);
#endif
}

// Perform post-send housekeeping
InterfaceImpl::handle_outgoing(data);
}
catch (std::exception& e) {
ERROR("Could not transmit on " + toString() + ". The contained exception was: " + e.what());
ERRORF("Could not transmit on %s. The contained exception was: %s", toString().c_str(), e.what());
}
}

void UDPInterface::on_incoming(const Bytes& data) {
DEBUG(toString() + ".on_incoming: data: " + data.toHex());
DEBUGF("%s.on_incoming: data: %s", toString().c_str(), data.toHex().c_str());
// Pass received data on to transport
InterfaceImpl::handle_incoming(data);
}
30 changes: 15 additions & 15 deletions examples/common/universal_filesystem/UniversalFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void UniversalFileSystem::listDir(const char* dir) {
return true;
}
else {
ERROR("file_exists: failed to open file " + std::string(file_path));
ERRORF("file_exists: failed to open file %s", file_path);
return false;
}
}
Expand Down Expand Up @@ -155,9 +155,9 @@ void UniversalFileSystem::listDir(const char* dir) {
//size_t read = fread(data.writable(size), size, 1, file);
read = fread(data.writable(size), 1, size, file);
#endif
TRACE("read_file: read " + std::to_string(read) + " bytes from file " + std::string(file_path));
TRACEF("read_file: read %zu bytes from file %s", read, file_path);
if (read != size) {
ERROR("read_file: failed to read file " + std::string(file_path));
ERRORF("read_file: failed to read file %s", file_path);
data.clear();
}
//TRACE("read_file: closing input file");
Expand All @@ -173,7 +173,7 @@ void UniversalFileSystem::listDir(const char* dir) {
#endif
}
else {
ERROR("read_file: failed to open input file " + std::string(file_path));
ERRORF("read_file: failed to open input file %s", file_path);
}
return read;
}
Expand Down Expand Up @@ -201,9 +201,9 @@ void UniversalFileSystem::listDir(const char* dir) {
//size_t wrote = fwrite(data.data(), data.size(), 1, file);
wrote = fwrite(data.data(), 1, data.size(), file);
#endif
TRACE("write_file: wrote " + std::to_string(wrote) + " bytes to file " + std::string(file_path));
TRACEF("write_file: wrote %zu bytes to file %s", wrote, file_path);
if (wrote < data.size()) {
WARNING("write_file: not all data was written to file " + std::string(file_path));
WARNINGF("write_file: not all data was written to file %s", file_path);
}
//TRACE("write_file: closing output file");
#ifdef ARDUINO
Expand All @@ -218,7 +218,7 @@ void UniversalFileSystem::listDir(const char* dir) {
#endif
}
else {
ERROR("write_file: failed to open output file " + std::string(file_path));
ERRORF("write_file: failed to open output file %s", file_path);
}
return wrote;
}
Expand Down Expand Up @@ -348,7 +348,7 @@ void UniversalFileSystem::listDir(const char* dir) {
}

/*virtua*/ bool UniversalFileSystem::directory_exists(const char* directory_path) {
TRACE("directory_exists: checking for existence of directory " + std::string(directory_path));
TRACEF("directory_exists: checking for existence of directory %s", directory_path);
#ifdef ARDUINO
#ifdef BOARD_ESP32
File file = SPIFFS.open(directory_path, FILE_READ);
Expand Down Expand Up @@ -382,13 +382,13 @@ void UniversalFileSystem::listDir(const char* dir) {
#ifdef ARDUINO
#ifdef BOARD_ESP32
if (!SPIFFS.mkdir(directory_path)) {
ERROR("create_directory: failed to create directorty " + std::string(directory_path));
ERRORF("create_directory: failed to create directorty %s", directory_path);
return false;
}
return true;
#elif BOARD_NRF52
if (!InternalFS.mkdir(directory_path)) {
ERROR("create_directory: failed to create directorty " + std::string(directory_path));
ERRORF("create_directory: failed to create directorty %s", directory_path);
return false;
}
return true;
Expand All @@ -406,18 +406,18 @@ void UniversalFileSystem::listDir(const char* dir) {
}

/*virtua*/ bool UniversalFileSystem::remove_directory(const char* directory_path) {
TRACE("remove_directory: removing directory " + std::string(directory_path));
TRACEF("remove_directory: removing directory %s", directory_path);
#ifdef ARDUINO
#ifdef BOARD_ESP32
//if (!LittleFS.rmdir_r(directory_path)) {
if (!SPIFFS.rmdir(directory_path)) {
ERROR("remove_directory: failed to remove directorty " + std::string(directory_path));
ERRORF("remove_directory: failed to remove directorty %s", directory_path);
return false;
}
return true;
#elif BOARD_NRF52
if (!InternalFS.rmdir_r(directory_path)) {
ERROR("remove_directory: failed to remove directory " + std::string(directory_path));
ERRORF("remove_directory: failed to remove directory %s", directory_path);
return false;
}
return true;
Expand All @@ -431,7 +431,7 @@ void UniversalFileSystem::listDir(const char* dir) {
}

/*virtua*/ std::list<std::string> UniversalFileSystem::list_directory(const char* directory_path) {
TRACE("list_directory: listing directory " + std::string(directory_path));
TRACEF("list_directory: listing directory %s", directory_path);
std::list<std::string> files;
#ifdef ARDUINO
#ifdef BOARD_ESP32
Expand All @@ -440,7 +440,7 @@ void UniversalFileSystem::listDir(const char* dir) {
File root = InternalFS.open(directory_path);
#endif
if (!root) {
ERROR("list_directory: failed to open directory " + std::string(directory_path));
ERRORF("list_directory: failed to open directory %s", directory_path);
return files;
}
File file = root.openNextFile();
Expand Down
19 changes: 5 additions & 14 deletions examples/link_native/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void server_packet_received(const RNS::Bytes& message, const RNS::Packet& packet
// it will all be directed to the last client
// that connected.
std::string text = message.toString();
RNS::log("Received data on the link: "+text);
RNS::logf(RNS::LOG_NOTICE, "Received data on the link: %s", text.c_str());

std::string reply_text = "I received \""+text+"\" over the link";
RNS::Bytes reply_data(reply_text);
Expand All @@ -86,11 +86,7 @@ void client_connected(RNS::Link& link) {

void server_loop(RNS::Destination& destination) {
// Let the user know that everything is ready
RNS::log(
"Link example <"+
destination.hash().toHex()+
"> running, waiting for a connection."
);
RNS::logf(RNS::LOG_NOTICE, "Link example <%s> running, waiting for a connection.", destination.hash().toHex().c_str());

RNS::log("Hit enter to manually send an announce (Ctrl-C to quit)");

Expand All @@ -105,7 +101,7 @@ void server_loop(RNS::Destination& destination) {
while (read(STDIN_FILENO, &ch, 1) > 0) {
if (ch == '\n') {
destination.announce();
RNS::log("Sent announce from "+destination.hash().toHex());
RNS::logf(RNS::LOG_NOTICE, "Sent announce from %s", destination.hash().toHex().c_str());
}
}
}
Expand Down Expand Up @@ -182,7 +178,7 @@ void link_closed(RNS::Link& link) {
// simply print out the data.
void client_packet_received(const RNS::Bytes& message, const RNS::Packet& packet) {
std::string text = message.toString();
RNS::log("Received data on the link: "+text);
RNS::logf(RNS::LOG_NOTICE, "Received data on the link: %s", text.c_str());
printf("> ");
fflush(stdout);
}
Expand Down Expand Up @@ -223,12 +219,7 @@ printf("(sending data: %s)\n", text.c_str());
RNS::Packet(server_link, data).send();
}
else {
RNS::log(
"Cannot send this packet, the data size of "+
std::to_string(data.size())+" bytes exceeds the link packet MDU of "+
std::to_string(RNS::Type::Link::MDU)+" bytes",
RNS::LOG_ERROR
);
RNS::logf(RNS::LOG_ERROR, "Cannot send this packet, the data size of %zu bytes exceeds the link packet MDU of %zu bytes", data.size(), (size_t)RNS::Type::Link::MDU);
}
}

Expand Down
24 changes: 12 additions & 12 deletions examples/lora_announce/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class ExampleAnnounceHandler : public RNS::AnnounceHandler {
virtual ~ExampleAnnounceHandler() {}
virtual void received_announce(const RNS::Bytes& destination_hash, const RNS::Identity& announced_identity, const RNS::Bytes& app_data) {
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
INFO("ExampleAnnounceHandler: destination hash: " + destination_hash.toHex());
INFOF("ExampleAnnounceHandler: destination hash: %s", destination_hash.toHex().c_str());
if (announced_identity) {
INFO("ExampleAnnounceHandler: announced identity hash: " + announced_identity.hash().toHex());
INFO("ExampleAnnounceHandler: announced identity app data: " + announced_identity.app_data().toHex());
INFOF("ExampleAnnounceHandler: announced identity hash: %s", announced_identity.hash().toHex().c_str());
INFOF("ExampleAnnounceHandler: announced identity app data: %s", announced_identity.app_data().toHex().c_str());
}
if (app_data) {
INFO("ExampleAnnounceHandler: app data text: \"" + app_data.toString() + "\"");
INFOF("ExampleAnnounceHandler: app data text: \"%s\"", app_data.toString().c_str());
}
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
Expand All @@ -70,18 +70,18 @@ class ExampleAnnounceHandler : public RNS::AnnounceHandler {
// Test packet receive callback
void onPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
INFO("onPacket: data: " + data.toHex());
INFO("onPacket: text: \"" + data.toString() + "\"");
//TRACE("onPacket: " + packet.debugString());
INFOF("onPacket: data: %s", data.toHex().c_str());
INFOF("onPacket: text: \"%s\"", data.toString().c_str());
//TRACEF("onPacket: %s", packet.debugString().c_str());
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}

// Ping packet receive callback
void onPingPacket(const RNS::Bytes& data, const RNS::Packet& packet) {
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
INFO("onPingPacket: data: " + data.toHex());
INFO("onPingPacket: text: \"" + data.toString() + "\"");
//TRACE("onPingPacket: " + packet.debugString());
INFOF("onPingPacket: data: %s", data.toHex().c_str());
INFOF("onPingPacket: text: \"%s\"", data.toString().c_str());
//TRACEF("onPingPacket: %s", packet.debugString().c_str());
INFO("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}

Expand Down Expand Up @@ -205,14 +205,14 @@ void reticulum_setup() {
HEAD("Sending send packet...", RNS::LOG_TRACE);
send_packet.pack();
#ifndef NDEBUG
TRACE("Test send_packet: " + send_packet.debugString());
TRACEF("Test send_packet: %s", send_packet.debugString().c_str());
#endif

HEAD("Creating recv packet...", RNS::LOG_TRACE);
RNS::Packet recv_packet({RNS::Type::NONE}, send_packet.raw());
recv_packet.unpack();
#ifndef NDEBUG
TRACE("Test recv_packet: " + recv_packet.debugString());
TRACEF("Test recv_packet: %s", recv_packet.debugString().c_str());
#endif

HEAD("Spoofing recv packet to destination...", RNS::LOG_TRACE);
Expand Down
Loading