Skip to content

Commit 8a75c5c

Browse files
author
Enzo Frese
committed
west: Update project generator with CLOUD v2 features
1 parent c4f0fb6 commit 8a75c5c

File tree

6 files changed

+75
-19
lines changed

6 files changed

+75
-19
lines changed

scripts/west_commands/project_generator/jinja_templates/CMakeLists.j2

+13-5
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,29 @@ set(ENV{FW_NAME} "{{data['project']['fw_name']}}")
2323
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
2424

2525
project({{ project_name }})
26-
{%- if 'subsystem_lte' in data['features']%}
26+
{%- if 'subsystem-lte' in data['features']%}
2727

2828
add_custom_command(
2929
COMMAND ../../../scripts/gen-msg-key.py ../codec/cbor-decoder.yaml ../src/msg_key.h
3030
OUTPUT ../src/msg_key.h
3131
MAIN_DEPENDENCY ../codec/cbor-decoder.yaml
3232
)
33+
34+
{%- endif %}
35+
36+
{%- if 'subsystem-lte-v2' in data['features']%}
37+
38+
add_custom_command(
39+
COMMAND west gen-codec -d ../codec/cbor-decoder.yaml -e ../codec/cbor-encoder.yaml -o ../src/app_codec.h
40+
OUTPUT ../src/app_codec.h
41+
DEPENDS ../codec/cbor-decoder.yaml ../codec/cbor-encoder.yaml
42+
)
43+
3344
{%- endif %}
3445
{% for file in sources %}
35-
{%- if file != 'app_ble_svc.c'%}
46+
{%- if file %}
3647
target_sources(app PRIVATE src/{{ file }})
3748
{%- endif %}
38-
{%- if file == 'app_ble_svc.c' %}
39-
target_sources_ifdef(CONFIG_CTR_BLE app PRIVATE src/app_ble_svc.c)
40-
{%- endif%}
4149
{%- endfor %}
4250

4351
target_precompile_headers(app PRIVATE src/feature.h)

scripts/west_commands/project_generator/jinja_templates/app_cbor_v2_c.j2

+11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
#include <stddef.h>
4141
#include <stdint.h>
4242
#include <stdlib.h>
43+
44+
/* ### Preserved code "functions" (begin) */
45+
/* ^^^ Preserved code "functions" (end) */
46+
4347
{%- macro encode_items(zs, items, prefix='', indent='') %}
4448
{%- for item in items -%}
4549
{% for key, sub_items in item.items() %}
@@ -203,6 +207,7 @@ static int encode(zcbor_state_t *zs)
203207

204208
return 0;
205209
}
210+
{%- if data['encoder']%}
206211

207212
int decode(zcbor_state_t *zs, struct app_cbor_received *received)
208213
{
@@ -247,6 +252,8 @@ int decode(zcbor_state_t *zs, struct app_cbor_received *received)
247252
return 0;
248253
}
249254

255+
{%- endif %}
256+
250257
int app_cbor_encode(zcbor_state_t *zs)
251258
{
252259
int ret;
@@ -265,6 +272,8 @@ int app_cbor_encode(zcbor_state_t *zs)
265272
return 0;
266273
}
267274

275+
{%- if data['encoder']%}
276+
268277
int app_cbor_decode(zcbor_state_t *zs, struct app_cbor_received *received)
269278
{
270279
int ret;
@@ -276,3 +285,5 @@ int app_cbor_decode(zcbor_state_t *zs, struct app_cbor_received *received)
276285

277286
return 0;
278287
}
288+
289+
{%- endif %}

scripts/west_commands/project_generator/jinja_templates/app_cbor_v2_h.j2

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#ifdef __cplusplus
2727
extern "C" {
2828
#endif
29+
{%- if data['encoder'] %}
2930

3031
struct app_cbor_received {
3132
{%- for key in data['encoder']['schema']%}
@@ -35,9 +36,12 @@ int32_t {{sub}};
3536
{%- endfor %}
3637
{%- endfor %}
3738
};
39+
{%- endif %}
3840

3941
int app_cbor_encode(zcbor_state_t *zs);
42+
{%- if data['encoder'] %}
4043
int app_cbor_decode(zcbor_state_t *zs, struct app_cbor_received *received);
44+
{%- endif %}
4145

4246
#ifdef __cplusplus
4347
}

