天嵌二次封装库使用手册  V2.1.2
tq_gsm.h 文件参考
#include "libhardware.h"
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

宏定义

#define GSM_API
 

函数

GSM_API int tqDetectModule (ModuleInfo *const module, const ModuleSettingList *const list)
 根据配置单检测4G模块 更多...
 
GSM_API int tqInitGSM (const ModuleInfo *const module, const char *const pin, const char *const puk, void(*infoCallback)(const char *const))
 模块初始化 更多...
 
GSM_API int tqGetAPN (const int fd, char *const apn, const int len)
 获取APN或IMSI中的MCC,MNC。 更多...
 
GSM_API int tqGetDriverSetting (const int fd, const ModuleInfo *const module, void(*infoCallback)(const char *const))
 获取模块当前使用的拨号方式 更多...
 
GSM_API int tqChangeDirverSetting (const int fd, const ModuleInfo *const module, void(*infoCallback)(const char *const))
 更改模块使用的拨号方式 更多...
 
GSM_API int tqDialGSM (const int fd, ModuleInfo *module, const char *const apn, const char *const user, const char *const pwd, void(*infoCallback)(const char *const))
 拨号函数,若拨号命令列表为空,则使用PPPD进行拨号 更多...
 
GSM_API int tqDisconnectGSM (const int fd, const ModuleInfo *const module, void(*infoCallback)(const char *const))
 拨号断开函数 更多...
 
GSM_API int tqCheckConnectGSM (const int fd, const ModuleInfo *const module, void(*infoCallback)(const char *const))
 检查连接状态 更多...
 
GSM_API int tqRestartGSM (const int fd, const ModuleInfo *const module, void(*infoCallback)(const char *const))
 重启模块 更多...
 
GSM_API int tqGetRSSI (const int fd)
 获取信号强度 更多...
 
GSM_API int tqGetCCID (const int fd, char *const ccid, const int ccidLen)
 获取模块ICCID 更多...
 
GSM_API int tqExecuteCommand (const int fd, const CommandNode *const node, void(*infoCallback)(const char *const))
 执行node->command的AT指令,并使用node->pattern的正则表达式匹配返回结果 更多...
 

详细描述

日期
2024-12-09

在文件 tq_gsm.h 中定义.

宏定义说明

#define GSM_API

在文件 tq_gsm.h17 行定义.

函数说明

GSM_API int tqChangeDirverSetting ( const int  fd,
const ModuleInfo *const  module,
void(*)(const char *const)  infoCallback 
)

更改模块使用的拨号方式

参数
fdAT调试串口文件描述符
moduleModuleInfo结构体,用于存储模块信息
infoCallback回调函数,用于输出错误与过程信息
返回
int 1,执行命令成功,结果匹配成功。 0,命令执行成功,但结果匹配失败。 -1,命令执行返回ERROR。 -2,参数fd错误或参数module->changeDriver为空。 -3,正则表达式匹配错误,错误信息由回调信息返回。 -5,模块状态异常,串口读写失败或未响应。
GSM_API int tqCheckConnectGSM ( const int  fd,
const ModuleInfo *const  module,
void(*)(const char *const)  infoCallback 
)

检查连接状态

参数
fdAT调试串口文件描述符
moduleModuleInfo结构体,用于存储模块信息
infoCallback回调函数,用于输出错误与过程信息
返回
int 1,执行命令成功,结果匹配成功。 0,执行命令成功,结果匹配失败。 -1,命令执行返回ERROR。 -2,参数fd错误或参数module->checkConnect为空。 -3,正则表达式匹配错误,错误信息由回调信息返回。 -5,模块状态异常,串口读写失败或未响应。
GSM_API int tqDetectModule ( ModuleInfo *const  module,
const ModuleSettingList *const  list 
)

根据配置单检测4G模块

参数
module模块信息,用于接收储存检测到的模块信息
list模块配置单
返回
int 1, 成功。 0, 未找到4G模块。 -1, 未能成功找到模块AT或MODEM接口节点名称(e.g. /dev/ttyUSB0) -2, 参数异常。
GSM_API int tqDialGSM ( const int  fd,
ModuleInfo module,
const char *const  apn,
const char *const  user,
const char *const  pwd,
void(*)(const char *const)  infoCallback 
)

拨号函数,若拨号命令列表为空,则使用PPPD进行拨号

参数
fdAT调试串口文件描述符
moduleModuleInfo结构体,用于存储模块信息
apnSIM卡对应的APN
user拨号所需的用户名
pwd拨号所需的密码
infoCallback回调函数,用于输出错误与过程信息
返回
int 1,使用PPPD时表明拨号成功,或执行拨号命令列表与CheckConnect命令成功,且结果匹配成功。 0,使用PPPD时表明拨号失败,或执行拨号命令列表与CheckConnect命令成功,但结果匹配失败。 -1,命令执行返回ERROR。 -2,参数fd错误或参数module->disconnect为空。 -3,正则表达式匹配错误,错误信息由回调信息返回。 -5,模块状态异常,串口读写失败或未响应。
GSM_API int tqDisconnectGSM ( const int  fd,
const ModuleInfo *const  module,
void(*)(const char *const)  infoCallback 
)

拨号断开函数

参数
fdAT调试串口文件描述符
moduleModuleInfo结构体,用于存储模块信息
infoCallback回调函数,用于输出错误与过程信息
返回
int 1,执行命令成功,结果匹配成功。 0,命令执行成功,但结果匹配失败。 -1,命令执行返回ERROR。 -2,参数fd错误或参数module->disconnect为空。 -3,正则表达式匹配错误,错误信息由回调信息返回。 -5,模块状态异常,串口读写失败或未响应。
GSM_API int tqExecuteCommand ( const int  fd,
const CommandNode *const  node,
void(*)(const char *const)  infoCallback 
)

执行node->command的AT指令,并使用node->pattern的正则表达式匹配返回结果

参数
fdAT调试串口文件描述符
nodeCommandNode结构体,用于存储AT指令和正则表达式
infoCallback回调函数,用于输出错误与过程信息
返回
int 1,匹配成功。 0,匹配失败。 -1,命令执行返回ERROR。 -2,参数fd错误或参数node为空。 -3,正则表达式匹配错误,错误信息由回调信息返回。 -5,模块状态异常,串口读写失败或未响应。
GSM_API int tqGetAPN ( const int  fd,
char *const  apn,
const int  len 
)

获取APN或IMSI中的MCC,MNC。

参数
fdAT调试串口文件描述符
apn存放获取的APN字符串
len参数apn的长度
返回
int 2,成功,但未能正确识别IMSI码,将MCC+MNC写入参数apn。 1,成功,将对应的APN写入参数apn中。 -2,参数错误。 -3,命令执行失败,请检查模块是否支持AT+CIMI命令。 -5,模块异常。
注解
APN为接入点名称,不同运营商使用不同的APN,如CMNET、CTNET、3GNET。每个运营商下又有多个APN,但大多通用。
IMSI码由MCC+MNC+MSIN组成,如460001357924680。
MCC为移动国家代码,中国为460。MNC为移动网络代码,2位或3位,由MCC决定,中国移动为00,中国联通为01,中国电信为03。MSIN为移动用户识别码,由11位数字组成。
根据MCC+MNC,可以推断SIM卡所属运营商,进而判断APN。
GSM_API int tqGetCCID ( const int  fd,
char *const  ccid,
const int  ccidLen 
)

获取模块ICCID

参数
fdAT调试串口文件描述符
ccid用于接受模块ICCID的字符串
ccidLenccid缓存区长度,需大于等于21。
返回
int 1,成功,将模块ICCID写入ccid中。 0,失败。 -2,参数fd错误或ccid为空或参数ccid长度不足。
GSM_API int tqGetDriverSetting ( const int  fd,
const ModuleInfo *const  module,
void(*)(const char *const)  infoCallback 
)

获取模块当前使用的拨号方式

参数
fdAT调试串口文件描述符
moduleModuleInfo结构体,用于存储模块信息
infoCallback回调函数,用于输出错误与过程信息
返回
int 1,执行命令成功,结果匹配成功。 0,命令执行成功,但结果匹配失败。 -1,命令执行返回ERROR。 -2,参数fd错误或参数module->getDriver为空。 -3,正则表达式匹配错误,错误信息由回调信息返回。 -5,模块状态异常,串口读写失败或未响应。
GSM_API int tqGetRSSI ( const int  fd)

获取信号强度

参数
fdAT调试串口文件描述符
errStr错误信息缓存区
errStrLen错误信息缓存区长度
返回
int >0,成功,值为信号强度,值范围1~98,值越小信号越强。 0,失败,信号强度未知或不可测。 -1,命令执行失败,请检查模块是否支持AT+CSQ命令。 -2,参数fd错误。 -5,模块异常。
GSM_API int tqInitGSM ( const ModuleInfo *const  module,
const char *const  pin,
const char *const  puk,
void(*)(const char *const)  infoCallback 
)

模块初始化

参数
moduleModuleInfo结构体,用于存储模块信息
pinPIN码,若SIM卡没有锁,可以为空
pukPUK码,若SIM卡没有锁,可以为空
infoCallback回调函数,用于输出错误与过程信息
返回
int >0,成功,返回AT指令串口文件描述符。 -1,失败,回调函数为NULL。 -2,参数module为NULL。 -3,AT指令串口打开失败。 -4,未检测到SIM卡。 -5,模块状态异常,串口读写失败或未响应。 -6,SIM卡锁定,需要输入PIN码。 -7,SIM卡锁定,需要输入PUK码和新的PIN码。 -8,SIM卡解锁失败,请检查PIN码或PUK码。 -9,信号强度未知或不可测,请检查天线。 -10,执行信号强度检查命令失败,请检查模块是否支持AT+CSQ命令。
GSM_API int tqRestartGSM ( const int  fd,
const ModuleInfo *const  module,
void(*)(const char *const)  infoCallback 
)

重启模块

参数
fdAT调试串口文件描述符
moduleModuleInfo结构体,用于存储模块信息
infoCallback回调函数,用于输出错误与过程信息
返回
int 1,执行命令成功,结果匹配成功。 0,命令执行成功,但结果匹配失败。 -1,命令执行返回ERROR。 -2,参数fd错误或参数module->checkConnect为空。 -3,正则表达式匹配错误,错误信息由回调信息返回。 -5,模块状态异常,串口读写失败或未响应。