⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 win32.c

📁 在VC6.0上编译通过的蓝牙通信演示程序, COM1口控制.
💻 C
📖 第 1 页 / 共 2 页
字号:
		else if((ucStatus[0] & 0x0f)== 0x08)	
		PRINT(" 				AV Status - Streaming.\n\n");
		
		else	
			PRINT(" 				AV Status - Wrong.\n\n");	
			
		/*The second byte is for power , mic and sco status*/	
		if((ucStatus[1]& 0xf0) == 0)
			PRINT(" 				Power Status - Off.\n\n");

		else if((ucStatus[1]& 0xf0) == 0x10)
			PRINT(" 				Power Status - On.\n\n");			
			
		else if((ucStatus[1]& 0xf0) == 0x20)
			PRINT(" 				Power Status - Powering down.\n\n");						
		
		else
				PRINT(" 				Power Status - Wrong.\n\n");	
		
		if((ucStatus[1]& 0x0C) == 0x04)
			PRINT(" 				Mic Status - Mute.\n\n");
		
		else 	if((ucStatus[1]& 0x0C) == 0x0)
			PRINT(" 				Mic Status - unMute.\n\n");
			
		else
			PRINT(" 				Mic Status - Wrong.\n\n");	
			
			
		if((ucStatus[1]& 0x03) == 0x01)
			PRINT(" 				SCO Status - exist.\n\n");
		
		else if((ucStatus[1]& 0x03) == 0x0)
			PRINT(" 				SCO Status - unExist.\n\n");
			
		else
			PRINT(" 				SCO Status - Wrong.\n\n");
		
		printf(" 				HFP - Vol %d\n\n", ucStatus[2]);	
		printf(" 				AV - Vol %d\n\n", ucStatus[3]);	
}

/*-------------------------------------------------
Function:	HBCP_HSHF_Status
Parameter:	0 - HsHf initialising
			1 - HsHf ready (to be connected)
			2 - HsHf connecting
			3 - HsHf connected
			4 - HsHf outgoing call
			5 - HsHf incoming call
			6 - HsHf active call
Description:Notify host HsHf status. 
			Host side can switch audio channel accordingly by the status change. 
Return: 	none
*/
void HBCP_HSHF_Status(unsigned char ucStatus)
{
	switch (ucStatus)
	{
		case HBCP_STATUS_HSHF_INITIALISING:
			PRINT(" 				HSHF initialising.\n\n");
			break;
		case HBCP_STATUS_HSHF_READY:
			PRINT(" 				HSHF ready.\n\n");
			break;
		case HBCP_STATUS_HSHF_CONNECTING:
			PRINT(" 				HSHF connecting.\n\n");
			break;
		case HBCP_STATUS_HSHF_CONNECTED:
			PRINT(" 				HSHF connected.\n\n");
			break;
		case HBCP_STATUS_HSHF_INCOMING_CALL:
			PRINT(" 				HSHF incoming call.\n\n");
			break;
		case HBCP_STATUS_HSHF_OUTGOING_CALL:
			PRINT(" 				HSHF outgoing call.\n\n");
			break;
		case HBCP_STATUS_HSHF_ACTIVE_CALL:
			PRINT(" 				HSHF active call.\n\n");
			break;
		default:
			break;
	}
}

/*-------------------------------------------------
Function:	 HBCP_Checksum_Error
Parameters:  none
Description: Notify host that there is a uart tx checksum error .
Return: 	 none
*/
void HBCP_Checksum_Error(void)
{
	PRINT(" 				Uart TX checksum error!");		
	PRINT("\n\n");	
}

/*-------------------------------------------------
Function:	HBCP_Debug_Msg
Parameter:	messages			
Description:This message is for debugging purpose and supportive in both directions 
			(host to BloreCore and BloreCore to host); after receiving this message, 
			receiver ignores subsequent commands or events; 
			it's helpful for using PC or other devices to sniff and print out debug 
			messages on UART. Also useful while tuning CVC.
Return: 	none
*/
void HBCP_Debug_Msg(unsigned char msg_len, unsigned char *pMessage)
{
	*(pMessage + msg_len) = 0;
	PRINT("\t\t");
	PRINT(pMessage);
	PRINT("\n\n");
	memset(pMessage, 0, msg_len);
}

