Compare commits
5 Commits
f7af8cd4b0
...
41afbe26fb
Author | SHA1 | Date | |
---|---|---|---|
41afbe26fb | |||
87bb8539b3 | |||
a7b057abd1 | |||
6ef0fdae55 | |||
19f2d650be |
@ -22,7 +22,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||||||
add_compile_options(-Wall -Wextra -pedantic -lstdc++)
|
add_compile_options(-Wall -Wextra -pedantic -lstdc++)
|
||||||
add_definitions(-DCFG_DEBUG -DCFG_eu868 -DCFG_sx1276_radio -DDEBUG_LMIC -DDEBUG_HAL -DDEBUG_RADIO)
|
add_definitions(-DCFG_DEBUG -DCFG_eu868 -DCFG_sx1276_radio -DDEBUG_LMIC -DDEBUG_HAL -DDEBUG_RADIO)
|
||||||
|
|
||||||
add_executable(mqtt2LoRaWAN main.cpp MQTTDataStreamer.cpp POHelperClasses.cpp ./lmic/lmic.c ./lmic/aes.c ./lmic/radio.c ./lmic/oslmic.c ./lora_gps_hat/debug.c ./lora_gps_hat/gpio.c ./lora_gps_hat/hal.c )
|
add_executable(mqtt2LoRaWAN main.cpp MQTTDataStreamer.cpp POHelperClasses.cpp POCmdlineHelperClasses.cpp ./lmic/lmic.c ./lmic/aes.c ./lmic/radio.c ./lmic/oslmic.c ./lora_gps_hat/debug.c ./lora_gps_hat/gpio.c ./lora_gps_hat/hal.c )
|
||||||
|
|
||||||
target_include_directories (mqtt2LoRaWAN PUBLIC
|
target_include_directories (mqtt2LoRaWAN PUBLIC
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
23
POCmdlineHelperClasses.cpp
Normal file
23
POCmdlineHelperClasses.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "POHelperClasses.hpp"
|
||||||
|
#include "POCmdlineHelperClasses.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
|
|
||||||
|
void po_cmdline_helper::init(boost::program_options::options_description *cmdline_desc){
|
||||||
|
|
||||||
|
cmdline_desc->add_options() ("help", "produce help message")
|
||||||
|
("version,v", "print the version number")
|
||||||
|
("hostname,h", po::value<std::string>()->default_value("localhost"), "Hostname")
|
||||||
|
("port,p", po::value<int>()->default_value(1883), "Port")
|
||||||
|
("config,c", po::value<std::string>(), "configuration file")
|
||||||
|
("magic,m", po::value<magic_number>(), "magic value (in NNN-NNN format)")
|
||||||
|
("appeui", po::value<appeui>(), "APPEUI")
|
||||||
|
("deveui", po::value<deveui>(), "DEVEUI")
|
||||||
|
("devkey", po::value<devkey>(), "DEVKEY");
|
||||||
|
|
||||||
|
}
|
17
POCmdlineHelperClasses.hpp
Normal file
17
POCmdlineHelperClasses.hpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef ProgramOptions_CmdLine_HelperClasses_HPP
|
||||||
|
#define ProgramOptions_CmdLine_HelperClasses_HPP
|
||||||
|
|
||||||
|
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
class po_cmdline_helper {
|
||||||
|
|
||||||
|
public:
|
||||||
|
void init(boost::program_options::options_description *cmdline_desc);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -1,9 +1,13 @@
|
|||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "POHelperClasses.hpp"
|
#include "POHelperClasses.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
#include <boost/regex.hpp>
|
||||||
|
#include <boost/algorithm/hex.hpp>
|
||||||
|
|
||||||
|
|
||||||
appeui::appeui(std::string appeui_hexstring){
|
appeui::appeui(std::string appeui_hexstring){
|
||||||
std::copy(appeui_hexstring.begin(), appeui_hexstring.end(), application_eui64.e8);
|
std::copy(appeui_hexstring.begin(), appeui_hexstring.end(), application_eui64.e8);
|
||||||
@ -17,8 +21,135 @@ deveui::deveui(std::string deveui_hexstring){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
devkey::devkey(std::string devkey_hexstring){
|
devkey::devkey(std::string devkey_hexstring){
|
||||||
std::copy(devkey_hexstring.begin(), devkey_hexstring.end(), device_key);
|
std::copy(devkey_hexstring.begin(), devkey_hexstring.end(), device_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Overload the 'validate' function for the user-defined class.
|
||||||
|
It makes sure that value is of form XXX-XXX
|
||||||
|
where X are digits and converts the second group to an integer.
|
||||||
|
This has no practical meaning, meant only to show how
|
||||||
|
regex can be used to validate values.
|
||||||
|
*/
|
||||||
|
void validate(boost::any& v,
|
||||||
|
const std::vector<std::string>& values,
|
||||||
|
magic_number*, int)
|
||||||
|
{
|
||||||
|
static boost::regex r("\\d\\d\\d-(\\d\\d\\d)");
|
||||||
|
|
||||||
|
using namespace boost::program_options;
|
||||||
|
|
||||||
|
// Make sure no previous assignment to 'a' was made.
|
||||||
|
validators::check_first_occurrence(v);
|
||||||
|
// Extract the first string from 'values'. If there is more than
|
||||||
|
// one string, it's an error, and exception will be thrown.
|
||||||
|
const std::string& s = validators::get_single_string(values);
|
||||||
|
|
||||||
|
// Do regex match and convert the interesting part to
|
||||||
|
// int.
|
||||||
|
boost::smatch match;
|
||||||
|
if (regex_match(s, match, r)) {
|
||||||
|
v = boost::any(magic_number(boost::lexical_cast<int>(match[1])));
|
||||||
|
} else {
|
||||||
|
throw validation_error(validation_error::invalid_option_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void validate(boost::any& v,
|
||||||
|
const std::vector<std::string>& values,
|
||||||
|
appeui*, int)
|
||||||
|
{
|
||||||
|
static boost::regex r("^([[:xdigit:]]{2}[:.-]?){7}[[:xdigit:]]{2}$");
|
||||||
|
|
||||||
|
boost::regex re("[:.-]");
|
||||||
|
|
||||||
|
using namespace boost::program_options;
|
||||||
|
|
||||||
|
// Make sure no previous assignment to 'a' was made.
|
||||||
|
validators::check_first_occurrence(v);
|
||||||
|
|
||||||
|
// Extract the first string from 'values'. If there is more than
|
||||||
|
// one string, it's an error, and exception will be thrown.
|
||||||
|
const std::string& s = validators::get_single_string(values);
|
||||||
|
|
||||||
|
// Do regex match and convert the interesting part to
|
||||||
|
// int.
|
||||||
|
boost::smatch match;
|
||||||
|
if (regex_match(s, match, r)) {
|
||||||
|
std::string unfilterd_string = match[0];
|
||||||
|
std::string filterd_string = boost::regex_replace( unfilterd_string, re, "" );
|
||||||
|
std::cout << "regex funktioniert .... " << filterd_string << std::endl;
|
||||||
|
std::cout << "boost algorithm ... " << boost::algorithm::unhex(filterd_string) << std::endl;
|
||||||
|
|
||||||
|
v = boost::any( appeui( boost::algorithm::unhex(filterd_string) ) );
|
||||||
|
} else {
|
||||||
|
throw validation_error(validation_error::invalid_option_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void validate(boost::any& v,
|
||||||
|
const std::vector<std::string>& values,
|
||||||
|
deveui*, int)
|
||||||
|
{
|
||||||
|
static boost::regex r("^([[:xdigit:]]{2}[:.-]?){7}[[:xdigit:]]{2}$");
|
||||||
|
|
||||||
|
boost::regex re("[:.-]");
|
||||||
|
|
||||||
|
using namespace boost::program_options;
|
||||||
|
|
||||||
|
// Make sure no previous assignment to 'a' was made.
|
||||||
|
validators::check_first_occurrence(v);
|
||||||
|
|
||||||
|
// Extract the first string from 'values'. If there is more than
|
||||||
|
// one string, it's an error, and exception will be thrown.
|
||||||
|
const std::string& s = validators::get_single_string(values);
|
||||||
|
|
||||||
|
// Do regex match and convert the interesting part to
|
||||||
|
// int.
|
||||||
|
boost::smatch match;
|
||||||
|
if (regex_match(s, match, r)) {
|
||||||
|
std::string unfilterd_string = match[0];
|
||||||
|
std::string filterd_string = boost::regex_replace( unfilterd_string, re, "" );
|
||||||
|
std::cout << "regex funktioniert .... " << filterd_string << std::endl;
|
||||||
|
std::cout << "boost algorithm ... " << boost::algorithm::unhex(filterd_string) << std::endl;
|
||||||
|
|
||||||
|
v = boost::any( deveui( boost::algorithm::unhex(filterd_string) ) );
|
||||||
|
} else {
|
||||||
|
throw validation_error(validation_error::invalid_option_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void validate(boost::any& v,
|
||||||
|
const std::vector<std::string>& values,
|
||||||
|
devkey*, int)
|
||||||
|
{
|
||||||
|
static boost::regex r("^([[:xdigit:]]{2}[:.-]?){15}[[:xdigit:]]{2}$");
|
||||||
|
|
||||||
|
boost::regex re("[:.-]");
|
||||||
|
|
||||||
|
using namespace boost::program_options;
|
||||||
|
|
||||||
|
// Make sure no previous assignment to 'a' was made.
|
||||||
|
validators::check_first_occurrence(v);
|
||||||
|
|
||||||
|
// Extract the first string from 'values'. If there is more than
|
||||||
|
// one string, it's an error, and exception will be thrown.
|
||||||
|
const std::string& s = validators::get_single_string(values);
|
||||||
|
|
||||||
|
// Do regex match and convert the interesting part to
|
||||||
|
// int.
|
||||||
|
boost::smatch match;
|
||||||
|
if (regex_match(s, match, r)) {
|
||||||
|
std::string unfilterd_string = match[0];
|
||||||
|
std::string filterd_string = boost::regex_replace( unfilterd_string, re, "" );
|
||||||
|
std::cout << "regex funktioniert .... " << filterd_string << std::endl;
|
||||||
|
std::cout << "boost algorithm ... " << boost::algorithm::unhex(filterd_string) << std::endl;
|
||||||
|
|
||||||
|
v = boost::any( devkey( boost::algorithm::unhex(filterd_string) ) );
|
||||||
|
} else {
|
||||||
|
throw validation_error(validation_error::invalid_option_value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
uint8_t e8[8]; /* lower 64-bit address */
|
uint8_t e8[8]; /* lower 64-bit address */
|
||||||
@ -31,7 +32,6 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class deveui {
|
class deveui {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -40,6 +40,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class devkey {
|
class devkey {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -48,5 +49,10 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void validate(boost::any& v, const std::vector<std::string>& values, magic_number*, int);
|
||||||
|
void validate(boost::any& v, const std::vector<std::string>& values, appeui*, int);
|
||||||
|
void validate(boost::any& v, const std::vector<std::string>& values, deveui*, int);
|
||||||
|
void validate(boost::any& v, const std::vector<std::string>& values, devkey*, int);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
APPEUI = 4523000000000101
|
APPEUI = 0101000000002345
|
||||||
DEVEUI = 70B3D57ED005538D
|
DEVEUI = 8D5305D07ED5B370
|
||||||
DEVKEY = 4499B4D3DB0207E3D61A066ECB26FCA2
|
DEVKEY = 4499B4D3DB0207E3D61A066ECB26FCA2
|
||||||
|
240
main.cpp
240
main.cpp
@ -4,6 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "POHelperClasses.hpp"
|
#include "POHelperClasses.hpp"
|
||||||
|
#include "POCmdlineHelperClasses.hpp"
|
||||||
#include "MQTTDataStreamer.hpp"
|
#include "MQTTDataStreamer.hpp"
|
||||||
|
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
@ -37,13 +38,13 @@ const auto TIMEOUT = std::chrono::seconds(1);
|
|||||||
//////////////////////////////////////////////////
|
//////////////////////////////////////////////////
|
||||||
|
|
||||||
// application router ID (LSBF)
|
// application router ID (LSBF)
|
||||||
static const u1_t APPEUI[8] = {0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x23, 0x45};
|
static u1_t APPEUI[8];
|
||||||
|
|
||||||
// unique device ID (LSBF)
|
// unique device ID (LSBF)
|
||||||
static const u1_t DEVEUI[8] = {0x8D, 0x53, 0x05, 0xD0, 0x7E, 0xD5, 0xB3, 0x70};
|
static u1_t DEVEUI[8];
|
||||||
|
|
||||||
// device-specific AES key (derived from device EUI)
|
// device-specific AES key (derived from device EUI)
|
||||||
static const u1_t DEVKEY[16] = {0x44, 0x99, 0xB4, 0xD3, 0xDB, 0x02, 0x07, 0xE3, 0xD6, 0x1A, 0x06, 0x6E, 0xCB, 0x26, 0xFC, 0xA2};
|
static u1_t DEVKEY[16];
|
||||||
|
|
||||||
//////////////////////////////////////////////////
|
//////////////////////////////////////////////////
|
||||||
// LMIC APPLICATION CALLBACKS
|
// LMIC APPLICATION CALLBACKS
|
||||||
@ -148,131 +149,18 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Overload the 'validate' function for the user-defined class.
|
|
||||||
It makes sure that value is of form XXX-XXX
|
|
||||||
where X are digits and converts the second group to an integer.
|
std::string mapper(std::string env_var)
|
||||||
This has no practical meaning, meant only to show how
|
|
||||||
regex can be used to validate values.
|
|
||||||
*/
|
|
||||||
void validate(boost::any& v,
|
|
||||||
const std::vector<std::string>& values,
|
|
||||||
magic_number*, int)
|
|
||||||
{
|
{
|
||||||
static boost::regex r("\\d\\d\\d-(\\d\\d\\d)");
|
// ensure the env_var is all caps
|
||||||
|
std::transform(env_var.begin(), env_var.end(), env_var.begin(), ::toupper);
|
||||||
|
|
||||||
using namespace boost::program_options;
|
if (env_var == "PATH") return "path";
|
||||||
|
if (env_var == "EXAMPLE_VERBOSE") return "verbosity";
|
||||||
// Make sure no previous assignment to 'a' was made.
|
if (env_var == "HOSTNAME") return "hostname";
|
||||||
validators::check_first_occurrence(v);
|
if (env_var == "HOME") return "home";
|
||||||
// Extract the first string from 'values'. If there is more than
|
return "";
|
||||||
// one string, it's an error, and exception will be thrown.
|
|
||||||
const std::string& s = validators::get_single_string(values);
|
|
||||||
|
|
||||||
// Do regex match and convert the interesting part to
|
|
||||||
// int.
|
|
||||||
boost::smatch match;
|
|
||||||
if (regex_match(s, match, r)) {
|
|
||||||
v = boost::any(magic_number(boost::lexical_cast<int>(match[1])));
|
|
||||||
} else {
|
|
||||||
throw validation_error(validation_error::invalid_option_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void validate(boost::any& v,
|
|
||||||
const std::vector<std::string>& values,
|
|
||||||
appeui*, int)
|
|
||||||
{
|
|
||||||
static boost::regex r("^([[:xdigit:]]{2}[:.-]?){7}[[:xdigit:]]{2}$");
|
|
||||||
|
|
||||||
boost::regex re("[:.-]");
|
|
||||||
|
|
||||||
using namespace boost::program_options;
|
|
||||||
|
|
||||||
// Make sure no previous assignment to 'a' was made.
|
|
||||||
validators::check_first_occurrence(v);
|
|
||||||
|
|
||||||
// Extract the first string from 'values'. If there is more than
|
|
||||||
// one string, it's an error, and exception will be thrown.
|
|
||||||
const std::string& s = validators::get_single_string(values);
|
|
||||||
|
|
||||||
// Do regex match and convert the interesting part to
|
|
||||||
// int.
|
|
||||||
boost::smatch match;
|
|
||||||
if (regex_match(s, match, r)) {
|
|
||||||
std::string unfilterd_string = match[0];
|
|
||||||
std::string filterd_string = boost::regex_replace( unfilterd_string, re, "" );
|
|
||||||
std::cout << "regex funktioniert .... " << filterd_string << std::endl;
|
|
||||||
std::cout << "boost algorithm ... " << boost::algorithm::unhex(filterd_string) << std::endl;
|
|
||||||
|
|
||||||
v = boost::any( appeui( boost::algorithm::unhex(filterd_string) ) );
|
|
||||||
} else {
|
|
||||||
throw validation_error(validation_error::invalid_option_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void validate(boost::any& v,
|
|
||||||
const std::vector<std::string>& values,
|
|
||||||
deveui*, int)
|
|
||||||
{
|
|
||||||
static boost::regex r("^([[:xdigit:]]{2}[:.-]?){7}[[:xdigit:]]{2}$");
|
|
||||||
|
|
||||||
boost::regex re("[:.-]");
|
|
||||||
|
|
||||||
using namespace boost::program_options;
|
|
||||||
|
|
||||||
// Make sure no previous assignment to 'a' was made.
|
|
||||||
validators::check_first_occurrence(v);
|
|
||||||
|
|
||||||
// Extract the first string from 'values'. If there is more than
|
|
||||||
// one string, it's an error, and exception will be thrown.
|
|
||||||
const std::string& s = validators::get_single_string(values);
|
|
||||||
|
|
||||||
// Do regex match and convert the interesting part to
|
|
||||||
// int.
|
|
||||||
boost::smatch match;
|
|
||||||
if (regex_match(s, match, r)) {
|
|
||||||
std::string unfilterd_string = match[0];
|
|
||||||
std::string filterd_string = boost::regex_replace( unfilterd_string, re, "" );
|
|
||||||
std::cout << "regex funktioniert .... " << filterd_string << std::endl;
|
|
||||||
std::cout << "boost algorithm ... " << boost::algorithm::unhex(filterd_string) << std::endl;
|
|
||||||
|
|
||||||
v = boost::any( deveui( boost::algorithm::unhex(filterd_string) ) );
|
|
||||||
} else {
|
|
||||||
throw validation_error(validation_error::invalid_option_value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void validate(boost::any& v,
|
|
||||||
const std::vector<std::string>& values,
|
|
||||||
devkey*, int)
|
|
||||||
{
|
|
||||||
static boost::regex r("^([[:xdigit:]]{2}[:.-]?){15}[[:xdigit:]]{2}$");
|
|
||||||
|
|
||||||
boost::regex re("[:.-]");
|
|
||||||
|
|
||||||
using namespace boost::program_options;
|
|
||||||
|
|
||||||
// Make sure no previous assignment to 'a' was made.
|
|
||||||
validators::check_first_occurrence(v);
|
|
||||||
|
|
||||||
// Extract the first string from 'values'. If there is more than
|
|
||||||
// one string, it's an error, and exception will be thrown.
|
|
||||||
const std::string& s = validators::get_single_string(values);
|
|
||||||
|
|
||||||
// Do regex match and convert the interesting part to
|
|
||||||
// int.
|
|
||||||
boost::smatch match;
|
|
||||||
if (regex_match(s, match, r)) {
|
|
||||||
std::string unfilterd_string = match[0];
|
|
||||||
std::string filterd_string = boost::regex_replace( unfilterd_string, re, "" );
|
|
||||||
std::cout << "regex funktioniert .... " << filterd_string << std::endl;
|
|
||||||
std::cout << "boost algorithm ... " << boost::algorithm::unhex(filterd_string) << std::endl;
|
|
||||||
|
|
||||||
v = boost::any( devkey( boost::algorithm::unhex(filterd_string) ) );
|
|
||||||
} else {
|
|
||||||
throw validation_error(validation_error::invalid_option_value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -297,30 +185,84 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
osjob_t initjob;
|
osjob_t initjob;
|
||||||
|
|
||||||
|
std::string hostname;
|
||||||
|
|
||||||
|
po_cmdline_helper po_cmdline_inst;
|
||||||
|
|
||||||
|
boost::program_options::options_description desc_env;
|
||||||
|
desc_env.add_options() ("path", "the execution path")
|
||||||
|
("home", "the home directory of the executing user")
|
||||||
|
("verbosity", po::value<std::string>()->default_value("INFO"), "set verbosity: DEBUG, INFO, WARN, ERROR, FATAL")
|
||||||
|
("hostname", boost::program_options::value<std::string>(&hostname));
|
||||||
|
|
||||||
|
boost::program_options::variables_map vm_env;
|
||||||
|
boost::program_options::store(boost::program_options::parse_environment(desc_env, boost::function1<std::string, std::string>(mapper)), vm_env);
|
||||||
|
boost::program_options::notify(vm_env);
|
||||||
|
|
||||||
|
if (vm_env.count("home"))
|
||||||
|
{
|
||||||
|
std::cout << "home path: " << vm_env["home"].as<std::string>() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vm_env.count("path"))
|
||||||
|
{
|
||||||
|
std::cout << "First 75 chars of the system path: \n";
|
||||||
|
std::cout << vm_env["path"].as<std::string>().substr(0, 75) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Verbosity: " << vm_env["verbosity"].as<std::string>() << std::endl;
|
||||||
|
|
||||||
|
if ( vm_env.count("hostname"))
|
||||||
|
{
|
||||||
|
std::cout << "hostname: " << vm_env["hostname"].as<std::string>() << std::endl; // correct value of HOSTNAME environent variable
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// set options allowed by the command line
|
// set options allowed by the command line
|
||||||
po::options_description command_line_options("Allowed options");
|
po::options_description command_line_options("Allowed options");
|
||||||
|
|
||||||
|
po_cmdline_inst.init( &command_line_options );
|
||||||
|
/*
|
||||||
command_line_options.add_options() ("help", "produce help message")
|
command_line_options.add_options() ("help", "produce help message")
|
||||||
("version,v", "print the version number")
|
("version,v", "print the version number")
|
||||||
("hostname,h", po::value<string>()->default_value("localhost"), "Hostname")
|
("hostname,h", po::value<string>()->default_value("localhost"), "Hostname")
|
||||||
("port,p", po::value<int>()->default_value(1883), "Port")
|
("port,p", po::value<int>()->default_value(1883), "Port")
|
||||||
("config,c", po::value<std::string>()->default_value("default.conf"), "configuration file")
|
("config,c", po::value<std::string>(), "configuration file")
|
||||||
("magic,m", po::value<magic_number>(), "magic value (in NNN-NNN format)")
|
("magic,m", po::value<magic_number>(), "magic value (in NNN-NNN format)")
|
||||||
("appeui", po::value<appeui>(), "APPEUI")
|
("appeui", po::value<appeui>(), "APPEUI")
|
||||||
("deveui", po::value<deveui>(), "DEVEUI")
|
("deveui", po::value<deveui>(), "DEVEUI")
|
||||||
("devkey", po::value<devkey>(), "DEVKEY");
|
("devkey", po::value<devkey>(), "DEVKEY");
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
// set options allowed in config file
|
// set options allowed in config file
|
||||||
po::options_description config_file_options;
|
po::options_description config_file_options;
|
||||||
config_file_options.add_options() ("APPEUI", po::value<appeui>(), "APPEUI")
|
config_file_options.add_options() ("APPEUI", po::value<appeui>(), "APPEUI")
|
||||||
("DEVEUI", po::value<deveui>(), "DEVEUI")
|
("DEVEUI", po::value<deveui>(), "DEVEUI")
|
||||||
("DEVKEY", po::value<devkey>(), "DEVKEY");
|
("DEVKEY", po::value<devkey>(), "DEVKEY");
|
||||||
|
|
||||||
|
|
||||||
po::variables_map variable_map;
|
po::variables_map variable_map;
|
||||||
po::store(po::parse_command_line(argc, argv, command_line_options), variable_map);
|
po::store(po::parse_command_line(argc, argv, command_line_options), variable_map);
|
||||||
po::notify(variable_map);
|
po::notify(variable_map);
|
||||||
|
|
||||||
auto config_file = variable_map.at("config").as<std::string>();
|
std::string config_file;
|
||||||
|
if( variable_map.count("config") ){
|
||||||
|
config_file = variable_map.at("config").as<std::string>();
|
||||||
|
}else if( vm_env.count("home") ){
|
||||||
|
|
||||||
|
if(std::filesystem::exists( vm_env["home"].as<std::string>() + "/.config/mqtt2LoRaWAN/default.conf" )){
|
||||||
|
config_file = vm_env["home"].as<std::string>() + "/.config/mqtt2LoRaWAN/default.conf";
|
||||||
|
}else if(std::filesystem::exists("/etc/mqtt2LoRaWAN/default.conf")){
|
||||||
|
config_file = "/etc/mqtt2LoRaWAN/default.conf";
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
if(std::filesystem::exists("/etc/mqtt2LoRaWAN/default.conf")){
|
||||||
|
config_file = "/etc/mqtt2LoRaWAN/default.conf";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::ifstream ifs(config_file.c_str());
|
std::ifstream ifs(config_file.c_str());
|
||||||
if (!ifs) {
|
if (!ifs) {
|
||||||
@ -355,9 +297,14 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
std::cout << "DEVEUI: " << std::endl;
|
std::cout << "DEVEUI: " << std::endl;
|
||||||
for( int i = 0; i < 8; i++ ){
|
for( int i = 0; i < 8; i++ ){
|
||||||
std::printf("%#02x", variable_map["DEVEUI"].as<deveui>().device_eui64.e8[i] );
|
std::printf("%#02x", variable_map["DEVEUI"].as<deveui>().device_eui64.e8[i] );
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
std::memcpy(DEVEUI, variable_map["DEVEUI"].as<deveui>().device_eui64.e8, 8);
|
||||||
|
|
||||||
|
}else{
|
||||||
|
std::cout << "No DEVEUI found in the config file. Add a 8 bytes long EUI to config file or specify an EUI as an option via the command line." << std::endl;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -365,9 +312,26 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
std::cout << "APPEUI: " << std::endl;
|
std::cout << "APPEUI: " << std::endl;
|
||||||
for( int i = 0; i < 8; i++ ){
|
for( int i = 0; i < 8; i++ ){
|
||||||
std::printf("%#02x", variable_map["APPEUI"].as<appeui>().application_eui64.e8[i] );
|
std::printf("%#02x", variable_map["APPEUI"].as<appeui>().application_eui64.e8[i] );
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
std::memcpy(APPEUI, variable_map["APPEUI"].as<appeui>().application_eui64.e8, 8);
|
||||||
|
}else{
|
||||||
|
std::cout << "No APPEUI found in the config file. Add a 8 bytes long EUI to config file or specify an EUI as an option via the command line." << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (variable_map.count("DEVKEY"))
|
||||||
|
{
|
||||||
|
std::cout << "DEVKEY: " << std::endl;
|
||||||
|
for( int i = 0; i < 16; i++ ){
|
||||||
|
std::printf("%#02x", variable_map["DEVKEY"].as<devkey>().device_key[i] );
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
std::memcpy(DEVKEY, variable_map["DEVKEY"].as<devkey>().device_key, 16);
|
||||||
|
}else{
|
||||||
|
std::cout << "No DEVKEY found in the config file. Add a 16 bytes long key to config file or specify a key as an option via the command line." << std::endl;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user