高级
30 分钟

使用 SIM7500E 和 PIC18F4455 实现在欧洲范围内的 LTE Cat 1 通信连接

为欧洲物联网应用提供可靠的 LTE 连接

LTE Cat.1 8 Click with EasyPIC v8

已发布 4月 02, 2025

点击板

LTE Cat.1 8 Click

开发板

EasyPIC v8

编译器

NECTO Studio

微控制器单元

PIC18F4455

可靠的 LTE Cat 1 连接,专为车队远程信息处理、工业路由器和远程诊断应用而设计

A

A

硬件概览

它是如何工作的?

LTE Cat.1 8 Click 是一款基于 SIMCom 的 SIM7500E 模块的紧凑型扩展板,该模块支持 LTE Cat 1 通信,并兼容多种无线标准,包括 LTE-TDD、LTE-FDD、HSPA+、GSM、GPRS 和 EDGE。其对 LTE、UMTS 和 GSM 网络的兼容性确保了全球广泛覆盖,使其非常适合需要跨地区稳定移动连接的应用。频段支持包括 LTE-FDD 的 B1、B3、B7、B8 和 B20,以及 GSM 的 900 和 1800 MHz,设备可灵活适应多种运营商网络。该模块专为远程信息处理、远程监控、CPE 系统、工业路由器和远程诊断等 IoT 场景而设计,是开发者在嵌入式系统中寻求稳定多功能移动通信的可靠平台。SIM7500E 支持最高 10Mbps 的下载速率和 5Mbps 的上传速率,数据吞吐均衡,适用于多种物联网用例。除了强大的蜂窝通信能力外,该模块还具备集成的多星座 GNSS 功能,提供高精度定位能力(当前此 Click 板未启用 GNSS,相关元件未焊接)。SIM7500E 模块集成了多种嵌入式网络协议,包括 TCP/IP、IPv4、IPv6、Multi-PDP、FTP、

FTPS、HTTP、HTTPS 和 DNS,提供安全灵活的数据传输解决方案。模块支持 Windows、Linux 和 Android 等主流操作系统的 USB 驱动,可轻松集成到各种开发环境中。SIM7500E 与主控 MCU 通过 UART 接口通信,采用标准的 UART RX 和 TX 引脚,并配有硬件流控引脚(CTS、RTS、RI),默认通信速率为 115200bps,支持通过 AT 指令进行数据交互。该 Click 板配有 USB Type C 接口,用于供电和数据传输,符合 USB 2.0 规范(仅限从设备模式),还提供 I2C 接口,仅用于读取和写入板载 I2C 外设的寄存器。板背面设有 BOOT 开关,用于固件升级(0 为正常运行,1 为 USB 下载),以及 FLIGHT 开关,用于在正常模式(1)与飞行模式(0)之间切换。板上集成了 PWR 按钮用于开启或关闭模块电源,RESET 按钮用于快速复位模块,这些功能也可通过 mikroBUS 引脚 PWR 和 RST 进行数字控制,同时提供测试点以方便调试与测试。两个视觉指示灯用于显示模块状态:红色 NET 指示灯显示网络连接状

态,常亮表示正在搜索网络,200ms 闪烁表示正在进行数据传输或已注册到 4G 网络,800ms 闪烁表示已注册到 2G 或 3G 网络,熄灭表示模块关闭或处于休眠状态;黄色 STAT 指示灯表示模块的电源状态,模块开启时常亮,关闭时熄灭。该板配有三个 u.FL 接口,分别用于连接 LTE 主天线、辅助分集天线以及可选的 GNSS 天线。用户可通过 GNSS ANT 跳线选择为 GNSS 天线提供 3.3V 或 5V 电源,但请注意此 Click 板当前不支持 GNSS 功能,因此 GNSS 相关元件未焊接。此外,该板还配有一个 micro SIM 卡座,兼容 1.8V 和 3.0V 的 uSIM 卡,便于用户根据实际需求选择合适的运营商。该 Click 板支持 3.3V 和 5V 逻辑电平,通过 VCC SEL 跳线进行选择。由于 SIM7500E 模块工作电压为 3.8V,因此板载集成了 TXB0106 和 PCA9306 电平转换器,确保不同电压主控 MCU 均能实现正确的通信。该 Click 板还附带配套函数库和示例代码,可供开发者参考与二次开发使用。

