-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: zephyr: location: add simple cellular location demo
Add a sample with cellular network cell towers collected over the city trip. This is a playback with configurable speed (1x by default) to quickly see results over time during testing (e.g. on a Grafana map plugin). Signed-off-by: Marcin Niestroj <[email protected]>
- Loading branch information
Showing
14 changed files
with
601 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(location_cellular) | ||
|
||
target_sources(app PRIVATE src/main.c) | ||
target_sources_ifdef(CONFIG_GOLIOTH_CELLULAR_PLAYBACK app PRIVATE src/cellular_playback.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) 2021-2024 Golioth, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
source "${ZEPHYR_GOLIOTH_FIRMWARE_SDK_MODULE_DIR}/examples/zephyr/common/Kconfig.defconfig" | ||
|
||
config GOLIOTH_CELLULAR_PLAYBACK | ||
bool | ||
default y | ||
depends on DT_HAS_GOLIOTH_CELLULAR_PLAYBACK_ENABLED | ||
|
||
if GOLIOTH_CELLULAR_PLAYBACK | ||
|
||
config GOLIOTH_CELLULAR_PLAYBACK_SPEED_FACTOR | ||
int "Speed factor" | ||
default 1000 | ||
help | ||
Speed of playback. | ||
|
||
1000 means 1x (normal) speed. | ||
3000 means 3x speed. | ||
500 means 0.5x speed. | ||
|
||
endif # GOLIOTH_CELLULAR_PLAYBACK | ||
|
||
source "Kconfig.zephyr" |
8 changes: 8 additions & 0 deletions
8
examples/zephyr/location/cellular/dts/bindings/modem/golioth,cellular-playback.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright (c) 2024 Golioth, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
description: Cellular driver with playback of scanned cellular networks | ||
|
||
compatible: "golioth,cellular-playback" | ||
|
||
include: base.yaml |
15 changes: 15 additions & 0 deletions
15
examples/zephyr/location/cellular/dts/bindings/vendor-prefixes.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Device tree binding vendor prefix registry. Keep this list in | ||
# alphabetical order. | ||
# | ||
# This isn't an exhaustive list, but you should add new prefixes to it | ||
# before using them to avoid name-space collisions. | ||
# | ||
# The contents of this file are parsed during documentation generation. | ||
# Anything that starts with a '#' is treated as a comment and ignored. | ||
# Non-empty lines should be in this format: | ||
# | ||
# <vendor-prefix><TAB><Full name of vendor> | ||
|
||
# zephyr-keep-sorted-start | ||
golioth Golioth, Inc. | ||
# zephyr-keep-sorted-stop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Application | ||
CONFIG_GOLIOTH_SAMPLE_COMMON=y | ||
CONFIG_GOLIOTH_SAMPLE_HARDCODED_CREDENTIALS=y | ||
|
||
# Golioth Firmware SDK with all dependencies | ||
CONFIG_GOLIOTH_FIRMWARE_SDK=y | ||
|
||
CONFIG_GOLIOTH_LOCATION=y | ||
CONFIG_GOLIOTH_LOCATION_CELLULAR=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
sample: | ||
description: Location Cellular | ||
name: location cellular | ||
common: | ||
build_only: true | ||
tags: | ||
- golioth | ||
- location | ||
- socket | ||
tests: | ||
sample.golioth.location_cellular: | ||
platform_allow: | ||
- native_sim | ||
- native_sim/native/64 | ||
- nrf9160dk/nrf9160/ns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Use offloaded sockets using host BSD sockets | ||
CONFIG_ETH_DRIVER=n | ||
CONFIG_ETH_NATIVE_POSIX=n | ||
CONFIG_NET_DRIVERS=y | ||
CONFIG_NET_SOCKETS=y | ||
CONFIG_NET_SOCKETS_OFFLOAD=y | ||
CONFIG_NET_NATIVE_OFFLOADED_SOCKETS=y | ||
CONFIG_HEAP_MEM_POOL_SIZE=1024 | ||
|
||
# Use embedded libc to use Zephyr's eventfd instead of host eventfd | ||
CONFIG_PICOLIBC=y | ||
|
||
# Static networking | ||
CONFIG_NET_CONFIG_LOG_LEVEL_DBG=y | ||
CONFIG_NET_CONFIG_SETTINGS=y | ||
CONFIG_NET_CONFIG_NEED_IPV4=y | ||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1" | ||
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2" | ||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/ { | ||
cellular-playback { | ||
compatible = "golioth,cellular-playback"; | ||
status = "okay"; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Use offloaded sockets using host BSD sockets | ||
CONFIG_ETH_DRIVER=n | ||
CONFIG_ETH_NATIVE_POSIX=n | ||
CONFIG_NET_DRIVERS=y | ||
CONFIG_NET_SOCKETS=y | ||
CONFIG_NET_SOCKETS_OFFLOAD=y | ||
CONFIG_NET_NATIVE_OFFLOADED_SOCKETS=y | ||
CONFIG_HEAP_MEM_POOL_SIZE=1024 | ||
|
||
# Use embedded libc to use Zephyr's eventfd instead of host eventfd | ||
CONFIG_PICOLIBC=y | ||
|
||
# Static networking | ||
CONFIG_NET_CONFIG_LOG_LEVEL_DBG=y | ||
CONFIG_NET_CONFIG_SETTINGS=y | ||
CONFIG_NET_CONFIG_NEED_IPV4=y | ||
CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1" | ||
CONFIG_NET_CONFIG_MY_IPV4_GW="192.0.2.2" | ||
CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "native.overlay" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright (c) 2024 Golioth, Inc. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef __CELLULAR_H__ | ||
#define __CELLULAR_H__ | ||
|
||
#include <golioth/location/cellular.h> | ||
|
||
int cellular_info_get(struct golioth_cellular_info *infos, | ||
size_t num_max_infos, | ||
size_t *num_returned_infos); | ||
|
||
#endif /* __CELLULAR_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright (c) 2024 Golioth, Inc. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(cellular_playback, LOG_LEVEL_DBG); | ||
|
||
#include <zephyr/net/net_offload.h> | ||
|
||
#include "cellular.h" | ||
|
||
struct cellular_playback_info | ||
{ | ||
int64_t ts; | ||
const struct golioth_cellular_info *infos; | ||
size_t num_infos; | ||
}; | ||
|
||
struct cellular_playback_config | ||
{ | ||
const struct cellular_playback_info *infos; | ||
size_t num_infos; | ||
}; | ||
|
||
struct cellular_playback_data | ||
{ | ||
const struct cellular_playback_config *config; | ||
size_t info_idx; | ||
}; | ||
|
||
static const struct cellular_playback_config cellular_playback_config_0; | ||
static struct cellular_playback_data cellular_playback_data_0; | ||
|
||
int cellular_info_get(struct golioth_cellular_info *infos, | ||
size_t num_max_infos, | ||
size_t *num_returned_infos) | ||
{ | ||
struct cellular_playback_data *data = &cellular_playback_data_0; | ||
const struct cellular_playback_config *config = data->config; | ||
const struct cellular_playback_info *playback_info = &config->infos[data->info_idx]; | ||
size_t num_copied_infos = MIN(playback_info->num_infos, num_max_infos); | ||
|
||
k_sleep( | ||
K_TIMEOUT_ABS_MS(playback_info->ts * 1000 / CONFIG_GOLIOTH_CELLULAR_PLAYBACK_SPEED_FACTOR)); | ||
|
||
memcpy(infos, playback_info->infos, num_copied_infos * sizeof(*infos)); | ||
*num_returned_infos = num_copied_infos; | ||
|
||
data->info_idx++; | ||
|
||
return 0; | ||
} | ||
|
||
static int cellular_playback_init(void) | ||
{ | ||
const struct cellular_playback_config *config = &cellular_playback_config_0; | ||
struct cellular_playback_data *data = &cellular_playback_data_0; | ||
|
||
data->config = config; | ||
|
||
return 0; | ||
} | ||
|
||
#include "cellular_playback_input.c" | ||
|
||
static const struct cellular_playback_config cellular_playback_config_0 = { | ||
.infos = cellular_infos, | ||
.num_infos = ARRAY_SIZE(cellular_infos), | ||
}; | ||
|
||
SYS_INIT(cellular_playback_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); |
Oops, something went wrong.