//#define LOG_FILE_ENABLE
void PRINT(unsigned char *str)
{
#ifdef LOG_FILE_ENABLE
	FILE *stream;
	char buffer[9];

	if(stream = fopen("DebugMsg.txt", "a+"))
	{
		_strtime(buffer);
		if (*str != '\n')
		{
			if(*str == '	')
				fprintf(stream, "					");
			else if (*str >= 48 && *str<= 57)
				fprintf(stream, "\n\n");
			fprintf(stream, buffer);
			fprintf(stream, "\n");
		}
		fprintf(stream, str);
	}
	else
		printf("					Open file failed.\n\n");
	if(fclose(stream))
		printf("					Close file failed.\n\n");
#endif
	printf(str);
}

// read a line from file stream
static int freadline(FILE * f, char * buf)
{
	int count=0, ch; 
	while((ch=fgetc(f)) != EOF) 
	{
		if (ch != '\n')
			buf[count++] = (char)ch;
		else 
			break;
	}
	buf[count++] = '\0';
	return ((ch == EOF) ? ch : count);
}

void HBCP_Select_vCard(unsigned char *pName)
{
	FILE *stream;
	char buffer[255];
	char *found;

	if(stream = fopen(pName, "r"))
	{
		while (!feof(stream))
		{
			freadline(stream, buffer);
#ifdef _DEBUG
			printf("%s\n", buffer);
#endif
			if(strncmp(buffer,"N:", 2) == 0)
			{
				found = (char *)&buffer[2];
				HBCP_Send_Command(HBCP_CMD_SET_BC_NAME, strlen(found), found);
			}
			else if(strncmp(buffer,"FN:", 3) == 0)
			{
				found = (char *)&buffer[3];
				HBCP_Send_Command(HBCP_CMD_SET_BC_FNAME, strlen(found), found);
			}
			else if(strncmp(buffer,"ORG:", 4) == 0)
			{
				found = (char *)&buffer[4];
				HBCP_Send_Command(HBCP_CMD_SET_BC_ORG, strlen(found), found);
			}
			else if(strncmp(buffer,"TITLE:", 6) == 0)
			{
				found = (char *)&buffer[6];
				HBCP_Send_Command(HBCP_CMD_SET_BC_TITLE, strlen(found), found);
			}
			else if(strncmp(buffer,"URL:", 4) == 0)
			{
				found = (char *)&buffer[4];
				HBCP_Send_Command(HBCP_CMD_SET_BC_URL, strlen(found), found);
			}
			else if(strncmp(buffer,"REV:", 4) == 0)
			{
				found = (char *)&buffer[4];
				HBCP_Send_Command(HBCP_CMD_SET_BC_REV, strlen(found), found);
			}
			else if(strncmp(buffer,"BDAY:", 5) == 0)
			{
				found = (char *)&buffer[5];
				HBCP_Send_Command(HBCP_CMD_SET_BC_BIRTH, strlen(found), found);
			}
			else if(strncmp(buffer,"TZ:", 3) == 0)
			{
				found = (char *)&buffer[3];
				HBCP_Send_Command(HBCP_CMD_SET_BC_TZ, strlen(found), found);
			}
			else if(strncmp(buffer,"ADR", 3) == 0)
			{
				found = strchr(buffer, ':');
				if(found) found++;
				HBCP_Send_Command(HBCP_CMD_SET_BC_ADDR, strlen(found), found);
			}
			else if(strncmp(buffer,"EMAIL", 5) == 0)
			{
				found = strchr(buffer, ':');
				if(found) found++;
				HBCP_Send_Command(HBCP_CMD_SET_BC_EMAIL, strlen(found), found);
			}
			else if(strncmp(buffer,"TEL", 3) == 0)
			{
				if(strstr(buffer, "FAX"))
				{
					found = strchr(buffer, ':');
					if(found) found++;
					HBCP_Send_Command(HBCP_CMD_SET_BC_FAX, strlen(found), found);
				}
				else if(strstr(buffer, "CELL"))
				{
					found = strchr(buffer, ':');
					if(found) found++;
					HBCP_Send_Command(HBCP_CMD_SET_BC_MOBILE, strlen(found), found);
				}
				else
				{
					found = strchr(buffer, ':');
					if(found) found++;
					HBCP_Send_Command(HBCP_CMD_SET_BC_TEL, strlen(found), found);
				}
			}
		}
	}
	else
	{
		PRINT("					Open file failed.\n\n");
	}
	if(fclose(stream))
	{
		PRINT("					Close file failed.\n\n");
	}
}