LTE Cat.1 8 Click hardware overview image

功能概述

开发板

EasyPIC v8 是一款专为快速开发嵌入式应用的需求而特别设计的开发板。它支持许多高引脚计数的8位PIC微控制器,来自Microchip,无论它们的引脚数量如何,并且具有一系列独特功能,例如首次集成的调试器/程序员。开发板布局合理,设计周到,使得最终用户可以在一个地方找到所有必要的元素,如开关、按钮、指示灯、连接器等。得益于创新的制造技术,EasyPIC v8 提供了流畅而沉浸式的工作体验,允许在任何情况下、任何地方、任何时候都能访问。

EasyPIC v8 开发板的每个部分都包含了使同一板块运行最高效的必要组件。除了先进的集成CODEGRIP程 序/调试模块,该模块提供许多有价值的编程/调试选项和与Mikroe软件环境的无缝集成外,该板还包括一个干净且调节过的开发板电源供应模块。它可以使用广泛的外部电源,包括电池、外部12V电源供应和通过USB Type-C(USB-C)连接器的电源。通信选项如USB-UART、USB DEVICE和CAN也包括在内,包括 广受好评的mikroBUS™标准、两种显示选项(图形和

基于字符的LCD)和几种不同的DIP插座。这些插座覆盖了从最小的只有八个至四十个引脚的8位PIC MCU的广泛范围。EasyPIC v8 是Mikroe快速开发生态系统的一个组成部分。它由Mikroe软件工具原生支持,得益于大量不同的Click板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。

EasyPIC v8 horizontal image

微控制器概述 

MCU卡片 / MCU

PIC18F4455

建筑

PIC

MCU 内存 (KB)

24

硅供应商

Microchip

引脚数

40

RAM (字节)

2048

你完善了我!

配件

Rubber Antenna GSM/GPRS Right Angle 是我们广泛产品线中所有 GSM Click boards™ 的理想伴侣。这款专用天线经过设计,旨在优化您的无线连接,具有令人印象深刻的功能。其宽频率范围覆盖 824-894/1710-1990MHz 或 890-960/1710-1890MHz,能够处理各种频段,确保无缝可靠的连接。天线具有 50 欧姆阻抗和 2dB 增益,增强了信号接收和传输。其 70/180MHz 带宽为各种应用提供了灵活性。垂直极化进一步提升了其性能。该天线的最大输入功率容量为 50W,确保即使在苛刻条件下也能实现强大的通信。天线长度仅为 50mm,配有 SMA 公头连接器,Rubber Antenna GSM/GPRS Right Angle 是一款多功能且紧凑的无线通信解决方案,能够满足您的各种无线通信需求。

LTE Cat.1 8 Click accessories 1 image

使用的MCU引脚

mikroBUS™映射器

Module Power-ON
RA2
AN
Reset / ID SEL
RE1
RST
UART CTS / ID COMM
RE0
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Ring Indicator
RC0
PWM
UART CTS
RB0
INT
UART TX
RC6
TX
UART RX
RC7
RX
I2C Clock
RC3
SCL
I2C Data
RC4
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

LTE Cat.1 8 Click Schematic schematic

一步一步来

项目组装

EasyPIC v8 front image hardware assembly

从选择您的开发板和Click板™开始。以EasyPIC v8作为您的开发板开始。

EasyPIC v8 front image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyPIC v8 Access DIPMB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

实时跟踪您的结果

应用程序输出

1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持

库描述

LTE Cat.1 8 Click 演示应用程序使用 NECTO Studio开发,确保与 mikroSDK 的开源库和工具兼容。该演示设计为即插即用,可与所有具有 mikroBUS™ 插座的 开发板、入门板和 mikromedia 板完全兼容,用于快速实现和测试。

示例描述
此示例展示了 LTE Cat.1 8 Click 板连接至网络并使用标准 "AT" 指令发送 SMS 或 TCP/UDP 消息的能力。

