Skip to content

Commit 6506f1a

Browse files
Merge pull request #103 from scsd-cdh/zephyr-logging
Replaces ULOG with zephyr dictionary logging
2 parents dbb9d99 + 85d7188 commit 6506f1a

31 files changed

+54
-1188
lines changed

APP/CDH_App/app.overlay

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
/ {
2-
chosen {
3-
ulog,usart = &usart1;
4-
};
52
};

APP/CDH_App/prj.conf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1+
CONFIG_MAIN_STACK_SIZE=2048
12
CONFIG_SERIAL=y
23
CONFIG_CACHE_MANAGEMENT=y
34
CONFIG_BUILD_OUTPUT_HEX=y
45
CONFIG_HW_STACK_PROTECTION=y
56
CONFIG_WDT_DISABLE_AT_BOOT=y
67
CONFIG_LOG=y
78
CONFIG_CONSOLE=y
8-
CONFIG_ULOG=y
9-
CONFIG_ULOG_USE_UART=y
10-
CONFIG_ULOG_SYSTEM_ID=0x5353
11-
CONFIG_ULOG_LOG_BACKEND=y
129
CONFIG_LFP=y
1310
CONFIG_ARM_MPU=y
1411
CONFIG_THREAD_MONITOR=y
1512
CONFIG_THREAD_NAME=y
1613
CONFIG_UART_CONSOLE=y
1714
CONFIG_LED=y
18-
# CONFIG_LOG_BACKEND_UART is not set
15+
CONFIG_LOG_FUNC_NAME_PREFIX_ERR=y
16+
CONFIG_LOG_FUNC_NAME_PREFIX_WRN=y
17+
CONFIG_LOG_FUNC_NAME_PREFIX_INF=y
18+
CONFIG_LOG_DBG_COLOR_BLUE=y
19+
CONFIG_LOG_BACKEND_UART_OUTPUT_DICTIONARY=y
1920
CONFIG_LOG_OUTPUT=y
2021
CONFIG_BUILD_OUTPUT_COMPRESS_DEBUG_SECTIONS=y
21-
CONFIG_MAIN_STACK_SIZE=2048

APP/CDH_App/src/main.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,38 @@
77
#include <lfp/body.h>
88
#include <lfp/header.h>
99
#include <lfp/stream.h>
10-
#include <ulog/ulog.h>
1110
#include <zephyr/kernel.h>
11+
#include <zephyr/logging/log.h>
1212

1313
#define SYSID_CDH 1
1414
#define SYSID_COMMS 3
1515
#define ENDPOINT_COMMS_TEST 154
1616

17+
LOG_MODULE_REGISTER(main);
18+
1719
void asn1_example_bms_system_status_req(const BMSSystemStatusRequest * p_payload, const asn1_lfp_decode_data_t * p_data) {
18-
ULOG_INFO("Received system status request");
20+
LOG_INF("Received system status request");
1921
}
2022
void asn1_example_bms_system_status_res(const BMSSystemStatusResponse * p_payload, const asn1_lfp_decode_data_t * p_data) {
21-
ULOG_INFO("Received system status response: version {}, uptime {}", p_payload->version, p_payload->uptime);
23+
LOG_INF("Received system status response: version %d, uptime %d", p_payload->version, p_payload->uptime);
2224
}
2325

2426
void asn1_example_stream_error_handler(lfp_code_t reason, void * p_ctx) {
2527
ARG_UNUSED(p_ctx);
2628

27-
ULOG_ERROR("Stream error: {}", reason);
29+
LOG_ERR("Stream error: %d", reason);
2830
}
2931

3032
void asn1_example_error_handler(const int asn1_error, const asn1_lfp_decode_data_t * p_data) {
31-
ULOG_ERROR("Failed to decode message {} (error {})", lfp_composite_id(p_data->p_header), asn1_error);
33+
LOG_ERR("Failed to decode message %d (error %d)", lfp_composite_id(p_data->p_header), asn1_error);
3234
}
3335

