diff options
author | Jesse Gilles <jgilles@multitech.com> | 2015-05-22 14:47:15 -0500 |
---|---|---|
committer | Jesse Gilles <jgilles@multitech.com> | 2015-05-22 14:47:15 -0500 |
commit | bfd5846c53d528c16a875f5b2469e1d29381763e (patch) | |
tree | 8182631bb580d0a05c05624b7e8a736f4ec983c6 /recipes-connectivity/lora/lora-packet-forwarder | |
parent | 2fe4b3bfcaef7164f8890d4eec58450e7271b639 (diff) | |
download | meta-mlinux-bfd5846c53d528c16a875f5b2469e1d29381763e.tar.gz meta-mlinux-bfd5846c53d528c16a875f5b2469e1d29381763e.tar.bz2 meta-mlinux-bfd5846c53d528c16a875f5b2469e1d29381763e.zip |
add recipes for initial LoRa support for MTAC-LORA
Diffstat (limited to 'recipes-connectivity/lora/lora-packet-forwarder')
4 files changed, 496 insertions, 0 deletions
diff --git a/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder-fixb64.patch b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder-fixb64.patch new file mode 100644 index 0000000..dc0df42 --- /dev/null +++ b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder-fixb64.patch @@ -0,0 +1,66 @@ +Index: git/basic_pkt_fwd/src/base64.c +=================================================================== +--- git.orig/basic_pkt_fwd/src/base64.c 2015-03-31 16:00:39.479058735 -0500 ++++ git/basic_pkt_fwd/src/base64.c 2015-03-31 16:02:18.529580540 -0500 +@@ -263,7 +263,7 @@ + DEBUG("ERROR: INVALID UNPADDED BASE64 STRING\n"); + return -1; + case 2: /* 2 chars in last block, must add 2 padding char */ +- if (max_len > (ret + 2 + 1)) { ++ if (max_len >= (ret + 2 + 1)) { + out[ret] = code_pad; + out[ret+1] = code_pad; + out[ret+2] = 0; +@@ -273,7 +273,7 @@ + return -1; + } + case 3: /* 3 chars in last block, must add 1 padding char */ +- if (max_len > (ret + 1 + 1)) { ++ if (max_len >= (ret + 1 + 1)) { + out[ret] = code_pad; + out[ret+1] = 0; + return ret+1; +Index: git/beacon_pkt_fwd/src/base64.c +=================================================================== +--- git.orig/beacon_pkt_fwd/src/base64.c 2015-03-31 16:00:39.479058735 -0500 ++++ git/beacon_pkt_fwd/src/base64.c 2015-03-31 16:03:26.040561508 -0500 +@@ -263,7 +263,7 @@ + DEBUG("ERROR: INVALID UNPADDED BASE64 STRING\n"); + return -1; + case 2: /* 2 chars in last block, must add 2 padding char */ +- if (max_len > (ret + 2 + 1)) { ++ if (max_len >= (ret + 2 + 1)) { + out[ret] = code_pad; + out[ret+1] = code_pad; + out[ret+2] = 0; +@@ -273,7 +273,7 @@ + return -1; + } + case 3: /* 3 chars in last block, must add 1 padding char */ +- if (max_len > (ret + 1 + 1)) { ++ if (max_len >= (ret + 1 + 1)) { + out[ret] = code_pad; + out[ret+1] = 0; + return ret+1; +Index: git/gps_pkt_fwd/src/base64.c +=================================================================== +--- git.orig/gps_pkt_fwd/src/base64.c 2015-03-31 16:02:59.344965478 -0500 ++++ git/gps_pkt_fwd/src/base64.c 2015-03-31 16:03:13.208755845 -0500 +@@ -263,7 +263,7 @@ + DEBUG("ERROR: INVALID UNPADDED BASE64 STRING\n"); + return -1; + case 2: /* 2 chars in last block, must add 2 padding char */ +- if (max_len > (ret + 2 + 1)) { ++ if (max_len >= (ret + 2 + 1)) { + out[ret] = code_pad; + out[ret+1] = code_pad; + out[ret+2] = 0; +@@ -273,7 +273,7 @@ + return -1; + } + case 3: /* 3 chars in last block, must add 1 padding char */ +- if (max_len > (ret + 1 + 1)) { ++ if (max_len >= (ret + 1 + 1)) { + out[ret] = code_pad; + out[ret+1] = 0; + return ret+1; diff --git a/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder-mts-enhancements.patch b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder-mts-enhancements.patch new file mode 100644 index 0000000..2bf82ff --- /dev/null +++ b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder-mts-enhancements.patch @@ -0,0 +1,265 @@ +Index: git/basic_pkt_fwd/src/basic_pkt_fwd.c +=================================================================== +--- git.orig/basic_pkt_fwd/src/basic_pkt_fwd.c 2015-04-01 15:14:12.192933389 -0500 ++++ git/basic_pkt_fwd/src/basic_pkt_fwd.c 2015-04-01 15:36:38.731731561 -0500 +@@ -42,6 +42,8 @@ + #include <netdb.h> /* gai_strerror */ + + #include <pthread.h> ++#include <getopt.h> ++#include <linux/limits.h> + + #include "parson.h" + #include "base64.h" +@@ -472,19 +474,65 @@ + return x; + } + ++void usage(char *proc_name) { ++ fprintf(stderr, "Usage: %s [-c config_dir] [-l logfile]\n", proc_name); ++ exit(1); ++} ++ ++ ++static char *short_options = "c:l:h"; ++static struct option long_options[] = { ++ {"config-dir", 1, 0, 'c'}, ++ {"logfile", 1, 0, 'l'}, ++ {"help", 0, 0, 'h'}, ++ {0, 0, 0, 0}, ++}; ++ + /* -------------------------------------------------------------------------- */ + /* --- MAIN FUNCTION -------------------------------------------------------- */ + +-int main(void) ++int main(int argc, char *argv[]) + { + struct sigaction sigact; /* SIGQUIT&SIGINT&SIGTERM signal handling */ + int i; /* loop variable and temporary variable for return value */ + + /* configuration file related */ +- char *global_cfg_path= "global_conf.json"; /* contain global (typ. network-wide) configuration */ +- char *local_cfg_path = "local_conf.json"; /* contain node specific configuration, overwrite global parameters for parameters that are defined in both */ +- char *debug_cfg_path = "debug_conf.json"; /* if present, all other configuration files are ignored */ +- ++ char *global_cfg_name = "global_conf.json"; /* contain global (typ. network-wide) configuration */ ++ char *local_cfg_name = "local_conf.json"; /* contain node specific configuration, overwrite global parameters for parameters that are defined in both */ ++ char *debug_cfg_name = "debug_conf.json"; /* if present, all other configuration files are ignored */ ++ ++ int opt_ind = 0; ++ char cfg_dir[PATH_MAX] = {0}; ++ char global_cfg_path[PATH_MAX] = {0}; ++ char local_cfg_path[PATH_MAX] = {0}; ++ char debug_cfg_path[PATH_MAX] = {0}; ++ char *logfile_path = NULL; ++ char *proc_name = argv[0]; ++ ++ while((i = getopt_long(argc, argv, short_options, long_options, &opt_ind)) >= 0) { ++ switch(i) { ++ case 0: ++ break; ++ case 'c': ++ strncpy(cfg_dir, optarg, sizeof(cfg_dir)-2); ++ strcat(cfg_dir, "/"); ++ break; ++ case 'l': ++ logfile_path = optarg; ++ break; ++ case 'h': ++ usage(proc_name); ++ break; ++ default: ++ usage(proc_name); ++ break; ++ } ++ } ++ ++ snprintf(global_cfg_path, sizeof(global_cfg_path), "%s%s", cfg_dir, global_cfg_name); ++ snprintf(local_cfg_path, sizeof(local_cfg_path), "%s%s", cfg_dir, local_cfg_name); ++ snprintf(debug_cfg_path, sizeof(debug_cfg_path), "%s%s", cfg_dir, debug_cfg_name); ++ + /* threads */ + pthread_t thrid_up; + pthread_t thrid_down; +@@ -522,6 +570,22 @@ + float rx_nocrc_ratio; + float up_ack_ratio; + float dw_ack_ratio; ++ ++ /* redirect stdout, stderr to logfile if specified */ ++ int logfile_fd; ++ FILE *logfile = NULL; ++ if (logfile_path) { ++ logfile = fopen(logfile_path, "w"); ++ if (logfile) { ++ logfile_fd = fileno(logfile); ++ dup2(logfile_fd, STDOUT_FILENO); ++ dup2(logfile_fd, STDERR_FILENO); ++ } ++ else { ++ printf("Error opening log file %s\n", logfile_path); ++ exit(1); ++ } ++ } + + /* display version informations */ + MSG("*** Basic Packet Forwarder for Lora Gateway ***\nVersion: " VERSION_STRING "\n"); +Index: git/gps_pkt_fwd/src/gps_pkt_fwd.c +=================================================================== +--- git.orig/gps_pkt_fwd/src/gps_pkt_fwd.c 2015-04-01 15:14:12.160933893 -0500 ++++ git/gps_pkt_fwd/src/gps_pkt_fwd.c 2015-04-01 15:14:12.280932001 -0500 +@@ -44,6 +44,8 @@ + #include <netdb.h> /* gai_strerror */ + + #include <pthread.h> ++#include <getopt.h> ++#include <linux/limits.h> + + #include "parson.h" + #include "base64.h" +@@ -539,19 +541,60 @@ + return x; + } + ++void usage(char *proc_name) { ++ fprintf(stderr, "Usage: %s [-c config_dir]\n", proc_name); ++ exit(1); ++} ++ ++ ++static char *short_options = "c:h"; ++static struct option long_options[] = { ++ {"config-dir", 1, 0, 'c'}, ++ {"help", 0, 0, 'h'}, ++ {0, 0, 0, 0}, ++}; ++ + /* -------------------------------------------------------------------------- */ + /* --- MAIN FUNCTION -------------------------------------------------------- */ + +-int main(void) ++int main(int argc, char *argv[]) + { + struct sigaction sigact; /* SIGQUIT&SIGINT&SIGTERM signal handling */ + int i; /* loop variable and temporary variable for return value */ + + /* configuration file related */ +- char *global_cfg_path= "global_conf.json"; /* contain global (typ. network-wide) configuration */ +- char *local_cfg_path = "local_conf.json"; /* contain node specific configuration, overwrite global parameters for parameters that are defined in both */ +- char *debug_cfg_path = "debug_conf.json"; /* if present, all other configuration files are ignored */ +- ++ char *global_cfg_name = "global_conf.json"; /* contain global (typ. network-wide) configuration */ ++ char *local_cfg_name = "local_conf.json"; /* contain node specific configuration, overwrite global parameters for parameters that are defined in both */ ++ char *debug_cfg_name = "debug_conf.json"; /* if present, all other configuration files are ignored */ ++ ++ int opt_ind = 0; ++ char cfg_dir[PATH_MAX] = {0}; ++ char global_cfg_path[PATH_MAX] = {0}; ++ char local_cfg_path[PATH_MAX] = {0}; ++ char debug_cfg_path[PATH_MAX] = {0}; ++ char *proc_name = argv[0]; ++ ++ while((i = getopt_long(argc, argv, short_options, long_options, &opt_ind)) >= 0) { ++ switch(i) { ++ case 0: ++ break; ++ case 'c': ++ strncpy(cfg_dir, optarg, sizeof(cfg_dir)-2); ++ strcat(cfg_dir, "/"); ++ break; ++ case 'h': ++ usage(proc_name); ++ break; ++ default: ++ usage(proc_name); ++ break; ++ } ++ } ++ ++ snprintf(global_cfg_path, sizeof(global_cfg_path), "%s%s", cfg_dir, global_cfg_name); ++ snprintf(local_cfg_path, sizeof(local_cfg_path), "%s%s", cfg_dir, local_cfg_name); ++ snprintf(debug_cfg_path, sizeof(debug_cfg_path), "%s%s", cfg_dir, debug_cfg_name); ++ + /* threads */ + pthread_t thrid_up; + pthread_t thrid_down; +Index: git/beacon_pkt_fwd/src/beacon_pkt_fwd.c +=================================================================== +--- git.orig/beacon_pkt_fwd/src/beacon_pkt_fwd.c 2015-04-01 15:14:12.156933956 -0500 ++++ git/beacon_pkt_fwd/src/beacon_pkt_fwd.c 2015-04-01 15:14:12.284931938 -0500 +@@ -45,6 +45,8 @@ + #include <netdb.h> /* gai_strerror */ + + #include <pthread.h> ++#include <getopt.h> ++#include <linux/limits.h> + + #include "parson.h" + #include "base64.h" +@@ -618,19 +620,60 @@ + return x; + } + ++void usage(char *proc_name) { ++ fprintf(stderr, "Usage: %s [-c config_dir]\n", proc_name); ++ exit(1); ++} ++ ++ ++static char *short_options = "c:h"; ++static struct option long_options[] = { ++ {"config-dir", 1, 0, 'c'}, ++ {"help", 0, 0, 'h'}, ++ {0, 0, 0, 0}, ++}; ++ + /* -------------------------------------------------------------------------- */ + /* --- MAIN FUNCTION -------------------------------------------------------- */ + +-int main(void) ++int main(int argc, char *argv[]) + { + struct sigaction sigact; /* SIGQUIT&SIGINT&SIGTERM signal handling */ + int i; /* loop variable and temporary variable for return value */ + + /* configuration file related */ +- char *global_cfg_path= "global_conf.json"; /* contain global (typ. network-wide) configuration */ +- char *local_cfg_path = "local_conf.json"; /* contain node specific configuration, overwrite global parameters for parameters that are defined in both */ +- char *debug_cfg_path = "debug_conf.json"; /* if present, all other configuration files are ignored */ +- ++ char *global_cfg_name = "global_conf.json"; /* contain global (typ. network-wide) configuration */ ++ char *local_cfg_name = "local_conf.json"; /* contain node specific configuration, overwrite global parameters for parameters that are defined in both */ ++ char *debug_cfg_name = "debug_conf.json"; /* if present, all other configuration files are ignored */ ++ ++ int opt_ind = 0; ++ char cfg_dir[PATH_MAX] = {0}; ++ char global_cfg_path[PATH_MAX] = {0}; ++ char local_cfg_path[PATH_MAX] = {0}; ++ char debug_cfg_path[PATH_MAX] = {0}; ++ char *proc_name = argv[0]; ++ ++ while((i = getopt_long(argc, argv, short_options, long_options, &opt_ind)) >= 0) { ++ switch(i) { ++ case 0: ++ break; ++ case 'c': ++ strncpy(cfg_dir, optarg, sizeof(cfg_dir)-2); ++ strcat(cfg_dir, "/"); ++ break; ++ case 'h': ++ usage(proc_name); ++ break; ++ default: ++ usage(proc_name); ++ break; ++ } ++ } ++ ++ snprintf(global_cfg_path, sizeof(global_cfg_path), "%s%s", cfg_dir, global_cfg_name); ++ snprintf(local_cfg_path, sizeof(local_cfg_path), "%s%s", cfg_dir, local_cfg_name); ++ snprintf(debug_cfg_path, sizeof(debug_cfg_path), "%s%s", cfg_dir, debug_cfg_name); ++ + /* threads */ + pthread_t thrid_up; + pthread_t thrid_down; diff --git a/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder-set-spi-path.patch b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder-set-spi-path.patch new file mode 100644 index 0000000..01ce509 --- /dev/null +++ b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder-set-spi-path.patch @@ -0,0 +1,111 @@ +Index: git/basic_pkt_fwd/src/basic_pkt_fwd.c +=================================================================== +--- git.orig/basic_pkt_fwd/src/basic_pkt_fwd.c 2015-01-07 14:38:10.016886785 -0600 ++++ git/basic_pkt_fwd/src/basic_pkt_fwd.c 2015-01-07 14:49:57.823412026 -0600 +@@ -106,6 +106,7 @@ + /* network configuration variables */ + static uint64_t lgwm = 0; /* Lora gateway MAC address */ + static char serv_addr[64] = STR(DEFAULT_SERVER); /* address of the server (host name or IPv4/IPv6) */ ++static char spi_device_path[64] = {0} ; /* custom SPI device path */ + static char serv_port_up[8] = STR(DEFAULT_PORT_UP); /* server port for upstream traffic */ + static char serv_port_down[8] = STR(DEFAULT_PORT_DW); /* server port for downstream traffic */ + static int keepalive_time = DEFAULT_KEEPALIVE; /* send a PULL_DATA request every X seconds, negative = disabled */ +@@ -393,6 +394,13 @@ + strncpy(serv_addr, str, sizeof serv_addr); + MSG("INFO: server hostname or IP address is configured to \"%s\"\n", serv_addr); + } ++ ++ /* spi device path (optional) */ ++ str = json_object_get_string(conf_obj, "spi_device"); ++ if (str != NULL) { ++ strncpy(spi_device_path, str, sizeof(spi_device_path)-1); ++ MSG("INFO: SPI device is configured to \"%s\"\n", spi_device_path); ++ } + + /* get up and down ports (optional) */ + val = json_object_get_value(conf_obj, "serv_port_up"); +@@ -629,6 +637,10 @@ + exit(EXIT_FAILURE); + } + freeaddrinfo(result); ++ ++ /* set custom SPI device path if configured */ ++ if (strlen(spi_device_path) > 0) ++ lgw_spi_set_path(spi_device_path); + + /* starting the concentrator */ + i = lgw_start(); +Index: git/beacon_pkt_fwd/src/beacon_pkt_fwd.c +=================================================================== +--- git.orig/beacon_pkt_fwd/src/beacon_pkt_fwd.c 2015-01-05 11:29:12.946020392 -0600 ++++ git/beacon_pkt_fwd/src/beacon_pkt_fwd.c 2015-01-07 14:57:00.338533303 -0600 +@@ -115,6 +115,7 @@ + /* network configuration variables */ + static uint64_t lgwm = 0; /* Lora gateway MAC address */ + static char serv_addr[64] = STR(DEFAULT_SERVER); /* address of the server (host name or IPv4/IPv6) */ ++static char spi_device_path[64] = {0} ; /* custom SPI device path */ + static char serv_port_up[8] = STR(DEFAULT_PORT_UP); /* server port for upstream traffic */ + static char serv_port_down[8] = STR(DEFAULT_PORT_DW); /* server port for downstream traffic */ + static int keepalive_time = DEFAULT_KEEPALIVE; /* send a PULL_DATA request every X seconds, negative = disabled */ +@@ -440,6 +441,13 @@ + strncpy(serv_addr, str, sizeof serv_addr); + MSG("INFO: server hostname or IP address is configured to \"%s\"\n", serv_addr); + } ++ ++ /* spi device path (optional) */ ++ str = json_object_get_string(conf_obj, "spi_device"); ++ if (str != NULL) { ++ strncpy(spi_device_path, str, sizeof(spi_device_path)-1); ++ MSG("INFO: SPI device is configured to \"%s\"\n", spi_device_path); ++ } + + /* get up and down ports (optional) */ + val = json_object_get_value(conf_obj, "serv_port_up"); +@@ -774,6 +782,10 @@ + exit(EXIT_FAILURE); + } + freeaddrinfo(result); ++ ++ /* set custom SPI device path if configured */ ++ if (strlen(spi_device_path) > 0) ++ lgw_spi_set_path(spi_device_path); + + /* starting the concentrator */ + i = lgw_start(); +Index: git/gps_pkt_fwd/src/gps_pkt_fwd.c +=================================================================== +--- git.orig/gps_pkt_fwd/src/gps_pkt_fwd.c 2015-01-05 11:29:12.946020392 -0600 ++++ git/gps_pkt_fwd/src/gps_pkt_fwd.c 2015-01-07 14:56:03.320278543 -0600 +@@ -110,6 +110,7 @@ + /* network configuration variables */ + static uint64_t lgwm = 0; /* Lora gateway MAC address */ + static char serv_addr[64] = STR(DEFAULT_SERVER); /* address of the server (host name or IPv4/IPv6) */ ++static char spi_device_path[64] = {0} ; /* custom SPI device path */ + static char serv_port_up[8] = STR(DEFAULT_PORT_UP); /* server port for upstream traffic */ + static char serv_port_down[8] = STR(DEFAULT_PORT_DW); /* server port for downstream traffic */ + static int keepalive_time = DEFAULT_KEEPALIVE; /* send a PULL_DATA request every X seconds, negative = disabled */ +@@ -424,6 +425,13 @@ + strncpy(serv_addr, str, sizeof serv_addr); + MSG("INFO: server hostname or IP address is configured to \"%s\"\n", serv_addr); + } ++ ++ /* spi device path (optional) */ ++ str = json_object_get_string(conf_obj, "spi_device"); ++ if (str != NULL) { ++ strncpy(spi_device_path, str, sizeof(spi_device_path)-1); ++ MSG("INFO: SPI device is configured to \"%s\"\n", spi_device_path); ++ } + + /* get up and down ports (optional) */ + val = json_object_get_value(conf_obj, "serv_port_up"); +@@ -717,6 +725,10 @@ + exit(EXIT_FAILURE); + } + freeaddrinfo(result); ++ ++ /* set custom SPI device path if configured */ ++ if (strlen(spi_device_path) > 0) ++ lgw_spi_set_path(spi_device_path); + + /* starting the concentrator */ + i = lgw_start(); diff --git a/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder-skip-bad-packets.patch b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder-skip-bad-packets.patch new file mode 100644 index 0000000..cb12a97 --- /dev/null +++ b/recipes-connectivity/lora/lora-packet-forwarder/lora-packet-forwarder-skip-bad-packets.patch @@ -0,0 +1,54 @@ +Index: git/basic_pkt_fwd/src/basic_pkt_fwd.c +=================================================================== +--- git.orig/basic_pkt_fwd/src/basic_pkt_fwd.c 2014-12-16 17:03:32.891297739 -0600 ++++ git/basic_pkt_fwd/src/basic_pkt_fwd.c 2014-12-18 10:49:22.379916372 -0600 +@@ -928,7 +928,8 @@ + MSG("ERROR: [up] received packet with unknown status\n"); + memcpy((void *)(buff_up + buff_index), (void *)",\"stat\":?", 9); + buff_index += 9; +- exit(EXIT_FAILURE); ++ continue; // skip packet ++ //exit(EXIT_FAILURE); + } + + /* Packet modulation, 13-14 useful chars */ +@@ -966,7 +967,8 @@ + MSG("ERROR: [up] lora packet with unknown datarate\n"); + memcpy((void *)(buff_up + buff_index), (void *)",\"datr\":\"SF?", 12); + buff_index += 12; +- exit(EXIT_FAILURE); ++ continue; // skip packet ++ //exit(EXIT_FAILURE); + } + switch (p->bandwidth) { + case BW_125KHZ: +@@ -985,7 +987,8 @@ + MSG("ERROR: [up] lora packet with unknown bandwidth\n"); + memcpy((void *)(buff_up + buff_index), (void *)"BW?\"", 4); + buff_index += 4; +- exit(EXIT_FAILURE); ++ continue; // skip packet ++ //exit(EXIT_FAILURE); + } + + /* Packet ECC coding rate, 11-13 useful chars */ +@@ -1014,7 +1017,8 @@ + MSG("ERROR: [up] lora packet with unknown coderate\n"); + memcpy((void *)(buff_up + buff_index), (void *)",\"codr\":\"?\"", 11); + buff_index += 11; +- exit(EXIT_FAILURE); ++ continue; // skip packet ++ //exit(EXIT_FAILURE); + } + + /* Lora SNR, 11-13 useful chars */ +@@ -1039,7 +1043,8 @@ + } + } else { + MSG("ERROR: [up] received packet with unknown modulation\n"); +- exit(EXIT_FAILURE); ++ continue; // skip packet ++ //exit(EXIT_FAILURE); + } + + /* Packet RSSI, payload size, 18-23 useful chars */ |