关键功能:

  • ltecat18_cfg_setup - 初始化 Click 配置结构为默认初始值。

  • ltecat18_init - 初始化该 Click 板所需的所有引脚和外设。

  • ltecat18_set_sim_apn - 设置 SIM 卡的 APN 参数。

  • ltecat18_send_sms_text - 向指定手机号发送短信。

  • ltecat18_cmd_set - 设置 Click 模块中指定 AT 指令的值。

应用初始化
初始化驱动程序和日志记录器。

应用任务
应用任务分为多个阶段:

  • LTECAT18_POWER_UP: 启动设备,执行设备出厂重置并读取系统信息。

  • LTECAT18_CONFIG_CONNECTION: 配置设备以连接到网络。

  • LTECAT18_CHECK_CONNECTION: 通过 CEREG 指令等待网络注册完成,并检查信号质量报告。

  • LTECAT18_CONFIG_EXAMPLE: 配置设备以执行选定的示例任务。

  • LTECAT18_EXAMPLE: 根据所选演示示例,发送 SMS 消息(PDU 或 TXT 模式)或 TCP/UDP 消息。默认选择 TCP/UDP 示例。

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * @file main.c
 * @brief LTE Cat.1 8 Click Example.
 *
 * # Description
 * Application example shows device capability of connecting to the network and
 * sending SMS or TCP/UDP messages using standard "AT" commands.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and logger.
 *
 * ## Application Task
 * Application task is split in few stages:
 *  - LTECAT18_POWER_UP:
 * Powers up the device, performs a device factory reset and reads system information.
 *
 *  - LTECAT18_CONFIG_CONNECTION:
 * Sets configuration to device to be able to connect to the network.
 *
 *  - LTECAT18_CHECK_CONNECTION:
 * Waits for the network registration indicated via CREG command and then checks the signal quality report.
 *
 *  - LTECAT18_CONFIG_EXAMPLE:
 * Configures device for the selected example.
 *
 *  - LTECAT18_EXAMPLE:
 * Depending on the selected demo example, it sends an SMS message (in PDU or TXT mode) or TCP/UDP message.
 *
 * By default, the TCP/UDP example is selected.
 *
 * ## Additional Function
 * - static void ltecat18_clear_app_buf ( void )
 * - static void ltecat18_log_app_buf ( void )
 * - static err_t ltecat18_process ( ltecat18_t *ctx )
 * - static err_t ltecat18_read_response ( ltecat18_t *ctx, uint8_t *rsp )
 * - static err_t ltecat18_power_up ( ltecat18_t *ctx )
 * - static err_t ltecat18_config_connection ( ltecat18_t *ctx )
 * - static err_t ltecat18_check_connection ( ltecat18_t *ctx )
 * - static err_t ltecat18_config_example ( ltecat18_t *ctx )
 * - static err_t ltecat18_example ( ltecat18_t *ctx )
 *
 * @note
 * In order for the examples to work, user needs to set the APN and SMSC (SMS PDU mode only)
 * of entered SIM card as well as the phone number (SMS mode only) to which he wants to send an SMS.
 * Enter valid values for the following macros: SIM_APN, SIM_SMSC and PHONE_NUMBER.
 * Example:
    SIM_APN "internet"
    SIM_SMSC "+381610401"
    PHONE_NUMBER "+381659999999"
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "ltecat18.h"
#include "conversions.h"

// Example selection macros
#define EXAMPLE_TCP_UDP                     0               // Example of sending messages to a TCP/UDP echo server
#define EXAMPLE_SMS                         1               // Example of sending SMS to a phone number
#define DEMO_EXAMPLE                        EXAMPLE_TCP_UDP // Example selection macro

// SIM APN config
#define SIM_APN                             "internet"      // Set valid SIM APN

// SMS example parameters
#define SIM_SMSC                            ""              // Set valid SMS Service Center Address - only in SMS PDU mode
#define PHONE_NUMBER                        ""              // Set Phone number to message
#define SMS_MODE                            "1"             // SMS mode: "0" - PDU, "1" - TXT

// TCP/UDP example parameters
#define REMOTE_IP                           "77.46.162.162" // TCP/UDP echo server IP address
#define REMOTE_PORT                         "51111"         // TCP/UDP echo server port

// Message content
#define MESSAGE_CONTENT                     "LTE Cat.1 8 Click board - demo example."

