Skip to content

Commit

Permalink
enabled modules are now listed in module_defs.h so this can be used i…
Browse files Browse the repository at this point in the history
…n precompiler directives. ALP will include support for LoRaWAN module only when enabled. Supported apps will also link lorawan stack only when enabled
  • Loading branch information
glennergeerts committed Oct 12, 2018
1 parent dbc5883 commit ebafde6
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 4 deletions.
8 changes: 7 additions & 1 deletion stack/apps/modem/CMakeLists.txt
Expand Up @@ -29,4 +29,10 @@
#SET_PROPERTY(CACHE ${APP_PREFIX}_<param_name> PROPERTY STRINGS "value1;value2")
#

APP_BUILD(NAME ${APP_NAME} SOURCES modem.c LIBS alp d7ap framework)
IF(${MODULE_LORAWAN})
SET(libs alp d7ap lorawan framework)
ELSE()
SET(libs alp d7ap framework)
ENDIF()

APP_BUILD(NAME ${APP_NAME} SOURCES modem.c LIBS ${libs})
8 changes: 7 additions & 1 deletion stack/apps/sensor_action/CMakeLists.txt
Expand Up @@ -29,4 +29,10 @@
#SET_PROPERTY(CACHE ${APP_PREFIX}_<param_name> PROPERTY STRINGS "value1;value2")
#

APP_BUILD(NAME ${APP_NAME} SOURCES sensor.c LIBS alp d7ap framework)
IF(${MODULE_LORAWAN})
SET(libs alp d7ap lorawan framework)
ELSE()
SET(libs alp d7ap framework)
ENDIF()

APP_BUILD(NAME ${APP_NAME} SOURCES sensor.c LIBS ${libs})
8 changes: 8 additions & 0 deletions stack/apps/sensor_multimodal/sensor_multimodal.c
Expand Up @@ -33,6 +33,14 @@
#include "alp_layer.h"
#include "lorawan_stack.h"

#include "string.h"

#include "modules_defs.h"

#ifndef MODULE_LORAWAN
#error "sensor multimodal requires MODULE_LORAWAN=y"
#endif

#define DEBUG_PRINTF(...) log_print_string(__VA_ARGS__)

#define LORAWAN_APP_PORT 10
Expand Down
4 changes: 4 additions & 0 deletions stack/apps/sensor_pull/sensor_pull.c
Expand Up @@ -48,6 +48,10 @@
#include "hwi2c.h"
#endif

#ifdef MODULE_LORAWAN
#error "sensor_pull app is not compatible with LoRaWAN, so disable MODULE_LORAWAN in cmake"
#endif

#ifndef USE_SX127X
#error "background frames are only supported by the sx127x driver for now"
#endif
Expand Down
8 changes: 7 additions & 1 deletion stack/apps/sensor_push/CMakeLists.txt
Expand Up @@ -29,4 +29,10 @@
#SET_PROPERTY(CACHE ${APP_PREFIX}_<param_name> PROPERTY STRINGS "value1;value2")
#

APP_BUILD(NAME ${APP_NAME} SOURCES sensor_push.c LIBS alp d7ap framework)
IF(${MODULE_LORAWAN})
SET(libs alp d7ap lorawan framework)
ELSE()
SET(libs alp d7ap framework)
ENDIF()

APP_BUILD(NAME ${APP_NAME} SOURCES sensor_push.c LIBS ${libs})
32 changes: 32 additions & 0 deletions stack/cmake/module_macros.cmake
Expand Up @@ -130,3 +130,35 @@ MACRO(MODULE_BUILD_SETTINGS_FILE)
SET_GLOBAL(MODULE_EXTRA_DEFS_NUMBER "")
ENDMACRO()

# Add one or more CMAKE variables as '#define' statements to the "modules_defs.h"
# generated by the MODULES_BUILD_SETTINGS_FILE MACRO. This MACRO adopts the same
# variable types used by the GEN_SETTINGS_HEADER MACRO. See the explanation of that macro
# in utils.cmake for more explanation.
#
# Usage:
# MODULES_BUILD_SETTINGS_FILE([STRING <string_var> <string_var> ...] [ID <id_var> <id_var> ...] [BOOL <bool_var> <bool_var> ...] [NUMBER <number_var> <number_var> ...])
#
MACRO(MODULES_HEADER_DEFINE)
PARSE_HEADER_VARS("MODULES_EXTRA_DEFS" ${ARGN})
ENDMACRO()


# Construct a "modules_defs.h" header file in the binary 'module' directory containing
# the enabled modules. By default an 'empty' header file is generated.
# Settings can be added to this file by calling the MODULES_HEADER_DEFINE macro.
#
# Usage:
# MODULES_BUILD_SETTINGS_FILE()
#
MACRO(MODULES_BUILD_SETTINGS_FILE)
GEN_SETTINGS_HEADER("${CMAKE_CURRENT_BINARY_DIR}/modules_defs.h"
STRING "${MODULES_EXTRA_DEFS_STRING}"
BOOL "${MODULES_EXTRA_DEFS_BOOL}"
ID "${MODULES_EXTRA_DEFS_ID}"
NUMBER "${MODULES_EXTRA_DEFS_NUMBER}"
)
SET_GLOBAL(MODULES_EXTRA_DEFS_STRING "")
SET_GLOBAL(MODULES_EXTRA_DEFS_BOOL "")
SET_GLOBAL(MODULES_EXTRA_DEFS_ID "")
SET_GLOBAL(MODULES_EXTRA_DEFS_NUMBER "")
ENDMACRO()
10 changes: 10 additions & 0 deletions stack/modules/CMakeLists.txt
Expand Up @@ -21,6 +21,10 @@ include(${PROJECT_SOURCE_DIR}/cmake/module_macros.cmake)

SET(MODULE_EXTRA_MODULES_DIR "" CACHE STRING "Path to directory containing extra, out of tree modules (optional)")

#Export the 'binary' platform directory so the 'modules_defs.h' file
#generated by MODULES_BUILD_SETTINGS_FILE file can be found
EXPORT_GLOBAL_INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})

#Add the 'BUILD_MODULES' option
OPTION(BUILD_MODULES "Build Modules" ON)
LIST_SUBDIRS(MODULE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
Expand Down Expand Up @@ -48,6 +52,12 @@ FOREACH(__dir ${MODULE_DIRS})
IF(BUILD_MODULES AND ${MODULE_PREFIX})
ADD_SUBDIRECTORY(${__dir} ${CMAKE_CURRENT_BINARY_DIR}/modules/${__module_name})
MESSAGE(STATUS "Added module " ${__module_name})
STRING(TOUPPER ${__module_name} __upper_name)
MODULES_HEADER_DEFINE(BOOL MODULE_${__upper_name})
ENDIF()
UNSET(MODULE_PREFIX)
ENDFOREACH()

MODULES_BUILD_SETTINGS_FILE()


13 changes: 12 additions & 1 deletion stack/modules/alp/alp_layer.c
Expand Up @@ -32,6 +32,7 @@
#include "log.h"
#include "shell.h"
#include "timer.h"
#include "modules_defs.h"
#include "MODULE_ALP_defs.h"
#include "d7ap.h"
#include "lorawan_stack.h"
Expand Down Expand Up @@ -142,7 +143,9 @@ void alp_layer_init(alp_init_args_t* alp_init_args, bool is_shell_enabled)
.unsolicited_cb = alp_layer_process_command_from_d7ap
};

#ifdef MODULE_LORAWAN
lora_register_cbs(lorwan_rx,alp_layer_command_completed_from_lorawan, lorawan_join_completed);
#endif

alp_client_id = d7ap_register(&alp_desc);
timer_init_event(&alp_layer_process_command_timer, &_async_process_command_from_d7ap);
Expand Down Expand Up @@ -624,10 +627,12 @@ static bool alp_layer_parse_and_execute_alp_command(alp_command_t* command)
if(forward_itf_id == ALP_ITF_ID_D7ASP) {
// forward rest of the actions over the D7ASP interface
if(d7ap_interface_state==STATE_NOT_INITIALIZED){
#ifdef MODULE_LORAWAN
if(lorawan_interface_state==STATE_INITIALIZED){
lorawan_stack_deinit();
lorawan_interface_state=STATE_NOT_INITIALIZED;
}
#endif
d7ap_stack_init();
d7ap_interface_state=STATE_INITIALIZED;
}
Expand All @@ -640,7 +645,9 @@ static bool alp_layer_parse_and_execute_alp_command(alp_command_t* command)
break; // TODO return response
} else if(forward_itf_id == ALP_ITF_ID_SERIAL) {
alp_cmd_handler_output_alp_command(&command->alp_command_fifo);
} else if(forward_itf_id == ALP_ITF_ID_LORWAN) {
}
#ifdef MODULE_LORAWAN
else if(forward_itf_id == ALP_ITF_ID_LORWAN) {
if(lorawan_interface_state==STATE_NOT_INITIALIZED){
if(d7ap_interface_state==STATE_INITIALIZED){
d7ap_stop();
Expand All @@ -664,6 +671,7 @@ static bool alp_layer_parse_and_execute_alp_command(alp_command_t* command)
}
break; // TODO return response
}
#endif
else
{
assert(false);
Expand Down Expand Up @@ -790,6 +798,8 @@ void alp_layer_command_completed(uint16_t trans_id, error_t error) {

free_command(command);
}

#ifdef MODULE_LORAWAN
void lorwan_rx(lora_AppData_t *AppData)
{
DPRINT("RECEIVED DATA"); //TODO
Expand Down Expand Up @@ -835,3 +845,4 @@ void lorawan_join_completed(bool success,uint8_t app_port2,bool request_ack2)
alp_layer_command_completed_from_lorawan(NULL); //join failed
}
}
#endif

0 comments on commit ebafde6

Please sign in to comment.