3436
void asn1_example_on_msg(const lfp_header_t * p_header, const uint8_t * p_body, const uint16_t body_length, void * p_ctx) {
3537
ARG_UNUSED(p_ctx);
3638
ARG_UNUSED(body_length);
3739

38-
ULOG_INFO("Decoded packet on endpoint {}: {}", p_header->endpoint, ((struct ulog_slice){.data=(void *)p_body,.size=body_length}));
40+
LOG_INF("Decoded packet on endpoint %d", p_header->endpoint);
41+
LOG_HEXDUMP_INF(p_body, body_length, "Decoded packet:");
3942

4043
const asn1_lfp_decode_data_t data = {
4144
.p_header = p_header,
@@ -52,7 +55,7 @@ void asn1_example_on_msg(const lfp_header_t * p_header, const uint8_t * p_body,
5255
return;
5356
}
5457

55-
ULOG_WARN("Received unknown message {}", ULOG_SLICE_PTR((lfp_header_t *)p_header));
58+
LOG_HEXDUMP_WRN(p_header, sizeof(lfp_header_t), "Received unknown message:");
5659
}
5760

5861
void asn1_example(void) {
@@ -63,10 +66,10 @@ void asn1_example(void) {
6366
.version = 12
6467
});
6568
if (!size) {
66-
ULOG_ERROR("LFP encoding failed! {} {}", ASN1_LFP_ERROR_CODE.asn1, ASN1_LFP_ERROR_CODE.lfp);
69+
LOG_ERR("LFP encoding failed! %d %d", ASN1_LFP_ERROR_CODE.asn1, ASN1_LFP_ERROR_CODE.lfp);
6770
}
6871

69-
ULOG_INFO("Sending: {}", ((struct ulog_slice) {.data = payload, .size = size}));
72+
LOG_HEXDUMP_INF(payload, size, "Sending:");
7073

7174
uint8_t payload2[ASN1_LFP_RECV_BUF_SIZE(BMSSystemStatusResponse)];
7275
lfp_stream_ctx_t stream;

APP/COMMS_App/app.overlay

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
/ {
2-
chosen {
3-
ulog,usart = &usart1;
4-
};
5-
62
aliases {
73
transmitter = &uart4;
84
};

APP/COMMS_App/prj.conf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ CONFIG_WDT_DISABLE_AT_BOOT=y
66
CONFIG_LOG=y
77
CONFIG_CONSOLE=y
88
CONFIG_LIBCSP=y
9-
CONFIG_ULOG=y
10-
CONFIG_ULOG_USE_UART=y
11-
CONFIG_ULOG_SYSTEM_ID=0x3133
12-
CONFIG_ULOG_LOG_BACKEND=y
139
CONFIG_ARM_MPU=y
1410
CONFIG_THREAD_MONITOR=y
1511
CONFIG_THREAD_NAME=y
1612
CONFIG_HEAP_MEM_POOL_SIZE=2048
1713
CONFIG_UART_CONSOLE=y
1814
CONFIG_POSIX_SYSTEM_INTERFACES=y
19-
# CONFIG_LOG_BACKEND_UART is not set
15+
CONFIG_LOG_FUNC_NAME_PREFIX_ERR=y
16+
CONFIG_LOG_FUNC_NAME_PREFIX_WRN=y
17+
CONFIG_LOG_FUNC_NAME_PREFIX_INF=y
18+
CONFIG_LOG_DBG_COLOR_BLUE=y
19+
CONFIG_LOG_BACKEND_UART_OUTPUT_DICTIONARY=y
2020
CONFIG_LOG_OUTPUT=y
2121
CONFIG_BUILD_OUTPUT_COMPRESS_DEBUG_SECTIONS=y

APP/COMMS_App/src/main.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
#include <csp/csp.h>
55
#include <csp/drivers/usart.h>
66
#include <csp/interfaces/csp_if_lo.h>
7-
#include <ulog/ulog.h>
87
#include <zephyr/kernel.h>
8+
#include <zephyr/logging/log.h>
99
#include <zephyr/sys/printk.h>
1010

1111
#include "server.h"
1212
#include "test_client.h"
1313

14+
LOG_MODULE_REGISTER(main);
15+
1416
static void router_task(void * p1, void * p2, void * p3) {
1517
ARG_UNUSED(p1);
1618
ARG_UNUSED(p2);
@@ -39,7 +41,7 @@ int main(void) {
3941
printk("Size: %d", sizeof(usart_context_t));
4042
const char * kiss_device = DEVICE_DT_NAME(DT_ALIAS(transmitter));
4143

42-
ULOG_INFO("Initialising CSP");
44+
LOG_INF("Initialising CSP");
4345

4446
csp_conf.version = 1;
4547

@@ -60,7 +62,7 @@ int main(void) {
6062
};
6163
const int error = csp_usart_open_and_add_kiss_interface(&conf, CSP_IF_KISS_DEFAULT_NAME, SERVER_ADDRESS, &p_iface);
6264
if (error != CSP_ERR_NONE) {
63-
ULOG_ERROR("failed to add KISS interface [{}], error: {}", kiss_device, error);
65+
LOG_ERR("failed to add KISS interface [%s], error: %d", kiss_device, error);
6466
exit(1);
6567
}
6668
p_iface->is_default = 1;

APP/COMMS_App/src/server.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
#include "server.h"
22

33
#include <csp/csp.h>
4-
#include <ulog/ulog.h>
54
#include <zephyr/kernel.h>
5+
#include <zephyr/logging/log.h>
6+
67

78
#include "main.h"
89

10+
LOG_MODULE_REGISTER(server);
11+
912

1013
static void server_task(void * p1, void * p2, void * p3) {
1114
ARG_UNUSED(p1);
1215
ARG_UNUSED(p2);
1316
ARG_UNUSED(p3);
1417

15-
ULOG_INFO("Server task started");
18+
LOG_INF("Server task started");
1619

1720
/* Create socket with no specific socket options, e.g. accepts CRC32, HMAC, etc. if enabled during compilation */
1821
csp_socket_t sock = {0};
@@ -39,7 +42,7 @@ static void server_task(void * p1, void * p2, void * p3) {
3942
switch (csp_conn_dport(conn)) {
4043
case SERVER_PORT:
4144
/* Process packet here */
42-
ULOG_INFO("Packet received on MY_SERVER_PORT: {}", (char *) packet->data);
45+
LOG_HEXDUMP_INF(packet->data, packet->length, "Packet received on MY_SERVER_PORT:");
4346
csp_buffer_free(packet);
4447
break;
4548

APP/COMMS_App/src/test_client.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
#include "test_client.h"
22

33
#include <csp/csp.h>
4-
#include <ulog/ulog.h>
4+
#include <zephyr/logging/log.h>
5+
56

67
#include "main.h"
78

9+
LOG_MODULE_REGISTER(client);
10+
811
static void client_task(void * p1, void * p2, void * p3) {
912
ARG_UNUSED(p1);
1013
ARG_UNUSED(p2);
1114
ARG_UNUSED(p3);
1215

13-
ULOG_INFO("Client task started");
16+
LOG_INF("Client task started");
1417

1518
unsigned int count = 'A';
1619

@@ -20,23 +23,23 @@ static void client_task(void * p1, void * p2, void * p3) {
2023

2124
/* Send ping to server, timeout 1000 mS, ping size 100 bytes */
2225
int __maybe_unused result = csp_ping(SERVER_ADDRESS, 1000, 100, CSP_O_NONE);
23-
ULOG_INFO("Ping address: {}, result {} [mS]", SERVER_ADDRESS, result);
26+
LOG_INF("Ping address: %d, result %d [mS]", SERVER_ADDRESS, result);
2427

2528
/* Send data packet (string) to server */
2629

2730
/* 1. Connect to host on 'server_address', port MY_SERVER_PORT with regular UDP-like protocol and 1000 ms timeout */
2831
csp_conn_t * conn = csp_connect(CSP_PRIO_NORM, SERVER_ADDRESS, SERVER_PORT, 1000, CSP_O_NONE);
2932
if (conn == NULL) {
3033
/* Connect failed */
31-
ULOG_ERROR("Connection failed");
34+
LOG_ERR("Connection failed");
3235
return;
3336
}
3437

3538
/* 2. Get packet buffer for message/data */
3639
csp_packet_t * packet = csp_buffer_get(0);
3740
if (packet == NULL) {
3841
/* Could not get buffer element */
39-
ULOG_ERROR("Failed to get CSP buffer");
42+
LOG_ERR("Failed to get CSP buffer");
4043
return;
4144
}
4245

MIDDLEWARE/ASN1SCC/example.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@
33
#define ENDPOINT_COMMS_TEST 154
44

55
void asn1_example_bms_system_status_req(const BMSSystemStatusRequest * p_payload, const asn1_lfp_decode_data_t * p_data) {
6-
ULOG_INFO("Received system status request");
6+
LOG_INF("Received system status request");
77
}
88
void asn1_example_bms_system_status_res(const BMSSystemStatusResponse * p_payload, const asn1_lfp_decode_data_t * p_data) {
9-
ULOG_INFO("Received system status response: version {}, uptime {}", p_payload->version, p_payload->uptime);
9+
LOG_INF("Received system status response: version %d, uptime %d", p_payload->version, p_payload->uptime);
1010
}
1111

1212
void asn1_example_stream_error_handler(lfp_code_t reason, void * p_ctx) {
1313
ARG_UNUSED(p_ctx);
1414

15-
ULOG_ERROR("Stream error: {}", reason);
15+
LOG_ERR("Stream error: %d", reason);
1616
}
1717

1818
void asn1_example_error_handler(const int asn1_error, const asn1_lfp_decode_data_t * p_data) {
19-
ULOG_ERROR("Failed to decode message {} (error {})", lfp_composite_id(p_data->p_header), asn1_error);
19+
LOG_ERR("Failed to decode message %d (error %d)", lfp_composite_id(p_data->p_header), asn1_error);
2020
}
2121

2222
void asn1_example_on_msg(const lfp_header_t * p_header, const uint8_t * p_body, const uint16_t body_length, void * p_ctx) {
2323
ARG_UNUSED(p_ctx);
2424
ARG_UNUSED(body_length);
2525

26-
ULOG_INFO("Decoded packet on endpoint {}: {}", p_header->endpoint, ((struct ulog_slice){.data=(void *)p_body,.size=body_length}));
26+
LOG_INF("Decoded packet on endpoint %d", p_header->endpoint);
27+
LOG_HEXDUMP_INF(p_body, body_length, "Decoded packet:");
2728

2829
const asn1_lfp_decode_data_t data = {
2930
.p_header = p_header,
@@ -40,7 +41,7 @@ void asn1_example_on_msg(const lfp_header_t * p_header, const uint8_t * p_body,
4041
return;
4142
}
4243

43-
ULOG_WARN("Received unknown message {}", ULOG_SLICE_PTR((lfp_header_t *)p_header));
44+
LOG_WRN(p_header, sizeof(lfp_header_t), "Received unknown message:");
4445
}
4546

4647
void asn1_example(void) {
@@ -51,10 +52,10 @@ void asn1_example(void) {
5152
.version = 12
5253
});
5354
if (!size) {
54-
ULOG_ERROR("LFP encoding failed! {} {}", ASN1_LFP_ERROR_CODE.asn1, ASN1_LFP_ERROR_CODE.lfp);
55+
LOG_ERR("LFP encoding failed! %d %d", ASN1_LFP_ERROR_CODE.asn1, ASN1_LFP_ERROR_CODE.lfp);
5556
}
5657

57-
ULOG_INFO("Sending: {}", ((struct ulog_slice) {.data = payload, .size = size}));
58+
LOG_HEXDUMP_INF(payload, size, "Sending:");
5859

5960
uint8_t payload2[ASN1_LFP_RECV_BUF_SIZE(BMSSystemStatusResponse)];
6061
lfp_stream_ctx_t stream;

MIDDLEWARE/ULOG/CMakeLists.txt

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)