// Application buffer size
#define APP_BUFFER_SIZE                     256
#define PROCESS_BUFFER_SIZE                 256

/**
 * @brief Example states.
 * @details Predefined enum values for application example state.
 */
typedef enum
{
    LTECAT18_POWER_UP = 1,
    LTECAT18_CONFIG_CONNECTION,
    LTECAT18_CHECK_CONNECTION,
    LTECAT18_CONFIG_EXAMPLE,
    LTECAT18_EXAMPLE

} ltecat18_app_state_t;

/**
 * @brief Application example variables.
 * @details Variables used in application example.
 */
static uint8_t app_buf[ APP_BUFFER_SIZE ] = { 0 };
static int32_t app_buf_len = 0;
static ltecat18_app_state_t app_state = LTECAT18_POWER_UP;

static ltecat18_t ltecat18;
static log_t logger;

/**
 * @brief LTE Cat.1 8 clearing application buffer.
 * @details This function clears memory of application buffer and reset its length.
 * @note None.
 */
static void ltecat18_clear_app_buf ( void );

/**
 * @brief LTE Cat.1 8 log application buffer.
 * @details This function logs data from application buffer to USB UART.
 * @note None.
 */
static void ltecat18_log_app_buf ( void );

/**
 * @brief LTE Cat.1 8 data reading function.
 * @details This function reads data from device and concatenates data to application buffer. 
 * @param[in] ctx : Click context object.
 * See #ltecat18_t object definition for detailed explanation.
 * @return @li @c  0 - Read some data.
 *         @li @c -1 - Nothing is read.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t ltecat18_process ( ltecat18_t *ctx );

/**
 * @brief LTE Cat.1 8 read response function.
 * @details This function waits for a response message, reads and displays it on the USB UART.
 * @param[in] ctx : Click context object.
 * See #ltecat18_t object definition for detailed explanation.
 * @param[in] rsp  Expected response.
 * @return @li @c  0 - OK response.
 *         @li @c -2 - Timeout error.
 *         @li @c -3 - Command error.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t ltecat18_read_response ( ltecat18_t *ctx, uint8_t *rsp );

/**
 * @brief LTE Cat.1 8 power up function.
 * @details This function powers up the device, performs device factory reset and reads system information.
 * @param[in] ctx : Click context object.
 * See #ltecat18_t object definition for detailed explanation.
 * @return @li @c    0 - OK.
 *         @li @c != 0 - Read response error.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t ltecat18_power_up ( ltecat18_t *ctx );

/**
 * @brief LTE Cat.1 8 config connection function.
 * @details This function configures and enables connection to the specified network.
 * @param[in] ctx : Click context object.
 * See #ltecat18_t object definition for detailed explanation.
 * @return @li @c    0 - OK.
 *         @li @c != 0 - Read response error.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t ltecat18_config_connection ( ltecat18_t *ctx );

/**
 * @brief LTE Cat.1 8 check connection function.
 * @details This function checks the connection to network.
 * @param[in] ctx : Click context object.
 * See #ltecat18_t object definition for detailed explanation.
 * @return @li @c    0 - OK.
 *         @li @c != 0 - Read response error.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t ltecat18_check_connection ( ltecat18_t *ctx );

/**
 * @brief LTE Cat.1 8 config example function.
 * @details This function configures device for the selected example.
 * @param[in] ctx : Click context object.
 * See #ltecat18_t object definition for detailed explanation.
 * @return @li @c    0 - OK.
 *         @li @c != 0 - Read response error.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t ltecat18_config_example ( ltecat18_t *ctx );

/**
 * @brief LTE Cat.1 8 example function.
 * @details This function executes SMS or TCP/UDP example depending on the DEMO_EXAMPLE macro.
 * @param[in] ctx : Click context object.
 * See #ltecat18_t object definition for detailed explanation.
 * @return @li @c    0 - OK.
 *         @li @c != 0 - Read response error.
 * See #err_t definition for detailed explanation.
 * @note None.
 */
