| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- /*
- * YM310 MQTT Driver - Main Entry Point - REFACTORED v3.0 (ALL FIXES)
- *
- * Fixes:
- * - Fixed initialization sequence
- * - Added proper thread synchronization
- * - Enhanced error handling
- *
- * Version: 3.0.0 (All Fixes)
- */
- #define DBG_TAG "Y-MAIN"
- #define DBG_LVL DBG_LOG
- #include <rtdbg.h>
- #include "ym310_mqtt.h"
- /*=============================================================================
- * Main Entry Point
- *=============================================================================*/
- /**
- * @brief YM310 MQTT driver initialization entry point
- *
- * This function should be called from your application to start the
- * YM310 4G module driver and MQTT functionality.
- *
- * @return RT_EOK on success, -RT_ERROR on failure
- */
- int ym310_driver_init(void)
- {
- LOG_I("========================================");
- LOG_I("YM310 MQTT Driver v3.0.0 (All Fixes)");
- LOG_I("========================================");
- /* Start initialization thread */
- g_init_thread = ym310_start_init_thread();
- if (g_init_thread == RT_NULL)
- {
- LOG_E("Failed to start YM310 init thread!");
- return -RT_ERROR;
- }
- //LOG_I("YM310 driver initialization started");
-
- return RT_EOK;
- }
- /**
- * @brief YM310 driver deinitialization
- */
- void ym310_driver_deinit(void)
- {
- LOG_I("YM310 driver deinitializing...");
- ym310_init_thread_stop();
- ym310_maintain_thread_stop();
- rt_thread_mdelay(100);
- ym310_mqtt_deinit();
- ym310_at_core_deinit();
- LOG_I("YM310 driver deinitialized");
- }
- /*=============================================================================
- * RT-Thread Auto Initialization (optional)
- *=============================================================================*/
- #ifdef RT_USING_COMPONENTS_INIT
- /* Uncomment to enable auto-initialization */
- /* INIT_APP_EXPORT(ym310_driver_init); */
- #endif
- /*=============================================================================
- * Example Application Integration
- *=============================================================================*/
- /**
- * @brief Example: How to integrate YM310 driver in your application
- *
- * Add the following to your main() or application init function:
- *
- * ```c
- * #include "ym310_mqtt.h"
- *
- * int main(void)
- * {
- * // Initialize YM310 driver
- * if (ym310_driver_init() != RT_EOK) {
- * LOG_E("YM310 init failed!");
- * return -1;
- * }
- *
- * // Wait for network to be ready
- * rt_thread_mdelay(30000); // Wait 30 seconds for initialization
- *
- * // Register MQTT receive callbacks (optional)
- * // ym310_register_mqtt_callbacks();
- *
- * // Main application loop
- * while (1) {
- * // Check MQTT connection
- * if (ym310_mqtt_is_connected(0)) {
- * // Send data via primary MQTT
- * ym310_mqtt_send_primary("{\"status\":\"online\"}", 0);
- * }
- *
- * rt_thread_mdelay(60000); // Every minute
- * }
- *
- * return 0;
- * }
- * ```
- */
- /**
- * @brief Example: Custom MQTT receive callback
- *
- * ```c
- * void my_mqtt_callback(rt_uint8_t client_idx,
- * const char *topic,
- * const char *payload,
- * rt_uint16_t len)
- * {
- * LOG_I("Received on MQTT[%d]: %.*s", client_idx, len, payload);
- *
- * // Parse your protocol here
- * // ...
- * }
- *
- * // Register callback:
- * ym310_mqtt_set_recv_callback(0, my_mqtt_callback);
- * ```
- */
|