void HBCP_Error(unsigned char ucStatus)
{
	if(ucStatus == 0)
		PRINT("					Command not handled.\n\n");
}

/*	Function:	HBCP_Set_Pin
	Params: 	ucLen	string length of pin
				pStr	string of pin
	return: 	none
*/

void HBCP_Set_Pin( unsigned char ucLen, unsigned char *pStr)
{
	if ( ucLen>(unsigned char)HBCP_MAX_PIN_LEN )
		ucLen = (unsigned char)HBCP_MAX_PIN_LEN;
		
    HBCP_Send_Command(HBCP_CMD_HSHF_SET_PIN, ucLen, pStr);
}


void HBCP_Set_Inquiry( unsigned char ucTimeoutSec)
{
    HBCP_Send_Command(HBCP_CMD_HSHF_INQUIRY, 1, &ucTimeoutSec);
}



/* 	Function: 	HBCP_Enter_Pair
	Params:		ucTimeoutSec	seconds for pairing to timer out
	return:		none
*/
void HBCP_Enter_Pair(unsigned char ucTimeoutSec)
{
    HBCP_Send_Command(HBCP_CMD_HSHF_ENTER_PAIR, 1, &ucTimeoutSec);
}

/* 	Function: 	HBCP_Send_DTMF
	Params:		DTMF code
	return:		none
*/
void HBCP_Send_DTMF(unsigned char ucDTMF)
{
    HBCP_Send_Command(HBCP_CMD_HSHF_SEND_DTMF, 1, &ucDTMF);
}

/* 	Function: 	HBCP_Get_CallList
	Params:		ucLen	string length of index
				pStr	string of index
	return:		none
*/
void HBCP_Get_CallList(unsigned char ucLen, unsigned char * pStr)
{
    unsigned char	code;

	if(ucLen == 1)
		code = pStr[0] & 0x0f;
	else
	{
		code = (pStr[0] & 0x0f) * 10;
		code += (pStr[1] & 0x0f);
	}
	
	printf("send char [%d]\n", code);
	
    HBCP_Send_Command(HBCP_CMD_HSHF_GET_LIST, 1, &code);
}

/* 	Function: 	HBCP_Set_storage
	Params:		storage mode
	return:		none
*/
void HBCP_Set_storage(unsigned char ucListType)
{
	ucListType -= '0';
    HBCP_Send_Command(HBCP_CMD_HSHF_SET_STORAGE, 1, &ucListType);
}

void HBCP_Connect_AG_By_Addr( unsigned char ucIndex)
{
	ucIndex -= '0';
    HBCP_Send_Command(HBCP_CMD_HSHF_CONNECT_AG_BY_ADDR, 1, &ucIndex);
}

/* 	Function: 	HBCP_Dial_Number
	Params:		ucLen	string length of phone number
				pStr	string of phone number
	return:		none
*/
void HBCP_Dial_Number(unsigned char ucLen, unsigned char * pStr)
{
    HBCP_Send_Command(HBCP_CMD_HSHF_DIAL_NUM, ucLen, pStr);
}		