static err_t ltecat18_example ( ltecat18_t *ctx );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    ltecat18_cfg_t ltecat18_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    ltecat18_cfg_setup( &ltecat18_cfg );
    LTECAT18_MAP_MIKROBUS( ltecat18_cfg, MIKROBUS_1 );
    if ( UART_ERROR == ltecat18_init( &ltecat18, &ltecat18_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );

    app_state = LTECAT18_POWER_UP;
    log_printf( &logger, ">>> APP STATE - POWER UP <<<\r\n\n" );
}

void application_task ( void ) 
{
    switch ( app_state )
    {
        case LTECAT18_POWER_UP:
        {
            if ( LTECAT18_OK == ltecat18_power_up( &ltecat18 ) )
            {
                app_state = LTECAT18_CONFIG_CONNECTION;
                log_printf( &logger, ">>> APP STATE - CONFIG CONNECTION <<<\r\n\n" );
            }
            break;
        }
        case LTECAT18_CONFIG_CONNECTION:
        {
            if ( LTECAT18_OK == ltecat18_config_connection( &ltecat18 ) )
            {
                app_state = LTECAT18_CHECK_CONNECTION;
                log_printf( &logger, ">>> APP STATE - CHECK CONNECTION <<<\r\n\n" );
            }
            break;
        }
        case LTECAT18_CHECK_CONNECTION:
        {
            if ( LTECAT18_OK == ltecat18_check_connection( &ltecat18 ) )
            {
                app_state = LTECAT18_CONFIG_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - CONFIG EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case LTECAT18_CONFIG_EXAMPLE:
        {
            if ( LTECAT18_OK == ltecat18_config_example( &ltecat18 ) )
            {
                app_state = LTECAT18_EXAMPLE;
                log_printf( &logger, ">>> APP STATE - EXAMPLE <<<\r\n\n" );
            }
            break;
        }
        case LTECAT18_EXAMPLE:
        {
            ltecat18_example( &ltecat18 );
            break;
        }
        default:
        {
            log_error( &logger, " APP STATE." );
            break;
        }
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

static void ltecat18_clear_app_buf ( void ) 
{
    memset( app_buf, 0, app_buf_len );
    app_buf_len = 0;
}

static void ltecat18_log_app_buf ( void )
{
    for ( int32_t buf_cnt = 0; buf_cnt < app_buf_len; buf_cnt++ )
    {
        log_printf( &logger, "%c", app_buf[ buf_cnt ] );
    }
}

static err_t ltecat18_process ( ltecat18_t *ctx ) 
{
    uint8_t rx_buf[ PROCESS_BUFFER_SIZE ] = { 0 };
    int32_t overflow_bytes = 0;
    int32_t rx_cnt = 0;
    int32_t rx_size = ltecat18_generic_read( ctx, rx_buf, PROCESS_BUFFER_SIZE );
    if ( ( rx_size > 0 ) && ( rx_size <= APP_BUFFER_SIZE ) ) 
    {
        if ( ( app_buf_len + rx_size ) > APP_BUFFER_SIZE ) 
        {
            overflow_bytes = ( app_buf_len + rx_size ) - APP_BUFFER_SIZE;
            app_buf_len = APP_BUFFER_SIZE - rx_size;
            memmove ( app_buf, &app_buf[ overflow_bytes ], app_buf_len );
            memset ( &app_buf[ app_buf_len ], 0, overflow_bytes );
        }
        for ( rx_cnt = 0; rx_cnt < rx_size; rx_cnt++ ) 
        {
            if ( rx_buf[ rx_cnt ] ) 
            {
                app_buf[ app_buf_len++ ] = rx_buf[ rx_cnt ];
            }
        }
        return LTECAT18_OK;
    }
    return LTECAT18_ERROR;
}

static err_t ltecat18_read_response ( ltecat18_t *ctx, uint8_t *rsp ) 
{
    #define READ_RESPONSE_TIMEOUT_MS    120000
    uint32_t timeout_cnt = 0;
    ltecat18_clear_app_buf( );
    ltecat18_process( ctx );
    while ( ( 0 == strstr( app_buf, rsp ) ) &&
            ( 0 == strstr( app_buf, LTECAT18_RSP_ERROR ) ) )
    {
        ltecat18_process( ctx );
        if ( timeout_cnt++ > READ_RESPONSE_TIMEOUT_MS )
        {
            ltecat18_log_app_buf( );
            ltecat18_clear_app_buf( );
            log_error( &logger, " Timeout!" );
            return LTECAT18_ERROR_TIMEOUT;
        }
        Delay_ms( 1 );
    }
    Delay_ms ( 200 );
    ltecat18_process( ctx );
    ltecat18_log_app_buf( );
    if ( strstr( app_buf, rsp ) )
    {
        log_printf( &logger, "--------------------------------\r\n" );
        return LTECAT18_OK;
    }
    return LTECAT18_ERROR_CMD;
}

static err_t ltecat18_power_up ( ltecat18_t *ctx )
{
    err_t error_flag = LTECAT18_OK;
    
    uint8_t power_state = LTECAT18_POWER_STATE_OFF;
    for ( ; ; )
    {
        ltecat18_process( ctx );
        ltecat18_log_app_buf( );
        ltecat18_clear_app_buf( );
        // Wake up UART interface
        ltecat18_cmd_run( ctx, LTECAT18_CMD_AT );

        log_printf( &logger, ">>> Check communication.\r\n" );
        ltecat18_cmd_run( ctx, LTECAT18_CMD_AT );
        if ( ( ( LTECAT18_OK == ltecat18_process( ctx ) ) && strstr( app_buf, LTECAT18_RSP_OK ) ) )
        {
            power_state = LTECAT18_POWER_STATE_ON;
            break;
        }
        else if ( LTECAT18_POWER_STATE_OFF == power_state )
        {
            power_state = LTECAT18_POWER_STATE_ON;
            log_printf( &logger, ">>> Power up device.\r\n" );
            ltecat18_set_power_state ( ctx, power_state );
        }
        else if ( LTECAT18_POWER_STATE_ON == power_state )
        {
            power_state = LTECAT18_POWER_STATE_OFF;
            log_printf( &logger, ">>> Power down device.\r\n" );
            ltecat18_set_power_state ( ctx, power_state );
        }
    }
    ltecat18_cmd_run( ctx, LTECAT18_CMD_AT );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );
    
    log_printf( &logger, ">>> Factory reset.\r\n" );
    ltecat18_cmd_run( ctx, LTECAT18_CMD_FACTORY_RESET );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );

    log_printf( &logger, ">>> Get device model ID.\r\n" );
    ltecat18_cmd_run( ctx, LTECAT18_CMD_GET_MODEL_ID );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );

    log_printf( &logger, ">>> Get device software version ID.\r\n" );
    ltecat18_cmd_run( ctx, LTECAT18_CMD_GET_SW_VERSION );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );

    log_printf( &logger, ">>> Get device serial number.\r\n" );
    ltecat18_cmd_run( ctx, LTECAT18_CMD_GET_SERIAL_NUM );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );

    return error_flag;
}

