From 294b8510d26b5e3b615c80c95a91262f0b5c4570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Oleksy?= Date: Thu, 7 Oct 2021 11:10:56 +0200 Subject: [PATCH] Anjay-freertos-client 21.10 Features: * Updated Anjay to version 2.14.0: - Used pre-implemented event loop. - Provided threading compatibility sources. - Used IPSO Objects API to implement sensors and push button. * Changed displayed sensor units. --- .gitignore | 1 + Application/Inc/anjay/anjay_config.h | 48 +- .../Inc/avsystem/coap/avs_coap_config.h | 12 +- .../Inc/avsystem/commons/avs_commons_config.h | 95 +- .../Inc/avsystem/commons/lwip-posix-compat.h | 1 - Application/Inc/basic_sensor_object.h | 39 - Application/Inc/lwm2m.h | 2 - Application/Inc/plf/plf_custom_config.h | 3 - Application/Inc/sensor_objects.h | 20 +- Application/Inc/three_axis_sensor_object.h | 38 - Application/Src/application.c | 1 - .../compat/threading/avs_cmsis_os_condvar.c | 137 + .../compat/threading/avs_cmsis_os_init_once.c | 60 + .../compat/threading/avs_cmsis_os_structs.h | 49 + .../Src/compat/threading/avs_csmis_os_mutex.c | 77 + Application/Src/lwm2m.c | 149 +- .../Src/objects/accelerometer_object.c | 32 - Application/Src/objects/barometer_object.c | 32 - Application/Src/objects/basic_sensor_object.c | 220 - .../Src/objects/basic_sensor_objects.c | 81 + Application/Src/objects/device_object.c | 2 +- Application/Src/objects/gyrometer_object.c | 32 - Application/Src/objects/humidity_object.c | 32 - Application/Src/objects/magnetometer_object.c | 32 - Application/Src/objects/temperature_object.c | 32 - .../Src/objects/three_axis_sensor_object.c | 172 - .../Src/objects/three_axis_sensor_objects.c | 92 + .../Inc/at_custom_modem_api.h | 96 +- .../Inc/at_custom_modem_signalling.h | 152 +- .../Inc/at_custom_modem_socket.h | 166 +- .../Inc/at_custom_modem_specific.h | 314 +- .../AT_modem_monarch/Inc/plf_modem_config.h | 170 +- .../AT_modem_monarch/Inc/sysctrl_specific.h | 118 +- .../Src/at_custom_modem_api.c | 146 +- .../Src/at_custom_modem_signalling.c | 932 +-- .../Src/at_custom_modem_socket.c | 1674 ++--- .../Src/at_custom_modem_specific.c | 4710 ++++++------- .../AT_modem_monarch/Src/sysctrl_specific.c | 904 +-- Drivers/CMSIS/Include/cmsis_armclang_ltm.h | 3782 +++++------ Drivers/CMSIS/Include/core_armv81mml.h | 5936 ++++++++--------- Drivers/CMSIS/Include/core_cm35p.h | 5820 ++++++++-------- .../Inc/cellular_service_utils.h | 280 +- .../Src/cellular_service_utils.c | 2894 ++++---- .../STM32_Cellular/Core/Rtosal/Inc/rtosal.h | 542 +- .../STM32_Cellular/Core/Rtosal/Src/rtosal.c | 1002 +-- Middlewares/Third_Party/Anjay | 2 +- Projects/B-L462E-CELL1/TYPE1SC/.cproject | 796 +-- Projects/STM32L496G-DISCO/BG96/.cproject | 56 +- Projects/STM32L496G-DISCO/MONARCH/.cproject | 32 +- .../app_compat/accelerometer_driver.c | 2 +- .../app_compat/barometer_driver.c | 7 +- .../app_compat/hygrometer_driver.c | 2 +- .../app_compat/magnetometer_driver.c | 6 +- README.md | 1 - 54 files changed, 15809 insertions(+), 16224 deletions(-) delete mode 100644 Application/Inc/basic_sensor_object.h delete mode 100644 Application/Inc/three_axis_sensor_object.h create mode 100644 Application/Src/compat/threading/avs_cmsis_os_condvar.c create mode 100644 Application/Src/compat/threading/avs_cmsis_os_init_once.c create mode 100644 Application/Src/compat/threading/avs_cmsis_os_structs.h create mode 100644 Application/Src/compat/threading/avs_csmis_os_mutex.c delete mode 100644 Application/Src/objects/accelerometer_object.c delete mode 100644 Application/Src/objects/barometer_object.c delete mode 100644 Application/Src/objects/basic_sensor_object.c create mode 100644 Application/Src/objects/basic_sensor_objects.c delete mode 100644 Application/Src/objects/gyrometer_object.c delete mode 100644 Application/Src/objects/humidity_object.c delete mode 100644 Application/Src/objects/magnetometer_object.c delete mode 100644 Application/Src/objects/temperature_object.c delete mode 100644 Application/Src/objects/three_axis_sensor_object.c create mode 100644 Application/Src/objects/three_axis_sensor_objects.c diff --git a/.gitignore b/.gitignore index 08f4d4d..d372043 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ Projects/*/.cproject Projects/*/.mxproject Projects/*/.project +__pycache__/ diff --git a/Application/Inc/anjay/anjay_config.h b/Application/Inc/anjay/anjay_config.h index ca44b78..264b89a 100644 --- a/Application/Inc/anjay/anjay_config.h +++ b/Application/Inc/anjay/anjay_config.h @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 AVSystem + * Copyright 2020-2021 AVSystem * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,7 +81,7 @@ * * Only meaningful if ANJAY_WITH_LOGS is enabled. */ -//#define ANJAY_WITH_TRACE_LOGS +/* #undef ANJAY_WITH_TRACE_LOGS */ /** * Enable core support for Access Control mechanisms. @@ -91,7 +91,7 @@ * ANJAY_WITH_MODULE_ACCESS_CONTROL, or a custom application-provided one * may be used. */ -#define ANJAY_WITH_ACCESS_CONTROL +/* #undef ANJAY_WITH_ACCESS_CONTROL */ /** * Enable support for the anjay_download() API. @@ -148,6 +148,28 @@ */ #define ANJAY_WITH_OBSERVATION_STATUS +/** + * Enable guarding of all accesses to anjay_t with a mutex. + */ +/* #undef ANJAY_WITH_THREAD_SAFETY */ + +/** + * Enable standard implementation of an event loop. + * + * Requires C11 stdatomic.h header to be available, and either a platform + * that provides a BSD-compatible socket API, or a compatibility layer file (see + * AVS_COMMONS_POSIX_COMPAT_HEADER in avs_commons_config.h). This + * is designed to best work with the defalt implementation of avs_net sockets + * (see AVS_COMMONS_NET_WITH_POSIX_AVS_SOCKET), but alternative socket + * implementations can also be used. + * + * The event loop is most useful when thread safety features + * (@ref ANJAY_WITH_THREAD_SAFETY and AVS_COMMONS_SCHED_THREAD_SAFE) are + * enabled as well, but this is not a hard requirement. See the documentation + * for anjay_event_loop_run() for details. + */ +#define ANJAY_WITH_EVENT_LOOP + /** * Enable support for features new to LwM2M protocol version 1.1. * @@ -319,18 +341,6 @@ */ #define ANJAY_MAX_PK_OR_IDENTITY_SIZE 256 -/** - * Maximum size in bytes supported for the "Server Public Key" resource in the - * LwM2M Security object. - * - * If editing this file manually, 256 shall - * be replaced with a positive integer literal. - * - * The default value defined in CMake build scripts is 2048. - * Minimal suggested setting for low-resource builds is 256. - */ -#define ANJAY_MAX_SERVER_PK_OR_IDENTITY_SIZE 256 - /** * Maximum size in bytes supported for the "Secret Key" resource in the LwM2M * Security Object. @@ -428,11 +438,15 @@ /** * Enable fw_update module (implementation of the Firmware Update object). - * - * Requires ANJAY_WITH_DOWNLOADER to be enabled. */ #define ANJAY_WITH_MODULE_FW_UPDATE +/** + * Enables ipso_objects module (generic implementation of the following kinds of + * the basic sensor and three axis sensor IPSO objects). + */ +#define ANJAY_WITH_MODULE_IPSO_OBJECTS + /** * Enable at_sms module (implementation of an SMS driver for AT modem devices). * diff --git a/Application/Inc/avsystem/coap/avs_coap_config.h b/Application/Inc/avsystem/coap/avs_coap_config.h index 8f3bb41..223b87a 100644 --- a/Application/Inc/avsystem/coap/avs_coap_config.h +++ b/Application/Inc/avsystem/coap/avs_coap_config.h @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 AVSystem + * Copyright 2020-2021 AVSystem * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,14 +52,14 @@ * In the repository, this file is provided as avs_coap_config.h.in, * intended to be processed by CMake. If editing this file manually, please copy * or rename it to avs_coap_config.h and for each of the - * #cmakedefine directives, please either replace it with regular - * #define to enable it, or comment it out to disable. You may also need + * \#cmakedefine directives, please either replace it with regular + * \#define to enable it, or comment it out to disable. You may also need * to replace variables wrapped in \@ signs with concrete values. Please * refer to the comments above each of the specific definition for details. * * If you are editing a file previously generated by CMake, these - * #cmakedefines will be already replaced by either #define or - * commented out #undef directives. + * \#cmakedefines will be already replaced by either \#define or + * commented out \#undef directives. */ /** @@ -161,7 +161,7 @@ /** * Enable poisoning of unwanted symbols when compiling avs_coap. * - * Requires a compiler that supports #pragma GCC poison. + * Requires a compiler that supports \#pragma GCC poison. * * This is mostly useful during development, to ensure that avs_commons do not * attempt to call functions considered harmful in this library, such as printf. diff --git a/Application/Inc/avsystem/commons/avs_commons_config.h b/Application/Inc/avsystem/commons/avs_commons_config.h index 63ccfdb..429347b 100644 --- a/Application/Inc/avsystem/commons/avs_commons_config.h +++ b/Application/Inc/avsystem/commons/avs_commons_config.h @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 AVSystem + * Copyright 2020-2021 AVSystem * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -217,7 +217,7 @@ * This implementation is usually very inefficient, and requires C11 stdatomic.h * header to be available. */ -#define AVS_COMMONS_COMPAT_THREADING_WITH_ATOMIC_SPINLOCK +/* #undef AVS_COMMONS_COMPAT_THREADING_WITH_ATOMIC_SPINLOCK */ /** * Enable implementation based on the POSIX Threads library. @@ -258,6 +258,16 @@ #define AVS_COMMONS_WITH_MBEDTLS /* #undef AVS_COMMONS_WITH_OPENSSL */ /* #undef AVS_COMMONS_WITH_TINYDTLS */ + +/** + * Enable support for custom TLS socket implementation. + * + * If enabled, the user needs to provide their own implementations of + * _avs_net_create_ssl_socket(), _avs_net_create_dtls_socket(), + * _avs_net_initialize_global_ssl_state() and + * _avs_net_cleanup_global_ssl_state(). + */ +/* #undef AVS_COMMONS_WITH_CUSTOM_TLS */ /**@}*/ /** @@ -266,7 +276,8 @@ /**@{*/ /** * Enable AEAD and HKDF support in avs_crypto. Requires MbedTLS in version at - * least 2.14.0 or OpenSSL in version at least 1.1.0. + * least 2.14.0, OpenSSL in version at least 1.1.0, or custom implementation in + * case of AVS_COMMONS_WITH_CUSTOM_TLS. */ /* #undef AVS_COMMONS_WITH_AVS_CRYPTO_ADVANCED_FEATURES */ @@ -292,8 +303,9 @@ * generating and managing keys and certificates via external engines. * * An actual implementation is required to use this feature. In the commercial - * version, you may use one of the default ones utilizing the PKCS#11 API (see - * @ref AVS_COMMONS_WITH_MBEDTLS_PKCS11_ENGINE and + * version, you may use one of the default ones (see + * @ref AVS_COMMONS_WITH_MBEDTLS_PKCS11_ENGINE, + * @ref AVS_COMMONS_WITH_MBEDTLS_PSA_ENGINE and * @ref AVS_COMMONS_WITH_OPENSSL_PKCS11_ENGINE) or provide your own. * * The functions that need to be provided in case of a custom implementation: @@ -314,7 +326,7 @@ * - _avs_crypto_openssl_engine_load_crls() * - _avs_crypto_openssl_engine_load_private_key() * - * External engines are supported only in OpenSSL and Mbed TLS backends. + * External engines are NOT supported in the TinyDTLS backend. */ /* #undef AVS_COMMONS_WITH_AVS_CRYPTO_ENGINE */ @@ -324,13 +336,58 @@ * * Requires @ref AVS_COMMONS_WITH_AVS_CRYPTO_ENGINE to be enabled. * + * NOTE: Query string format for this engine is a subset of the PKCS#11 URI + * scheme (see RFC 7512), modelled after the format accepted by libp11 OpenSSL + * engine. + * * NOTE: The unit tests for this feature depend on SoftHSM and pkcs11-tool. * These must be installed for the tests to pass. * * IMPORTANT: Only available in the commercial version. Ignored in the open - * source version. */ + * source version. + */ /* #undef AVS_COMMONS_WITH_MBEDTLS_PKCS11_ENGINE */ +/** + * Enables the default implementation of avs_crypto engine, based on Mbed TLS + * and Platform Security Architecture (PSA). + * + * Requires @ref AVS_COMMONS_WITH_AVS_CRYPTO_ENGINE to be enabled. + * + * NOTE: Query string format for this engine is: + * + *
+ * kid=[,lifetime=]|uid=
+ * 
+ * + * The values are parsed using strtoull() with base=0, so may be in decimal, + * 0-prefixed octal or 0x-prefixed hexadecimal. On key generation and + * certificate storage, the specified lifetime will be used, or lifetime 1 + * (default persistent storage) will be used if not. On key or certificate use, + * the lifetime of the actual key will be verified if present on the query + * string and the key will be rejected if different. + * + * Certificates are stored as PSA_KEY_TYPE_RAW_DATA key entries containing + * X.509 DER data. Alternatively, the PSA Protected Storage API can be used if + * @ref AVS_COMMONS_WITH_MBEDTLS_PSA_ENGINE_PROTECTED_STORAGE is enabled, by + * using the uid=... syntax. + * + * IMPORTANT: Only available in the commercial version. Ignored in the open + * source version. + */ +/* #undef AVS_COMMONS_WITH_MBEDTLS_PSA_ENGINE */ + +/** + * Enables support for the PSA Protected Storage API in the PSA-based avs_crypto + * engine. + * + * Requires @ref AVS_COMMONS_WITH_MBEDTLS_PSA_ENGINE to be enabled. + * + * IMPORTANT: Only available in the commercial version. Ignored in the open + * source version. + */ +/* #undef AVS_COMMONS_WITH_MBEDTLS_PSA_ENGINE_PROTECTED_STORAGE */ + /** * Is the dlsym() function available? * @@ -352,11 +409,16 @@ * * Requires @ref AVS_COMMONS_WITH_AVS_CRYPTO_ENGINE to be enabled. * + * NOTE: Query string format for this engine is a subset of the PKCS#11 URI + * scheme (see RFC 7512), modelled after the format accepted by libp11 OpenSSL + * engine. + * * NOTE: The unit tests for this feature depend on SoftHSM and pkcs11-tool. * These must be installed for the tests to pass. * * IMPORTANT: Only available in the commercial version. Ignored in the open - * source version. */ + * source version. + */ /* #undef AVS_COMMONS_WITH_OPENSSL_PKCS11_ENGINE */ /**@}*/ @@ -440,6 +502,13 @@ * components. */ /* #undef AVS_COMMONS_WITH_INTERNAL_TRACE */ + +/** + * Enables external implementation of logger subsystem with provided header. + * + * Default logger implementation can be found in avs_log_impl.h + */ +/* #undef AVS_COMMONS_WITH_EXTERNAL_LOGGER_HEADER */ /**@}*/ /** @@ -573,14 +642,6 @@ */ /* #undef AVS_COMMONS_NET_POSIX_AVS_SOCKET_HAVE_INET_NTOP */ -/** - * Is the inet_pton() function available? - * - * Disabling this flag will cause an internal implementation of this function - * adapted from BIND 4.9.4 to be used instead. - */ -/* #undef AVS_COMMONS_NET_POSIX_AVS_SOCKET_HAVE_INET_PTON */ - /** * Is the poll() function available? * @@ -606,7 +667,7 @@ * Makes all scheduler accesses synchronized and thread-safe, at the cost of * requiring avs_compat_threading to be enabled, and higher resource usage. */ -/* #undef AVS_COMMONS_SCHED_THREAD_SAFE */ +#define AVS_COMMONS_SCHED_THREAD_SAFE /** * Enable support for file I/O in avs_stream. diff --git a/Application/Inc/avsystem/commons/lwip-posix-compat.h b/Application/Inc/avsystem/commons/lwip-posix-compat.h index 87ce23f..4827856 100644 --- a/Application/Inc/avsystem/commons/lwip-posix-compat.h +++ b/Application/Inc/avsystem/commons/lwip-posix-compat.h @@ -46,7 +46,6 @@ #if LWIP_VERSION_MAJOR >= 2 # define AVS_COMMONS_NET_POSIX_AVS_SOCKET_HAVE_INET_NTOP -# define AVS_COMMONS_NET_POSIX_AVS_SOCKET_HAVE_INET_PTON #endif // LWIP_VERSION_MAJOR >= 2 typedef int sockfd_t; diff --git a/Application/Inc/basic_sensor_object.h b/Application/Inc/basic_sensor_object.h deleted file mode 100644 index 428fff9..0000000 --- a/Application/Inc/basic_sensor_object.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2020-2021 AVSystem - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BASIC_SENSOR_OBJECT_H -#define BASIC_SENSOR_OBJECT_H - -#include "sensor_drivers/basic_sensor_driver.h" - -typedef struct { - const anjay_dm_object_def_t *def_ptr; - anjay_dm_object_def_t def; - - const basic_sensor_driver_t *driver; - float current_value; - float min_value; - float max_value; -} basic_sensor_object_t; - -int basic_sensor_object_install(anjay_t *anjay, - const basic_sensor_driver_t *driver, - anjay_oid_t oid, - basic_sensor_object_t *obj); - -void basic_sensor_object_update(anjay_t *anjay, basic_sensor_object_t *obj); - -#endif // BASIC_SENSOR_OBJECT_H diff --git a/Application/Inc/lwm2m.h b/Application/Inc/lwm2m.h index 654baaf..f1ee53f 100644 --- a/Application/Inc/lwm2m.h +++ b/Application/Inc/lwm2m.h @@ -21,6 +21,4 @@ void lwm2m_init(void); void lwm2m_start(void); -void lwm2m_notify_start(void); - #endif // LWM2M_H diff --git a/Application/Inc/plf/plf_custom_config.h b/Application/Inc/plf/plf_custom_config.h index a026c4a..86b840d 100644 --- a/Application/Inc/plf/plf_custom_config.h +++ b/Application/Inc/plf/plf_custom_config.h @@ -24,9 +24,6 @@ #define LWM2M_THREAD_STACK_SIZE (12288U) #define LWM2M_THREAD_PRIO osPriorityNormal -#define LWM2M_NOTIFY_THREAD_STACK_SIZE (512U) -#define LWM2M_NOTIFY_THREAD_PRIO osPriorityNormal - #define BOARD_BUTTONS_THREAD_STACK_SIZE (256U) #define BOARD_BUTTONS_THREAD_PRIO osPriorityBelowNormal diff --git a/Application/Inc/sensor_objects.h b/Application/Inc/sensor_objects.h index 37ce9bb..a16dd76 100644 --- a/Application/Inc/sensor_objects.h +++ b/Application/Inc/sensor_objects.h @@ -19,22 +19,10 @@ #include -int accelerometer_object_install(anjay_t *anjay); -void accelerometer_object_update(anjay_t *anjay); +int basic_sensor_objects_install(anjay_t *anjay); +void basic_sensor_objects_update(anjay_t *anjay); -int gyrometer_object_install(anjay_t *anjay); -void gyrometer_object_update(anjay_t *anjay); - -int magnetometer_object_install(anjay_t *anjay); -void magnetometer_object_update(anjay_t *anjay); - -int temperature_object_install(anjay_t *anjay); -void temperature_object_update(anjay_t *anjay); - -int humidity_object_install(anjay_t *anjay); -void humidity_object_update(anjay_t *anjay); - -int barometer_object_install(anjay_t *anjay); -void barometer_object_update(anjay_t *anjay); +int three_axis_sensor_objects_install(anjay_t *anjay); +void three_axis_sensor_objects_update(anjay_t *anjay); #endif // SENSOR_OBJECTS_H diff --git a/Application/Inc/three_axis_sensor_object.h b/Application/Inc/three_axis_sensor_object.h deleted file mode 100644 index aa79c37..0000000 --- a/Application/Inc/three_axis_sensor_object.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2020-2021 AVSystem - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef THREE_AXIS_SENSOR_OBJECT_H -#define THREE_AXIS_SENSOR_OBJECT_H - -#include "sensor_drivers/three_axis_sensor_driver.h" - -typedef struct { - const anjay_dm_object_def_t *def_ptr; - anjay_dm_object_def_t def; - - const three_axis_sensor_driver_t *driver; - three_axis_sensor_values_t values; -} three_axis_sensor_object_t; - -int three_axis_sensor_object_install(anjay_t *anjay, - const three_axis_sensor_driver_t *driver, - anjay_oid_t oid, - three_axis_sensor_object_t *obj); - -void three_axis_sensor_object_update(anjay_t *anjay, - three_axis_sensor_object_t *obj); - -#endif // THREE_AXIS_SENSOR_OBJECT_H diff --git a/Application/Src/application.c b/Application/Src/application.c index e531046..6a468dc 100644 --- a/Application/Src/application.c +++ b/Application/Src/application.c @@ -91,6 +91,5 @@ void application_init() { cellular_start(); lwm2m_start(); - lwm2m_notify_start(); utilities_start(); } diff --git a/Application/Src/compat/threading/avs_cmsis_os_condvar.c b/Application/Src/compat/threading/avs_cmsis_os_condvar.c new file mode 100644 index 0000000..3221e43 --- /dev/null +++ b/Application/Src/compat/threading/avs_cmsis_os_condvar.c @@ -0,0 +1,137 @@ +/* + * Copyright 2020-2021 AVSystem + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "avs_cmsis_os_structs.h" + +#include + +// Code partially inspired by: +// https://github.com/yaahallo/nachos/blob/master/threads/Condition.java +// The Nachos project is the code examples for the Operating Systems course on +// the University of California, see: +// https://eng.ucmerced.edu/crf/engineering/cse-150-operating-systems/ +// Copyright (c) 1992-2001 The Regents of the University of California. +// All rights reserved. Used under BSD license +// (https://github.com/yaahallo/nachos/blob/master/README) + +int avs_condvar_create(avs_condvar_t **out_condvar) { + AVS_ASSERT(!*out_condvar, + "possible attempt to reinitialize a condition variable"); + + *out_condvar = (avs_condvar_t *) avs_calloc(1, sizeof(avs_condvar_t)); + if (!*out_condvar) { + return -1; + } + if (_avs_mutex_init(&(*out_condvar)->waiters_mutex)) { + avs_free(*out_condvar); + *out_condvar = NULL; + return -1; + } + return 0; +} + +int avs_condvar_notify_all(avs_condvar_t *condvar) { + avs_mutex_lock(&condvar->waiters_mutex); + condvar_waiter_node_t *waiter = condvar->first_waiter; + while (waiter) { + // wake up the waiter + atomic_flag_clear(&waiter->waiting); + + waiter = waiter->next; + } + avs_mutex_unlock(&condvar->waiters_mutex); + return 0; +} + +static void insert_new_waiter(avs_condvar_t *condvar, + condvar_waiter_node_t *waiter) { + avs_mutex_lock(&condvar->waiters_mutex); + + // Initialize the waiting flag to true + atomic_flag_clear(&waiter->waiting); + bool value = atomic_flag_test_and_set(&waiter->waiting); + assert(!value); + (void) value; + + // Insert waiter as the first element on the list + waiter->next = condvar->first_waiter; + condvar->first_waiter = waiter; + + avs_mutex_unlock(&condvar->waiters_mutex); +} + +static void remove_waiter(avs_condvar_t *condvar, + condvar_waiter_node_t *waiter) { + avs_mutex_lock(&condvar->waiters_mutex); + + condvar_waiter_node_t **waiter_node_ptr = &condvar->first_waiter; + while (*waiter_node_ptr && *waiter_node_ptr != waiter) { + waiter_node_ptr = &(*waiter_node_ptr)->next; + } + AVS_ASSERT(*waiter_node_ptr == waiter, + "waiter node inexplicably disappeared from condition variable"); + if (*waiter_node_ptr == waiter) { + // detach it + *waiter_node_ptr = (*waiter_node_ptr)->next; + } + + avs_mutex_unlock(&condvar->waiters_mutex); +} + +int avs_condvar_wait(avs_condvar_t *condvar, + avs_mutex_t *mutex, + avs_time_monotonic_t deadline) { + // Precondition: mutex is locked by the current thread + // although we can't check if it's the current thread that locked it :( + + bool use_deadline = avs_time_monotonic_valid(deadline); + bool flag_value; + condvar_waiter_node_t waiter; + insert_new_waiter(condvar, &waiter); + + avs_mutex_unlock(mutex); + do { + flag_value = atomic_flag_test_and_set(&waiter.waiting); + } while (flag_value + && (!use_deadline + || avs_time_monotonic_before(avs_time_monotonic_now(), + deadline))); + avs_mutex_lock(mutex); + + remove_waiter(condvar, &waiter); + + // flag_value == 0 -> it means it was cleared, so we've been woken up + // flag_value == 1 -> it mean we haven't, so timeout occurred + return flag_value ? AVS_CONDVAR_TIMEOUT : 0; +} + +void avs_condvar_cleanup(avs_condvar_t **condvar) { + if (!*condvar) { + return; + } + + AVS_ASSERT(!(*condvar)->first_waiter, + "attempted to cleanup a condition variable some thread is " + "waiting on"); + + _avs_mutex_destroy(&(*condvar)->waiters_mutex); + avs_free(*condvar); + *condvar = NULL; +} diff --git a/Application/Src/compat/threading/avs_cmsis_os_init_once.c b/Application/Src/compat/threading/avs_cmsis_os_init_once.c new file mode 100644 index 0000000..102af96 --- /dev/null +++ b/Application/Src/compat/threading/avs_cmsis_os_init_once.c @@ -0,0 +1,60 @@ +/* + * Copyright 2020-2021 AVSystem + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include +#include + +#include +#include + +AVS_STATIC_ASSERT(sizeof(avs_init_once_handle_t) >= sizeof(atomic_int), + avs_init_once_handle_too_small); +AVS_STATIC_ASSERT(AVS_ALIGNOF(avs_init_once_handle_t) + >= AVS_ALIGNOF(atomic_int), + avs_init_once_alignment_incompatible); + +enum init_state { INIT_NOT_STARTED, INIT_IN_PROGRESS, INIT_DONE }; + +int avs_init_once(volatile avs_init_once_handle_t *handle, + avs_init_once_func_t *func, + void *func_arg) { + volatile atomic_int *state = (volatile atomic_int *) handle; + + int expected; + do { + expected = INIT_NOT_STARTED; + /* + * `*_weak` version may fail spuriously (return false when + * *state == expected); this does not matter to us, because we check + * it in a loop anyway, and according to cppreference it may have + * better performance than `*_strong` variant on some platforms. + */ + } while (!atomic_compare_exchange_weak(state, &expected, INIT_IN_PROGRESS) + && expected != INIT_DONE); + + int result = 0; + if (expected != INIT_DONE) { + result = func(func_arg); + if (result) { + atomic_store(state, INIT_NOT_STARTED); + } else { + atomic_store(state, INIT_DONE); + } + } + return result; +} diff --git a/Application/Src/compat/threading/avs_cmsis_os_structs.h b/Application/Src/compat/threading/avs_cmsis_os_structs.h new file mode 100644 index 0000000..d8aebda --- /dev/null +++ b/Application/Src/compat/threading/avs_cmsis_os_structs.h @@ -0,0 +1,49 @@ +/* + * Copyright 2020-2021 AVSystem + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AVS_FREERTOS_STRUCTS_H +#define AVS_FREERTOS_STRUCTS_H + +#include +#include + +#include + +#include "cmsis_os.h" + +struct avs_mutex { + osStaticMutexDef_t control_block; + osMutexDef_t def; + osMutexId id; +}; + +// we are not using AVS_LIST because we want to use stack allocation +typedef struct condvar_waiter_node_struct { + volatile atomic_flag waiting; + struct condvar_waiter_node_struct *next; +} condvar_waiter_node_t; + +struct avs_condvar { + // first_waiter and every condvar_waiter_node_t::next are only accessed when + // waiters_mutex is locked + avs_mutex_t waiters_mutex; + condvar_waiter_node_t *first_waiter; +}; + +int _avs_mutex_init(avs_mutex_t *mutex); +void _avs_mutex_destroy(avs_mutex_t *mutex); + +#endif // AVS_FREERTOS_STRUCTS_H diff --git a/Application/Src/compat/threading/avs_csmis_os_mutex.c b/Application/Src/compat/threading/avs_csmis_os_mutex.c new file mode 100644 index 0000000..2040a9e --- /dev/null +++ b/Application/Src/compat/threading/avs_csmis_os_mutex.c @@ -0,0 +1,77 @@ +/* + * Copyright 2020-2021 AVSystem + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "avs_cmsis_os_structs.h" + +int _avs_mutex_init(avs_mutex_t *mutex) { + mutex->def.controlblock = &mutex->control_block; + + mutex->id = osMutexCreate(&mutex->def); + if (!mutex->id) { + return -1; + } + + return 0; +} + +int avs_mutex_create(avs_mutex_t **out_mutex) { + AVS_ASSERT(!*out_mutex, "possible attempt to reinitialize a mutex"); + + *out_mutex = (avs_mutex_t *) avs_calloc(1, sizeof(avs_mutex_t)); + if (!*out_mutex) { + return -1; + } + + if (_avs_mutex_init(*out_mutex)) { + avs_free(*out_mutex); + *out_mutex = NULL; + return -1; + } + + return 0; +} + +int avs_mutex_lock(avs_mutex_t *mutex) { + return osMutexWait(mutex->id, osWaitForever) == osOK ? 0 : -1; +} + +int avs_mutex_try_lock(avs_mutex_t *mutex) { + return osMutexWait(mutex->id, 0) ? 0 : 1; +} + +int avs_mutex_unlock(avs_mutex_t *mutex) { + return osMutexRelease(mutex->id) == osOK ? 0 : -1; +} + +void _avs_mutex_destroy(avs_mutex_t *mutex) { + osStatus ret = osMutexDelete(mutex->id); + (void) ret; + AVS_ASSERT(ret == osOK, "osMutexDelete failed"); +} + +void avs_mutex_cleanup(avs_mutex_t **mutex) { + if (!*mutex) { + return; + } + + _avs_mutex_destroy(*mutex); + avs_free(*mutex); + *mutex = NULL; +} diff --git a/Application/Src/lwm2m.c b/Application/Src/lwm2m.c index 189e08d..3b79a23 100644 --- a/Application/Src/lwm2m.c +++ b/Application/Src/lwm2m.c @@ -45,22 +45,12 @@ static anjay_t *g_anjay; static avs_crypto_prng_ctx_t *g_prng_ctx; static osThreadId g_lwm2m_task_handle; -static osThreadId g_lwm2m_notify_task_handle; - -osMutexDef(anjay_mtx); -static osMutexId g_anjay_mtx; - -#define LOCKED(mtx) \ - for (osStatus s = osMutexWait((mtx), osWaitForever); s == osOK; \ - s = osErrorOS, osMutexRelease((mtx))) extern RNG_HandleTypeDef hrng; // Used to communicate between datacache callback and lwm2m thread static osMessageQId status_msg_queue; -static volatile bool g_network_up; - static void dc_cellular_callback(dc_com_event_id_t dc_event_id, const void *user_arg) { (void) user_arg; @@ -70,11 +60,10 @@ static void dc_cellular_callback(dc_com_event_id_t dc_event_id, (void) dc_com_read(&dc_com_db, DC_CELLULAR_NIFMAN_INFO, (void *) &dc_nifman_info, sizeof(dc_nifman_info)); if (dc_nifman_info.rt_state == DC_SERVICE_ON) { - g_network_up = true; LOG(INFO, "network is up"); (void) osMessagePut(status_msg_queue, (uint32_t) dc_event_id, 0); } else { - g_network_up = false; + anjay_event_loop_interrupt(g_anjay); LOG(INFO, "network is down"); } } else if (dc_event_id == DC_CELLULAR_CONFIG) { @@ -88,50 +77,27 @@ static void dc_cellular_callback(dc_com_event_id_t dc_event_id, } } -void main_loop(void) { - while (g_network_up) { - AVS_LIST(avs_net_socket_t *const) sockets = NULL; - LOCKED(g_anjay_mtx) { - sockets = anjay_get_sockets(g_anjay); - } - - size_t numsocks = AVS_LIST_SIZE(sockets); - struct pollfd pollfds[numsocks]; - size_t i = 0; - AVS_LIST(avs_net_socket_t *const) sock; - AVS_LIST_FOREACH(sock, sockets) { - pollfds[i].fd = *(const int *) avs_net_socket_get_system(*sock); - pollfds[i].events = POLLIN; - pollfds[i].revents = 0; - ++i; - } +static void heartbeat_led_toggle(void) { + HAL_GPIO_TogglePin(BSP_HEARTBEAT_LED_PORT, BSP_HEARTBEAT_LED); +} - const int max_wait_time_ms = 1000; - int wait_ms = max_wait_time_ms; - LOCKED(g_anjay_mtx) { - wait_ms = anjay_sched_calculate_wait_time_ms(g_anjay, - max_wait_time_ms); - } +static void lwm2m_notify_job(avs_sched_t *sched, const void *anjay_ptr) { + static size_t cycle = 0; + anjay_t *anjay = *(anjay_t *const *) anjay_ptr; - if (poll(pollfds, numsocks, wait_ms) > 0) { - int socket_id = 0; - AVS_LIST(avs_net_socket_t *const) socket = NULL; - AVS_LIST_FOREACH(socket, sockets) { - if (pollfds[socket_id].revents) { - LOCKED(g_anjay_mtx) { - if (anjay_serve(g_anjay, *socket)) { - LOG(ERROR, "anjay_serve() failed"); - } - } - } - ++socket_id; - } - } + device_object_update(anjay); + joystick_object_update(anjay); - LOCKED(g_anjay_mtx) { - anjay_sched_run(g_anjay); - } + three_axis_sensor_objects_update(anjay); + if (cycle % 5 == 0) { + basic_sensor_objects_update(anjay); } + + heartbeat_led_toggle(); + + cycle++; + AVS_SCHED_DELAYED(sched, NULL, avs_time_duration_from_scalar(1, AVS_TIME_S), + lwm2m_notify_job, &anjay, sizeof(anjay)); } static void lwm2m_thread(void const *user_arg) { @@ -139,35 +105,9 @@ static void lwm2m_thread(void const *user_arg) { (void) osMessageGet(status_msg_queue, RTOS_WAIT_FOREVER); + lwm2m_notify_job(anjay_get_scheduler(g_anjay), &g_anjay); // TODO handle connection lost - main_loop(); -} - -static void heartbeat_led_toggle(void) { - HAL_GPIO_TogglePin(BSP_HEARTBEAT_LED_PORT, BSP_HEARTBEAT_LED); -} - -static void lwm2m_notify_thread(void const *user_arg) { - (void) user_arg; - - size_t cycle = 0; - while (true) { - LOCKED(g_anjay_mtx) { - device_object_update(g_anjay); - joystick_object_update(g_anjay); - accelerometer_object_update(g_anjay); - gyrometer_object_update(g_anjay); - magnetometer_object_update(g_anjay); - if (cycle % 5 == 0) { - temperature_object_update(g_anjay); - humidity_object_update(g_anjay); - barometer_object_update(g_anjay); - } - } - heartbeat_led_toggle(); - cycle++; - osDelay(1000); - } + anjay_event_loop_run(g_anjay, avs_time_duration_from_scalar(1, AVS_TIME_S)); } static int @@ -244,15 +184,6 @@ void lwm2m_init(void) { ERROR_Handler(DBG_CHAN_APPLICATION, 0, ERROR_FATAL); } - // Registration to datacache - dc_com_reg_id_t reg = - dc_com_register_gen_event_cb(&dc_com_db, dc_cellular_callback, - NULL); - if (reg == DC_COM_INVALID_ENTRY) { - LOG(ERROR, "failed to subscribe to datacache events"); - ERROR_Handler(DBG_CHAN_APPLICATION, 0, ERROR_FATAL); - } - g_prng_ctx = avs_crypto_prng_new(entropy_callback, NULL); if (!g_prng_ctx) { LOG(ERROR, "failed to create PRNG ctx"); @@ -272,6 +203,15 @@ void lwm2m_init(void) { ERROR_Handler(DBG_CHAN_APPLICATION, 0, ERROR_FATAL); } + // Registration to datacache + dc_com_reg_id_t reg = + dc_com_register_gen_event_cb(&dc_com_db, dc_cellular_callback, + NULL); + if (reg == DC_COM_INVALID_ENTRY) { + LOG(ERROR, "failed to subscribe to datacache events"); + ERROR_Handler(DBG_CHAN_APPLICATION, 0, ERROR_FATAL); + } + if (setup_security_object() || setup_server_object() || anjay_attr_storage_install(g_anjay) || device_object_install(g_anjay)) { @@ -279,18 +219,9 @@ void lwm2m_init(void) { ERROR_Handler(DBG_CHAN_APPLICATION, 0, ERROR_FATAL); } - accelerometer_object_install(g_anjay); - gyrometer_object_install(g_anjay); - magnetometer_object_install(g_anjay); - temperature_object_install(g_anjay); - humidity_object_install(g_anjay); - barometer_object_install(g_anjay); + basic_sensor_objects_install(g_anjay); + three_axis_sensor_objects_install(g_anjay); joystick_object_install(g_anjay); - - if (!(g_anjay_mtx = osMutexCreate(osMutex(anjay_mtx)))) { - LOG(ERROR, "failed to create Anjay mutex"); - ERROR_Handler(DBG_CHAN_APPLICATION, 0, ERROR_FATAL); - } } static uint32_t lwm2m_thread_stack_buffer[LWM2M_THREAD_STACK_SIZE]; @@ -306,21 +237,3 @@ void lwm2m_start(void) { ERROR_Handler(DBG_CHAN_APPLICATION, 0, ERROR_FATAL); } } - -static uint32_t - lwm2m_notify_thread_stack_buffer[LWM2M_NOTIFY_THREAD_STACK_SIZE]; -static osStaticThreadDef_t lwm2m_notify_controlblock; -void lwm2m_notify_start(void) { - osThreadStaticDef(lwm2m_notify_task, lwm2m_notify_thread, - LWM2M_NOTIFY_THREAD_PRIO, 0, - LWM2M_NOTIFY_THREAD_STACK_SIZE, - lwm2m_notify_thread_stack_buffer, - &lwm2m_notify_controlblock); - g_lwm2m_notify_task_handle = - osThreadCreate(osThread(lwm2m_notify_task), NULL); - - if (!g_lwm2m_notify_task_handle) { - LOG(ERROR, "failed to create thread"); - ERROR_Handler(DBG_CHAN_APPLICATION, 0, ERROR_FATAL); - } -} diff --git a/Application/Src/objects/accelerometer_object.c b/Application/Src/objects/accelerometer_object.c deleted file mode 100644 index beca80f..0000000 --- a/Application/Src/objects/accelerometer_object.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2020-2021 AVSystem - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "sensor_drivers/bsp_sensor_drivers.h" -#include "sensor_drivers/three_axis_sensor_driver.h" -#include "three_axis_sensor_object.h" - -static three_axis_sensor_object_t g_accelerometer_obj; - -int accelerometer_object_install(anjay_t *anjay) { - return three_axis_sensor_object_install(anjay, &BSP_ACCELEROMETER_DRIVER, - 3313, &g_accelerometer_obj); -} - -void accelerometer_object_update(anjay_t *anjay) { - three_axis_sensor_object_update(anjay, &g_accelerometer_obj); -} diff --git a/Application/Src/objects/barometer_object.c b/Application/Src/objects/barometer_object.c deleted file mode 100644 index 698299b..0000000 --- a/Application/Src/objects/barometer_object.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2020-2021 AVSystem - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "basic_sensor_object.h" -#include "sensor_drivers/basic_sensor_driver.h" -#include "sensor_drivers/bsp_sensor_drivers.h" - -static basic_sensor_object_t g_barometer_obj; - -int barometer_object_install(anjay_t *anjay) { - return basic_sensor_object_install(anjay, &BSP_BAROMETER_DRIVER, 3315, - &g_barometer_obj); -} - -void barometer_object_update(anjay_t *anjay) { - basic_sensor_object_update(anjay, &g_barometer_obj); -} diff --git a/Application/Src/objects/basic_sensor_object.c b/Application/Src/objects/basic_sensor_object.c deleted file mode 100644 index c4d5ed4..0000000 --- a/Application/Src/objects/basic_sensor_object.c +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright 2020-2021 AVSystem - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include -#include -#include -#include - -#include "basic_sensor_object.h" - -#define BASIC_SENSOR_OBJ_LOG(...) avs_log(basic_sensor_obj, __VA_ARGS__) - -/** - * Min Measured Value: R, Single, Optional - * type: float, range: N/A, unit: N/A - * The minimum value measured by the sensor since power ON or reset. - */ -#define RID_MIN_MEASURED_VALUE 5601 - -/** - * Max Measured Value: R, Single, Optional - * type: float, range: N/A, unit: N/A - * The maximum value measured by the sensor since power ON or reset. - */ -#define RID_MAX_MEASURED_VALUE 5602 - -/** - * Reset Min and Max Measured Values: E, Single, Optional - * type: N/A, range: N/A, unit: N/A - * Reset the Min and Max Measured Values to Current Value. - */ -#define RID_RESET_MIN_AND_MAX_MEASURED_VALUES 5605 - -/** - * Sensor Value: R, Single, Mandatory - * type: float, range: N/A, unit: N/A - * Last or Current Measured Value from the Sensor. - */ -#define RID_SENSOR_VALUE 5700 - -/** - * Sensor Units: R, Single, Optional - * type: string, range: N/A, unit: N/A - * Measurement Units Definition. - */ -#define RID_SENSOR_UNITS 5701 - -#define BASIC_SENSOR_OBJ_DEF(Oid) \ - (anjay_dm_object_def_t) { \ - .oid = (Oid), \ - .handlers = { \ - .list_instances = anjay_dm_list_instances_SINGLE, \ - .list_resources = basic_sensor_list_resources, \ - .resource_read = basic_sensor_resource_read, \ - .resource_execute = basic_sensor_resource_execute \ - } \ - } - -static basic_sensor_object_t * -get_obj(const anjay_dm_object_def_t *const *obj_ptr) { - assert(obj_ptr); - return AVS_CONTAINER_OF(obj_ptr, basic_sensor_object_t, def_ptr); -} - -static int -basic_sensor_list_resources(anjay_t *anjay, - const anjay_dm_object_def_t *const *obj_ptr, - anjay_iid_t iid, - anjay_dm_resource_list_ctx_t *ctx) { - (void) anjay; - (void) obj_ptr; - (void) iid; - - anjay_dm_emit_res(ctx, RID_MIN_MEASURED_VALUE, ANJAY_DM_RES_R, - ANJAY_DM_RES_PRESENT); - anjay_dm_emit_res(ctx, RID_MAX_MEASURED_VALUE, ANJAY_DM_RES_R, - ANJAY_DM_RES_PRESENT); - anjay_dm_emit_res(ctx, RID_RESET_MIN_AND_MAX_MEASURED_VALUES, - ANJAY_DM_RES_E, ANJAY_DM_RES_PRESENT); - anjay_dm_emit_res(ctx, RID_SENSOR_VALUE, ANJAY_DM_RES_R, - ANJAY_DM_RES_PRESENT); - anjay_dm_emit_res(ctx, RID_SENSOR_UNITS, ANJAY_DM_RES_R, - ANJAY_DM_RES_PRESENT); - return 0; -} - -static int -basic_sensor_resource_read(anjay_t *anjay, - const anjay_dm_object_def_t *const *obj_ptr, - anjay_iid_t iid, - anjay_rid_t rid, - anjay_riid_t riid, - anjay_output_ctx_t *ctx) { - (void) anjay; - - basic_sensor_object_t *obj = get_obj(obj_ptr); - assert(obj); - assert(iid == 0); - - switch (rid) { - case RID_MIN_MEASURED_VALUE: - assert(riid == ANJAY_ID_INVALID); - return anjay_ret_float(ctx, obj->min_value); - - case RID_MAX_MEASURED_VALUE: - assert(riid == ANJAY_ID_INVALID); - return anjay_ret_float(ctx, obj->max_value); - - case RID_SENSOR_VALUE: - assert(riid == ANJAY_ID_INVALID); - return anjay_ret_float(ctx, obj->current_value); - - case RID_SENSOR_UNITS: - assert(riid == ANJAY_ID_INVALID); - return anjay_ret_string(ctx, obj->driver->unit); - - default: - return ANJAY_ERR_METHOD_NOT_ALLOWED; - } -} - -static int -basic_sensor_resource_execute(anjay_t *anjay, - const anjay_dm_object_def_t *const *obj_ptr, - anjay_iid_t iid, - anjay_rid_t rid, - anjay_execute_ctx_t *arg_ctx) { - (void) arg_ctx; - - basic_sensor_object_t *obj = get_obj(obj_ptr); - assert(obj); - assert(iid == 0); - - switch (rid) { - case RID_RESET_MIN_AND_MAX_MEASURED_VALUES: - obj->max_value = obj->current_value; - obj->min_value = obj->current_value; - return 0; - - default: - return ANJAY_ERR_METHOD_NOT_ALLOWED; - } -} - -static int read_value(const basic_sensor_driver_t *driver, float *out_value) { - if (driver->read(out_value)) { - BASIC_SENSOR_OBJ_LOG(ERROR, "Failed to read from %s", driver->name); - return -1; - } - return 0; -} - -int basic_sensor_object_install(anjay_t *anjay, - const basic_sensor_driver_t *driver, - anjay_oid_t oid, - basic_sensor_object_t *obj) { - if (driver->init()) { - return -1; - } - - float initial_value; - if (read_value(driver, &initial_value)) { - BASIC_SENSOR_OBJ_LOG(ERROR, "Failed to initialize %s values", - driver->name); - return -1; - } - - obj->def = BASIC_SENSOR_OBJ_DEF(oid); - obj->def_ptr = &obj->def; - obj->driver = driver; - obj->current_value = initial_value; - obj->min_value = initial_value; - obj->max_value = initial_value; - - return anjay_register_object(anjay, &obj->def_ptr); -} - -void basic_sensor_object_update(anjay_t *anjay, basic_sensor_object_t *obj) { - if (!obj->def_ptr) { - return; - } - - float sensor_value; - if (read_value(obj->driver, &sensor_value)) { - return; - } - - if (obj->current_value != sensor_value) { - obj->current_value = sensor_value; - (void) anjay_notify_changed(anjay, obj->def.oid, 0, RID_SENSOR_VALUE); - } - - if (obj->min_value > sensor_value) { - obj->min_value = sensor_value; - (void) anjay_notify_changed(anjay, obj->def.oid, 0, - RID_MIN_MEASURED_VALUE); - } - - if (obj->max_value < sensor_value) { - obj->max_value = sensor_value; - (void) anjay_notify_changed(anjay, obj->def.oid, 0, - RID_MAX_MEASURED_VALUE); - } -} diff --git a/Application/Src/objects/basic_sensor_objects.c b/Application/Src/objects/basic_sensor_objects.c new file mode 100644 index 0000000..37ba4c6 --- /dev/null +++ b/Application/Src/objects/basic_sensor_objects.c @@ -0,0 +1,81 @@ +/* + * Copyright 2020-2021 AVSystem + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "sensor_drivers/basic_sensor_driver.h" +#include "sensor_drivers/bsp_sensor_drivers.h" + +typedef struct { + anjay_oid_t oid; + const basic_sensor_driver_t *driver; +} sensor_context_t; + +static sensor_context_t basic_sensors_def[] = { + { + .oid = 3303, + .driver = &BSP_THERMOMETER_DRIVER, + }, + { + .oid = 3304, + .driver = &BSP_HYGROMETER_DRIVER, + }, + { + .oid = 3315, + .driver = &BSP_BAROMETER_DRIVER, + } +}; + +static int read_value(anjay_iid_t iid, void *_ctx, double *out_value) { + const basic_sensor_driver_t *driver = ((sensor_context_t *) _ctx)->driver; + + float fvalue; + if (driver->read(&fvalue)) { + return -1; + } + + *out_value = (double) fvalue; + + return 0; +} + +void basic_sensor_objects_install(anjay_t *anjay) { + for (int i = 0; i < AVS_ARRAY_SIZE(basic_sensors_def); i++) { + sensor_context_t *ctx = &basic_sensors_def[i]; + + if (ctx->driver->init() + || anjay_ipso_basic_sensor_install(anjay, ctx->oid, 1)) { + continue; + } + + anjay_ipso_basic_sensor_instance_add(anjay, ctx->oid, 0, + (anjay_ipso_basic_sensor_impl_t) { + .unit = ctx->driver->unit, + .user_context = ctx, + .min_range_value = NAN, + .max_range_value = NAN, + .get_value = read_value + }); + } +} + +void basic_sensor_objects_update(anjay_t *anjay) { + for (int i = 0; i < AVS_ARRAY_SIZE(basic_sensors_def); i++) { + anjay_ipso_basic_sensor_update(anjay, basic_sensors_def[i].oid, 0); + } +} diff --git a/Application/Src/objects/device_object.c b/Application/Src/objects/device_object.c index 7eb20a6..b95a1f1 100644 --- a/Application/Src/objects/device_object.c +++ b/Application/Src/objects/device_object.c @@ -171,7 +171,7 @@ static int resource_read(anjay_t *anjay, case RID_FIRMWARE_VERSION: assert(riid == ANJAY_ID_INVALID); - return anjay_ret_string(ctx, "21.06"); + return anjay_ret_string(ctx, "21.10"); case RID_ERROR_CODE: assert(riid == 0); diff --git a/Application/Src/objects/gyrometer_object.c b/Application/Src/objects/gyrometer_object.c deleted file mode 100644 index 4663d64..0000000 --- a/Application/Src/objects/gyrometer_object.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2020-2021 AVSystem - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "sensor_drivers/bsp_sensor_drivers.h" -#include "sensor_drivers/three_axis_sensor_driver.h" -#include "three_axis_sensor_object.h" - -static three_axis_sensor_object_t g_gyrometer_obj; - -int gyrometer_object_install(anjay_t *anjay) { - return three_axis_sensor_object_install(anjay, &BSP_GYROMETER_DRIVER, 3334, - &g_gyrometer_obj); -} - -void gyrometer_object_update(anjay_t *anjay) { - three_axis_sensor_object_update(anjay, &g_gyrometer_obj); -} diff --git a/Application/Src/objects/humidity_object.c b/Application/Src/objects/humidity_object.c deleted file mode 100644 index eafaf46..0000000 --- a/Application/Src/objects/humidity_object.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2020-2021 AVSystem - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "basic_sensor_object.h" -#include "sensor_drivers/basic_sensor_driver.h" -#include "sensor_drivers/bsp_sensor_drivers.h" - -static basic_sensor_object_t g_humidity_obj; - -int humidity_object_install(anjay_t *anjay) { - return basic_sensor_object_install(anjay, &BSP_HYGROMETER_DRIVER, 3304, - &g_humidity_obj); -} - -void humidity_object_update(anjay_t *anjay) { - basic_sensor_object_update(anjay, &g_humidity_obj); -} diff --git a/Application/Src/objects/magnetometer_object.c b/Application/Src/objects/magnetometer_object.c deleted file mode 100644 index 0ed25e5..0000000 --- a/Application/Src/objects/magnetometer_object.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2020-2021 AVSystem - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "sensor_drivers/bsp_sensor_drivers.h" -#include "sensor_drivers/three_axis_sensor_driver.h" -#include "three_axis_sensor_object.h" - -static three_axis_sensor_object_t g_magnetometer_obj; - -int magnetometer_object_install(anjay_t *anjay) { - return three_axis_sensor_object_install(anjay, &BSP_MAGNETOMETER_DRIVER, - 3314, &g_magnetometer_obj); -} - -void magnetometer_object_update(anjay_t *anjay) { - three_axis_sensor_object_update(anjay, &g_magnetometer_obj); -} diff --git a/Application/Src/objects/temperature_object.c b/Application/Src/objects/temperature_object.c deleted file mode 100644 index 78cf674..0000000 --- a/Application/Src/objects/temperature_object.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2020-2021 AVSystem - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "basic_sensor_object.h" -#include "sensor_drivers/basic_sensor_driver.h" -#include "sensor_drivers/bsp_sensor_drivers.h" - -static basic_sensor_object_t g_temperature_obj; - -int temperature_object_install(anjay_t *anjay) { - return basic_sensor_object_install(anjay, &BSP_THERMOMETER_DRIVER, 3303, - &g_temperature_obj); -} - -void temperature_object_update(anjay_t *anjay) { - basic_sensor_object_update(anjay, &g_temperature_obj); -} diff --git a/Application/Src/objects/three_axis_sensor_object.c b/Application/Src/objects/three_axis_sensor_object.c deleted file mode 100644 index 978915e..0000000 --- a/Application/Src/objects/three_axis_sensor_object.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright 2020-2021 AVSystem - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include -#include -#include -#include - -#include "three_axis_sensor_object.h" - -#define THREE_AXIS_SENSOR_OBJ_LOG(...) \ - avs_log(three_axis_sensor_obj, __VA_ARGS__) - -/** - * Sensor Units: R, Single, Optional - * type: string, range: N/A, unit: N/A - * Measurement Units Definition. - */ -#define RID_SENSOR_UNITS 5701 - -/** - * X Value: R, Single, Mandatory - * type: float, range: N/A, unit: N/A - * The measured value along the X axis. - */ -#define RID_X_VALUE 5702 - -/** - * Y Value: R, Single, Optional - * type: float, range: N/A, unit: N/A - * The measured value along the Y axis. - */ -#define RID_Y_VALUE 5703 - -/** - * Z Value: R, Single, Optional - * type: float, range: N/A, unit: N/A - * The measured value along the Z axis. - */ -#define RID_Z_VALUE 5704 - -#define THREE_AXIS_SENSOR_OBJ_DEF(Oid) \ - (anjay_dm_object_def_t) { \ - .oid = (Oid), \ - .handlers = { \ - .list_instances = anjay_dm_list_instances_SINGLE, \ - .list_resources = three_axis_sensor_list_resources, \ - .resource_read = three_axis_sensor_resource_read \ - } \ - } - -static inline three_axis_sensor_object_t * -get_obj(const anjay_dm_object_def_t *const *obj_ptr) { - assert(obj_ptr); - return AVS_CONTAINER_OF(obj_ptr, three_axis_sensor_object_t, def_ptr); -} - -static int -three_axis_sensor_list_resources(anjay_t *anjay, - const anjay_dm_object_def_t *const *obj_ptr, - anjay_iid_t iid, - anjay_dm_resource_list_ctx_t *ctx) { - (void) anjay; - (void) obj_ptr; - (void) iid; - - anjay_dm_emit_res(ctx, RID_SENSOR_UNITS, ANJAY_DM_RES_R, - ANJAY_DM_RES_PRESENT); - anjay_dm_emit_res(ctx, RID_X_VALUE, ANJAY_DM_RES_R, ANJAY_DM_RES_PRESENT); - anjay_dm_emit_res(ctx, RID_Y_VALUE, ANJAY_DM_RES_R, ANJAY_DM_RES_PRESENT); - anjay_dm_emit_res(ctx, RID_Z_VALUE, ANJAY_DM_RES_R, ANJAY_DM_RES_PRESENT); - return 0; -} - -static int -three_axis_sensor_resource_read(anjay_t *anjay, - const anjay_dm_object_def_t *const *obj_ptr, - anjay_iid_t iid, - anjay_rid_t rid, - anjay_riid_t riid, - anjay_output_ctx_t *ctx) { - (void) anjay; - - three_axis_sensor_object_t *obj = get_obj(obj_ptr); - assert(obj); - assert(iid == 0); - assert(riid == ANJAY_ID_INVALID); - - switch (rid) { - case RID_SENSOR_UNITS: - return anjay_ret_string(ctx, obj->driver->unit); - - case RID_X_VALUE: - return anjay_ret_float(ctx, obj->values.x); - - case RID_Y_VALUE: - return anjay_ret_float(ctx, obj->values.y); - - case RID_Z_VALUE: - return anjay_ret_float(ctx, obj->values.z); - - default: - return ANJAY_ERR_METHOD_NOT_ALLOWED; - } -} - -static int read_values(const three_axis_sensor_driver_t *driver, - three_axis_sensor_values_t *out_values) { - if (driver->read(out_values)) { - THREE_AXIS_SENSOR_OBJ_LOG(ERROR, "Failed to read from %s", - driver->name); - return -1; - } - return 0; -} - -int three_axis_sensor_object_install(anjay_t *anjay, - const three_axis_sensor_driver_t *driver, - anjay_oid_t oid, - three_axis_sensor_object_t *obj) { - if (driver->init()) { - return -1; - } - - obj->def = THREE_AXIS_SENSOR_OBJ_DEF(oid); - obj->def_ptr = &obj->def; - obj->driver = driver; - return anjay_register_object(anjay, &obj->def_ptr); -} - -void three_axis_sensor_object_update(anjay_t *anjay, - three_axis_sensor_object_t *obj) { - if (!obj->def_ptr) { - return; - } - - three_axis_sensor_values_t sensor_values; - if (read_values(obj->driver, &sensor_values)) { - return; - } - - if (obj->values.x != sensor_values.x) { - obj->values.x = sensor_values.x; - (void) anjay_notify_changed(anjay, obj->def.oid, 0, RID_X_VALUE); - } - - if (obj->values.y != sensor_values.y) { - obj->values.y = sensor_values.y; - (void) anjay_notify_changed(anjay, obj->def.oid, 0, RID_Y_VALUE); - } - - if (obj->values.z != sensor_values.z) { - obj->values.z = sensor_values.z; - (void) anjay_notify_changed(anjay, obj->def.oid, 0, RID_Z_VALUE); - } -} diff --git a/Application/Src/objects/three_axis_sensor_objects.c b/Application/Src/objects/three_axis_sensor_objects.c new file mode 100644 index 0000000..4139baa --- /dev/null +++ b/Application/Src/objects/three_axis_sensor_objects.c @@ -0,0 +1,92 @@ +/* + * Copyright 2020-2021 AVSystem + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "sensor_drivers/bsp_sensor_drivers.h" +#include "sensor_drivers/three_axis_sensor_driver.h" + +typedef struct { + anjay_oid_t oid; + const three_axis_sensor_driver_t *driver; +} sensor_context_t; + +static sensor_context_t three_axis_sensors_def[] = { + { + .oid = 3313, + .driver = &BSP_ACCELEROMETER_DRIVER + }, + { + .oid = 3314, + .driver = &BSP_MAGNETOMETER_DRIVER + }, + { + .oid = 3334, + .driver = &BSP_GYROMETER_DRIVER + } +}; + +static int read_values(anjay_iid_t iid, + void *_ctx, + double *x_value, + double *y_value, + double *z_value) { + const three_axis_sensor_driver_t *driver = + ((sensor_context_t *) _ctx)->driver; + + three_axis_sensor_values_t out_values; + if (driver->read(&out_values)) { + return -1; + } + + *x_value = (double) out_values.x; + *y_value = (double) out_values.y; + *z_value = (double) out_values.z; + + return 0; +} + +void three_axis_sensor_objects_install(anjay_t *anjay) { + for (int i = 0; i < AVS_ARRAY_SIZE(three_axis_sensors_def); i++) { + sensor_context_t *ctx = &three_axis_sensors_def[i]; + + if (ctx->driver->init() + || anjay_ipso_3d_sensor_install(anjay, ctx->oid, 1)) { + continue; + } + + anjay_ipso_3d_sensor_instance_add(anjay, + ctx->oid, + 0, + (anjay_ipso_3d_sensor_impl_t) { + .unit = ctx->driver->unit, + .use_y_value = true, + .use_z_value = true, + .user_context = ctx, + .min_range_value = NAN, + .max_range_value = NAN, + .get_values = read_values + }); + } +} + +void three_axis_sensor_objects_update(anjay_t *anjay) { + for (int i = 0; i < AVS_ARRAY_SIZE(three_axis_sensors_def); i++) { + anjay_ipso_3d_sensor_update(anjay, three_axis_sensors_def[i].oid, 0); + } +} diff --git a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_api.h b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_api.h index 4510926..50a21fd 100644 --- a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_api.h +++ b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_api.h @@ -1,48 +1,48 @@ -/** - ****************************************************************************** - * @file at_custom_modem_api.h - * @author MCD Application Team - * @brief Header for at_custom_modem_api.c module - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef AT_CUSTOM_MODEM_API_H -#define AT_CUSTOM_MODEM_API_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "at_core.h" -#include "at_modem_api.h" -#include "sysctrl.h" - -/* Exported constants --------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -/* External variables --------------------------------------------------------*/ -/* Exported macros -----------------------------------------------------------*/ - -/* Exported functions ------------------------------------------------------- */ -void atcma_init_at_func_ptrs(atcustom_funcPtrs_t *funcPtrs); -void atcma_init_sysctrl_func_ptrs(sysctrl_funcPtrs_t *funcPtrs); - -#ifdef __cplusplus -} -#endif - -#endif /* AT_CUSTOM_MODEM_API_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +/** + ****************************************************************************** + * @file at_custom_modem_api.h + * @author MCD Application Team + * @brief Header for at_custom_modem_api.c module + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef AT_CUSTOM_MODEM_API_H +#define AT_CUSTOM_MODEM_API_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "at_core.h" +#include "at_modem_api.h" +#include "sysctrl.h" + +/* Exported constants --------------------------------------------------------*/ +/* Exported types ------------------------------------------------------------*/ +/* External variables --------------------------------------------------------*/ +/* Exported macros -----------------------------------------------------------*/ + +/* Exported functions ------------------------------------------------------- */ +void atcma_init_at_func_ptrs(atcustom_funcPtrs_t *funcPtrs); +void atcma_init_sysctrl_func_ptrs(sysctrl_funcPtrs_t *funcPtrs); + +#ifdef __cplusplus +} +#endif + +#endif /* AT_CUSTOM_MODEM_API_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_signalling.h b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_signalling.h index 6b36e9a..ea72777 100644 --- a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_signalling.h +++ b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_signalling.h @@ -1,76 +1,76 @@ -/** - ****************************************************************************** - * @file at_custom_modem_signalling.h - * @author MCD Application Team - * @brief Header for at_custom_modem_signalling.c module - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef AT_CUSTOM_SIGNALLING_MONARCH_H -#define AT_CUSTOM_SIGNALLING_MONARCH_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "at_core.h" -#include "at_parser.h" -#include "at_modem_api.h" -#include "at_modem_signalling.h" -#include "at_custom_modem_specific.h" - -/* Exported constants --------------------------------------------------------*/ - -/* Exported types ------------------------------------------------------------*/ - -/* External variables --------------------------------------------------------*/ - -/* Exported macros -----------------------------------------------------------*/ - -/* Exported functions ------------------------------------------------------- */ -/* MONARCH specific build commands */ -at_status_t fCmdBuild_ATD_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_SQNCTM_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_AUTOATT_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_CGDCONT_REPROGRAM_MONARCH(atparser_context_t *p_atp_ctxt, - atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_CLEAR_SCAN_CFG_MONARCH(atparser_context_t *p_atp_ctxt, - atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_ADD_SCAN_BAND_MONARCH(atparser_context_t *p_atp_ctxt, - atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_SQNDNSLKUP_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_SMST_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); - -/* MONARCH specific analyze commands */ -at_action_rsp_t fRspAnalyze_Error_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); -at_action_rsp_t fRspAnalyze_SQNCCID_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); -at_action_rsp_t fRspAnalyze_SQNDNSLKUP_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); -at_action_rsp_t fRspAnalyze_SMST_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); -at_action_rsp_t fRspAnalyze_CESQ_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); - -#ifdef __cplusplus -} -#endif - -#endif /* AT_CUSTOM_SIGNALLING_MONARCH_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - +/** + ****************************************************************************** + * @file at_custom_modem_signalling.h + * @author MCD Application Team + * @brief Header for at_custom_modem_signalling.c module + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef AT_CUSTOM_SIGNALLING_MONARCH_H +#define AT_CUSTOM_SIGNALLING_MONARCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "at_core.h" +#include "at_parser.h" +#include "at_modem_api.h" +#include "at_modem_signalling.h" +#include "at_custom_modem_specific.h" + +/* Exported constants --------------------------------------------------------*/ + +/* Exported types ------------------------------------------------------------*/ + +/* External variables --------------------------------------------------------*/ + +/* Exported macros -----------------------------------------------------------*/ + +/* Exported functions ------------------------------------------------------- */ +/* MONARCH specific build commands */ +at_status_t fCmdBuild_ATD_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_SQNCTM_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_AUTOATT_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_CGDCONT_REPROGRAM_MONARCH(atparser_context_t *p_atp_ctxt, + atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_CLEAR_SCAN_CFG_MONARCH(atparser_context_t *p_atp_ctxt, + atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_ADD_SCAN_BAND_MONARCH(atparser_context_t *p_atp_ctxt, + atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_SQNDNSLKUP_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_SMST_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); + +/* MONARCH specific analyze commands */ +at_action_rsp_t fRspAnalyze_Error_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); +at_action_rsp_t fRspAnalyze_SQNCCID_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); +at_action_rsp_t fRspAnalyze_SQNDNSLKUP_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); +at_action_rsp_t fRspAnalyze_SMST_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); +at_action_rsp_t fRspAnalyze_CESQ_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); + +#ifdef __cplusplus +} +#endif + +#endif /* AT_CUSTOM_SIGNALLING_MONARCH_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + diff --git a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_socket.h b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_socket.h index 84aa35a..06f9b8a 100644 --- a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_socket.h +++ b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_socket.h @@ -1,83 +1,83 @@ -/** - ****************************************************************************** - * @file at_custom_modem_socket.h - * @author MCD Application Team - * @brief Header for at_custom_modem_socket.c module - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef AT_CUSTOM_SOCKET_MONARCH_H -#define AT_CUSTOM_SOCKET_MONARCH_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "at_core.h" -#include "at_parser.h" -#include "at_modem_api.h" -#include "at_modem_signalling.h" -#include "at_custom_modem_specific.h" - -/* Exported constants --------------------------------------------------------*/ - -/* Exported types ------------------------------------------------------------*/ - -/* External variables --------------------------------------------------------*/ - -/* Exported macros -----------------------------------------------------------*/ - -/* Exported functions ------------------------------------------------------- */ -void clear_ping_resp_struct(atcustom_modem_context_t *p_modem_ctxt); - -/* MONARCH specific build commands */ -at_status_t fCmdBuild_SQNSCFG_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_SQNSCFGEXT_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_SQNSD_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_SQNSH_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_SQNSI_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_SQNSRECV_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_SQNSSENDEXT_MONARCH(atparser_context_t *p_atp_ctxt, - atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_SQNSSEND_WRITE_DATA_MONARCH(atparser_context_t *p_atp_ctxt, - atcustom_modem_context_t *p_modem_ctxt); -at_status_t fCmdBuild_PING_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); - -/* MONARCH specific analyze commands */ -at_action_rsp_t fRspAnalyze_SQNSRING_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); -at_action_rsp_t fRspAnalyze_SQNSI_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); -at_action_rsp_t fRspAnalyze_SQNSS_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); -at_action_rsp_t fRspAnalyze_SQNSH_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); -at_action_rsp_t fRspAnalyze_SQNSRECV_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); -at_action_rsp_t fRspAnalyze_SQNSRECV_data_MONARCH(at_context_t *p_at_ctxt, - atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); -at_action_rsp_t fRspAnalyze_PING_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); - -#ifdef __cplusplus -} -#endif - -#endif /* AT_CUSTOM_SOCKET_MONARCH_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - +/** + ****************************************************************************** + * @file at_custom_modem_socket.h + * @author MCD Application Team + * @brief Header for at_custom_modem_socket.c module + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef AT_CUSTOM_SOCKET_MONARCH_H +#define AT_CUSTOM_SOCKET_MONARCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "at_core.h" +#include "at_parser.h" +#include "at_modem_api.h" +#include "at_modem_signalling.h" +#include "at_custom_modem_specific.h" + +/* Exported constants --------------------------------------------------------*/ + +/* Exported types ------------------------------------------------------------*/ + +/* External variables --------------------------------------------------------*/ + +/* Exported macros -----------------------------------------------------------*/ + +/* Exported functions ------------------------------------------------------- */ +void clear_ping_resp_struct(atcustom_modem_context_t *p_modem_ctxt); + +/* MONARCH specific build commands */ +at_status_t fCmdBuild_SQNSCFG_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_SQNSCFGEXT_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_SQNSD_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_SQNSH_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_SQNSI_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_SQNSRECV_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_SQNSSENDEXT_MONARCH(atparser_context_t *p_atp_ctxt, + atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_SQNSSEND_WRITE_DATA_MONARCH(atparser_context_t *p_atp_ctxt, + atcustom_modem_context_t *p_modem_ctxt); +at_status_t fCmdBuild_PING_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt); + +/* MONARCH specific analyze commands */ +at_action_rsp_t fRspAnalyze_SQNSRING_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); +at_action_rsp_t fRspAnalyze_SQNSI_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); +at_action_rsp_t fRspAnalyze_SQNSS_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); +at_action_rsp_t fRspAnalyze_SQNSH_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); +at_action_rsp_t fRspAnalyze_SQNSRECV_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); +at_action_rsp_t fRspAnalyze_SQNSRECV_data_MONARCH(at_context_t *p_at_ctxt, + atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); +at_action_rsp_t fRspAnalyze_PING_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos); + +#ifdef __cplusplus +} +#endif + +#endif /* AT_CUSTOM_SOCKET_MONARCH_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + diff --git a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_specific.h b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_specific.h index 38a5786..15164a6 100644 --- a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_specific.h +++ b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/at_custom_modem_specific.h @@ -1,157 +1,157 @@ -/** - ****************************************************************************** - * @file at_custom_modem_specific.h - * @author MCD Application Team - * @brief Header for at_custom_modem_specific.c module - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef AT_CUSTOM_MODEM_MONARCH_H -#define AT_CUSTOM_MODEM_MONARCH_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "at_core.h" -#include "at_parser.h" -#include "at_modem_api.h" -#include "at_modem_signalling.h" -#include "cellular_service.h" -#include "cellular_service_int.h" -#include "ipc_common.h" - -/* Exported constants --------------------------------------------------------*/ -/* device specific parameters */ -#define MODEM_MAX_SOCKET_TX_DATA_SIZE CONFIG_MODEM_MAX_SOCKET_TX_DATA_SIZE -#define MODEM_MAX_SOCKET_RX_DATA_SIZE CONFIG_MODEM_MAX_SOCKET_RX_DATA_SIZE -#define SEQUANS_PING_LENGTH ((uint16_t)32U) -#define GM01Q_ACTIVATE_PING_REPORT (1) /* temporary solution, ping is synchrone, report not supported by com */ -#define ENABLE_SEQUANS_LOW_POWER_MODE (0) /* not applicable yet for this modem - Do not activate !!! */ - -/* Exported types ------------------------------------------------------------*/ -typedef enum -{ - /* modem specific commands */ - CMD_AT_SQNSRING = (CMD_AT_LAST_GENERIC + 1U), /* socket ring */ - CMD_AT_SQNSCFG, /* socket configuration */ - CMD_AT_SQNSCFGEXT, /* socket extended configuration */ - CMD_AT_SQNSD, /* socket dial */ - CMD_AT_SQNSH, /* socket shutdown */ - CMD_AT_SQNSI, /* socket information */ - CMD_AT_SQNSS, /* socket status */ - CMD_AT_SQNSRECV, /* socket, receive data in command mode */ - CMD_AT_SQNSSENDEXT, /* socket, extended send data in command mode (waiting for prompt) */ - CMD_AT_SQNSSEND_WRITE_DATA, /* socket, send data in command mode (send data) */ - CMD_AT_RESET, /* hardware reset */ - CMD_AT_SQNCTM, /* Conformance Test mode (not described in Monarch ref. manual but in Calliope ref. manual */ - CMD_AT_AUTOATT, /* Automatic Attach */ - CMD_AT_CGDCONT_REPROGRAM, /* special case, reprogram CGDCONT */ - CMD_AT_CLEAR_SCAN_CFG, /* clear bands */ - CMD_AT_ADD_SCAN_BAND, /* add a band */ - CMD_AT_ICCID, /* ICCID request */ - CMD_AT_SQNDNSLKUP, /* DNS request */ - CMD_AT_PING, /* Ping request */ - CMD_AT_SMST, /* SIM test */ - CMD_AT_CESQ, /* Extended signal quality */ - CMD_AT_SQNSSHDN, /* Power Down Modem */ - - /* modem specific events (URC, BOOT, ...) */ - CMD_AT_WAIT_EVENT, - CMD_AT_SIMREADY_EVENT, - CMD_AT_SYSSTART_TYPE1, - CMD_AT_SYSSTART_TYPE2, - CMD_AT_SYSSHDN, - CMD_AT_SOCKET_PROMPT, - CMD_AT_SHUTDOWN, - -} ATCustom_MONARCH_cmdlist_t; - -typedef struct -{ - AT_CHAR_t hostIPaddr[MAX_SIZE_IPADDR]; /* = host_name parameter from CS_DnsReq_t */ -} ATCustom_MONARCH_dns_t; - -typedef enum -{ - /* Command syntax - * +SQNSRECV:,[,,] - * - * OK - */ - RX_SQNSRECV_header_not_started, - RX_SQNSRECV_header_prefix, /* receiving prefix, ie +SQNSRECV: */ - RX_SQNSRECV_header_connId, /* receiving connId parameter */ - RX_SQNSRECV_header_maxByte, /* receiving maxByte parameter */ - RX_SQNSRECV_header_other, /* receiving other parameter */ - -} atcustom_RxSQNSRECV_header_t; - -#define MAXBYTE_MAXIMUM_SIZE ((uint8_t)8U) - -typedef struct -{ - /* structure used to manage answer to AT+SQNSRECV in case crossing-cases, especially when - * +SQNSRING URC is received instead of +SQNSRECV answer. - */ - uint16_t counter_header; /* count number of characters received in header */ - uint16_t counter_maxByte; /* count number of characters received for maxByte parameter */ - atcustom_RxSQNSRECV_header_t analyze_state; /* state of header analyze */ - AT_CHAR_t buf_maxByte[MAXBYTE_MAXIMUM_SIZE]; /* buffer to stote header characters */ - -} ATCustom_MONARCH_RxSQNSRECV_header_t; - -typedef struct -{ - ATCustom_MONARCH_dns_t SQNDNSLKUP_dns_info; /* memorize infos received for DNS in +SQNDNSLKUP */ - uint8_t SMST_sim_error_status; /* memorize infos received for DNS in +SMST */ - bool waiting_for_ring_irq; - ATCustom_MONARCH_RxSQNSRECV_header_t RxSQNSRECV_header_info; /* structure used to manage SQNSRECV answer */ -} monarch_shared_variables_t; - -/* External variables --------------------------------------------------------*/ -extern monarch_shared_variables_t monarch_shared; - -/* Exported macros -----------------------------------------------------------*/ - -/* Exported functions ------------------------------------------------------- */ -void ATCustom_MONARCH_init(atparser_context_t *p_atp_ctxt); -uint8_t ATCustom_MONARCH_checkEndOfMsgCallback(uint8_t rxChar); -at_status_t ATCustom_MONARCH_getCmd(at_context_t *p_at_ctxt, uint32_t *p_ATcmdTimeout); -at_endmsg_t ATCustom_MONARCH_extractElement(atparser_context_t *p_atp_ctxt, - const IPC_RxMessage_t *p_msg_in, - at_element_info_t *element_infos); -at_action_rsp_t ATCustom_MONARCH_analyzeCmd(at_context_t *p_at_ctxt, - const IPC_RxMessage_t *p_msg_in, - at_element_info_t *element_infos); -at_action_rsp_t ATCustom_MONARCH_analyzeParam(at_context_t *p_at_ctxt, - const IPC_RxMessage_t *p_msg_in, - at_element_info_t *element_infos); -at_action_rsp_t ATCustom_MONARCH_terminateCmd(atparser_context_t *p_atp_ctxt, at_element_info_t *element_infos); - -at_status_t ATCustom_MONARCH_get_rsp(atparser_context_t *p_atp_ctxt, at_buf_t *p_rsp_buf); -at_status_t ATCustom_MONARCH_get_urc(atparser_context_t *p_atp_ctxt, at_buf_t *p_rsp_buf); -at_status_t ATCustom_MONARCH_get_error(atparser_context_t *p_atp_ctxt, at_buf_t *p_rsp_buf); -at_status_t ATCustom_MONARCH_hw_event(sysctrl_device_type_t deviceType, at_hw_event_t hwEvent, GPIO_PinState gstate); - -#ifdef __cplusplus -} -#endif - -#endif /* AT_CUSTOM_MODEM_MONARCH_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - +/** + ****************************************************************************** + * @file at_custom_modem_specific.h + * @author MCD Application Team + * @brief Header for at_custom_modem_specific.c module + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef AT_CUSTOM_MODEM_MONARCH_H +#define AT_CUSTOM_MODEM_MONARCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "at_core.h" +#include "at_parser.h" +#include "at_modem_api.h" +#include "at_modem_signalling.h" +#include "cellular_service.h" +#include "cellular_service_int.h" +#include "ipc_common.h" + +/* Exported constants --------------------------------------------------------*/ +/* device specific parameters */ +#define MODEM_MAX_SOCKET_TX_DATA_SIZE CONFIG_MODEM_MAX_SOCKET_TX_DATA_SIZE +#define MODEM_MAX_SOCKET_RX_DATA_SIZE CONFIG_MODEM_MAX_SOCKET_RX_DATA_SIZE +#define SEQUANS_PING_LENGTH ((uint16_t)32U) +#define GM01Q_ACTIVATE_PING_REPORT (1) /* temporary solution, ping is synchrone, report not supported by com */ +#define ENABLE_SEQUANS_LOW_POWER_MODE (0) /* not applicable yet for this modem - Do not activate !!! */ + +/* Exported types ------------------------------------------------------------*/ +typedef enum +{ + /* modem specific commands */ + CMD_AT_SQNSRING = (CMD_AT_LAST_GENERIC + 1U), /* socket ring */ + CMD_AT_SQNSCFG, /* socket configuration */ + CMD_AT_SQNSCFGEXT, /* socket extended configuration */ + CMD_AT_SQNSD, /* socket dial */ + CMD_AT_SQNSH, /* socket shutdown */ + CMD_AT_SQNSI, /* socket information */ + CMD_AT_SQNSS, /* socket status */ + CMD_AT_SQNSRECV, /* socket, receive data in command mode */ + CMD_AT_SQNSSENDEXT, /* socket, extended send data in command mode (waiting for prompt) */ + CMD_AT_SQNSSEND_WRITE_DATA, /* socket, send data in command mode (send data) */ + CMD_AT_RESET, /* hardware reset */ + CMD_AT_SQNCTM, /* Conformance Test mode (not described in Monarch ref. manual but in Calliope ref. manual */ + CMD_AT_AUTOATT, /* Automatic Attach */ + CMD_AT_CGDCONT_REPROGRAM, /* special case, reprogram CGDCONT */ + CMD_AT_CLEAR_SCAN_CFG, /* clear bands */ + CMD_AT_ADD_SCAN_BAND, /* add a band */ + CMD_AT_ICCID, /* ICCID request */ + CMD_AT_SQNDNSLKUP, /* DNS request */ + CMD_AT_PING, /* Ping request */ + CMD_AT_SMST, /* SIM test */ + CMD_AT_CESQ, /* Extended signal quality */ + CMD_AT_SQNSSHDN, /* Power Down Modem */ + + /* modem specific events (URC, BOOT, ...) */ + CMD_AT_WAIT_EVENT, + CMD_AT_SIMREADY_EVENT, + CMD_AT_SYSSTART_TYPE1, + CMD_AT_SYSSTART_TYPE2, + CMD_AT_SYSSHDN, + CMD_AT_SOCKET_PROMPT, + CMD_AT_SHUTDOWN, + +} ATCustom_MONARCH_cmdlist_t; + +typedef struct +{ + AT_CHAR_t hostIPaddr[MAX_SIZE_IPADDR]; /* = host_name parameter from CS_DnsReq_t */ +} ATCustom_MONARCH_dns_t; + +typedef enum +{ + /* Command syntax + * +SQNSRECV:,[,,] + * + * OK + */ + RX_SQNSRECV_header_not_started, + RX_SQNSRECV_header_prefix, /* receiving prefix, ie +SQNSRECV: */ + RX_SQNSRECV_header_connId, /* receiving connId parameter */ + RX_SQNSRECV_header_maxByte, /* receiving maxByte parameter */ + RX_SQNSRECV_header_other, /* receiving other parameter */ + +} atcustom_RxSQNSRECV_header_t; + +#define MAXBYTE_MAXIMUM_SIZE ((uint8_t)8U) + +typedef struct +{ + /* structure used to manage answer to AT+SQNSRECV in case crossing-cases, especially when + * +SQNSRING URC is received instead of +SQNSRECV answer. + */ + uint16_t counter_header; /* count number of characters received in header */ + uint16_t counter_maxByte; /* count number of characters received for maxByte parameter */ + atcustom_RxSQNSRECV_header_t analyze_state; /* state of header analyze */ + AT_CHAR_t buf_maxByte[MAXBYTE_MAXIMUM_SIZE]; /* buffer to stote header characters */ + +} ATCustom_MONARCH_RxSQNSRECV_header_t; + +typedef struct +{ + ATCustom_MONARCH_dns_t SQNDNSLKUP_dns_info; /* memorize infos received for DNS in +SQNDNSLKUP */ + uint8_t SMST_sim_error_status; /* memorize infos received for DNS in +SMST */ + bool waiting_for_ring_irq; + ATCustom_MONARCH_RxSQNSRECV_header_t RxSQNSRECV_header_info; /* structure used to manage SQNSRECV answer */ +} monarch_shared_variables_t; + +/* External variables --------------------------------------------------------*/ +extern monarch_shared_variables_t monarch_shared; + +/* Exported macros -----------------------------------------------------------*/ + +/* Exported functions ------------------------------------------------------- */ +void ATCustom_MONARCH_init(atparser_context_t *p_atp_ctxt); +uint8_t ATCustom_MONARCH_checkEndOfMsgCallback(uint8_t rxChar); +at_status_t ATCustom_MONARCH_getCmd(at_context_t *p_at_ctxt, uint32_t *p_ATcmdTimeout); +at_endmsg_t ATCustom_MONARCH_extractElement(atparser_context_t *p_atp_ctxt, + const IPC_RxMessage_t *p_msg_in, + at_element_info_t *element_infos); +at_action_rsp_t ATCustom_MONARCH_analyzeCmd(at_context_t *p_at_ctxt, + const IPC_RxMessage_t *p_msg_in, + at_element_info_t *element_infos); +at_action_rsp_t ATCustom_MONARCH_analyzeParam(at_context_t *p_at_ctxt, + const IPC_RxMessage_t *p_msg_in, + at_element_info_t *element_infos); +at_action_rsp_t ATCustom_MONARCH_terminateCmd(atparser_context_t *p_atp_ctxt, at_element_info_t *element_infos); + +at_status_t ATCustom_MONARCH_get_rsp(atparser_context_t *p_atp_ctxt, at_buf_t *p_rsp_buf); +at_status_t ATCustom_MONARCH_get_urc(atparser_context_t *p_atp_ctxt, at_buf_t *p_rsp_buf); +at_status_t ATCustom_MONARCH_get_error(atparser_context_t *p_atp_ctxt, at_buf_t *p_rsp_buf); +at_status_t ATCustom_MONARCH_hw_event(sysctrl_device_type_t deviceType, at_hw_event_t hwEvent, GPIO_PinState gstate); + +#ifdef __cplusplus +} +#endif + +#endif /* AT_CUSTOM_MODEM_MONARCH_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + diff --git a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/plf_modem_config.h b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/plf_modem_config.h index 75508b0..e8a879f 100644 --- a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/plf_modem_config.h +++ b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/plf_modem_config.h @@ -1,85 +1,85 @@ -/** - ****************************************************************************** - * @file plf_modem_config.h - * @author MCD Application Team - * @brief This file contains the modem configuration for VZM20X/GM01Q - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef PLF_MODEM_CONFIG_H -#define PLF_MODEM_CONFIG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ - -/* Exported constants --------------------------------------------------------*/ -/* You can specify in project configuration the modem and hardware interface used. -* If this is not specified, default configuration is specified below. -*/ -#if defined(HWREF_GM01QDBA1) -/* already explicitly defined: - * using HWREF_GM01QDBA1 directly on STMOD+ connector - */ -#else -/* set default config */ -#define HWREF_GM01QDBA1 -#endif /* HWREF_GM01QDBA1 */ - -/* Low Power */ -#define ENABLE_MONARCH_PSM (1U) /* active PSM: 1U, deactivate PSM: 0U */ -#define ENABLE_MONARCH_LOW_POWER_MODE (0U) /* Monarch Low Power mode (UART deactivation): not supported yet */ - -/* MODEM parameters */ - -#define USE_MODEM_GM01Q -#define CONFIG_MODEM_UART_BAUDRATE (115200U) -#define CONFIG_MODEM_USE_STMOD_CONNECTOR - -#define UDP_SERVICE_SUPPORTED (0U) -#define CONFIG_MODEM_UDP_SERVICE_CONNECT_IP ((uint8_t *)"127.0.0.1") -#define CONFIG_MODEM_MAX_SOCKET_TX_DATA_SIZE ((uint32_t)1460U) -#define CONFIG_MODEM_MAX_SOCKET_RX_DATA_SIZE ((uint32_t)1500U) -#define CONFIG_MODEM_MAX_SIM_GENERIC_ACCESS_CMD_SIZE ((uint32_t)1460U) -#define CONFIG_MODEM_MIN_SIM_GENERIC_ACCESS_RSP_SIZE ((uint32_t)4U) - -/* Ping URC received before or after Reply */ -#define PING_URC_RECEIVED_AFTER_REPLY (0U) - -/* UART flow control settings */ -#if defined(USER_FLAG_MODEM_FORCE_NO_FLOW_CTRL) -#define CONFIG_MODEM_UART_RTS_CTS (0) -#elif defined(USER_FLAG_MODEM_FORCE_HW_FLOW_CTRL) -#define CONFIG_MODEM_UART_RTS_CTS (1) -#else /* default FLOW CONTROL setting for GM01Q */ -#define CONFIG_MODEM_UART_RTS_CTS (1) -#endif /* user flag for modem flow control */ - -/* At the end of the modem power on, this parameter defines whether we apply the theoretical delay to let the - * modem start or if we try to establish communication immediately. - * - * SEQMONARCH_FASTEST_POWER_ON : not supported by MONARCH - */ - -#ifdef __cplusplus -} -#endif - -#endif /*_PLF_MODEM_CONFIG_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - +/** + ****************************************************************************** + * @file plf_modem_config.h + * @author MCD Application Team + * @brief This file contains the modem configuration for VZM20X/GM01Q + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef PLF_MODEM_CONFIG_H +#define PLF_MODEM_CONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ + +/* Exported constants --------------------------------------------------------*/ +/* You can specify in project configuration the modem and hardware interface used. +* If this is not specified, default configuration is specified below. +*/ +#if defined(HWREF_GM01QDBA1) +/* already explicitly defined: + * using HWREF_GM01QDBA1 directly on STMOD+ connector + */ +#else +/* set default config */ +#define HWREF_GM01QDBA1 +#endif /* HWREF_GM01QDBA1 */ + +/* Low Power */ +#define ENABLE_MONARCH_PSM (1U) /* active PSM: 1U, deactivate PSM: 0U */ +#define ENABLE_MONARCH_LOW_POWER_MODE (0U) /* Monarch Low Power mode (UART deactivation): not supported yet */ + +/* MODEM parameters */ + +#define USE_MODEM_GM01Q +#define CONFIG_MODEM_UART_BAUDRATE (115200U) +#define CONFIG_MODEM_USE_STMOD_CONNECTOR + +#define UDP_SERVICE_SUPPORTED (0U) +#define CONFIG_MODEM_UDP_SERVICE_CONNECT_IP ((uint8_t *)"127.0.0.1") +#define CONFIG_MODEM_MAX_SOCKET_TX_DATA_SIZE ((uint32_t)1460U) +#define CONFIG_MODEM_MAX_SOCKET_RX_DATA_SIZE ((uint32_t)1500U) +#define CONFIG_MODEM_MAX_SIM_GENERIC_ACCESS_CMD_SIZE ((uint32_t)1460U) +#define CONFIG_MODEM_MIN_SIM_GENERIC_ACCESS_RSP_SIZE ((uint32_t)4U) + +/* Ping URC received before or after Reply */ +#define PING_URC_RECEIVED_AFTER_REPLY (0U) + +/* UART flow control settings */ +#if defined(USER_FLAG_MODEM_FORCE_NO_FLOW_CTRL) +#define CONFIG_MODEM_UART_RTS_CTS (0) +#elif defined(USER_FLAG_MODEM_FORCE_HW_FLOW_CTRL) +#define CONFIG_MODEM_UART_RTS_CTS (1) +#else /* default FLOW CONTROL setting for GM01Q */ +#define CONFIG_MODEM_UART_RTS_CTS (1) +#endif /* user flag for modem flow control */ + +/* At the end of the modem power on, this parameter defines whether we apply the theoretical delay to let the + * modem start or if we try to establish communication immediately. + * + * SEQMONARCH_FASTEST_POWER_ON : not supported by MONARCH + */ + +#ifdef __cplusplus +} +#endif + +#endif /*_PLF_MODEM_CONFIG_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + diff --git a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/sysctrl_specific.h b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/sysctrl_specific.h index 214577f..c236dab 100644 --- a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/sysctrl_specific.h +++ b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Inc/sysctrl_specific.h @@ -1,59 +1,59 @@ -/** - ****************************************************************************** - * @file sysctrl_specific.h - * @author MCD Application Team - * @brief Header for sysctrl_specific.c module - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -/* Define to prevent recursive inclusion -------------------------------------*/ -#ifndef SYSCTRL_MONARCH_H -#define SYSCTRL_MONARCH_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* Includes ------------------------------------------------------------------*/ -#include "sysctrl.h" -#include "at_custom_modem_specific.h" - -/* Exported constants --------------------------------------------------------*/ -/* Exported types ------------------------------------------------------------*/ -/* External variables --------------------------------------------------------*/ -/* Exported macros -----------------------------------------------------------*/ - -/* Exported functions ------------------------------------------------------- */ -sysctrl_status_t SysCtrl_MONARCH_getDeviceDescriptor(sysctrl_device_type_t type, sysctrl_info_t *p_devices_list); -sysctrl_status_t SysCtrl_MONARCH_open_channel(sysctrl_device_type_t type); -sysctrl_status_t SysCtrl_MONARCH_close_channel(sysctrl_device_type_t type); -sysctrl_status_t SysCtrl_MONARCH_power_on(sysctrl_device_type_t type); -sysctrl_status_t SysCtrl_MONARCH_power_off(sysctrl_device_type_t type); -sysctrl_status_t SysCtrl_MONARCH_reset(sysctrl_device_type_t type); -sysctrl_status_t SysCtrl_MONARCH_sim_select(sysctrl_device_type_t type, sysctrl_sim_slot_t sim_slot); - -#if (ENABLE_SEQUANS_LOW_POWER_MODE == 1) -sysctrl_status_t SysCtrl_MONARCH_suspend_channel_request(IPC_Handle_t *ipc_handle, sysctrl_device_type_t type); -sysctrl_status_t SysCtrl_MONARCH_suspend_channel_complete(IPC_Handle_t *ipc_handle, sysctrl_device_type_t type); -sysctrl_status_t SysCtrl_MONARCH_resume_channel(IPC_Handle_t *ipc_handle, sysctrl_device_type_t type); -sysctrl_status_t SysCtrl_MONARCH_setup_LowPower_Int(uint8_t set); -#endif /* (ENABLE_SEQUANS_LOW_POWER_MODE == 1) */ - -#ifdef __cplusplus -} -#endif - -#endif /* SYSCTRL_MONARCH_H */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +/** + ****************************************************************************** + * @file sysctrl_specific.h + * @author MCD Application Team + * @brief Header for sysctrl_specific.c module + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef SYSCTRL_MONARCH_H +#define SYSCTRL_MONARCH_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "sysctrl.h" +#include "at_custom_modem_specific.h" + +/* Exported constants --------------------------------------------------------*/ +/* Exported types ------------------------------------------------------------*/ +/* External variables --------------------------------------------------------*/ +/* Exported macros -----------------------------------------------------------*/ + +/* Exported functions ------------------------------------------------------- */ +sysctrl_status_t SysCtrl_MONARCH_getDeviceDescriptor(sysctrl_device_type_t type, sysctrl_info_t *p_devices_list); +sysctrl_status_t SysCtrl_MONARCH_open_channel(sysctrl_device_type_t type); +sysctrl_status_t SysCtrl_MONARCH_close_channel(sysctrl_device_type_t type); +sysctrl_status_t SysCtrl_MONARCH_power_on(sysctrl_device_type_t type); +sysctrl_status_t SysCtrl_MONARCH_power_off(sysctrl_device_type_t type); +sysctrl_status_t SysCtrl_MONARCH_reset(sysctrl_device_type_t type); +sysctrl_status_t SysCtrl_MONARCH_sim_select(sysctrl_device_type_t type, sysctrl_sim_slot_t sim_slot); + +#if (ENABLE_SEQUANS_LOW_POWER_MODE == 1) +sysctrl_status_t SysCtrl_MONARCH_suspend_channel_request(IPC_Handle_t *ipc_handle, sysctrl_device_type_t type); +sysctrl_status_t SysCtrl_MONARCH_suspend_channel_complete(IPC_Handle_t *ipc_handle, sysctrl_device_type_t type); +sysctrl_status_t SysCtrl_MONARCH_resume_channel(IPC_Handle_t *ipc_handle, sysctrl_device_type_t type); +sysctrl_status_t SysCtrl_MONARCH_setup_LowPower_Int(uint8_t set); +#endif /* (ENABLE_SEQUANS_LOW_POWER_MODE == 1) */ + +#ifdef __cplusplus +} +#endif + +#endif /* SYSCTRL_MONARCH_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Src/at_custom_modem_api.c b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Src/at_custom_modem_api.c index 9967bf6..1561d51 100644 --- a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Src/at_custom_modem_api.c +++ b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Src/at_custom_modem_api.c @@ -1,73 +1,73 @@ -/** - ****************************************************************************** - * @file at_custom_modem_api.c - * @author MCD Application Team - * @brief This file provides all the specific code to the - * Sequans MONARCH modem - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "string.h" -#include "at_custom_modem_api.h" -#include "at_custom_modem_specific.h" -#include "sysctrl_specific.h" -#include "plf_config.h" - -/* Private typedef -----------------------------------------------------------*/ -/* Private defines -----------------------------------------------------------*/ - -/* Private macros ------------------------------------------------------------*/ - -/* Private variables ---------------------------------------------------------*/ -/* Global variables ----------------------------------------------------------*/ -/* Private function prototypes -----------------------------------------------*/ - -/* Functions Definition ------------------------------------------------------*/ -void atcma_init_at_func_ptrs(atcustom_funcPtrs_t *funcPtrs) -{ -#if defined(USE_MODEM_GM01Q) - /* init function pointers with MONARCH functions */ - funcPtrs->f_init = ATCustom_MONARCH_init; - funcPtrs->f_checkEndOfMsgCallback = ATCustom_MONARCH_checkEndOfMsgCallback; - funcPtrs->f_getCmd = ATCustom_MONARCH_getCmd; - funcPtrs->f_extractElement = ATCustom_MONARCH_extractElement; - funcPtrs->f_analyzeCmd = ATCustom_MONARCH_analyzeCmd; - funcPtrs->f_analyzeParam = ATCustom_MONARCH_analyzeParam; - funcPtrs->f_terminateCmd = ATCustom_MONARCH_terminateCmd; - funcPtrs->f_get_rsp = ATCustom_MONARCH_get_rsp; - funcPtrs->f_get_urc = ATCustom_MONARCH_get_urc; - funcPtrs->f_get_error = ATCustom_MONARCH_get_error; - funcPtrs->f_hw_event = ATCustom_MONARCH_hw_event; -#else -#error AT custom does not match with selected modem -#endif /* USE_MODEM_GM01Q */ -} - -void atcma_init_sysctrl_func_ptrs(sysctrl_funcPtrs_t *funcPtrs) -{ -#if defined(USE_MODEM_GM01Q) - /* init function pointers with MONARCH functions */ - funcPtrs->f_getDeviceDescriptor = SysCtrl_MONARCH_getDeviceDescriptor; - funcPtrs->f_open_channel = SysCtrl_MONARCH_open_channel; - funcPtrs->f_close_channel = SysCtrl_MONARCH_close_channel; - funcPtrs->f_power_on = SysCtrl_MONARCH_power_on; - funcPtrs->f_power_off = SysCtrl_MONARCH_power_off; - funcPtrs->f_reset_device = SysCtrl_MONARCH_reset; - funcPtrs->f_sim_select = SysCtrl_MONARCH_sim_select; -#else -#error SysCtrl does not match with selected modem -#endif /* USE_MODEM_GM01Q */ -} -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ +/** + ****************************************************************************** + * @file at_custom_modem_api.c + * @author MCD Application Team + * @brief This file provides all the specific code to the + * Sequans MONARCH modem + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "string.h" +#include "at_custom_modem_api.h" +#include "at_custom_modem_specific.h" +#include "sysctrl_specific.h" +#include "plf_config.h" + +/* Private typedef -----------------------------------------------------------*/ +/* Private defines -----------------------------------------------------------*/ + +/* Private macros ------------------------------------------------------------*/ + +/* Private variables ---------------------------------------------------------*/ +/* Global variables ----------------------------------------------------------*/ +/* Private function prototypes -----------------------------------------------*/ + +/* Functions Definition ------------------------------------------------------*/ +void atcma_init_at_func_ptrs(atcustom_funcPtrs_t *funcPtrs) +{ +#if defined(USE_MODEM_GM01Q) + /* init function pointers with MONARCH functions */ + funcPtrs->f_init = ATCustom_MONARCH_init; + funcPtrs->f_checkEndOfMsgCallback = ATCustom_MONARCH_checkEndOfMsgCallback; + funcPtrs->f_getCmd = ATCustom_MONARCH_getCmd; + funcPtrs->f_extractElement = ATCustom_MONARCH_extractElement; + funcPtrs->f_analyzeCmd = ATCustom_MONARCH_analyzeCmd; + funcPtrs->f_analyzeParam = ATCustom_MONARCH_analyzeParam; + funcPtrs->f_terminateCmd = ATCustom_MONARCH_terminateCmd; + funcPtrs->f_get_rsp = ATCustom_MONARCH_get_rsp; + funcPtrs->f_get_urc = ATCustom_MONARCH_get_urc; + funcPtrs->f_get_error = ATCustom_MONARCH_get_error; + funcPtrs->f_hw_event = ATCustom_MONARCH_hw_event; +#else +#error AT custom does not match with selected modem +#endif /* USE_MODEM_GM01Q */ +} + +void atcma_init_sysctrl_func_ptrs(sysctrl_funcPtrs_t *funcPtrs) +{ +#if defined(USE_MODEM_GM01Q) + /* init function pointers with MONARCH functions */ + funcPtrs->f_getDeviceDescriptor = SysCtrl_MONARCH_getDeviceDescriptor; + funcPtrs->f_open_channel = SysCtrl_MONARCH_open_channel; + funcPtrs->f_close_channel = SysCtrl_MONARCH_close_channel; + funcPtrs->f_power_on = SysCtrl_MONARCH_power_on; + funcPtrs->f_power_off = SysCtrl_MONARCH_power_off; + funcPtrs->f_reset_device = SysCtrl_MONARCH_reset; + funcPtrs->f_sim_select = SysCtrl_MONARCH_sim_select; +#else +#error SysCtrl does not match with selected modem +#endif /* USE_MODEM_GM01Q */ +} +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Src/at_custom_modem_signalling.c b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Src/at_custom_modem_signalling.c index 2a263a8..2250714 100644 --- a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Src/at_custom_modem_signalling.c +++ b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Src/at_custom_modem_signalling.c @@ -1,466 +1,466 @@ -/** - ****************************************************************************** - * @file at_custom_modem_signalling.c - * @author MCD Application Team - * @brief This file provides all the specific code to the - * Sequans Monarch modem - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "string.h" -#include "at_modem_api.h" -#include "at_modem_common.h" -#include "at_modem_signalling.h" -#include "at_modem_socket.h" -#include "at_custom_modem_signalling.h" -#include "at_custom_modem_specific.h" -#include "at_datapack.h" -#include "at_util.h" -#include "cellular_runtime_custom.h" -#include "plf_config.h" -#include "plf_modem_config.h" -#include "error_handler.h" - -/* Private typedef -----------------------------------------------------------*/ - -/* Private macros ------------------------------------------------------------*/ -#if (USE_TRACE_ATCUSTOM_SPECIFIC == 1U) -#if (USE_PRINTF == 0U) -#include "trace_interface.h" -#define PRINT_INFO(format, args...) TRACE_PRINT(DBG_CHAN_ATCMD, DBL_LVL_P0, "MONARCH:" format "\n\r", ## args) -#define PRINT_DBG(format, args...) TRACE_PRINT(DBG_CHAN_ATCMD, DBL_LVL_P1, "MONARCH:" format "\n\r", ## args) -#define PRINT_API(format, args...) TRACE_PRINT(DBG_CHAN_ATCMD, DBL_LVL_P2, "MONARCH API:" format "\n\r", ## args) -#define PRINT_ERR(format, args...) TRACE_PRINT(DBG_CHAN_ATCMD, DBL_LVL_ERR, "MONARCH ERROR:" format "\n\r", ## args) -#define PRINT_BUF(pbuf, size) TRACE_PRINT_BUF_CHAR(DBG_CHAN_ATCMD, DBL_LVL_P1, (const CRC_CHAR_t *)pbuf, size); -#else -#define PRINT_INFO(format, args...) (void) printf("MONARCH:" format "\n\r", ## args); -#define PRINT_DBG(...) __NOP(); /* Nothing to do */ -#define PRINT_API(...) __NOP(); /* Nothing to do */ -#define PRINT_ERR(format, args...) (void) printf("MONARCH ERROR:" format "\n\r", ## args); -#define PRINT_BUF(...) __NOP(); /* Nothing to do */ -#endif /* USE_PRINTF */ -#else -#define PRINT_INFO(...) __NOP(); /* Nothing to do */ -#define PRINT_DBG(...) __NOP(); /* Nothing to do */ -#define PRINT_API(...) __NOP(); /* Nothing to do */ -#define PRINT_ERR(...) __NOP(); /* Nothing to do */ -#define PRINT_BUF(...) __NOP(); /* Nothing to do */ -#endif /* USE_TRACE_ATCUSTOM_SPECIFIC */ - -/* START_PARAM_LOOP and END_PARAM_LOOP macros are used to loop on all fields -* received in a message. -* Only non-null length fields are analysed. -* End the analyze when the end of the message or an error has been detected. -*/ -#define START_PARAM_LOOP() uint8_t exitcode = 0U;\ - do {\ - if (atcc_extractElement(p_at_ctxt, p_msg_in, element_infos) != ATENDMSG_NO) {exitcode = 1U;}\ - if (element_infos->str_size != 0U)\ - {\ - -#define END_PARAM_LOOP() }\ - if (retval == ATACTION_RSP_ERROR) {exitcode = 1U;}\ - } while (exitcode == 0U); - -/* Private defines -----------------------------------------------------------*/ - -/* Global variables ----------------------------------------------------------*/ - -/* Private variables ---------------------------------------------------------*/ - -/* Private function prototypes -----------------------------------------------*/ - -/* Functions Definition ------------------------------------------------------*/ - -/* Build command functions ------------------------------------------------------- */ -at_status_t fCmdBuild_ATD_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) -{ - UNUSED(p_modem_ctxt); - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_ATD_MONARCH()") - - /* only for execution command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_EXECUTION_CMD) - { - CS_PDN_conf_id_t current_conf_id = atcm_get_cid_current_SID(p_modem_ctxt); - uint8_t modem_cid = atcm_get_affected_modem_cid(&p_modem_ctxt->persist, current_conf_id); - PRINT_INFO("Activate PDN (user cid = %d, modem cid = %d)", (uint8_t)current_conf_id, modem_cid) - - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "*99***%d#", modem_cid); - } - return (retval); -} - -at_status_t fCmdBuild_SQNCTM_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) -{ - UNUSED(p_modem_ctxt); - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_SQNCTM_MONARCH()") - - /* only for write command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) - { - /* - * AT+SQNCTM= - * - * implementation: if MONARCH_CONFORMANCE_TEST_MODE is defined, use it for value. - * Otherwise, use "standard" by default - */ -#if defined(MONARCH_CONFORMANCE_TEST_MODE) - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "\"%s\"", MONARCH_CONFORMANCE_TEST_MODE); -#else - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "\"standard\""); -#endif /* MONARCH_CONFORMANCE_TEST_MODE */ - } - - return (retval); - -} - -at_status_t fCmdBuild_AUTOATT_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) -{ - UNUSED(p_modem_ctxt); - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_AUTOATT_MONARCH()") - - /* only for write command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) - { - /* - * AT^AUTOATT= - * - * implementation: if MONARCH_AUTOATTACH is defined, use it for value. - * Otherwise, use 1 by default - */ -#if defined(MONARCH_AUTOATTACH) - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "%d", MONARCH_AUTOATTACH); -#else - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "1"); -#endif /* MONARCH_AUTOATTACH */ - } - - return (retval); - -} - -at_status_t fCmdBuild_CGDCONT_REPROGRAM_MONARCH(atparser_context_t *p_atp_ctxt, - atcustom_modem_context_t *p_modem_ctxt) -{ - UNUSED(p_modem_ctxt); - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_CGDCONT_REPROGRAM_MONARCH()") - - /* only for raw command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_RAW_CMD) - { - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "AT+CGDCONT=%d,\"%s\",\"%s\"\r", - 1U, - "IP", - ""); - p_atp_ctxt->current_atcmd.raw_cmd_size = strlen((const CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params); - } - - return (retval); -} - -at_status_t fCmdBuild_SQNDNSLKUP_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) -{ - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_SQNDNSLKUP_MONARCH()") - - /* only for write command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) - { - /* - * AT+QIDNSGIP=[,] - * - * Write command will return in ERROR if data APN is not yet activated (see AT+CGDCONT). - */ - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "\"%s\"", - p_modem_ctxt->SID_ctxt.dns_request_infos->dns_req.host_name); - } - - return (retval); -} - -at_status_t fCmdBuild_SMST_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) -{ - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_SMST_MONARCH()") - - /* only for write command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) - { - /* +SMST= - * interface - * Optional parameter to select the SIM interface. - * > 0: selects external SIM (default interface) - * > 1: selects internal SIM - * > 0: selects SCI0 interface (default interface) - * > 1: selects SCI1 interface - */ - uint8_t interface; - if (p_modem_ctxt->persist.sim_selected == CS_MODEM_SIM_SOCKET_0) - { - interface = 0U; - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "%d", interface); - } - else if (p_modem_ctxt->persist.sim_selected == CS_MODEM_SIM_ESIM_1) - { - interface = 1U; - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "%d", interface); - } - else - { - retval = ATSTATUS_ERROR; - } - } - - return (retval); -} - -/* Analyze command functions ------------------------------------------------------- */ -at_action_rsp_t fRspAnalyze_Error_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) -{ - atparser_context_t *p_atp_ctxt = &(p_at_ctxt->parser); - at_action_rsp_t retval; - PRINT_API("enter fRspAnalyze_Error_MONARCH()") - - switch (p_atp_ctxt->current_SID) - { - case SID_CS_DIAL_COMMAND: - /* in case of error during socket connection, - * release the modem CID for this socket_handle - */ - (void) atcm_socket_release_modem_cid(p_modem_ctxt, p_modem_ctxt->socket_ctxt.socket_info->socket_handle); - break; - - default: - break; - } - - /* analyze Error for Sequans modems */ - switch (p_atp_ctxt->current_atcmd.id) - { - case CMD_AT_CLEAR_SCAN_CFG: - case CMD_AT_ADD_SCAN_BAND: - /* error is ignored */ - retval = ATACTION_RSP_FRC_END; - break; - - default: - retval = fRspAnalyze_Error(p_at_ctxt, p_modem_ctxt, p_msg_in, element_infos); - break; - } - - return (retval); -} - -at_action_rsp_t fRspAnalyze_SQNCCID_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) -{ - UNUSED(p_at_ctxt); - at_action_rsp_t retval = ATACTION_RSP_INTERMEDIATE; /* received a valid intermediate answer */ - PRINT_API("enter fRspAnalyze_SQNCCID_MONARCH()") - - /* analyze parameters for +QCCID */ - START_PARAM_LOOP() - if (element_infos->param_rank == 2U) - { - PRINT_DBG("ICCID:") - PRINT_BUF((const uint8_t *)&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size) - - (void) memcpy((void *) & (p_modem_ctxt->SID_ctxt.device_info->u.iccid), - (const void *)&p_msg_in->buffer[element_infos->str_start_idx], - (size_t) element_infos->str_size); - } - else - { - /* other parameters ignored */ - __NOP(); /* to avoid warning */ - } - END_PARAM_LOOP() - - return (retval); -} - -at_action_rsp_t fRspAnalyze_SQNDNSLKUP_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) -{ - UNUSED(p_at_ctxt); - UNUSED(p_modem_ctxt); - at_action_rsp_t retval = ATACTION_RSP_INTERMEDIATE; /* received a valid intermediate answer */ - PRINT_API("enter fRspAnalyze_SQNDNSLKUP_MONARCH()") - - /* analyze parameters for +SQNDNSLKUP: - * +SQNDNSLKUP: , - */ - START_PARAM_LOOP() - - if (element_infos->param_rank == 2U) - { - /* ignore parameter */ - } - else if (element_infos->param_rank == 3U) - { - (void) memcpy((void *)monarch_shared.SQNDNSLKUP_dns_info.hostIPaddr, - (const void *) & (p_msg_in->buffer[element_infos->str_start_idx]), - (size_t) element_infos->str_size); - } - else - { /* nothing to do */ } - - END_PARAM_LOOP() - - return (retval); -} - -at_action_rsp_t fRspAnalyze_SMST_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) -{ - UNUSED(p_at_ctxt); - UNUSED(p_modem_ctxt); - at_action_rsp_t retval = ATACTION_RSP_INTERMEDIATE; /* received a valid intermediate answer */ - PRINT_API("enter fRspAnalyze_SMST_MONARCH()") - - /* analyze parameters for +SMST: - * +SMST=status - * - * status = OK (test completed with a positive status) - * status = NO SIM (no sim card was detected) - * status = NOK (test completed and detected a problem) - */ - START_PARAM_LOOP() - - if (element_infos->param_rank == 2U) - { - CRC_CHAR_t status[32]; - (void) memset((void *)status, 0, 32); - - /* retrieve SMST value */ - (void) memcpy((void *)status, - (const void *)&p_msg_in->buffer[element_infos->str_start_idx], - (size_t) element_infos->str_size); - PRINT_DBG(" +SMST: status=%s", status) - - /* extract value and compare it to expected value */ - if ((AT_CHAR_t *) strstr((const CRC_CHAR_t *)&status[0], "NOK") != NULL) - { - /* keep it before OK test !! */ - PRINT_ERR("decoded value = NOK (ERROR !)") - monarch_shared.SMST_sim_error_status = 1U; - } - else if ((AT_CHAR_t *) strstr((const CRC_CHAR_t *)&status[0], "NO SIM") != NULL) - { - PRINT_ERR("decoded value = NO SIM (ERROR !)") - monarch_shared.SMST_sim_error_status = 1U; - } - else if ((AT_CHAR_t *) strstr((const CRC_CHAR_t *)&status[0], "OK") != NULL) - { - PRINT_DBG("decoded value = OK") - monarch_shared.SMST_sim_error_status = 0U; - } - else - { - /* value not expected */ - PRINT_ERR("+SMST unexpected decoded value (ERROR!)") - monarch_shared.SMST_sim_error_status = 1U; - } - } - - END_PARAM_LOOP() - - return (retval); -} - -at_action_rsp_t fRspAnalyze_CESQ_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) -{ - UNUSED(p_modem_ctxt); - atparser_context_t *p_atp_ctxt = &(p_at_ctxt->parser); - at_action_rsp_t retval = ATACTION_RSP_IGNORED; - PRINT_API("enter fRspAnalyze_CESQ_MONARCH()") - - /* analyze parameters for CESQ */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_EXECUTION_CMD) - { - /* - * format: +QCSQ: ,sysmode>,[,[,[,[,]]]] - * - * "NOSERVICE", "GSM", "CAT-M1" or "CAT-NB1" - * - * if = "NOSERVICE" - * no values - * if = "GSM" - * = - * if = "CAT-M1" or "CAT-NB1" - * = / = / = / = - */ - - START_PARAM_LOOP() - if (element_infos->param_rank == 2U) - { - /* */ - PRINT_DBG(" = %ld", - ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)); - } - else if (element_infos->param_rank == 3U) - { - /* */ - PRINT_DBG(" = %ld", - ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)); - } - else if (element_infos->param_rank == 4U) - { - /* */ - PRINT_DBG(" = %ld", - ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)); - } - else if (element_infos->param_rank == 5U) - { - /* */ - PRINT_DBG(" = %ld", - ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)); - } - else if (element_infos->param_rank == 6U) - { - /* */ - PRINT_DBG(" = %ld", - ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)); - } - else if (element_infos->param_rank == 7U) - { - /* */ - /* rsrp range is -44 dBm to -140 dBm */ - PRINT_INFO(" = %ld (about -%ld dBm)", - ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], - element_infos->str_size), - (ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], - element_infos->str_size) - 141U)); - } - else - { /* nothing to do */ } - - END_PARAM_LOOP() - } - - return (retval); -} - -/* Private function Definition -----------------------------------------------*/ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ - +/** + ****************************************************************************** + * @file at_custom_modem_signalling.c + * @author MCD Application Team + * @brief This file provides all the specific code to the + * Sequans Monarch modem + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2020 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + ****************************************************************************** + */ + +/* Includes ------------------------------------------------------------------*/ +#include "string.h" +#include "at_modem_api.h" +#include "at_modem_common.h" +#include "at_modem_signalling.h" +#include "at_modem_socket.h" +#include "at_custom_modem_signalling.h" +#include "at_custom_modem_specific.h" +#include "at_datapack.h" +#include "at_util.h" +#include "cellular_runtime_custom.h" +#include "plf_config.h" +#include "plf_modem_config.h" +#include "error_handler.h" + +/* Private typedef -----------------------------------------------------------*/ + +/* Private macros ------------------------------------------------------------*/ +#if (USE_TRACE_ATCUSTOM_SPECIFIC == 1U) +#if (USE_PRINTF == 0U) +#include "trace_interface.h" +#define PRINT_INFO(format, args...) TRACE_PRINT(DBG_CHAN_ATCMD, DBL_LVL_P0, "MONARCH:" format "\n\r", ## args) +#define PRINT_DBG(format, args...) TRACE_PRINT(DBG_CHAN_ATCMD, DBL_LVL_P1, "MONARCH:" format "\n\r", ## args) +#define PRINT_API(format, args...) TRACE_PRINT(DBG_CHAN_ATCMD, DBL_LVL_P2, "MONARCH API:" format "\n\r", ## args) +#define PRINT_ERR(format, args...) TRACE_PRINT(DBG_CHAN_ATCMD, DBL_LVL_ERR, "MONARCH ERROR:" format "\n\r", ## args) +#define PRINT_BUF(pbuf, size) TRACE_PRINT_BUF_CHAR(DBG_CHAN_ATCMD, DBL_LVL_P1, (const CRC_CHAR_t *)pbuf, size); +#else +#define PRINT_INFO(format, args...) (void) printf("MONARCH:" format "\n\r", ## args); +#define PRINT_DBG(...) __NOP(); /* Nothing to do */ +#define PRINT_API(...) __NOP(); /* Nothing to do */ +#define PRINT_ERR(format, args...) (void) printf("MONARCH ERROR:" format "\n\r", ## args); +#define PRINT_BUF(...) __NOP(); /* Nothing to do */ +#endif /* USE_PRINTF */ +#else +#define PRINT_INFO(...) __NOP(); /* Nothing to do */ +#define PRINT_DBG(...) __NOP(); /* Nothing to do */ +#define PRINT_API(...) __NOP(); /* Nothing to do */ +#define PRINT_ERR(...) __NOP(); /* Nothing to do */ +#define PRINT_BUF(...) __NOP(); /* Nothing to do */ +#endif /* USE_TRACE_ATCUSTOM_SPECIFIC */ + +/* START_PARAM_LOOP and END_PARAM_LOOP macros are used to loop on all fields +* received in a message. +* Only non-null length fields are analysed. +* End the analyze when the end of the message or an error has been detected. +*/ +#define START_PARAM_LOOP() uint8_t exitcode = 0U;\ + do {\ + if (atcc_extractElement(p_at_ctxt, p_msg_in, element_infos) != ATENDMSG_NO) {exitcode = 1U;}\ + if (element_infos->str_size != 0U)\ + {\ + +#define END_PARAM_LOOP() }\ + if (retval == ATACTION_RSP_ERROR) {exitcode = 1U;}\ + } while (exitcode == 0U); + +/* Private defines -----------------------------------------------------------*/ + +/* Global variables ----------------------------------------------------------*/ + +/* Private variables ---------------------------------------------------------*/ + +/* Private function prototypes -----------------------------------------------*/ + +/* Functions Definition ------------------------------------------------------*/ + +/* Build command functions ------------------------------------------------------- */ +at_status_t fCmdBuild_ATD_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) +{ + UNUSED(p_modem_ctxt); + at_status_t retval = ATSTATUS_OK; + PRINT_API("enter fCmdBuild_ATD_MONARCH()") + + /* only for execution command, set parameters */ + if (p_atp_ctxt->current_atcmd.type == ATTYPE_EXECUTION_CMD) + { + CS_PDN_conf_id_t current_conf_id = atcm_get_cid_current_SID(p_modem_ctxt); + uint8_t modem_cid = atcm_get_affected_modem_cid(&p_modem_ctxt->persist, current_conf_id); + PRINT_INFO("Activate PDN (user cid = %d, modem cid = %d)", (uint8_t)current_conf_id, modem_cid) + + (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "*99***%d#", modem_cid); + } + return (retval); +} + +at_status_t fCmdBuild_SQNCTM_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) +{ + UNUSED(p_modem_ctxt); + at_status_t retval = ATSTATUS_OK; + PRINT_API("enter fCmdBuild_SQNCTM_MONARCH()") + + /* only for write command, set parameters */ + if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) + { + /* + * AT+SQNCTM= + * + * implementation: if MONARCH_CONFORMANCE_TEST_MODE is defined, use it for value. + * Otherwise, use "standard" by default + */ +#if defined(MONARCH_CONFORMANCE_TEST_MODE) + (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "\"%s\"", MONARCH_CONFORMANCE_TEST_MODE); +#else + (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "\"standard\""); +#endif /* MONARCH_CONFORMANCE_TEST_MODE */ + } + + return (retval); + +} + +at_status_t fCmdBuild_AUTOATT_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) +{ + UNUSED(p_modem_ctxt); + at_status_t retval = ATSTATUS_OK; + PRINT_API("enter fCmdBuild_AUTOATT_MONARCH()") + + /* only for write command, set parameters */ + if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) + { + /* + * AT^AUTOATT= + * + * implementation: if MONARCH_AUTOATTACH is defined, use it for value. + * Otherwise, use 1 by default + */ +#if defined(MONARCH_AUTOATTACH) + (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "%d", MONARCH_AUTOATTACH); +#else + (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "1"); +#endif /* MONARCH_AUTOATTACH */ + } + + return (retval); + +} + +at_status_t fCmdBuild_CGDCONT_REPROGRAM_MONARCH(atparser_context_t *p_atp_ctxt, + atcustom_modem_context_t *p_modem_ctxt) +{ + UNUSED(p_modem_ctxt); + at_status_t retval = ATSTATUS_OK; + PRINT_API("enter fCmdBuild_CGDCONT_REPROGRAM_MONARCH()") + + /* only for raw command, set parameters */ + if (p_atp_ctxt->current_atcmd.type == ATTYPE_RAW_CMD) + { + (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "AT+CGDCONT=%d,\"%s\",\"%s\"\r", + 1U, + "IP", + ""); + p_atp_ctxt->current_atcmd.raw_cmd_size = strlen((const CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params); + } + + return (retval); +} + +at_status_t fCmdBuild_SQNDNSLKUP_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) +{ + at_status_t retval = ATSTATUS_OK; + PRINT_API("enter fCmdBuild_SQNDNSLKUP_MONARCH()") + + /* only for write command, set parameters */ + if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) + { + /* + * AT+QIDNSGIP=[,] + * + * Write command will return in ERROR if data APN is not yet activated (see AT+CGDCONT). + */ + (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "\"%s\"", + p_modem_ctxt->SID_ctxt.dns_request_infos->dns_req.host_name); + } + + return (retval); +} + +at_status_t fCmdBuild_SMST_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) +{ + at_status_t retval = ATSTATUS_OK; + PRINT_API("enter fCmdBuild_SMST_MONARCH()") + + /* only for write command, set parameters */ + if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) + { + /* +SMST= + * interface + * Optional parameter to select the SIM interface. + * > 0: selects external SIM (default interface) + * > 1: selects internal SIM + * > 0: selects SCI0 interface (default interface) + * > 1: selects SCI1 interface + */ + uint8_t interface; + if (p_modem_ctxt->persist.sim_selected == CS_MODEM_SIM_SOCKET_0) + { + interface = 0U; + (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "%d", interface); + } + else if (p_modem_ctxt->persist.sim_selected == CS_MODEM_SIM_ESIM_1) + { + interface = 1U; + (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "%d", interface); + } + else + { + retval = ATSTATUS_ERROR; + } + } + + return (retval); +} + +/* Analyze command functions ------------------------------------------------------- */ +at_action_rsp_t fRspAnalyze_Error_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) +{ + atparser_context_t *p_atp_ctxt = &(p_at_ctxt->parser); + at_action_rsp_t retval; + PRINT_API("enter fRspAnalyze_Error_MONARCH()") + + switch (p_atp_ctxt->current_SID) + { + case SID_CS_DIAL_COMMAND: + /* in case of error during socket connection, + * release the modem CID for this socket_handle + */ + (void) atcm_socket_release_modem_cid(p_modem_ctxt, p_modem_ctxt->socket_ctxt.socket_info->socket_handle); + break; + + default: + break; + } + + /* analyze Error for Sequans modems */ + switch (p_atp_ctxt->current_atcmd.id) + { + case CMD_AT_CLEAR_SCAN_CFG: + case CMD_AT_ADD_SCAN_BAND: + /* error is ignored */ + retval = ATACTION_RSP_FRC_END; + break; + + default: + retval = fRspAnalyze_Error(p_at_ctxt, p_modem_ctxt, p_msg_in, element_infos); + break; + } + + return (retval); +} + +at_action_rsp_t fRspAnalyze_SQNCCID_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) +{ + UNUSED(p_at_ctxt); + at_action_rsp_t retval = ATACTION_RSP_INTERMEDIATE; /* received a valid intermediate answer */ + PRINT_API("enter fRspAnalyze_SQNCCID_MONARCH()") + + /* analyze parameters for +QCCID */ + START_PARAM_LOOP() + if (element_infos->param_rank == 2U) + { + PRINT_DBG("ICCID:") + PRINT_BUF((const uint8_t *)&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size) + + (void) memcpy((void *) & (p_modem_ctxt->SID_ctxt.device_info->u.iccid), + (const void *)&p_msg_in->buffer[element_infos->str_start_idx], + (size_t) element_infos->str_size); + } + else + { + /* other parameters ignored */ + __NOP(); /* to avoid warning */ + } + END_PARAM_LOOP() + + return (retval); +} + +at_action_rsp_t fRspAnalyze_SQNDNSLKUP_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) +{ + UNUSED(p_at_ctxt); + UNUSED(p_modem_ctxt); + at_action_rsp_t retval = ATACTION_RSP_INTERMEDIATE; /* received a valid intermediate answer */ + PRINT_API("enter fRspAnalyze_SQNDNSLKUP_MONARCH()") + + /* analyze parameters for +SQNDNSLKUP: + * +SQNDNSLKUP: , + */ + START_PARAM_LOOP() + + if (element_infos->param_rank == 2U) + { + /* ignore parameter */ + } + else if (element_infos->param_rank == 3U) + { + (void) memcpy((void *)monarch_shared.SQNDNSLKUP_dns_info.hostIPaddr, + (const void *) & (p_msg_in->buffer[element_infos->str_start_idx]), + (size_t) element_infos->str_size); + } + else + { /* nothing to do */ } + + END_PARAM_LOOP() + + return (retval); +} + +at_action_rsp_t fRspAnalyze_SMST_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) +{ + UNUSED(p_at_ctxt); + UNUSED(p_modem_ctxt); + at_action_rsp_t retval = ATACTION_RSP_INTERMEDIATE; /* received a valid intermediate answer */ + PRINT_API("enter fRspAnalyze_SMST_MONARCH()") + + /* analyze parameters for +SMST: + * +SMST=status + * + * status = OK (test completed with a positive status) + * status = NO SIM (no sim card was detected) + * status = NOK (test completed and detected a problem) + */ + START_PARAM_LOOP() + + if (element_infos->param_rank == 2U) + { + CRC_CHAR_t status[32]; + (void) memset((void *)status, 0, 32); + + /* retrieve SMST value */ + (void) memcpy((void *)status, + (const void *)&p_msg_in->buffer[element_infos->str_start_idx], + (size_t) element_infos->str_size); + PRINT_DBG(" +SMST: status=%s", status) + + /* extract value and compare it to expected value */ + if ((AT_CHAR_t *) strstr((const CRC_CHAR_t *)&status[0], "NOK") != NULL) + { + /* keep it before OK test !! */ + PRINT_ERR("decoded value = NOK (ERROR !)") + monarch_shared.SMST_sim_error_status = 1U; + } + else if ((AT_CHAR_t *) strstr((const CRC_CHAR_t *)&status[0], "NO SIM") != NULL) + { + PRINT_ERR("decoded value = NO SIM (ERROR !)") + monarch_shared.SMST_sim_error_status = 1U; + } + else if ((AT_CHAR_t *) strstr((const CRC_CHAR_t *)&status[0], "OK") != NULL) + { + PRINT_DBG("decoded value = OK") + monarch_shared.SMST_sim_error_status = 0U; + } + else + { + /* value not expected */ + PRINT_ERR("+SMST unexpected decoded value (ERROR!)") + monarch_shared.SMST_sim_error_status = 1U; + } + } + + END_PARAM_LOOP() + + return (retval); +} + +at_action_rsp_t fRspAnalyze_CESQ_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, + const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) +{ + UNUSED(p_modem_ctxt); + atparser_context_t *p_atp_ctxt = &(p_at_ctxt->parser); + at_action_rsp_t retval = ATACTION_RSP_IGNORED; + PRINT_API("enter fRspAnalyze_CESQ_MONARCH()") + + /* analyze parameters for CESQ */ + if (p_atp_ctxt->current_atcmd.type == ATTYPE_EXECUTION_CMD) + { + /* + * format: +QCSQ: ,sysmode>,[,[,[,[,]]]] + * + * "NOSERVICE", "GSM", "CAT-M1" or "CAT-NB1" + * + * if = "NOSERVICE" + * no values + * if = "GSM" + * = + * if = "CAT-M1" or "CAT-NB1" + * = / = / = / = + */ + + START_PARAM_LOOP() + if (element_infos->param_rank == 2U) + { + /* */ + PRINT_DBG(" = %ld", + ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)); + } + else if (element_infos->param_rank == 3U) + { + /* */ + PRINT_DBG(" = %ld", + ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)); + } + else if (element_infos->param_rank == 4U) + { + /* */ + PRINT_DBG(" = %ld", + ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)); + } + else if (element_infos->param_rank == 5U) + { + /* */ + PRINT_DBG(" = %ld", + ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)); + } + else if (element_infos->param_rank == 6U) + { + /* */ + PRINT_DBG(" = %ld", + ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)); + } + else if (element_infos->param_rank == 7U) + { + /* */ + /* rsrp range is -44 dBm to -140 dBm */ + PRINT_INFO(" = %ld (about -%ld dBm)", + ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], + element_infos->str_size), + (ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], + element_infos->str_size) - 141U)); + } + else + { /* nothing to do */ } + + END_PARAM_LOOP() + } + + return (retval); +} + +/* Private function Definition -----------------------------------------------*/ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ + diff --git a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Src/at_custom_modem_socket.c b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Src/at_custom_modem_socket.c index 4745ad6..b184c24 100644 --- a/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Src/at_custom_modem_socket.c +++ b/Drivers/BSP/X_STMOD_PLUS_MODEMS/MONARCH/AT_modem_monarch/Src/at_custom_modem_socket.c @@ -1,837 +1,837 @@ -/** - ****************************************************************************** - * @file at_custom_modem_specific.c - * @author MCD Application Team - * @brief This file provides all the specific code to the - * Sequans Monarch modem - ****************************************************************************** - * @attention - * - *

