Morse Micro IoT SDK  2.11.2
m2m_agent.c
Go to the documentation of this file.
1/*
2 * Copyright 2024 Morse Micro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
18#include "mmosal.h"
19#include "mmutils.h"
20#include "mmagic.h"
21#include "mmregdb.h"
22#include "mmwlan.h"
23
24#if !defined(MBEDTLS_CONFIG_FILE)
25#include "mbedtls/mbedtls_config.h"
26#else
27#include MBEDTLS_CONFIG_FILE
28#endif
29#ifdef MBEDTLS_THREADING_ALT
30#include "threading_alt.h"
31#endif
32
33
34#ifndef APPLICATION_VERSION
35#error Please define APPLICATION_VERSION to an appropriate value.
36#endif
37
39static void app_print_version_info(void)
40{
41 enum mmwlan_status status;
42 struct mmwlan_version version = { 0 };
43 struct mmwlan_bcf_metadata bcf_metadata = { 0 };
44 char hw_version_string[32] = { 0 };
45
46 bool ok = mmhal_get_hardware_version(hw_version_string, sizeof(hw_version_string));
47 if (!ok)
48 {
49 snprintf(hw_version_string, sizeof(hw_version_string), "%s", "Unknown");
50 }
51
52 printf("-----------------------------------\n");
53
54 printf(" HW Version: %s\n", hw_version_string);
55 status = mmwlan_get_bcf_metadata(&bcf_metadata);
56 if (status == MMWLAN_SUCCESS)
57 {
58 printf(" BCF API version: %u.%u.%u\n",
59 bcf_metadata.version.major,
60 bcf_metadata.version.minor,
61 bcf_metadata.version.patch);
62 if (bcf_metadata.build_version[0] != '\0')
63 {
64 printf(" BCF build version: %s\n", bcf_metadata.build_version);
65 }
66 if (bcf_metadata.board_desc[0] != '\0')
67 {
68 printf(" BCF board description: %s\n", bcf_metadata.board_desc);
69 }
70 }
71 else
72 {
73 printf(" !! BCF metadata retrival failed !!\n");
74 }
75
76 status = mmwlan_get_version(&version);
77 if (status != MMWLAN_SUCCESS)
78 {
79 printf(" !! Error occured whilst retrieving version info !!\n");
80 }
81 printf(" Morselib version: %s\n", version.morselib_version);
82 printf(" Morse firmware version: %s\n", version.morse_fw_version);
83 printf(" Morse chip ID: 0x%04lx\n", version.morse_chip_id);
84 printf(" Morse chip name: %s\n", version.morse_chip_id_string);
85 printf(" Application version: %s\n", APPLICATION_VERSION);
86 printf("-----------------------------------\n");
87
89}
90
95void app_init(void)
96{
97 printf("\n\nM2M Agent Example (Built " __DATE__ " " __TIME__ ")\n\n");
98
99
100 /* Initialize mbedTLS threading (required if MBEDTLS_THREADING_ALT is defined) */
101#ifdef MBEDTLS_THREADING_ALT
102 mbedtls_platform_threading_init();
103#endif
104
105 const struct mmagic_m2m_agent_init_args init_args = {
106 .app_version = APPLICATION_VERSION,
107 .reg_db = get_regulatory_db(),
108 };
109 struct mmagic_m2m_agent *m2m_agent = mmagic_m2m_agent_init(&init_args);
110 MM_UNUSED(m2m_agent);
111 printf("M2M interface enabled\n");
113}
struct mmagic_m2m_agent * mmagic_m2m_agent_init(const struct mmagic_m2m_agent_init_args *args)
Initialize the M2M agent.
bool mmhal_get_hardware_version(char *version_buffer, size_t version_buffer_length)
Reads information that can be used to identify the hardware platform, such as hardware ID and version...
#define MMOSAL_ASSERT(expr)
Assert that the given expression evaluates to true and abort execution if not.
Definition: mmosal.h:1006
#define MM_UNUSED(_x)
Casts the given expression to void to avoid "unused" warnings from the compiler.
Definition: mmutils.h:70
enum mmwlan_status mmwlan_get_version(struct mmwlan_version *version)
Retrieve version information from morselib and the connected Morse transceiver.
enum mmwlan_status mmwlan_get_bcf_metadata(struct mmwlan_bcf_metadata *metadata)
Read the metadata from the board configuration file (BCF).
mmwlan_status
Enumeration of status return codes.
Definition: mmwlan.h:50
@ MMWLAN_SUCCESS
The operation was successful.
Definition: mmwlan.h:52
static void app_print_version_info(void)
Prints various version information.
Definition: m2m_agent.c:39
void app_init(void)
Main entry point to the application.
Definition: m2m_agent.c:95
M2M initialization args.
Definition: mmagic.h:294
char app_version[MMAGIC_SYS_MAX_APP_VERSION_LENGTH+1]
Application version string.
Definition: mmagic.h:296
Board configuration file (BCF) metadata.
Definition: mmwlan.h:350
char board_desc[MMWLAN_BCF_BOARD_DESC_MAXLEN+1]
Board description string.
Definition: mmwlan.h:368
uint8_t patch
Patch version field.
Definition: mmwlan.h:359
struct mmwlan_bcf_metadata::@1 version
BCF semantic version.
uint16_t major
Major version field.
Definition: mmwlan.h:355
uint8_t minor
Minor version field.
Definition: mmwlan.h:357
char build_version[MMWLAN_BCF_BUILD_VERSION_MAXLEN+1]
Build version string.
Definition: mmwlan.h:376
Structure for retrieving version information from the mmwlan subsystem.
Definition: mmwlan.h:320