static err_t ltecat18_config_connection ( ltecat18_t *ctx )
{
    err_t error_flag = LTECAT18_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    log_printf( &logger, ">>> Deregister from network.\r\n" );
    #define DEREGISTER_FROM_NETWORK "2"
    ltecat18_cmd_set( ctx, LTECAT18_CMD_OPERATOR_SELECTION, DEREGISTER_FROM_NETWORK );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );

    log_printf( &logger, ">>> Set SIM APN.\r\n" );
    ltecat18_set_sim_apn( &ltecat18, SIM_APN );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );
    
    log_printf( &logger, ">>> Enable full functionality.\r\n" );
    #define FULL_FUNCTIONALITY "1"
    ltecat18_cmd_set( ctx, LTECAT18_CMD_SET_PHONE_FUNCTIONALITY, FULL_FUNCTIONALITY );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );

    log_printf( &logger, ">>> Enable network registration.\r\n" );
    #define ENABLE_REG "2"
    ltecat18_cmd_set( ctx, LTECAT18_CMD_NETWORK_REGISTRATION, ENABLE_REG );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );

    log_printf( &logger, ">>> Set automatic registration.\r\n" );
    #define AUTOMATIC_REGISTRATION "0"
    ltecat18_cmd_set( ctx, LTECAT18_CMD_OPERATOR_SELECTION, AUTOMATIC_REGISTRATION );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );
#endif
    return error_flag;
}

