#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>
static char *runStatusFile = "/syscfg/etc/runStatusFile";
FILE *pFile = NULL;
char runCountStr[6]={0};
unsigned runCountInt = 0;
char runTimeStr[6]={0};
unsigned runTimeInt = 0;
void doTask()
{
pFile = fopen(runStatusFile, "r+");
fseek (pFile, 6L, SEEK_SET);
fread (runTimeStr, sizeof(char), 5, pFile);
runTimeInt = atoi(runTimeStr);
runTimeInt += 10;
fseek (pFile, 6L, SEEK_SET);
sprintf(runTimeStr,"%d",runTimeInt);
fwrite(runTimeStr, sizeof(char),5, pFile);
//fseek (pFile, 6L, SEEK_SET);
//fread (runTimeStr, sizeof(char), 5, pFile);
//printf("runTimeStr = %s\n",runTimeStr);
fclose(pFile);
}
int main()
{
pFile = fopen(runStatusFile, "r+");
if(pFile == NULL)
{
pFile = fopen(runStatusFile,"w+");
fseek (pFile, 0L, SEEK_SET);
fwrite("0", sizeof(char), 1, pFile);
fseek (pFile, 6L, SEEK_SET);
fwrite("0", sizeof(char), 1, pFile);
}
fseek (pFile, 0L, SEEK_SET);
fread (runCountStr, sizeof(char), 5, pFile);
runCountInt = atoi(runCountStr);
runCountInt++;
sprintf(runCountStr,"%d",runCountInt);
fseek (pFile, 0L, SEEK_SET);
fwrite(runCountStr, sizeof(char), 5, pFile);
fclose(pFile);
struct sigaction act;
union sigval tsval;
act.sa_handler = doTask;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
sigaction(50, &act, NULL);
while(1)
{
sleep(10); //睡眠10秒
sigqueue(getpid(), 50, tsval);//向主进程发送信号,实际上是自己给自己发信号
}
return 0;
1. HCI层协议概述:
HCI提供一套统一的方法来访问Bluetooth底层。如图所示:
从图上可以看出,Host Controller Interface(HCI) 就是用来沟通Host和Module。Host通常就是PC, Module则是以各种物理连接形式(USB,serial,pc-card等)连接到PC上的bluetooth Dongle。
在Host这一端:application,SDP,L2cap等协议 ......