/*-------------------------------------------------
Function:	Host_Call_List
Parameters: 
Description:
Return: 	none
*/
static void Host_Call_List(unsigned char ucId, unsigned char *pNum,  unsigned char *pName, unsigned char *pTime)
{
	char buffer[3];

	if(ucId == 0)
		PRINT(" 				No record\n\n");
	else
	{
		PRINT(" 				Storage entry: ");
		PRINT(itoa(ucId, buffer, 10));
		PRINT("\n");
		PRINT(" 				Number: ");
		PRINT(pNum);
		PRINT("\n");
		PRINT(" 				Name: ");
		if(pName == NULL)
			PRINT(" ");
		else
			PRINT(pName);
		PRINT("\n");
		PRINT(" 				Time: ");
		if(pTime == NULL)
			PRINT(" ");
		else
			PRINT(pTime);
		PRINT("\n\n");
		memset(pNum-2, 0, *(pNum-3));
	}
}

/* 	Function: 	Call_list_display
	Params:		pParam string of call info
	return:		none
*/
void HBCP_Call_List_Display(unsigned char * pParam)
{
	unsigned char ucItem;		// Call index
	unsigned char ucId;		// Call index
	unsigned char *pNum;
	unsigned char *pName;
	unsigned char *pTime;

	ucId = pParam[0];
	ucItem = pParam[1];
	pNum = pParam + 2;
	
	//Don't use "ucItem && 0x03" !! It would confuse the display name and time.
	if(ucItem == 0x03)
	{
		pName = pNum + strlen(pNum) + 1;
		pTime = pName + strlen(pName) + 1;		
	}
	else if(ucItem == 0x01)
	{
		pName = pNum + strlen(pNum) + 1;
		pTime = NULL;
	}
	else if(ucItem == 0x02)
	{
		pTime = pNum + strlen(pNum) + 1;
		pName = NULL;			
	}
	else
	{
		pTime = NULL;
		pName = NULL;		
	}

	Host_Call_List(ucId, pNum, pName, pTime);
}

void HBCP_Connect_SPP_By_Addr( unsigned char ucIndex)
{
	ucIndex -= '0';
    HBCP_Send_Command(HBCP_CMD_CONNECT_SPP_BY_ADDR, 1, &ucIndex);
}

void HBCP_Spp_send_Data(unsigned char ucLen, unsigned char * pStr)
{
    HBCP_Send_Command(HBCP_CMD_SPP_DATA, ucLen, pStr);
}		

void HBCP_Spp_receive_Data(unsigned char len, unsigned char *pData)
{
	unsigned char i;
	for(i = 0; i < len; i++)
	{
		printf("%c", *pData++);
	}
}


void HBCP_OPP_Filename(unsigned char ucLen, unsigned char *pData)
{
	int i, j;

	printf("object filename: ");

	for(i = 0, j = 0; i < 79; i++)
	{
		if(j < ucLen)
		{
			filename[i] = *pData;/* file name received is UTF-16 */
			pData += 2;
			j += 2;
		}
		else
		{
			filename[i] = 0;
		}
		printf("%c", filename[i]);
	}
	printf("received data length:%d, name length:%d\n", ucLen, strlen(filename));

	isInStream = False;
}


void HBCP_Save_OPP_Data(unsigned char ucLen, unsigned char *pData)
{
	FILE *opp_fd = fopen(filename, (isInStream)?"ab+":"wb");
	if (!opp_fd)
	{
		PRINT("					Open file failed.\n\n");
	}

	isInStream = True;

	if (opp_fd)
	{
		fwrite(pData, sizeof(unsigned char), ucLen, opp_fd);
		printf("write %d bytes data to opp file\n", ucLen);
	}
	else
	{
		PRINT("					Open file failed.\n\n");
	}

	if(fclose(opp_fd))
	{
		PRINT("					Close file failed.\n\n");
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -