Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

add native platform #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

liamw9534
Copy link

This PR provides some improvements to the NATIVE build support. Refer to the README.md file under stack/framework/hal/platforms/NATIVE for information on how to build and run some applications natively on Linux.

The native build supports:

  • Serial port emulation, including a modem interface allowing interaction with py7da
  • Push button emulation
  • Hardware timer emulation
  • Hardware radio interface emulation

There are some other changes included in this PR relating to some minor bugs I've encountered in the stack during the development of this PR. I've also extended the alp_layer to support application completion of write ALP commands in much the same manner as read ALP commands, as it led to nicer code not having to do everything explicitly through the file system layer.

This PR also has some new applications and chip support for the U-blox M8N GPS chip which will work both with the native build (if you have one of their "click" eval. boards attached to your computer via a serial port or FTDI cable) and the B_L072Z_LRWAN1 platform.

…enable cmake option.

phy: some defensive programming changes to prevent possible divide by zero and stack overrun.
serial_interface: if PLATFORM_MODEM_INTERFACE_UART is not defined then don't try to register a serial interface.
alp_layer: initialise with a default D7 interface.
alp_layer: add support for application layer to accept write file operations in the same manner as read file operations.  Useful if we want to bypass fs completely.
log: added new stack logging options to give improved trace read out.
log: added timestamps to logging output.
d7ap: these structs are used for constructing payloads in the stack and rely on byte alignment of members.
platforms/native: now supports emulated uart, timer, radio and buttons.
hwradio: extended API for platform/native implementation only.
console: new platform/native console option added.
apps/sensor_pull: bug fix as fs layer is not initialised before initialising the stack.
platforms/B_L072Z_LRWAN1: add support for USART4 which is excellent for TX pini only debug logging as an alt. to the JLink output.
platforms/B_L072Z_LRWAN1: add support for including GPS chip into platform build.
chip/neo_m8n_gps: new chip driver support (using UART) for the M8N GPS receiver.
apps/gateway_gps: new variant GPS gateway for testing GPS enabled sensor.
apps/sensor_gps: new GPS enabled sensor application.
@glennergeerts
Copy link
Contributor

Thanks for this extensive work! I will need some time to review this but will come back to you

Copy link
Contributor

@glennergeerts glennergeerts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for this very useful contribution. I added some review comments inline.

More generally: I would suggest to remove the extra apps and GPS driver introduced here. I think it is better to not add examples and drivers for a specific use case in this repo, to keep the code base smaller and better maintainable. Most users are not interested in a specific GPS chip for instance. It can be added to an external repo if needed, as described here http://mosaic-lopow.github.io/dash7-ap-open-source-stack/docs/out-of-tree/

@@ -49,7 +71,7 @@ __LINK_C void log_print_string(char* format, ...)
{
va_list args;
va_start(args, format);
printf("\n\r[%03d] ", NG(counter)++);
printf("\n\r[%u] [%03d] ", timer_get_counter_value(), NG(counter)++ );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make logging more expensive when running on an MCU. I suggest to remove this or make it configurable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think the overhead is that large? Still it does no harm to make it a compile-time option.

@@ -58,14 +80,14 @@ __LINK_C void log_print_stack_string(log_stack_layer_t type, char* format, ...)
{
va_list args;
va_start(args, format);
printf("\n\r[%03d] ", NG(counter)++);
printf("\n\r[%u] [%03d] [%s] ", timer_get_counter_value(), NG(counter)++, stack_layer_str[type]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

vprintf(format, args);
va_end(args);
}

__LINK_C void log_print_data(uint8_t* message, uint32_t length)
{
printf("\n\r[%03d]", NG(counter)++);
printf("\n\r[%u] [%03d]", timer_get_counter_value(), NG(counter)++);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@@ -79,7 +101,7 @@ void log_print_error_string(char* format,...)
{
va_list args;
va_start(args, format);
printf("\n\r%s[%03d]%s ", RTT_CTRL_BG_BRIGHT_RED, NG(counter)++, RTT_CTRL_RESET);
printf("\n\r%s[%u] [%03d]%s ", RTT_CTRL_BG_BRIGHT_RED, timer_get_counter_value(), NG(counter)++, RTT_CTRL_RESET);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@@ -33,9 +33,31 @@
#include "framework_defs.h"
#include "hwsystem.h"
#include "SEGGER_RTT.h"
#include "timer.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed when not used (see comment below)

@@ -0,0 +1,43 @@
# Overview
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be moved to the documentation site (http://mosaic-lopow.github.io/dash7-ap-open-source-stack/docs/home/) by moving this to docs/_docs/platform-native.md and linking to this from docs/_docs/hardware.md and docs/_data/docs.yaml

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will do that.


PYTHONPATH=`pwd` python examples/query_nodes.py -d /tmp/S1

# Related repositories
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy paste leftover?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will fix it.

@@ -457,6 +457,10 @@ void hw_radio_set_tx_power(int8_t eirp);

void hw_radio_set_rx_timeout(uint32_t timeout);

void hwradio_set_addr(int);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All 3 of the API functions seem rather specific to native, hence I would not add them to the public API but keep it internal?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Is there any convention I can follow for the private API calls?

// a single local machine, one can use the PID to set the address since PID
// is unique on a single machine.

struct radio_packet_header
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to add __attribute__((__packed__)) here, this makes it easier to distinguish the fields when looking at network traces in wireshark for instnace

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@@ -68,7 +68,9 @@ typedef enum
AES_CCM_32 = 0x07, /* data confidentiality and authenticity*/
} nls_method_t;

typedef struct {
#pragma pack(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I am not sure why this should be any different to __attribute__((__packed__)) but the compiler generates different code which breaks the packet construction unless I use #pragma pack(1) when compiling natively.

@glennergeerts glennergeerts changed the title d7ap_fs: use D7AP stack logging rather than NWL. Add missing logging… add native platform Nov 18, 2020

Run the following command to build using the assigned device /tmp/S0 from socat above:

cmake <stack_directory> -DCMAKE_TOOLCHAIN_FILE=<stack_directory>/cmake/toolchains/gcc.cmake -DAPP_GATEWAY=y -DAPP_SENSOR_PUSH=y -DAPP_SENSOR_PULL=y -DPLATFORM_UART_DEV0=/tmp/S0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is missing a -DPLATFORM=NATIVE parameter.


socat pty,link=/tmp/S0,raw,echo=0 pty,link=/tmp/S1,raw,echo=0 &

Run the following command to build using the assigned device /tmp/S0 from socat above:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now the fd to use for the UART is a build time parameter, which means that on one host PC it is only possible to run one node which uses UART right? Unless you have multiple build directories but this is cumbersome. I was wondering if it would not be easier and more flexible to pass the filename to use as a parameter to the binary (eg ./modem -d /tmp/S1)? This would simplify the build a bit and allow to start multiple nodes using different serial ports easily.

This is just a thought, and is not something which is blocking this PR. It can be done afterwards just as well if we decide to do so. WDYT?

@liamw9534
Copy link
Author

liamw9534 commented Nov 19, 2020 via email

@glennergeerts
Copy link
Contributor

Hi, are you still working on this PR? Do you need any help from us?

@liamw9534
Copy link
Author

liamw9534 commented Feb 1, 2021 via email

@glennergeerts
Copy link
Contributor

Sure, I was just curious ;)

bourne-h pushed a commit to bourne-h/dash7-ap-open-source-stack that referenced this pull request Jul 15, 2021
Resolve "Split alp_layer and D7"

Closes Sub-IoT#98

See merge request aloxy/oss-7!65
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants