1.蓝牙业务修改
This commit is contained in:
parent
baefeb41c0
commit
d62d2d4525
376
code/application/source/sf_app/code/source/sf_blue/src/hciconfig.c
Executable file → Normal file
376
code/application/source/sf_app/code/source/sf_blue/src/hciconfig.c
Executable file → Normal file
|
@ -21,13 +21,59 @@
|
|||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "bluetooth.h"
|
||||
#include "hci.h"
|
||||
#include "hci_lib.h"
|
||||
#include "src/util.h"
|
||||
|
||||
static struct hci_dev_info di;
|
||||
static char g_sf_ble_ssid[14] = {0};
|
||||
static void cmd_lecc(int dev_id, char *addr)
|
||||
{
|
||||
int err, dd;
|
||||
bdaddr_t bdaddr;
|
||||
uint16_t interval, latency, max_ce_length, max_interval, min_ce_length;
|
||||
uint16_t min_interval, supervision_timeout, window, handle;
|
||||
uint8_t initiator_filter, own_bdaddr_type, peer_bdaddr_type;
|
||||
|
||||
own_bdaddr_type = LE_RANDOM_ADDRESS;
|
||||
peer_bdaddr_type = LE_RANDOM_ADDRESS;
|
||||
initiator_filter = 1; /* Use peer address */
|
||||
|
||||
dd = hci_open_dev(dev_id);
|
||||
if (dd < 0) {
|
||||
perror("Could not open device");
|
||||
return ;
|
||||
}
|
||||
|
||||
memset(&bdaddr, 0, sizeof(bdaddr_t));
|
||||
if (addr)
|
||||
str2ba(addr, &bdaddr);
|
||||
|
||||
printf("Conn_Address: %02x %02x %02x %02x %02x %02x.\n", bdaddr.b[0], bdaddr.b[1], bdaddr.b[2], bdaddr.b[3], bdaddr.b[4], bdaddr.b[5]);
|
||||
|
||||
interval = htobs(0x0004);
|
||||
window = htobs(0x0004);
|
||||
min_interval = htobs(0x000F);
|
||||
max_interval = htobs(0x000F);
|
||||
latency = htobs(0x0000);
|
||||
supervision_timeout = htobs(0x0C80);
|
||||
min_ce_length = htobs(0x0001);
|
||||
max_ce_length = htobs(0x0001);
|
||||
|
||||
err = hci_le_create_conn(dd, interval, window, initiator_filter,
|
||||
peer_bdaddr_type, bdaddr, own_bdaddr_type, min_interval,
|
||||
max_interval, latency, supervision_timeout,
|
||||
min_ce_length, max_ce_length, &handle, 25000);
|
||||
if (err < 0) {
|
||||
perror("Could not create connection");
|
||||
return ;
|
||||
}
|
||||
|
||||
printf("Connection handle %d\n", handle);
|
||||
|
||||
hci_close_dev(dd);
|
||||
}
|
||||
|
||||
static void cmd_up(int ctl, int hdev)
|
||||
{
|
||||
|
@ -42,48 +88,19 @@ static void cmd_up(int ctl, int hdev)
|
|||
}
|
||||
}
|
||||
|
||||
static void cmd_piscan(int ctl, int hdev)
|
||||
static void cmd_down(int ctl, int hdev)
|
||||
{
|
||||
struct hci_dev_req dr;
|
||||
|
||||
dr.dev_id = hdev;
|
||||
dr.dev_opt = SCAN_DISABLED;
|
||||
dr.dev_opt = SCAN_PAGE | SCAN_INQUIRY;
|
||||
|
||||
if (ioctl(ctl, HCISETSCAN, (unsigned long) &dr) < 0)
|
||||
/* Start HCI device */
|
||||
if (ioctl(ctl, HCIDEVDOWN, hdev) < 0)
|
||||
{
|
||||
fprintf(stderr, "Can't set scan mode on hci%d: %s (%d)\n",
|
||||
if (errno == EALREADY)
|
||||
return;
|
||||
fprintf(stderr, "Can't init device hci%d: %s (%d)\n",
|
||||
hdev, strerror(errno), errno);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void cmd_name(int ctl, int hdev, char *name)
|
||||
{
|
||||
int dd;
|
||||
|
||||
dd = hci_open_dev(hdev);
|
||||
if (dd < 0)
|
||||
{
|
||||
fprintf(stderr, "Can't open device hci%d: %s (%d)\n",
|
||||
hdev, strerror(errno), errno);
|
||||
return;
|
||||
}
|
||||
|
||||
char *opt = name;
|
||||
if (hci_write_local_name(dd, opt, 2000) < 0)
|
||||
{
|
||||
fprintf(stderr, "Can't change local name on hci%d: %s (%d)\n",
|
||||
hdev, strerror(errno), errno);
|
||||
return;
|
||||
}
|
||||
printf("Name: '%s'\n", name);
|
||||
hci_close_dev(dd);
|
||||
}
|
||||
static int sf_ba2str(const bdaddr_t *ba, char *str)
|
||||
{
|
||||
return sprintf(str, "%2.2X%2.2X%2.2X",ba->b[2], ba->b[1], ba->b[0]);
|
||||
}
|
||||
static void cmd_address(int ctl, int hdev, char *ssid)
|
||||
{
|
||||
int dd;
|
||||
|
@ -96,115 +113,185 @@ static void cmd_address(int ctl, int hdev, char *ssid)
|
|||
return;
|
||||
}
|
||||
|
||||
hci_read_bd_addr(dd, &di.bdaddr, 1000);
|
||||
bdaddr_t bdaddr = {0};
|
||||
if (hci_read_bd_addr(dd, &bdaddr, 0) < 0)
|
||||
{
|
||||
fprintf(stderr, "Get bd address on hci%d: %s (%d)\n",
|
||||
hdev, strerror(errno), errno);
|
||||
return;
|
||||
}
|
||||
|
||||
sf_ba2str(&di.bdaddr, ssid);
|
||||
if (NULL != ssid)
|
||||
{
|
||||
ssid[0] = bdaddr.b[5];
|
||||
ssid[1] = bdaddr.b[4];
|
||||
ssid[2] = bdaddr.b[3];
|
||||
ssid[3] = bdaddr.b[2];
|
||||
ssid[4] = bdaddr.b[1];
|
||||
ssid[5] = bdaddr.b[0];
|
||||
|
||||
printf("BT Address: %s.\n", ssid);
|
||||
printf("BT_Address: %02x,%02x,%02x,%02x,%02x,%02x.\n", ssid[0], ssid[1], ssid[2], ssid[3], ssid[4], ssid[5]);
|
||||
}
|
||||
|
||||
hci_close_dev(dd);
|
||||
}
|
||||
|
||||
static void cmd_le_adv(int ctl, int hdev)
|
||||
static void set_random_address(int fd)
|
||||
{
|
||||
struct hci_request rq;
|
||||
le_set_advertise_enable_cp advertise_cp;
|
||||
le_set_advertising_parameters_cp adv_params_cp;
|
||||
uint8_t status;
|
||||
int dd, ret;
|
||||
le_set_random_address_cp cmd;
|
||||
|
||||
if (hdev < 0)
|
||||
hdev = hci_get_route(NULL);
|
||||
memset(&cmd, 0, sizeof(cmd));
|
||||
|
||||
dd = hci_open_dev(hdev);
|
||||
if (dd < 0)
|
||||
{
|
||||
perror("Could not open device");
|
||||
return;
|
||||
int urandom_fd;
|
||||
urandom_fd = open("/dev/urandom", O_RDONLY);
|
||||
if (urandom_fd < 0) {
|
||||
fprintf(stderr, "Failed to open /dev/urandom device\n");
|
||||
cmd.bdaddr.b[5] = 0xc0;
|
||||
cmd.bdaddr.b[4] = 0x55;
|
||||
cmd.bdaddr.b[3] = 0x44;
|
||||
cmd.bdaddr.b[2] = 0x33;
|
||||
cmd.bdaddr.b[1] = 0x22;
|
||||
cmd.bdaddr.b[0] = 0x11;
|
||||
|
||||
} else {
|
||||
ssize_t len;
|
||||
|
||||
len = read(urandom_fd, cmd.bdaddr.b, sizeof(cmd.bdaddr.b));
|
||||
if (len < 0 || len != sizeof(cmd.bdaddr.b)) {
|
||||
fprintf(stderr, "Failed to read random data\n");
|
||||
return;
|
||||
}
|
||||
|
||||
cmd.bdaddr.b[5] &= 0x3f;
|
||||
cmd.bdaddr.b[5] |= 0xc0;
|
||||
}
|
||||
|
||||
memset(&adv_params_cp, 0, sizeof(adv_params_cp));
|
||||
adv_params_cp.min_interval = htobs(0x0800);
|
||||
adv_params_cp.max_interval = htobs(0x0800);
|
||||
adv_params_cp.advtype = 0; //mt set
|
||||
adv_params_cp.chan_map = 7;
|
||||
|
||||
memset(&rq, 0, sizeof(rq));
|
||||
rq.ogf = OGF_LE_CTL;
|
||||
rq.ocf = OCF_LE_SET_ADVERTISING_PARAMETERS;
|
||||
rq.cparam = &adv_params_cp;
|
||||
rq.clen = LE_SET_ADVERTISING_PARAMETERS_CP_SIZE;
|
||||
rq.rparam = &status;
|
||||
rq.rlen = 1;
|
||||
|
||||
ret = hci_send_req(dd, &rq, 1000);
|
||||
if (ret < 0)
|
||||
goto done;
|
||||
|
||||
memset(&advertise_cp, 0, sizeof(advertise_cp));
|
||||
advertise_cp.enable = 0x01;
|
||||
|
||||
memset(&rq, 0, sizeof(rq));
|
||||
rq.ogf = OGF_LE_CTL;
|
||||
rq.ocf = OCF_LE_SET_ADVERTISE_ENABLE;
|
||||
rq.cparam = &advertise_cp;
|
||||
rq.clen = LE_SET_ADVERTISE_ENABLE_CP_SIZE;
|
||||
rq.rparam = &status;
|
||||
rq.rlen = 1;
|
||||
|
||||
ret = hci_send_req(dd, &rq, 1000);
|
||||
|
||||
done:
|
||||
hci_close_dev(dd);
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf(stderr, "Can't set advertise mode on hci%d: %s (%d)\n",
|
||||
hdev, strerror(errno), errno);
|
||||
return;
|
||||
}
|
||||
|
||||
if (status)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"LE set advertise enable on hci%d returned status %d\n",
|
||||
hdev, status);
|
||||
return;
|
||||
}
|
||||
if (hci_send_cmd(fd, OGF_LE_CTL, OCF_LE_SET_RANDOM_ADDRESS, sizeof(cmd),
|
||||
&cmd) < 0)
|
||||
perror("Send msg for set random address error");
|
||||
}
|
||||
|
||||
int hciconfig_open_piscan(void)
|
||||
static void set_adv_parameters(int fd)
|
||||
{
|
||||
int ctl = -1;
|
||||
int hdev = 0;
|
||||
le_set_advertising_parameters_cp cmd;
|
||||
|
||||
/* Open HCI socket */
|
||||
if ((ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0)
|
||||
cmd.min_interval = cpu_to_le16(0x0001);
|
||||
cmd.max_interval = cpu_to_le16(0x0001);
|
||||
//cmd.min_interval = cpu_to_le16(0x0020);
|
||||
//cmd.max_interval = cpu_to_le16(0x0020);
|
||||
|
||||
/* 0x00: Connectable undirected advertising
|
||||
* 0x03: Non connectable undirected advertising
|
||||
* */
|
||||
cmd.advtype = 0x00;
|
||||
/* 0: public address
|
||||
* 1: random address */
|
||||
cmd.own_bdaddr_type = 0x00;
|
||||
cmd.direct_bdaddr_type = 0x00;
|
||||
memset(cmd.direct_bdaddr.b, 0, 6);
|
||||
cmd.chan_map = 0x07;
|
||||
cmd.filter = 0x00;
|
||||
|
||||
if (hci_send_cmd(fd, OGF_LE_CTL, OCF_LE_SET_ADVERTISING_PARAMETERS,
|
||||
sizeof(cmd), &cmd))
|
||||
perror("Send msg for set adv params error");
|
||||
}
|
||||
|
||||
static void set_scan_enable(int fd, uint8_t enable, uint8_t filter_dup)
|
||||
{
|
||||
le_set_scan_enable_cp scan_cp;
|
||||
//uint8_t status;
|
||||
|
||||
if (enable)
|
||||
enable = 0x01;
|
||||
|
||||
memset(&scan_cp, 0, sizeof(scan_cp));
|
||||
scan_cp.enable = enable;
|
||||
scan_cp.filter_dup = filter_dup;
|
||||
|
||||
if (hci_send_cmd(fd, OGF_LE_CTL, OCF_LE_SET_SCAN_ENABLE, sizeof(scan_cp),
|
||||
&scan_cp) < 0)
|
||||
perror("Send cmd for set scan enable error");
|
||||
}
|
||||
|
||||
static void set_adv_enable(int fd, uint8_t enable)
|
||||
{
|
||||
if (enable)
|
||||
enable = 0x01;
|
||||
|
||||
if (hci_send_cmd(fd, OGF_LE_CTL, OCF_LE_SET_ADVERTISE_ENABLE, 1,
|
||||
&enable) < 0)
|
||||
perror("Send cmd for set adv enable error");
|
||||
}
|
||||
|
||||
static void set_adv_data(int fd, const char* name)
|
||||
{
|
||||
le_set_advertising_data_cp cmd;
|
||||
int i = 0;
|
||||
int n;
|
||||
//const char *name = "ADVTEST";
|
||||
|
||||
cmd.length = 0;
|
||||
memset(cmd.data, 0, sizeof(cmd.data));
|
||||
/* set adv data */
|
||||
cmd.data[i] = 0x02; /* Field length */
|
||||
cmd.length += (1 + cmd.data[i++]);
|
||||
cmd.data[i++] = 0x01; /* Flags */
|
||||
/* LE General Discoverable Mode, BR/EDR Not Supported */
|
||||
cmd.data[i++] = (0x02 | 0x04);
|
||||
|
||||
cmd.data[i] = 0x03;
|
||||
cmd.length += (1 + cmd.data[i++]);
|
||||
cmd.data[i++] = 0x03; /* complete list of 15-bit service class uuids */
|
||||
cmd.data[i++] = 0xa0;
|
||||
cmd.data[i++] = 0x0a;
|
||||
|
||||
n = strlen(name);
|
||||
cmd.data[i] = 1 + n;
|
||||
cmd.length += (1 + cmd.data[i++]);
|
||||
cmd.data[i++] = 0x09; /* complete local name */
|
||||
memcpy(&cmd.data[i], name, n);
|
||||
i += n;
|
||||
|
||||
printf("advertise_data, len=%d:\n", i);
|
||||
for (int k = 0; k < i; k++)
|
||||
{
|
||||
perror("Can't open HCI socket.");
|
||||
return -1;
|
||||
printf("%02x ", cmd.data);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
if (hci_send_cmd(fd, OGF_LE_CTL, OCF_LE_SET_ADVERTISING_DATA,
|
||||
sizeof(cmd), &cmd))
|
||||
perror("Send cmd for set adv data error");
|
||||
|
||||
}
|
||||
|
||||
int hciconfig_start_advertising(const char *ssid)
|
||||
{
|
||||
int hci_fd;
|
||||
|
||||
//printf("Start advertising\n");
|
||||
|
||||
hci_fd = hci_open_dev(0);
|
||||
if (hci_fd < 0)
|
||||
{
|
||||
perror("Failed to open hci dev");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd_up(ctl, hdev);
|
||||
usleep(100*1000);
|
||||
//cmd_name(ctl, hdev, g_sf_ble_ssid);
|
||||
//usleep(100*1000);
|
||||
cmd_piscan(ctl, hdev);
|
||||
usleep(100*1000);
|
||||
set_scan_enable(hci_fd, 0, 1);
|
||||
set_adv_enable(hci_fd, 0);
|
||||
set_adv_data(hci_fd, ssid);
|
||||
set_random_address(hci_fd);
|
||||
set_adv_parameters(hci_fd);
|
||||
set_adv_enable(hci_fd, 1);
|
||||
|
||||
cmd_le_adv(ctl, hdev);
|
||||
//usleep(500*1000);
|
||||
//cmd_le_adv(ctl, hdev);
|
||||
|
||||
close(ctl);
|
||||
printf("blue scan.\n");
|
||||
hci_close_dev(hci_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hciconfig_set_name(char *name)
|
||||
int hciconfig_open_device(void)
|
||||
{
|
||||
snprintf(g_sf_ble_ssid, sizeof(g_sf_ble_ssid), "%s",name);
|
||||
printf("set bluename:%s\n",g_sf_ble_ssid);
|
||||
int ctl = -1;
|
||||
int hdev = 0;
|
||||
|
||||
|
@ -214,11 +301,32 @@ int hciconfig_set_name(char *name)
|
|||
perror("Can't open HCI socket.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd_up(ctl, hdev);
|
||||
cmd_name(ctl, hdev, name);
|
||||
usleep(100*1000);
|
||||
|
||||
close(ctl);
|
||||
printf("set bluename.\n");
|
||||
printf("open hci0 device.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hciconfig_close_device(void)
|
||||
{
|
||||
int ctl = -1;
|
||||
int hdev = 0;
|
||||
|
||||
/* Open HCI socket */
|
||||
if ((ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0)
|
||||
{
|
||||
perror("Can't open HCI socket.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd_down(ctl, hdev);
|
||||
|
||||
close(ctl);
|
||||
printf("close hci0 device.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -233,15 +341,19 @@ int hciconfig_get_address(char *ssid)
|
|||
perror("Can't open HCI socket.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd_up(ctl, hdev);
|
||||
|
||||
if (ioctl(ctl, HCIGETDEVINFO, (void *) &di)) {
|
||||
perror("Can't get device info");
|
||||
}
|
||||
|
||||
cmd_address(ctl, hdev, ssid);
|
||||
usleep(100*1000);
|
||||
|
||||
close(ctl);
|
||||
printf("get blueaddress.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hciconfig_conn_le(char *addr)
|
||||
{
|
||||
cmd_lecc(0, addr);
|
||||
|
||||
printf("connect le.\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
3501
code/application/source/sf_app/code/source/sf_blue/src/hcitool.c
Normal file
3501
code/application/source/sf_app/code/source/sf_blue/src/hcitool.c
Normal file
File diff suppressed because it is too large
Load Diff
81
code/application/source/sf_app/code/source/sf_blue/src/sf_blue_app.c
Executable file → Normal file
81
code/application/source/sf_app/code/source/sf_blue/src/sf_blue_app.c
Executable file → Normal file
|
@ -29,6 +29,8 @@
|
|||
#include "sf_systemMng.h"
|
||||
#include <netinet/in.h>
|
||||
#include <unistd.h> //usleep()
|
||||
#include "sf_device.h"
|
||||
#include "sf_message_queue.h"
|
||||
|
||||
#define MSG_BLE_PRE_FIX 0x55AA
|
||||
#define MSG_BLE_END_FIX 0xFFEE
|
||||
|
@ -40,6 +42,32 @@
|
|||
|
||||
static BLE_APP_PACKET_T gst_msgResult = {0};
|
||||
static unsigned int gmsgResultLen = 0;
|
||||
SF_BLE_STATUS_E BleStatus = SF_BLE_BUTT;
|
||||
SF_BLE_STATUS_E sf_get_ble_status(void)
|
||||
{
|
||||
return BleStatus;
|
||||
}
|
||||
|
||||
void sf_set_ble_status(SF_BLE_STATUS_E enStatus)
|
||||
{
|
||||
SF_MESSAGE_BUF_S stMessageBuf = {0};
|
||||
if(enStatus < SF_BLE_BUTT)
|
||||
{
|
||||
if(BleStatus != enStatus)
|
||||
{
|
||||
stMessageBuf.arg2 = enStatus;
|
||||
stMessageBuf.arg1 = SF_PARA_CMD_BLE;
|
||||
stMessageBuf.cmdId = CMD_PARA;
|
||||
sf_com_message_send_to_cardv(&stMessageBuf);
|
||||
}
|
||||
BleStatus = enStatus;
|
||||
}
|
||||
|
||||
else
|
||||
SLOGE("Type format error\n");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
static void sf_clear_poweroff_time(void)
|
||||
{
|
||||
|
@ -147,7 +175,7 @@ static void sf_blue_command_get_camera_para(MSG_DEV_BLE_Param_Get_Rsp_T *CamPara
|
|||
//printf("[sf_app_Get_Camera_Para],snapnum:%d\n",puiPara->snapnum);
|
||||
CamPara->cmdRet = 0;
|
||||
|
||||
CamPara->zoom = puiPara->Zoom;
|
||||
CamPara->zoom = puiPara->Zoom + 1;
|
||||
|
||||
CamPara->cameraMode = (puiPara->CamMode==2)?1:0;
|
||||
|
||||
|
@ -278,7 +306,7 @@ static signed int sf_blue_command_request_process(U8 *val, unsigned int nval, U8
|
|||
UINT8 paraNeedReboot = 0;
|
||||
UINT8 SendingFile = 0;
|
||||
UINT16 tmp = 0;
|
||||
|
||||
SF_MESSAGE_BUF_S stMessageBuf = {0};
|
||||
UIMenuStoreInfo *puiPara = sf_app_ui_para_get();
|
||||
BLE_APP_PACKET_T msgParse;
|
||||
BLE_APP_PACKET_T *pMsgStruct = NULL;
|
||||
|
@ -288,6 +316,7 @@ static signed int sf_blue_command_request_process(U8 *val, unsigned int nval, U8
|
|||
UINT16 PreFind=0;
|
||||
UINT16 uTemp=0;
|
||||
UINT16 msgTotolLen=0, msgEndVal=0;
|
||||
SINT8 ret = -1;
|
||||
|
||||
for(offset = 0; offset < nval && offset < sizeof(BLE_APP_PACKET_T);)
|
||||
{
|
||||
|
@ -403,7 +432,7 @@ static signed int sf_blue_command_request_process(U8 *val, unsigned int nval, U8
|
|||
{
|
||||
SLOGI("[BLE_SET_CAMERA_Zoom],Zoom:%d\n",puiPara->Zoom);
|
||||
puiPara->Zoom = pMsgStruct->msgBuf.deviceZoomSet.zoom;
|
||||
puiPara->Zoom = (puiPara->Zoom > 4 ? 1 : puiPara->Zoom);
|
||||
puiPara->Zoom = (puiPara->Zoom > 4 ? 1 : puiPara->Zoom) - 1;
|
||||
|
||||
//forbuild sp5kModeGet(&curMode);
|
||||
//curMode = 0;//forbuild
|
||||
|
@ -447,7 +476,7 @@ static signed int sf_blue_command_request_process(U8 *val, unsigned int nval, U8
|
|||
}
|
||||
else if (tmpMode == 1)
|
||||
{
|
||||
puiPara->CamMode = SF_CAM_MODE_PHOTO_VIDEO;
|
||||
puiPara->CamMode = SF_CAM_MODE_VIDEO2;
|
||||
}
|
||||
else if (tmpMode == 2)
|
||||
{
|
||||
|
@ -803,6 +832,50 @@ static signed int sf_blue_command_request_process(U8 *val, unsigned int nval, U8
|
|||
}
|
||||
break;
|
||||
|
||||
case BLE_CONTROL_CAMERA_FormatSDCard:
|
||||
{
|
||||
SLOGI("[BLE_CONTROL_CAMERA_FormatSDCard],format:%d\n",pMsgStruct->msgBuf.ctrlFormat.format);
|
||||
if(pMsgStruct->msgBuf.ctrlFormat.format == 1)
|
||||
{
|
||||
if((sf_in_card_exist()) && (sf_is_card()))
|
||||
{
|
||||
stMessageBuf.arg1 = CMD_SD_FORMAT;
|
||||
stMessageBuf.cmdId = CMD_SD;
|
||||
sf_com_message_send_to_cardv(&stMessageBuf);
|
||||
}
|
||||
sf_set_card_statu(CMD_FORMAT_SD_STA);
|
||||
// while(CMD_FORMAT_SD_STA == sf_get_card_statu())
|
||||
// {
|
||||
// usleep(100*1000);
|
||||
// }
|
||||
ret = sf_get_card_statu();
|
||||
if(ret == CMD_FORMAT_SD_OK)
|
||||
{
|
||||
ret = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = 0x10;
|
||||
}
|
||||
}
|
||||
msgParse.msgBuf.camreaSetRsp.cmdRet = ret;
|
||||
msgParse.msgBuf.camreaSetRsp.suffix = htons(MSG_BLE_END_FIX);
|
||||
msgParse.msglen = htons(sizeof(MSG_DEV_BLE_SET_Rsp_T) + 2*sizeof(UINT16));
|
||||
respFlag = 1;
|
||||
}
|
||||
break;
|
||||
case BLE_CONTROL_CAMERA_Recovery:
|
||||
{
|
||||
SLOGI("[BLE_CONTROL_CAMERA_Recovery]\n");
|
||||
SF_PDT_PARAM_STATISTICS_S *pSifarPara = sf_statistics_param_get();
|
||||
sf_statistics_param_reset(pSifarPara);
|
||||
stMessageBuf.arg1 = SF_PARA_CMD_RESET;
|
||||
stMessageBuf.cmdId = CMD_PARA;
|
||||
sf_com_message_send_to_cardv(&stMessageBuf);
|
||||
paraNeedReboot = 1;
|
||||
respFlag = 2;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
msgParse.msgBuf.camreaSetRsp.cmdRet = -1;
|
||||
|
|
65
code/application/source/sf_app/code/source/sf_blue/src/sf_blue_app.h
Executable file → Normal file
65
code/application/source/sf_app/code/source/sf_blue/src/sf_blue_app.h
Executable file → Normal file
|
@ -58,6 +58,10 @@ typedef enum
|
|||
BLE_SET_CAMERA_timeLapse = 0x23, //设置相机缩时摄影
|
||||
BLE_SET_CAMERA_PicUponDailyReport = 0x24, //设置DailyReport时是否发送照片.
|
||||
|
||||
//*APP待增加项
|
||||
BLE_CONTROL_CAMERA_FormatSDCard = 0x30,//格式化SD卡
|
||||
BLE_CONTROL_CAMERA_Recovery = 0x32, //恢复出厂设置
|
||||
|
||||
BLE_CMD_MAX = 0x40,
|
||||
} BLE_CMD_E;
|
||||
|
||||
|
@ -67,6 +71,14 @@ typedef enum
|
|||
BLE_CMD_ERR = 0x01, //command error
|
||||
} BLE_ErrCode_t;
|
||||
|
||||
typedef enum sfBLE_STATUS_E
|
||||
{
|
||||
SF_BLE_OK = 0x01,/*BLE start success*/
|
||||
SF_BLE_CON, /*BLE has been connected*/
|
||||
SF_BLE_FAIL, /*BLE start fail*/
|
||||
SF_BLE_BUTT,
|
||||
} SF_BLE_STATUS_E;
|
||||
|
||||
/*--------------------BLE Module Get CMD-------------------------------*/
|
||||
typedef struct
|
||||
{
|
||||
|
@ -365,6 +377,44 @@ typedef struct
|
|||
UINT16 suffix; /* 0xFFEE */
|
||||
} __attribute__((packed)) MSG_DEV_BLE_DebugMode_Set_T;
|
||||
|
||||
/*******相机控制指令结构体***********/
|
||||
typedef struct
|
||||
{
|
||||
UINT8 format; /* 1:format immediately */
|
||||
UINT16 sufix; /* 0xFFEE */
|
||||
} __attribute__((packed)) MSG_DEV_BLE_FormatSDCard_Ctrl_T;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT8 cmdRet; /* 0: mean cmd OK other:mean cmd error */
|
||||
UINT16 suffix; /* 0xFFEE */
|
||||
} __attribute__((packed)) MSG_DEV_BLE_FormatSDCard_Ctrl_RSP_T;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT8 reboot; /* 1: Reboot */
|
||||
UINT16 sufix; /* 0xFFEE */
|
||||
} __attribute__((packed)) MSG_DEV_BLE_REBOOT_Ctrl_T;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT8 cmdRet; /* 0: mean cmd OK other:mean cmd error */
|
||||
UINT16 suffix; /* 0xFFEE */
|
||||
} __attribute__((packed)) MSG_DEV_BLE_REBOOT_Ctrl_RSP_T;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT8 reset; /* reset */
|
||||
UINT16 sufix; /* 0xFFEE */
|
||||
} __attribute__((packed)) MSG_DEV_BLE_Reset_Ctrl_T;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT8 cmdRet; /* 0: mean cmd OK other:mean cmd error */
|
||||
UINT16 suffix; /* 0xFFEE */
|
||||
} __attribute__((packed)) MSG_DEV_BLE_Reset_Ctrl_RSP_T;
|
||||
|
||||
|
||||
/************* APP_MSG_T 数据结构 **************/
|
||||
typedef struct
|
||||
{
|
||||
|
@ -463,6 +513,19 @@ typedef struct
|
|||
|
||||
/*设置调试模式*/
|
||||
MSG_DEV_BLE_DebugMode_Set_T setDebugMode;
|
||||
|
||||
/*******相机控制指令结构体***********/
|
||||
/*格式化SD卡*/
|
||||
MSG_DEV_BLE_FormatSDCard_Ctrl_T ctrlFormat;
|
||||
MSG_DEV_BLE_FormatSDCard_Ctrl_RSP_T rctrlFormat;
|
||||
|
||||
/*重启*/
|
||||
MSG_DEV_BLE_REBOOT_Ctrl_T ctrlReboot;
|
||||
MSG_DEV_BLE_REBOOT_Ctrl_RSP_T rctrlReboot;
|
||||
|
||||
/*恢复出厂设置*/
|
||||
MSG_DEV_BLE_Reset_Ctrl_T ctrlReset;
|
||||
MSG_DEV_BLE_Reset_Ctrl_RSP_T rctrlReset;
|
||||
};
|
||||
} __attribute__((packed)) BLE_APP_MSG_T;
|
||||
typedef struct
|
||||
|
@ -477,6 +540,8 @@ typedef struct
|
|||
unsigned int sf_blue_app_start(void);
|
||||
unsigned int sf_blue_app_stop(void);
|
||||
int sf_set_ble_name(char *name);
|
||||
void sf_set_ble_status(SF_BLE_STATUS_E enStatus);
|
||||
SF_BLE_STATUS_E sf_get_ble_status(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
81
code/application/source/sf_app/code/source/sf_blue/src/sf_blue_hal.c
Executable file → Normal file
81
code/application/source/sf_app/code/source/sf_blue/src/sf_blue_hal.c
Executable file → Normal file
|
@ -31,9 +31,11 @@
|
|||
#include <net/if.h>
|
||||
#include "sf_blue_app.h"
|
||||
|
||||
extern int hciconfig_start_advertising(const char *ssid);
|
||||
extern int hciconfig_close_device(void);
|
||||
extern int hciconfig_open_device(void);
|
||||
extern int hciconfig_conn_le(char *addr);
|
||||
extern int hciconfig_get_address(char *ssid);
|
||||
extern int hciconfig_set_name(char *name);
|
||||
extern int hciconfig_open_piscan(void);
|
||||
extern int gatt_service_register(BLE_RD rcb, BLE_WR wcb);
|
||||
|
||||
static pthread_t gblue_piscan_task_pid;
|
||||
|
@ -42,7 +44,9 @@ static pthread_t gblue_disconnect_pid;
|
|||
static BLE_RD gst_ble_rcb = NULL;
|
||||
static BLE_WR gst_ble_wcb = NULL;
|
||||
|
||||
static char g_ble_ssid[14] = {0};
|
||||
static char g_ble_bdaddr[6] = {0};
|
||||
static char g_ble_ssid[16] = {0};
|
||||
static char g_ble_connect = 0;
|
||||
|
||||
/*************************************************
|
||||
Function: sf_bluetooth_disconnect_task
|
||||
|
@ -54,13 +58,33 @@ static char g_ble_ssid[14] = {0};
|
|||
*************************************************/
|
||||
static void *sf_bluetooth_disconnect_task(void *arg)
|
||||
{
|
||||
//int count = 0;
|
||||
while (1)
|
||||
{
|
||||
if (access("/tmp/blue_disconnect", F_OK) == 0)
|
||||
{
|
||||
remove("/tmp/blue_disconnect");
|
||||
remove("/tmp/blue_connect");
|
||||
SLOGI("reset piscan.\n");
|
||||
hciconfig_open_piscan();
|
||||
g_ble_connect = 0;
|
||||
sf_set_ble_status(SF_BLE_OK);
|
||||
|
||||
hciconfig_start_advertising(g_ble_ssid);
|
||||
}
|
||||
else if (access("/tmp/blue_connect", F_OK) == 0)
|
||||
{
|
||||
//SF_BLUE_LOGI("blue_connect.\n");
|
||||
g_ble_connect = 1;
|
||||
//sf_clear_poweroff_time();/*reset power off count time*/
|
||||
sf_set_ble_status(SF_BLE_CON);
|
||||
}
|
||||
|
||||
if (access("/tmp/blue_le", F_OK) == 0)
|
||||
{
|
||||
remove("/tmp/blue_le");
|
||||
//char *addr = "2C:C3:E6:DF:59:C0";
|
||||
char *addr = "C0:59:DF:E6:C3:2C";
|
||||
hciconfig_conn_le(addr);
|
||||
}
|
||||
|
||||
usleep(500*1000);
|
||||
|
@ -83,36 +107,6 @@ static void sf_bluetooth_power_enable(void)
|
|||
// system("echo 1 > /sys/class/gpio/gpio44/value");
|
||||
}
|
||||
|
||||
int sf_getb_mac(char *ifName, UINT8 *pbMacAddr)
|
||||
{
|
||||
struct ifreq ifreq;
|
||||
int sock = 0;
|
||||
int i = 0;
|
||||
|
||||
sock = socket(AF_BLUETOOTH, SOCK_STREAM, 0);
|
||||
if(sock < 0)
|
||||
{
|
||||
MLOGE("error sock");
|
||||
return 2;
|
||||
}
|
||||
|
||||
strcpy(ifreq.ifr_name, ifName);
|
||||
if(ioctl(sock,SIOCGIFHWADDR,&ifreq) < 0)
|
||||
{
|
||||
MLOGE("error ioctl");
|
||||
return 3;
|
||||
}
|
||||
|
||||
for(i = 0; i < 6; i++)
|
||||
{
|
||||
pbMacAddr[i]=(unsigned char)ifreq.ifr_hwaddr.sa_data[i];
|
||||
}
|
||||
|
||||
MLOGI("MAC: %02X-%02X-%02X-%02X-%02X-%02X\n", pbMacAddr[0],pbMacAddr[1],pbMacAddr[2],pbMacAddr[3],pbMacAddr[4],pbMacAddr[5]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************
|
||||
Function: sf_bluetooth_scaning_task
|
||||
Description: Bluetooth radio on and set to low power mode
|
||||
|
@ -156,10 +150,9 @@ static void *sf_bluetooth_piscan_task(void *arg)
|
|||
}
|
||||
}
|
||||
|
||||
char ssid[14]= {0};
|
||||
hciconfig_get_address(ssid);
|
||||
snprintf(g_ble_ssid, sizeof(g_ble_ssid), "X-PRO_%s",ssid);
|
||||
hciconfig_set_name(g_ble_ssid);
|
||||
hciconfig_get_address(g_ble_bdaddr);
|
||||
|
||||
snprintf(g_ble_ssid, sizeof(g_ble_ssid), "X-PRO_%02X%02X%02X",g_ble_bdaddr[3],g_ble_bdaddr[4],g_ble_bdaddr[5]);
|
||||
sf_set_ble_name(g_ble_ssid);
|
||||
|
||||
system("dbus-daemon --system");
|
||||
|
@ -187,11 +180,17 @@ static void *sf_bluetooth_piscan_task(void *arg)
|
|||
}
|
||||
}
|
||||
}
|
||||
//sleep(15);
|
||||
printf("%s:%d --------------test blu------------\n",__FUNCTION__,__LINE__);
|
||||
sleep(2);
|
||||
hciconfig_open_device();
|
||||
usleep(200*1000);
|
||||
|
||||
hciconfig_open_piscan();
|
||||
//!< start to advertise
|
||||
hciconfig_start_advertising(g_ble_ssid);
|
||||
|
||||
//!< register gatt callback
|
||||
gatt_service_register(gst_ble_rcb, gst_ble_wcb);
|
||||
|
||||
sf_set_ble_status(SF_BLE_OK);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
1
code/application/source/sf_app/code/source/sf_blue/src/sf_blue_hal.h
Executable file → Normal file
1
code/application/source/sf_app/code/source/sf_blue/src/sf_blue_hal.h
Executable file → Normal file
|
@ -31,6 +31,7 @@ extern "C" {
|
|||
typedef int (*BLE_RD)(unsigned char **, unsigned int *);
|
||||
typedef int (*BLE_WR)(unsigned char *, unsigned int, unsigned char **, unsigned int *);
|
||||
|
||||
void sf_blue_hal_get_ssid(char *ssid);
|
||||
unsigned int sf_blue_hal_init(BLE_RD rcb, BLE_WR wcb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Reference in New Issue
Block a user