scripts/west_commands/project_generator/jinja_templates/app_config_new_c.j2

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
{#- GLOBAL VARIABLES #}
22
{%- set variant_name_lower = data['project']['variant']|lower -%}
3+
4+
{#- COM MODES #}
35
{%- set config_mode = [] -%}
46
{%- set array_mode = ['none'] -%}
5-
{%- if 'subsystem-lte' in data['features'] and 'subsystem-lrw' in data['features'] -%}
7+
8+
{%- set has_lte = 'subsystem-lte' in data['features'] -%}
9+
{%- set has_lte_v2 = 'subsystem-lte-v2' in data['features'] -%}
10+
{%- set has_lrw = 'subsystem-lrw' in data['features'] -%}
11+
12+
{%- if has_lte and has_lrw -%}
613
{%- do config_mode.append('NONE') %}
7-
{%- do array_mode.append('lte') %}
8-
{%- do array_mode.append('lrw') %}
9-
{%- elif 'subsystem-lte' in data['features'] and 'subsystem-lrw' not in data['features'] -%}
14+
{%- do array_mode.extend(['lte', 'lrw']) %}
15+
{%- elif has_lte_v2 and has_lrw -%}
16+
{%- do config_mode.append('NONE') %}
17+
{%- do array_mode.extend(['lte-v2', 'lrw']) %}
18+
{%- elif has_lte -%}
1019
{%- do config_mode.append('LTE') %}
1120
{%- do array_mode.append('lte') %}
12-
{%- elif 'subsystem-lte' not in data['features'] and 'subsystem-lrw' in data['features'] -%}
21+
{%- elif has_lte_v2 -%}
22+
{%- do config_mode.append('LTE_V2') %}
23+
{%- do array_mode.append('lte-v2') %}
24+
{%- elif has_lrw -%}
1325
{%- do config_mode.append('LRW') %}
1426
{%- do array_mode.append('lrw') %}
1527
{%- else -%}

scripts/west_commands/project_generator/jinja_templates/app_config_new_h.j2

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
{#- GLOBAL VARIABLES #}
22
{%- set variant_name_lower = data['project']['variant']|lower -%}
3+
4+
{#- COM MODES #}
35
{%- set config_mode = [] -%}
46
{%- set array_mode = ['none'] -%}
5-
{%- if 'subsystem-lte' in data['features'] and 'subsystem-lrw' in data['features'] -%}
7+
8+
{%- set has_lte = 'subsystem-lte' in data['features'] -%}
9+
{%- set has_lte_v2 = 'subsystem-lte-v2' in data['features'] -%}
10+
{%- set has_lrw = 'subsystem-lrw' in data['features'] -%}
11+
12+
{%- if has_lte and has_lrw -%}
613
{%- do config_mode.append('NONE') %}
7-
{%- do array_mode.append('lte') %}
8-
{%- do array_mode.append('lrw') %}
9-
{%- elif 'subsystem-lte' in data['features'] and 'subsystem-lrw' not in data['features'] -%}
14+
{%- do array_mode.extend(['lte', 'lrw']) %}
15+
{%- elif has_lte_v2 and has_lrw -%}
16+
{%- do config_mode.append('NONE') %}
17+
{%- do array_mode.extend(['lte_v2', 'lrw']) %}
18+
{%- elif has_lte -%}
1019
{%- do config_mode.append('LTE') %}
1120
{%- do array_mode.append('lte') %}
12-
{%- elif 'subsystem-lte' not in data['features'] and 'subsystem-lrw' in data['features'] -%}
21+
{%- elif has_lte_v2 -%}
22+
{%- do config_mode.append('LTE_V2') %}
23+
{%- do array_mode.append('lte_v2') %}
24+
{%- elif has_lrw -%}
1325
{%- do config_mode.append('LRW') %}
1426
{%- do array_mode.append('lrw') %}
1527
{%- else -%}

scripts/west_commands/project_generator/project_generator.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def generate_cmake(self, data):
473473
for root, dirs, files in os.walk(src_dir):
474474
# Collect sources
475475
for file in files:
476-
if file.endswith(".c") or file == "msg_key.h":
476+
if file.endswith(".c") or file == "msg_key.h" or file == "app_codec.h":
477477
file_path = os.path.relpath(os.path.join(root, file), src_dir)
478478
sources.append(file_path)
479479
# Render the template with data
@@ -524,9 +524,18 @@ def yaml_source(self, name, mode, ext):
524524
apps_dir = os.path.join(self.app_dir, name)
525525
yaml_dir = apps_dir
526526
try:
527-
with open(yaml_dir, "r") as stream:
528-
data = yaml.safe_load(stream)
529-
return data
527+
if ext != "cbor-encoder.yaml":
528+
with open(yaml_dir, "r") as stream:
529+
data = yaml.safe_load(stream)
530+
return data
531+
else:
532+
try:
533+
with open(yaml_dir, "r") as stream:
534+
data = yaml.safe_load(stream)
535+
return data
536+
except:
537+
log.wrn('The cbor-encoder.yaml file was not found in the project folder.')
538+
return None
530539

531540
except Exception as e:
532541
log.err(f"The {ext} file was not found in the project folder. Error: {e}")

0 commit comments

Comments
 (0)