20230731_XiaoFuZi_emb/ZheDaXiaoFuZi/Src/Usr/Driver/Ldrv/E104-BT52/McuE104BT52Drv.c
Rjh913828050 a8560d741e 类型:重构
内容:重新整理项目文件分类
人员:任家豪
2023-10-08 16:10:23 +08:00

74 lines
3.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "McuE104BT52Drv.h"
#include <string.h>
/* 模块返回值 */
static char gMcuE104BT52DrvOkAck[3] = "OK";
//static char gMcuE104BT52DrvErrAck[4] = "ERR";
static char gMcuE104BT52DrvATCmd[3] = "AT"; // 模块上电确认指令
//static char gMcuE104BT52DrvSLEEPCmd[9] = "AT+SLEEP"; // 睡眠指令
static char gMcuE104BT52DrvTransCmd[12] = "AT+TRANMD=1"; // 设置模块为透传模式
static char gMcuE104BT52DrvAdvCmd[9] = "AT+ADV=1"; // 设置模块为普通广播
static char gMcuE104BT52DrvRoleCmd[10] = "AT+ROLE=0"; // 设置模块为从机模式
//static char gMcuE104BT52DrvDiscon0CMd[12] = "AT+DISCON=0"; // 断开第零路蓝牙连接
//static char gMcuE104BT52DrvDiscon1CMd[12] = "AT+DISCON=1"; // 断开第一路蓝牙连接
static char gMcuE104BT52DrvNameSet[29] = "AT+NAME=ZTT-XFZ-LP-V100-0001"; // 设置设备名指令
static char gMcuE104BT52DrvRecvBuf[20] = {0};//不需要过大只需要接收指令
/* 等待模块自身初始化完成 */
int McuE104BT52DrvInit(E104BT52_OBJ *BlueObj)
{
unsigned int rt;
/* 发送AT命令判断返回值 */
BlueObj->BluetoothSend((unsigned char *)gMcuE104BT52DrvATCmd, strlen(gMcuE104BT52DrvATCmd));
/* 启动接收 */
rt = BlueObj->BluetoothRecv((unsigned char *)gMcuE104BT52DrvRecvBuf, sizeof(gMcuE104BT52DrvRecvBuf));
if (rt > 0) {
if (NULL == strstr(gMcuE104BT52DrvRecvBuf, gMcuE104BT52DrvOkAck)) {
return -1;
}
}
/* 设置设备名 */
/* 发送透传模式命令,判断返回值 */
gMcuE104BT52DrvNameSet[27] = '0' + BlueObj->BlueToothId;
BlueObj->BluetoothSend((unsigned char *)gMcuE104BT52DrvNameSet, strlen(gMcuE104BT52DrvNameSet));
/* 启动接收 */
rt = BlueObj->BluetoothRecv((unsigned char *)gMcuE104BT52DrvRecvBuf, sizeof(gMcuE104BT52DrvRecvBuf));
if (rt > 0) {
if (NULL == strstr(gMcuE104BT52DrvRecvBuf, gMcuE104BT52DrvOkAck)) {
return -1;
}
}
/* 设置模块为透传模式 */
/* 发送透传模式命令,判断返回值 */
BlueObj->BluetoothSend((unsigned char *)gMcuE104BT52DrvTransCmd, strlen(gMcuE104BT52DrvTransCmd));
/* 启动接收 */
rt = BlueObj->BluetoothRecv((unsigned char *)gMcuE104BT52DrvRecvBuf, sizeof(gMcuE104BT52DrvRecvBuf));
if (rt > 0) {
if (NULL == strstr(gMcuE104BT52DrvRecvBuf, gMcuE104BT52DrvOkAck)) {
return -1;
}
}
/* 设置广播模式 */
BlueObj->BluetoothSend((unsigned char *)gMcuE104BT52DrvAdvCmd, strlen(gMcuE104BT52DrvAdvCmd));
/* 启动接收 */
rt = BlueObj->BluetoothRecv((unsigned char *)gMcuE104BT52DrvRecvBuf, sizeof(gMcuE104BT52DrvRecvBuf));
if (rt > 0) {
if (NULL == strstr(gMcuE104BT52DrvRecvBuf, gMcuE104BT52DrvOkAck)) {
return -1;
}
}
/* 设置从机模式 */
BlueObj->BluetoothSend((unsigned char *)gMcuE104BT52DrvRoleCmd, strlen(gMcuE104BT52DrvRoleCmd));
/* 启动接收 */
rt = BlueObj->BluetoothRecv((unsigned char *)gMcuE104BT52DrvRecvBuf, sizeof(gMcuE104BT52DrvRecvBuf));
if (rt > 0) {
if (NULL == strstr(gMcuE104BT52DrvRecvBuf, gMcuE104BT52DrvOkAck)) {
return -1;
}
}
return 0;
}