© Copyright (c) 2020 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - * - ****************************************************************************** - */ - -/* Includes ------------------------------------------------------------------*/ -#include "string.h" -#include "at_modem_api.h" -#include "at_modem_common.h" -#include "at_modem_signalling.h" -#include "at_modem_socket.h" -#include "at_custom_modem_socket.h" -#include "at_custom_modem_specific.h" -#include "at_datapack.h" -#include "at_util.h" -#include "cellular_runtime_custom.h" -#include "plf_config.h" -#include "plf_modem_config.h" -#include "error_handler.h" - -/* Private typedef -----------------------------------------------------------*/ - -/* Private macros ------------------------------------------------------------*/ -#if (USE_TRACE_ATCUSTOM_SPECIFIC == 1U) -#if (USE_PRINTF == 0U) -#include "trace_interface.h" -#define PRINT_INFO(format, args...) TRACE_PRINT(DBG_CHAN_ATCMD, DBL_LVL_P0, "MONARCH:" format "\n\r", ## args) -#define PRINT_DBG(format, args...) TRACE_PRINT(DBG_CHAN_ATCMD, DBL_LVL_P1, "MONARCH:" format "\n\r", ## args) -#define PRINT_API(format, args...) TRACE_PRINT(DBG_CHAN_ATCMD, DBL_LVL_P2, "MONARCH API:" format "\n\r", ## args) -#define PRINT_ERR(format, args...) TRACE_PRINT(DBG_CHAN_ATCMD, DBL_LVL_ERR, "MONARCH ERROR:" format "\n\r", ## args) -#else -#define PRINT_INFO(format, args...) (void) printf("MONARCH:" format "\n\r", ## args); -#define PRINT_DBG(...) __NOP(); /* Nothing to do */ -#define PRINT_API(...) __NOP(); /* Nothing to do */ -#define PRINT_ERR(format, args...) (void) printf("MONARCH ERROR:" format "\n\r", ## args); -#endif /* USE_PRINTF */ -#else -#define PRINT_INFO(...) __NOP(); /* Nothing to do */ -#define PRINT_DBG(...) __NOP(); /* Nothing to do */ -#define PRINT_API(...) __NOP(); /* Nothing to do */ -#define PRINT_ERR(...) __NOP(); /* Nothing to do */ -#endif /* USE_TRACE_ATCUSTOM_SPECIFIC */ - -/* START_PARAM_LOOP and END_PARAM_LOOP macros are used to loop on all fields -* received in a message. -* Only non-null length fields are analysed. -* End the analyze when the end of the message or an error has been detected. -*/ -#define START_PARAM_LOOP() uint8_t exitcode = 0U;\ - do {\ - if (atcc_extractElement(p_at_ctxt, p_msg_in, element_infos) != ATENDMSG_NO) {exitcode = 1U;}\ - if (element_infos->str_size != 0U)\ - {\ - -#define END_PARAM_LOOP() }\ - if (retval == ATACTION_RSP_ERROR) {exitcode = 1U;}\ - } while (exitcode == 0U); - -/* Private defines -----------------------------------------------------------*/ - -/* Global variables ----------------------------------------------------------*/ - -/* Private variables ---------------------------------------------------------*/ - -/* Private function prototypes -----------------------------------------------*/ - -/* Functions Definition ------------------------------------------------------*/ -/* Build command functions ------------------------------------------------------- */ - -at_status_t fCmdBuild_SQNSCFG_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) -{ - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_SQNSCFG_MONARCH()") - - /* only for write command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) - { - if (p_modem_ctxt->socket_ctxt.socket_info != NULL) - { - /* - * AT+SQNSCFG=,, , ,, - * - * is the PDP context identifier - * : used for online data mode only (NOT SUPPORTED) - */ - - /* convert user cid (CS_PDN_conf_id_t) to PDP modem cid (value) */ - uint8_t pdp_modem_cid = atcm_get_affected_modem_cid(&p_modem_ctxt->persist, - p_modem_ctxt->socket_ctxt.socket_info->conf_id); - PRINT_DBG("user cid = %d, PDP modem cid = %d", - (uint8_t)p_modem_ctxt->socket_ctxt.socket_info->conf_id, pdp_modem_cid) - /* build the command */ - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "%ld,%d,%d,%d,%d,0", - atcm_socket_get_modem_cid(p_modem_ctxt, p_modem_ctxt->socket_ctxt.socket_info->socket_handle), - pdp_modem_cid, - p_modem_ctxt->socket_ctxt.socket_info->ip_max_packet_size, - p_modem_ctxt->socket_ctxt.socket_info->trp_max_timeout, - p_modem_ctxt->socket_ctxt.socket_info->trp_conn_setup_timeout); - } - else - { - retval = ATSTATUS_ERROR; - } - } - - return (retval); -} - -at_status_t fCmdBuild_SQNSCFGEXT_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) -{ - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_SQNSCFGEXT_MONARCH()") - - /* only for write command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) - { - /* - * AT+SQNSCFGEXT=,, ,,, - * - * is currently not used - * - * AT+SQNSCFGEXT=,,, ,[],[] - */ - uint8_t srMode = 1U; /* SQNSRING format = 1 => SQNSRING: , */ - uint8_t recvDataMode = 0U; /* 0: as text */ - uint8_t keepalive = 0U; /* 0 (currently unused) */ - uint8_t listenAutorsp = 0U; /* 0 */ - uint8_t sendDataMode = 0U; /* 0: as text */ - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "%ld,%d,%d,%d,%d,%d", - atcm_socket_get_modem_cid(p_modem_ctxt, p_modem_ctxt->socket_ctxt.socket_info->socket_handle), - srMode, - recvDataMode, - keepalive, - listenAutorsp, - sendDataMode); - } - - return (retval); -} - -at_status_t fCmdBuild_SQNSD_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) -{ - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_SQNSD_MONARCH()") - - /* only for write command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) - { - if (p_modem_ctxt->socket_ctxt.socket_info != NULL) - { - /* - * AT+SQNSD=,,, - * [, [, [,]]] - * - */ - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "%ld,%d,%d,\"%s\",0,%d,%d", - atcm_socket_get_modem_cid(p_modem_ctxt, p_modem_ctxt->socket_ctxt.socket_info->socket_handle), - ((p_modem_ctxt->socket_ctxt.socket_info->protocol == CS_TCP_PROTOCOL) ? 0 : 1), - p_modem_ctxt->socket_ctxt.socket_info->remote_port, - p_modem_ctxt->socket_ctxt.socket_info->ip_addr_value, - /*closureType fixed to 0*/ - p_modem_ctxt->socket_ctxt.socket_info->local_port, - ((p_modem_ctxt->socket_ctxt.socket_info->trp_connect_mode == CS_CM_COMMAND_MODE) ? 1 : 0) - ); - } - else - { - retval = ATSTATUS_ERROR; - } - } - - return (retval); -} - -at_status_t fCmdBuild_SQNSH_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) -{ - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_SQNSH_MONARCH()") - - /* only for write command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) - { - if (p_modem_ctxt->socket_ctxt.socket_info != NULL) - { - /* - * AT+SQNSH= - */ - uint32_t connID = atcm_socket_get_modem_cid(p_modem_ctxt, p_modem_ctxt->socket_ctxt.socket_info->socket_handle); - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "%ld", connID); - } - else - { - retval = ATSTATUS_ERROR; - } - } - return (retval); -} - -at_status_t fCmdBuild_SQNSSENDEXT_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) -{ - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_SQNSSENDEXT_MONARCH()") - - /* only for write command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) - { - /* - * send data in command mode: - * AT+SQNSSENDEXT=, - * > ...DATA... - * - * DATA are sent using fCmdBuild_WRITE_SOCKET_DATA_MONARCH() - */ - - /* FIXED SIZE MODE - * prepare message with connectionId, length and datas - */ - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "%ld,%ld", - atcm_socket_get_modem_cid(p_modem_ctxt, p_modem_ctxt->SID_ctxt.socketSendData_struct.socket_handle), - p_modem_ctxt->SID_ctxt.socketSendData_struct.buffer_size); - } - - return (retval); -} - -at_status_t fCmdBuild_SQNSSEND_WRITE_DATA_MONARCH(atparser_context_t *p_atp_ctxt, - atcustom_modem_context_t *p_modem_ctxt) -{ - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_SQNSSEND_WRITE_DATA_MONARCH()") - - /* after having send AT+SQNSSENDEXT and prompt received, now send DATA */ - - /* only for raw command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_RAW_CMD) - { - if (p_modem_ctxt->SID_ctxt.socketSendData_struct.p_buffer_addr_send != NULL) - { - uint32_t str_size = p_modem_ctxt->SID_ctxt.socketSendData_struct.buffer_size; - (void) memcpy((void *)p_atp_ctxt->current_atcmd.params, - (const CRC_CHAR_t *)p_modem_ctxt->SID_ctxt.socketSendData_struct.p_buffer_addr_send, - (size_t) str_size); - - /* FIXED SIZE MODE: set raw command size */ - p_atp_ctxt->current_atcmd.raw_cmd_size = str_size; - } - else - { - PRINT_ERR("ERROR, send buffer is a NULL ptr !!!") - retval = ATSTATUS_ERROR; - } - } - - return (retval); -} - -at_status_t fCmdBuild_SQNSI_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) -{ - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_SQNSI_MONARCH()") - - /* only for write command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) - { - /* - * AT+SQNSI= - */ - if (p_atp_ctxt->current_SID == (at_msg_t) SID_CS_RECEIVE_DATA) - { - /* request socket infos to know amount of data available */ - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "%ld", - atcm_socket_get_modem_cid(p_modem_ctxt, - p_modem_ctxt->socket_ctxt.socketReceivedata.socket_handle)); - } - } - - return (retval); -} - -at_status_t fCmdBuild_SQNSRECV_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) -{ - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_SQNSRECV_MONARCH()") - - /* only for write command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) - { - /* - * AT+SQNSRECV=, - * - * implementation: in , we put the value received in +SQNSI - * The value socket_rx_expected_buf_size used to fill this field has been already checked. - */ - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "%ld,%ld", - atcm_socket_get_modem_cid(p_modem_ctxt, p_modem_ctxt->socket_ctxt.socketReceivedata.socket_handle), - p_modem_ctxt->socket_ctxt.socket_rx_expected_buf_size); - - /* ready to start receive socket buffer */ - p_modem_ctxt->socket_ctxt.socket_RxData_state = SocketRxDataState_waiting_header; - } - - return (retval); - -} - -at_status_t fCmdBuild_PING_MONARCH(atparser_context_t *p_atp_ctxt, atcustom_modem_context_t *p_modem_ctxt) -{ - at_status_t retval = ATSTATUS_OK; - PRINT_API("enter fCmdBuild_PING_MONARCH()") - - /* only for write command, set parameters */ - if (p_atp_ctxt->current_atcmd.type == ATTYPE_WRITE_CMD) - { - /* - * Ping a remote server: - * AT+PING=,[,[,[,[,[,]]]]]] - * (str): Address of the remote host. - * Any valid IP address in the format “xxx.xxx.xxx.xxx” or any host name solved with a DNS query. - * (int)[1-64]: Number of Ping Echo Request to send (default: 4) - * Ping stop after sending ECHO_REQUEST packets. - * With deadline option, ping waits for count ECHO_REPLY packets, until the timeout expires. - * (int)[32-1400]: Length of Ping Echo Request message (default: 32). - * (int)[1-600]: Wait interval seconds between sending each Ping Echo Request (default: 1) - * (int)[1-60]: Time to wait for a Echo Reply (in seconds)(default: 10). - * The option affects only timeout in absence of any responses, - * otherwise ping waits for two RTTs. - * (int)[1-255]: IP time to live (default: 128) - * (int)[0-6]: PDP context identifier (default: Internet PDN) - */ - - /* validate ping request - * As PING request are synchronous for this modem, always validate PING request before to send PING command. - */ - atcm_validate_ping_request(p_modem_ctxt); - /* prepare request */ - CS_PDN_conf_id_t current_conf_id = atcm_get_cid_current_SID(p_modem_ctxt); - uint8_t modem_cid = atcm_get_affected_modem_cid(&p_modem_ctxt->persist, current_conf_id); - uint8_t ttl = 128U; - uint16_t interval = 1U; - (void) sprintf((CRC_CHAR_t *)p_atp_ctxt->current_atcmd.params, "\"%s\",%d,%d,%d,%d,%d,%d", - p_modem_ctxt->SID_ctxt.ping_infos.ping_params.host_addr, - p_modem_ctxt->SID_ctxt.ping_infos.ping_params.pingnum, - SEQUANS_PING_LENGTH, - interval, - p_modem_ctxt->SID_ctxt.ping_infos.ping_params.timeout, - ttl, - modem_cid); - } - - return (retval); -} - -/* Analyze command functions ------------------------------------------------------- */ - -at_action_rsp_t fRspAnalyze_SQNSRING_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) -{ - at_action_rsp_t retval = ATACTION_RSP_IGNORED; - PRINT_API("enter fRspAnalyze_SQNSRING()") - - /* - * analyze parameters for +SQNSRING - * SQNSRING: - * or SQNSRING: , - * or SQNSRING: ,, - * - * where recData = size of received data - */ - - /* this is an URC */ - START_PARAM_LOOP(); - if (element_infos->param_rank == 2U) - { - uint32_t connId = ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], - element_infos->str_size); - - socket_handle_t sockHandle = atcm_socket_get_socket_handle(p_modem_ctxt, connId); - bool forward_this_urc = true; - if (p_at_ctxt->parser.current_atcmd.id == (CMD_ID_t) CMD_AT_SQNSRECV) - { - /* Special case: - * When +SQNSRING URC is received while we are requesting to receive data on a socket with AT+SQNSRECV, - * if +SQNSRING concerns the same socket (= same connId) that the pendind AT+SQNSRECV, a crash occur. - * To avoid this, in this particular case, the +SQNSRING URC is not forwaded to upper layer. - */ - PRINT_INFO("+SQNSRING URC for socket handle=%ld (pending AT+SQNSRECV concerns socket handle=%ld)", - sockHandle, - p_modem_ctxt->socket_ctxt.socketReceivedata.socket_handle) - - if (sockHandle == p_modem_ctxt->socket_ctxt.socketReceivedata.socket_handle) - { - PRINT_INFO("+SQNSRING URC ignored, concerns same socket than pending AT+SQNSRECV") - forward_this_urc = false; - } - } - - if (forward_this_urc) - { - (void) atcm_socket_set_urc_data_pending(p_modem_ctxt, sockHandle); - PRINT_INFO(" +SQNSRING URC for connId=%ld (socket handle=%ld)", - connId, - sockHandle) - } - } - if (element_infos->param_rank == 3U) - { - /* - parameter not used */ - PRINT_DBG(" +SQNSRING URC recData=%ld bytes", - ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)) - } - if (element_infos->param_rank == 4U) - { - /* data in command not supported actually (and probably never) */ - PRINT_ERR("error, receiving data in SQNSRING not supported !!! ") - } - END_PARAM_LOOP(); - - return (retval); -} - -at_action_rsp_t fRspAnalyze_SQNSI_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) -{ - UNUSED(p_at_ctxt); - at_action_rsp_t retval = ATACTION_RSP_IGNORED; - PRINT_API("enter fRspAnalyze_SQNSI()") - - /* - * +SQNSI:,,,, - */ - START_PARAM_LOOP(); - if (element_infos->param_rank == 2U) - { - /* */ - uint32_t connId = ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], - element_infos->str_size); - p_modem_ctxt->socket_ctxt.socket_current_connId = connId; - PRINT_DBG(" +SQNSI: connId=%ld", connId) - } - if (element_infos->param_rank == 3U) - { - /* - parameter not used */ - PRINT_DBG(" +SQNSI: sent=%ld", - ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)) - } - if (element_infos->param_rank == 4U) - { - /* - parameter not used */ - PRINT_DBG(" +SQNSI: received=%ld", - ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)) - } - if (element_infos->param_rank == 5U) - { - /* */ - uint32_t buff_in = ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], - element_infos->str_size); - PRINT_DBG(" +SQNSI: buff_in=%ld", buff_in) - - /* check that the size to read does not exceed maximum size ( = client buffer size) */ - if (buff_in > p_modem_ctxt->socket_ctxt.socketReceivedata.max_buffer_size) - { - /* The size to read exceed client buffer size. - * Limit the value to max client buffer size. - */ - p_modem_ctxt->socket_ctxt.socket_rx_expected_buf_size = - p_modem_ctxt->socket_ctxt.socketReceivedata.max_buffer_size; - PRINT_INFO("Limit request to maximum buffer size (%ld) whereas more data are available (%ld)", - p_modem_ctxt->socket_ctxt.socketReceivedata.max_buffer_size, - buff_in) - } - else - { - /* Update size to read */ - p_modem_ctxt->socket_ctxt.socket_rx_expected_buf_size = buff_in; - } - } - if (element_infos->param_rank == 6U) - { - /* - parameter not used */ - PRINT_DBG(" +SQNSI: ack_waiting=%ld", - ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)) - } - END_PARAM_LOOP(); - - return (retval); -} - -at_action_rsp_t fRspAnalyze_SQNSS_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) -{ - UNUSED(p_at_ctxt); - at_action_rsp_t retval = ATACTION_RSP_IGNORED; - PRINT_API("enter fRspAnalyze_SQNSS()") - at_bool_t monarch_snqss_for_requested_socket = AT_FALSE; - - /* - * +SQNSS: ,,,,, - * ... - * +SQNSS: ,,,,, - * - * if a channel is close (state=0), ,,, are omitted - */ - - START_PARAM_LOOP(); - if (element_infos->param_rank == 2U) - { - /* */ - uint32_t connId = ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], - element_infos->str_size); - socket_handle_t sockHandle = atcm_socket_get_socket_handle(p_modem_ctxt, connId); - /* if this connection ID corresponds to requested socket handle, we will report the following infos */ - if (sockHandle == p_modem_ctxt->socket_ctxt.socket_cnx_infos->socket_handle) - { - monarch_snqss_for_requested_socket = AT_TRUE; - } - else - { - monarch_snqss_for_requested_socket = AT_FALSE; - } - PRINT_DBG(" +SQNSS: connId=%ld (requested=%d)", - connId, ((monarch_snqss_for_requested_socket == AT_TRUE) ? 1 : 0)) - } - else if (element_infos->param_rank == 3U) - { - /* - parameter not used */ - PRINT_DBG(" +SQNSS: state=%ld", - ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)) - } - else if (element_infos->param_rank == 4U) - { - /* */ - atcm_extract_IP_address((const uint8_t *)&p_msg_in->buffer[element_infos->str_start_idx], - (uint16_t) element_infos->str_size, - (uint8_t *) p_modem_ctxt->socket_ctxt.socket_cnx_infos->infos->loc_ip_addr_value); - PRINT_DBG(" +SQNSS: locIP=%s", - p_modem_ctxt->socket_ctxt.socket_cnx_infos->infos->loc_ip_addr_value) - } - else if (element_infos->param_rank == 5U) - { - /* */ - uint32_t locPort = ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], - element_infos->str_size); - PRINT_DBG(" +SQNSS: locPort=%ld", locPort) - - if (monarch_snqss_for_requested_socket == AT_TRUE) - { - p_modem_ctxt->socket_ctxt.socket_cnx_infos->infos->loc_port = (uint16_t) locPort; - } - } - else if (element_infos->param_rank == 6U) - { - /* */ - atcm_extract_IP_address((const uint8_t *)&p_msg_in->buffer[element_infos->str_start_idx], - (uint16_t) element_infos->str_size, - (uint8_t *) p_modem_ctxt->socket_ctxt.socket_cnx_infos->infos->rem_ip_addr_value); - PRINT_DBG(" +SQNSS: remIP=%s", - p_modem_ctxt->socket_ctxt.socket_cnx_infos->infos->rem_ip_addr_value) - } - else if (element_infos->param_rank == 7U) - { - /* */ - uint32_t remPort = ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], - element_infos->str_size); - PRINT_DBG(" +SQNSS: remPort=%ld", remPort) - - if (monarch_snqss_for_requested_socket == AT_TRUE) - { - p_modem_ctxt->socket_ctxt.socket_cnx_infos->infos->rem_port = (uint16_t) remPort; - } - } - END_PARAM_LOOP(); - - return (retval); -} - -at_action_rsp_t fRspAnalyze_SQNSH_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) -{ - atparser_context_t *p_atp_ctxt = &(p_at_ctxt->parser); - at_action_rsp_t retval = ATACTION_RSP_IGNORED; - PRINT_API("enter fRspAnalyze_SQNSH_MONARCH()") - - if (p_atp_ctxt->current_atcmd.id == (CMD_ID_t)CMD_AT_SQNSH) - { - /* - * +SQNSH: - */ - START_PARAM_LOOP(); - if (element_infos->param_rank == 2U) - { - /* */ - uint32_t connId = ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], - element_infos->str_size); - p_modem_ctxt->socket_ctxt.socket_current_connId = connId; - PRINT_INFO(" +SQNSH: connId=%ld", connId) - } - END_PARAM_LOOP(); - } - else - { - /* this is an URC */ - START_PARAM_LOOP(); - if (element_infos->param_rank == 2U) - { - /* */ - uint32_t connId = ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], - element_infos->str_size); - socket_handle_t sockHandle = atcm_socket_get_socket_handle(p_modem_ctxt, connId); - (void) atcm_socket_set_urc_closed_by_remote(p_modem_ctxt, sockHandle); - PRINT_INFO(" URC +SQNSH: connId=%ld (socket handle=%ld)", - connId, - sockHandle) - } - END_PARAM_LOOP(); - } - - return (retval); -} - -at_action_rsp_t fRspAnalyze_SQNSRECV_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) -{ - UNUSED(p_at_ctxt); - at_action_rsp_t retval = ATACTION_RSP_IGNORED; - PRINT_API("enter fRspAnalyze_SQNSRECV()") - - /* - * +SQNSRECV:, - */ - START_PARAM_LOOP(); - if (element_infos->param_rank == 2U) - { - /* */ - uint32_t connId = ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], - element_infos->str_size); - PRINT_DBG(" +SQNSRECV: connId=%ld", connId) - - /* check if connId received is the one we asked */ - if (connId != p_modem_ctxt->socket_ctxt.socket_current_connId) - { - PRINT_ERR(" error, data received not on the expected socket (%ld instead of %ld)", connId, - p_modem_ctxt->socket_ctxt.socket_current_connId) - retval = ATACTION_RSP_ERROR; - } - } - if (element_infos->param_rank == 3U) - { - /* */ - /* NOTE !!! the size is purely informative in current implementation - * indeed, due to real time constraints, the socket data header is analyzed directly - * in ATCustom_MONARCH_checkEndOfMsgCallback() - */ - PRINT_INFO(" +SQNSRECV: bytes_received=%ld", - ATutil_convertStringToInt(&p_msg_in->buffer[element_infos->str_start_idx], element_infos->str_size)) - - - if (p_modem_ctxt->socket_ctxt.socket_receive_state == SocketRcvState_RequestData_Header) - { - /* data header analyzed, ready to analyze data payload */ - p_modem_ctxt->socket_ctxt.socket_receive_state = SocketRcvState_RequestData_Payload; - } - } - END_PARAM_LOOP(); - - return (retval); -} - -at_action_rsp_t fRspAnalyze_SQNSRECV_data_MONARCH(at_context_t *p_at_ctxt, - atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) -{ - UNUSED(p_at_ctxt); - at_action_rsp_t retval = ATACTION_RSP_IGNORED; - PRINT_API("enter fRspAnalyze_SQNSRECV_data()") - - PRINT_DBG("DATA received: size=%ld vs %d", p_modem_ctxt->socket_ctxt.socket_rx_expected_buf_size, - element_infos->str_size) - - /* Recopy data to client buffer if: - * - pointer on data buffer exists - * - and size of data <= maximum size - */ - if ((p_modem_ctxt->socket_ctxt.socketReceivedata.p_buffer_addr_rcv != NULL) && - (element_infos->str_size <= p_modem_ctxt->socket_ctxt.socketReceivedata.max_buffer_size)) - { - /* recopy data to client buffer */ - (void)memcpy((void *)p_modem_ctxt->socket_ctxt.socketReceivedata.p_buffer_addr_rcv, - (const void *)&p_msg_in->buffer[element_infos->str_start_idx], - (size_t) element_infos->str_size); - p_modem_ctxt->socket_ctxt.socketReceivedata.buffer_size = element_infos->str_size; - } - else - { - PRINT_ERR("ERROR (receive buffer is a NULL ptr or data exceed buffer size)") - retval = ATACTION_RSP_ERROR; - } - - return (retval); -} - -at_action_rsp_t fRspAnalyze_PING_MONARCH(at_context_t *p_at_ctxt, atcustom_modem_context_t *p_modem_ctxt, - const IPC_RxMessage_t *p_msg_in, at_element_info_t *element_infos) -{ - UNUSED(p_at_ctxt); - at_action_rsp_t retval; -#if (GM01Q_ACTIVATE_PING_REPORT == 1) - retval = ATACTION_RSP_URC_FORWARDED; /* received a valid intermediate answer */ -#else - retval = ATACTION_RSP_INTERMEDIATE; /* because report is not managed actually */ -#endif /* (GM01Q_ACTIVATE_PING_REPORT == 1) */ - - PRINT_API("enter fRspAnalyze_PING_MONARCH()") - - START_PARAM_LOOP() - - /* answer to AT+PING - * Once the single Echo Reply message is receive +PING notification will be displayed on AT channel: - * +PING: ,,