-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update Zephyr Module setup and include UDP interface * Update README.md
- Loading branch information
Showing
10 changed files
with
254 additions
and
9 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
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 |
---|---|---|
|
@@ -87,6 +87,7 @@ recv | |
recvbytes | ||
repo | ||
sdk | ||
september | ||
sni | ||
ssh | ||
stdlib | ||
|
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
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
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,29 @@ | ||
/** | ||
* @file udp_interface_zephyr.h | ||
* @brief UDP interface definitions to send and receive data over the | ||
* network via UDP in ZEPHYR OS. | ||
*/ | ||
|
||
|
||
#include "udp_interface.h" | ||
|
||
/** | ||
* @typedef OSNetwork_t | ||
*/ | ||
struct OSNetwork | ||
{ | ||
int os_socket; | ||
}; | ||
|
||
int nce_os_udp_connect( OSNetwork_t osnetwork, | ||
OSEndPoint_t nce_oboarding ); | ||
|
||
int nce_os_udp_send( OSNetwork_t osnetwork, | ||
void * pBuffer, | ||
size_t bytesToSend ); | ||
|
||
int nce_os_udp_recv( OSNetwork_t osnetwork, | ||
void * pBuffer, | ||
size_t bytesToRecv ); | ||
|
||
int nce_os_udp_disconnect( OSNetwork_t osnetwork ); |
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,93 @@ | ||
/** | ||
* @file udp_interface_zephyr.c | ||
* @brief Implements a UDP interface for ZEPHYR OS. | ||
* @author Hatim Jamali & Mohamed Abdelmaksoud | ||
* @date 01 September 2022 | ||
*/ | ||
|
||
|
||
#ifndef NCE_SDK_H_ | ||
#include <nce_iot_c_sdk.h> | ||
#endif | ||
|
||
#include <zephyr/kernel.h> | ||
#include <stdio.h> | ||
#include <modem/lte_lc.h> | ||
#include <zephyr/net/socket.h> | ||
#include "log_interface.h" | ||
#include <udp_interface_zephyr.h> | ||
|
||
|
||
LOG_MODULE_DECLARE( NCE_SDK, CONFIG_NCE_SDK_LOG_LEVEL ); | ||
|
||
/* Sample Network definitions */ | ||
struct OSNetwork xOSNetwork = { .os_socket = 0 }; | ||
|
||
int nce_os_udp_connect( OSNetwork_t osnetwork, | ||
OSEndPoint_t nce_oboarding ) | ||
{ | ||
int socket = zsock_socket( AF_INET, SOCK_DGRAM, | ||
IPPROTO_UDP ); | ||
int err; | ||
struct zsock_addrinfo * addr; | ||
struct zsock_addrinfo hints = | ||
{ | ||
.ai_family = AF_INET, | ||
.ai_socktype = SOCK_DGRAM | ||
}; | ||
|
||
err = getaddrinfo( nce_oboarding.host, | ||
NULL, &hints, &addr ); | ||
|
||
NceOSLogDebug( "getaddrinfo status: %d\n", err ); | ||
|
||
osnetwork->os_socket = socket; | ||
|
||
( ( struct sockaddr_in * ) addr->ai_addr )->sin_port = htons( nce_oboarding.port ); | ||
|
||
size_t peer_addr_size = sizeof( struct sockaddr_in ); | ||
|
||
err = zsock_connect( socket, addr->ai_addr, | ||
peer_addr_size ); | ||
NceOSLogDebug( "UDP Socket Connect: %d\n", err ); | ||
|
||
|
||
return err; | ||
} | ||
|
||
int nce_os_udp_send( OSNetwork_t osnetwork, | ||
void * pBuffer, | ||
size_t bytesToSend ) | ||
{ | ||
int flags = 0; | ||
int ret; | ||
|
||
ret = zsock_send( osnetwork->os_socket, pBuffer, bytesToSend, flags ); | ||
NceOSLogDebug( "UDP Socket Send: %d\n", ret ); | ||
|
||
return ret; | ||
} | ||
|
||
|
||
int nce_os_udp_recv( OSNetwork_t osnetwork, | ||
void * pBuffer, | ||
size_t bytesToRecv ) | ||
{ | ||
int flags = 0; | ||
int ret; | ||
|
||
ret = zsock_recv( osnetwork->os_socket, pBuffer, bytesToRecv, flags ); | ||
NceOSLogDebug( "UDP Socket Receive: %d\n", ret ); | ||
|
||
return ret; | ||
} | ||
|
||
int nce_os_udp_disconnect( OSNetwork_t osnetwork ) | ||
{ | ||
int err; | ||
|
||
err = zsock_close( osnetwork->os_socket ); | ||
NceOSLogDebug( "UDP Socket Disconnect: %d\n", err ); | ||
|
||
return err; | ||
} |
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 @@ | ||
west-commands: | ||
- file: scripts/west_commands/quickstart.py | ||
commands: | ||
- name: quickstart | ||
class: QuickStart | ||
help: Build a 1NCE OS Demo and flash it to a connected nrf9160 DK |
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,50 @@ | ||
|
||
from textwrap import dedent | ||
from west.commands import WestCommand | ||
from west import log | ||
import subprocess | ||
|
||
class QuickStart(WestCommand): | ||
|
||
def __init__(self): | ||
super().__init__( | ||
'quickstart', | ||
'Build a 1NCE OS Demo and flash it to a connected nrf9160 DK', | ||
dedent(''' Build and flash CoAP (With DTLS), LwM2M or UDP Demos, the payload reduction (using 1NCE Energy saver) can also be enabled. | ||
''')) | ||
|
||
def do_add_parser(self, parser_adder): | ||
parser = parser_adder.add_parser(self.name, | ||
help=self.help, | ||
description=self.description) | ||
parser.add_argument('-p', '--protocol', help='Select the protocol: coap (Default), lwm2m or udp') | ||
parser.add_argument('-e', '--energysaving', help='Set to "y" to enable energy saver') | ||
|
||
return parser | ||
|
||
def do_run(self, args, unknown_args): | ||
cmd = "west build -b nrf9160dk_nrf9160_ns " | ||
if (args.protocol is None or (args.protocol is not None and args.protocol.lower() == "coap") ): | ||
log.inf('Building 1NCE CoAP Demo') | ||
cmd = cmd + "nce-blueprint/nce_coap_demo --build-dir build_coap_demo " | ||
if( (args.energysaving is not None and args.energysaving.lower() == "y") ): | ||
cmd = cmd + "-DCONFIG_NCE_ENERGY_SAVER=y" | ||
log.inf('1NCE Energy Saver is Enabled') | ||
subprocess.run(cmd,shell=True) | ||
subprocess.run("west flash",shell=True) | ||
elif ( (args.protocol is not None and args.protocol.lower() == "udp") ): | ||
log.inf('Building 1NCE UDP Demo') | ||
cmd = cmd + "nce-blueprint/nce_udp_demo --build-dir build_udp_demo " | ||
if((args.energysaving is not None and args.energysaving.lower() == "y")): | ||
cmd = cmd + "-DCONFIG_NCE_ENERGY_SAVER=y" | ||
log.inf('1NCE Energy Saver is Enabled') | ||
subprocess.run(cmd,shell=True) | ||
subprocess.run("west flash",shell=True) | ||
elif ( (args.protocol is not None and args.protocol.lower() == "lwm2m") ): | ||
log.inf('Building 1NCE LwM2M Demo') | ||
cmd = cmd + "nce-blueprint/nce_lwm2m_demo --build-dir build_lwm2m_demo " | ||
subprocess.run(cmd,shell=True) | ||
subprocess.run("west flash",shell=True) | ||
else : | ||
log.err('Unsupported argument') | ||
|
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,26 @@ | ||
# Copyright (c) 2021 Nordic Semiconductor ASA | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
manifest: | ||
self: | ||
path: modules/lib/nce-sdk | ||
west-commands: scripts/west-commands.yml | ||
|
||
remotes: | ||
- name: ncs | ||
url-base: https://github.com/nrfconnect | ||
- name: nce | ||
url-base: https://github.com/1NCE-GmbH | ||
|
||
projects: | ||
- name: nrf | ||
remote: ncs | ||
repo-path: sdk-nrf | ||
revision: v2.2.0 | ||
import: true | ||
- name: nce-blueprint | ||
remote: nce | ||
repo-path: blueprint-zephyr | ||
revision: main | ||
|
||
|
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