static err_t ltecat18_check_connection ( ltecat18_t *ctx )
{
    err_t error_flag = LTECAT18_OK;
#if ( ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP ) || ( DEMO_EXAMPLE == EXAMPLE_SMS ) )
    log_printf( &logger, ">>> Check network registration.\r\n" );
    #define CONNECTED "+CREG: 2,1"
    ltecat18_cmd_get( &ltecat18, LTECAT18_CMD_NETWORK_REGISTRATION );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );
    if ( strstr( app_buf, CONNECTED ) )
    {
        Delay_ms ( 1000 );
        log_printf( &logger, ">>> Check signal quality.\r\n" );
        ltecat18_cmd_run( &ltecat18, LTECAT18_CMD_SIGNAL_QUALITY_REPORT );
        error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );
    }
    else
    {
        error_flag = LTECAT18_ERROR;
        Delay_ms ( 1000 );
        Delay_ms ( 1000 );
    }
#endif
    return error_flag;
}

static err_t ltecat18_config_example ( ltecat18_t *ctx )
{
    err_t error_flag = LTECAT18_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
    log_printf( &logger, ">>> Activate PDP context.\r\n" );
    #define ACTIVATE_PDP_CONTEXT "1,1"
    ltecat18_cmd_set( &ltecat18, LTECAT18_CMD_ACTIVATE_PDP_CONTEXT, ACTIVATE_PDP_CONTEXT );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );

    log_printf( &logger, ">>> Show PDP address.\r\n" );
    #define PDP_CID "1"
    ltecat18_cmd_set( &ltecat18, LTECAT18_CMD_SHOW_PDP_ADDRESS, PDP_CID );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );
    
    log_printf( &logger, ">>> Start TCPIP service.\r\n" );
    ltecat18_cmd_run( &ltecat18, LTECAT18_CMD_START_TCPIP_SERVICE );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );

    log_printf( &logger, ">>> Set RX mode to manually.\r\n" );
    #define RX_MODE_MANUALLY "1"
    ltecat18_cmd_set( &ltecat18, LTECAT18_CMD_RECEIVE_DATA_VIA_CONNECTION, RX_MODE_MANUALLY );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
    log_printf( &logger, ">>> Select SMS format.\r\n" );
    ltecat18_cmd_set( &ltecat18, LTECAT18_CMD_SELECT_SMS_FORMAT, SMS_MODE );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );
#endif
    return error_flag;
}

static err_t ltecat18_example ( ltecat18_t *ctx )
{
    err_t error_flag = LTECAT18_OK;
#if ( DEMO_EXAMPLE == EXAMPLE_TCP_UDP )
    uint8_t cmd_buf[ 100 ] = { 0 };
    
    log_printf( &logger, ">>> Open TCP connection.\r\n" );
    #define TCP_LINK_NUM "0"
    #define TCP_CONN_TYPE "TCP"
    strcpy( cmd_buf, TCP_LINK_NUM );
    strcat( cmd_buf, ",\"" );
    strcat( cmd_buf, TCP_CONN_TYPE );
    strcat( cmd_buf, "\",\"" );
    strcat( cmd_buf, REMOTE_IP );
    strcat( cmd_buf, "\"," );
    strcat( cmd_buf, REMOTE_PORT );
    ltecat18_cmd_set( &ltecat18, LTECAT18_CMD_OPEN_TCP_UDP_CONNECTION, cmd_buf );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_URC_CONNECTION_OPEN );

    log_printf( &logger, ">>> Open UDP connection.\r\n" );
    #define UDP_LINK_NUM "1"
    #define UDP_CONN_TYPE "UDP"
    #define UDP_LOCAL_PORT "5000"
    strcpy( cmd_buf, UDP_LINK_NUM );
    strcat( cmd_buf, ",\"" );
    strcat( cmd_buf, UDP_CONN_TYPE );
    strcat( cmd_buf, "\",,," );
    strcat( cmd_buf, UDP_LOCAL_PORT );
    ltecat18_cmd_set( &ltecat18, LTECAT18_CMD_OPEN_TCP_UDP_CONNECTION, cmd_buf );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_URC_CONNECTION_OPEN );

    // Get message length
    uint8_t message_len_buf[ 10 ] = { 0 };
    uint16_t message_len = strlen( MESSAGE_CONTENT );
    uint16_to_str( message_len, message_len_buf );
    l_trim( message_len_buf );
    r_trim( message_len_buf );

    log_printf( &logger, ">>> Write message to TCP connection.\r\n" );
    strcpy( cmd_buf, TCP_LINK_NUM );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, message_len_buf );
    ltecat18_cmd_set( &ltecat18, LTECAT18_CMD_SEND_DATA_VIA_CONNECTION, cmd_buf );
    Delay_ms ( 100 );
    ltecat18_generic_write ( &ltecat18, MESSAGE_CONTENT, message_len );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_URC_RECEIVED_DATA );
    log_printf( &logger, ">>> Read response from TCP connection.\r\n" );
    #define RX_DATA_READ "2"
    strcpy( cmd_buf, RX_DATA_READ );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, TCP_LINK_NUM );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, message_len_buf );
    ltecat18_cmd_set( &ltecat18, LTECAT18_CMD_RECEIVE_DATA_VIA_CONNECTION, cmd_buf );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );

    log_printf( &logger, ">>> Write message to UDP connection.\r\n" );
    strcpy( cmd_buf, UDP_LINK_NUM );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, message_len_buf );
    strcat( cmd_buf, ",\"" );
    strcat( cmd_buf, REMOTE_IP );
    strcat( cmd_buf, "\"," );
    strcat( cmd_buf, REMOTE_PORT );
    ltecat18_cmd_set( &ltecat18, LTECAT18_CMD_SEND_DATA_VIA_CONNECTION, cmd_buf );
    Delay_ms ( 100 );
    ltecat18_generic_write ( &ltecat18, MESSAGE_CONTENT, message_len );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_URC_RECEIVED_DATA );
    log_printf( &logger, ">>> Read response from UDP connection.\r\n" );
    strcpy( cmd_buf, RX_DATA_READ );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, UDP_LINK_NUM );
    strcat( cmd_buf, "," );
    strcat( cmd_buf, message_len_buf );
    ltecat18_cmd_set( &ltecat18, LTECAT18_CMD_RECEIVE_DATA_VIA_CONNECTION, cmd_buf );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );
    
    log_printf( &logger, ">>> Close TCP connection.\r\n" );
    ltecat18_cmd_set( &ltecat18, LTECAT18_CMD_CLOSE_TCP_UDP_CONNECTION, TCP_LINK_NUM );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_URC_CONNECTION_CLOSED );
    
    log_printf( &logger, ">>> Close UDP connection.\r\n" );
    ltecat18_cmd_set( &ltecat18, LTECAT18_CMD_CLOSE_TCP_UDP_CONNECTION, UDP_LINK_NUM );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_URC_CONNECTION_CLOSED );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
#elif ( DEMO_EXAMPLE == EXAMPLE_SMS )
    // Check SMS mode
    #define CMGF_PDU "+CMGF: 0"
    #define CMGF_TXT "+CMGF: 1"
    log_printf( &logger, ">>> Check SMS format.\r\n" );
    ltecat18_cmd_get( &ltecat18, LTECAT18_CMD_SELECT_SMS_FORMAT );
    error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );
    if ( strstr( app_buf, CMGF_PDU ) )
    {
        // Send SMS in PDU mode
        log_printf( &logger, ">>> Send SMS in PDU mode.\r\n" );
        ltecat18_send_sms_pdu( &ltecat18, SIM_SMSC, PHONE_NUMBER, MESSAGE_CONTENT );
        error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );
    }
    else if ( strstr( app_buf, CMGF_TXT ) )
    {
        // Send SMS in TXT mode
        log_printf( &logger, ">>> Send SMS in TXT mode.\r\n" );
        ltecat18_send_sms_text ( &ltecat18, PHONE_NUMBER, MESSAGE_CONTENT );
        error_flag |= ltecat18_read_response( ctx, LTECAT18_RSP_OK );
    }
    // 30 seconds delay
    for ( uint8_t delay_cnt = 0; delay_cnt < 30; delay_cnt++ )
    {
        Delay_ms ( 1000 );
    }
#else
    #error "No demo example selected"
#endif
    return error_flag;
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。

想查看更多

类似项目