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

📄 tskwicresp.c

📁 本人编写的无线电话程序,给予PIC18C801设计,包括了uCOS的移植以及菜单,自己设计的拼音注入法,完整地一级汉字库,希望对大家有所帮助
💻 C
📖 第 1 页 / 共 2 页
字号:
			else if(k < 71) k = 1;
			else if(k < 79) k = 2;
			else k = 3;
			Display_Bat_Lvl(k);
			WICWorkBufPTR = 0;
			break;
		case RESP_WIND:
			i = Func_Search_Char(Search.Pos, WICWorkBufPTR, 0x0d);
			k = 0;
			for(j = Search.Pos; j<i; j++){
				chrT = chrWICWorkBuf[j]-'0';
				if(chrT <= 9){
					k = k*10 + chrT;
				}
				else k = 0;
			}
			if (k == 128){
				Display_Ser(0xff);
			}
			else if (k == 64){
				Display_Ser(1);
			}
			WICWorkBufPTR = 0;
			break;
		case RESP_WCNT:
			i = Func_Search_Char(Search.Pos, WICWorkBufPTR, 0x0d);
			k = 0;
			for(j = Search.Pos; j<i; j++){
				chrT = chrWICWorkBuf[j]-'0';
				if(chrT <= 9){
					k = k*10 + chrT;
				}
				else k = 0;
			}
			if(k == 3) OSQPost(peventDVS, (OS_EVENT *) MSG_VOICE_CONNECT);
			WICWorkBufPTR = 0;
			break;
		case RESP_WEND:
			i = Func_Search_Char(Search.Pos, WICWorkBufPTR, 0x0d);
			k = 0;
			for(j = Search.Pos; j<i; j++){
				chrT = chrWICWorkBuf[j]-'0';
				if(chrT <= 9){
					k = k*10 + chrT;
				}
				else k = 0;
			}
			if(k == 6 || k == 9) OSQPost(peventDVS, (OS_EVENT *) MSG_VOICE_BUSY);
			WICWorkBufPTR = 0;
			break;
		case RESP_PROMPT:
			WICWorkBufPTR = 0;
			OSQPost(peventWIC, (OS_EVENT *)MSG_WICRESP_SMPROMPT);
			break;
		case RESP_CMT:
			//data example:
			//+CMT:"13705153921","02/05/17,10:43:07",129,,,5<CR><LF>
			//HELLO<CR><LF>
			
			i = Func_Search_Char(Search.Pos, WICWorkBufPTR, 0x0d);
			if(i == 0xffff){ //cann't find length field
				WICWorkBufPTR = 0;
				break;
			}
			//calculate the length
			j=i-1;
			for(;;){
				if(chrWICWorkBuf[j] == ','){
					break;
				}
				j--; 
			}
			k=0;
			for(j =j+1; j<i; j++){
				k = k*10 + (chrWICWorkBuf[j]&0x0f);
			}
			if(k > 200){
				WICWorkBufPTR = 0;
			}
			else if(i == WICWorkBufPTR - 3 - k){	//the body of SM has been received
				if(Save_SM(i+2,k)==0){
					Display_SM(1);
					OSQPost(peventTone, (OS_EVENT *)MSG_SM_NEW);
					OSQPost(peventWICCmd, (OS_EVENT *)MSG_SM_ACCEPT);
				}
				WICWorkBufPTR = 0;
			}
			else if (WICWorkBufPTR>i+3+k){	//the length is too large
				WICWorkBufPTR = 0;
			}
			break;
		case RESP_CONNECT:
			OSQPost(peventWIC, (OS_EVENT *)MSG_DATA_CONSUCC);
			WICWorkBufPTR = 0;
			break;
		default:	//0xff
			WICWorkBufPTR = 0;
			break;
	}
}

INT16U Func_Search_Char(INT16U Start, INT16U End, INT8U chrX){
	INT16U i;
	for(i=Start; i< End; i++){
		if(chrWICWorkBuf[i] == chrX) return (i);
	}
	return (0xffff);
}

INT8U Save_SM(INT8U start, INT8U len){
	INT8U i,j,k;
	INT8U item;
	SM_TABLE_ITEM *p;
	INT8U rom * pT;
	if(len>140) len=140;
	//find a empty item
	p = &SystemFile.SMTbl[0];
	for(i=0; i<SMTBLLEN; i++){
		if(p->chrOtherSideNum[0] == 0xff) break;
		p++;
	}
	if(i < SMTBLLEN){	//not illegal value
		item = i;
		//data example:
		//+CMT:"13705153921","02/05/17,10:43:07",129,0,4,5<CR><LF>
		//HELLO<CR><LF>
		//process the number of transmitter
		j = Func_Search_Char(0,WICWorkBufPTR,'\"');
		k = Func_Search_Char(j+1,WICWorkBufPTR,'\"');
		j++;
		for(i=0; i<8; i++){
			p->chrOtherSideNum[i] = 0xff;
		}
		i = 0;
		for(;j<k;j++){
			if((i&0x01) == 0){//even
				p->chrOtherSideNum[i/2]
					= p->chrOtherSideNum[i/2]&((chrWICWorkBuf[j]<<4) | 0x0f);
			}
			else{	//odd
				p->chrOtherSideNum[i/2]
					= p->chrOtherSideNum[i/2]&(chrWICWorkBuf[j] | 0xf0);
			}
			i++;
		}
		//process time
		j = Func_Search_Char(k+1,WICWorkBufPTR,'\"');
		k = Func_Search_Char(j+1,WICWorkBufPTR,'\"');
		j++;
		//
		pT = &(p->Time.chrYear);
		//
		for(i=0; ; i++){
			*pT = (chrWICWorkBuf[j]&0x0f)*10 + (chrWICWorkBuf[j+1]&0x0f);
			pT++;
			if(i==5) break;
			else if(i>=3) j+=4;
			else j+=3;
		}
		j++;
		//The coding field
		i=0;
		for(;j<WICWorkBufPTR;j++){
			if(chrWICWorkBuf[j] == ',') i++;
			if(i==3)break;
		}
		j++;
		p->chrProperty = chrWICWorkBuf[j] & 0x0f;
		//the length field
		p->SMLength = len;
		//
		j=start;
		for(i=0; i<len; i++){
			p->SMContent[i] = chrWICWorkBuf[j];
			j++;
		}
		//
		p->Next = SystemFile.SMTblHead;
		p->Front = 0xff;
		if(SystemFile.SMTblTail >SMTBLLEN) SystemFile.SMTblTail = item;
		SystemFile.SMTblHead = item;
		//save SM and head pointer
		FileSave(SYS_FILE_ID,
				(INT16U)((INT24U)p - (INT24U)&SystemFile),
				(INT8U rom *)p,
				sizeof(SM_TABLE_ITEM));
		Save_Domain(79,&SystemFile.SMTblHead);
		return(0);
	}
	return(1);
}


//This section of code is suit for process responses of Wavecom GSM module: Q2403A

/*************************************************************************************************************/
	                                                //How many responses are there
#define NUM_OF_NOD 100	                     //The number of nods. It must be larger than the actual value. The 
//responses conresponding 55 nods, the number of nods will not larger than the total number of effective bytes
#define END_OF_TREE 0xff

struct TblItem{
//	unsigned char ID;			
//	unsigned char Lvl;
	unsigned char ptr[30]; //The index of next nod. if it's an end nod, it's END_OF_TREE. if a invilade value, 
	//it's "0", point to the root Nod.
};

#pragma romdata EXTRAM
unsigned char rom asciimap[0x80];  //+, > and "A~Z" have to be maped to a smaller region, this is the map table
struct TblItem rom Nod[NUM_OF_NOD];                                                           //The nods itself
unsigned char nodmap[NUM_OF_NOD];                                      //a map to map the nod to response index


//The function to initialize tables and nod
void Make_Index_Table(void){
	unsigned char curNod,curResp,curChar,t1,t2;

	unsigned int i,j;
	unsigned char NumOfNod;
	NumOfNod = 1;
	//clear the Nod's data
	for(i=0;i<NUM_OF_NOD;i++){
		//Nod[i].ID = 0x00;
		//Nod[i].Lvl = 0;
		for(j=0;j<30;j++){
			Nod[i].ptr[j] = 0x0;
		}
	}
	//make the ascii code map table
	for(i=0;i<0x80;i++){
		if(i>='A' && i <='Z') asciimap[i] = i-'A'+3;	//ASCII code map to X - A +3
		else if(i=='>') asciimap[i] = 2;
		else if(i=='+') asciimap[i] = 1;
		else asciimap[i]=0;
	}
	//make the nods
	curResp = 0;
	for(;;){	
		curNod = 0;
		curChar = 0;
		for(;;){	
			t1 = chrResp[curResp][curChar];
			t1 = asciimap[t1];		
			if(Nod[curNod].ptr[t1] == 0){
				if(chrResp[curResp][curChar+1] == '\0'){
					Nod[curNod].ptr[t1] = END_OF_TREE;
					nodmap[curNod] = curResp;
					break;
				}
				Nod[curNod].ptr[t1] = NumOfNod;
				//Nod[NumOfNod].ID = chrResp[curResp][curChar];
				NumOfNod++;
				curNod = Nod[curNod].ptr[t1];
			}
			else{
				curNod = Nod[curNod].ptr[t1];
			}
			curChar++;
		}
		curResp++;
		if(curResp == sizeof(chrResp)/20) break;
	}
}


struct S_R Search_ch(void){
	unsigned char i,j,x,t1;
	struct S_R Result;
	j=0;
	for(i=0;i<WICWorkBufPTR;i++){
		t1 = chrWICWorkBuf[i];
		t1 = asciimap[t1];		
		if(Nod[j].ptr[t1] != END_OF_TREE){
			j = Nod[j].ptr[t1];
			if(j==0) j= Nod[j].ptr[t1];
		}
		else {
			Result.Pos = i;
			Result.R_Num = nodmap[j];
			return (Result);
		}
	}
	Result.Pos = 0;
	Result.R_Num = 0xff;
	return (Result);
}

/*
INT8U Save_SM(INT8U start, INT8U len){
	INT8U i,j,k;
	INT8U item;
	INT8U rom *ptrT;
	//find a empty item
	if(len>140) len=140;
	for(i=0; i<SMTBLLEN; i++){
		if(SystemFile.SMTbl[i].chrOtherSideNum[0] == 0xff) break;
	}
	if(i < SMTBLLEN){	//not illegal value
		item = i;
		//data example:
		//+CMT:"13705153921","02/05/17,10:43:07",129,0,4,5<CR><LF>
		//HELLO<CR><LF>
		//process the number of transmitter
		j = Func_Search_Char(0,WICWorkBufPTR,'\"');
		k = Func_Search_Char(j+1,WICWorkBufPTR,'\"');
		j++;
		for(i=0; i<8; i++){
			SystemFile.SMTbl[item].chrOtherSideNum[i] = 0xff;
		}
		i = 0;
		for(;j<k;j++){
			if((i&0x01) == 0){//even
				SystemFile.SMTbl[item].chrOtherSideNum[i/2]
					= SystemFile.SMTbl[item].chrOtherSideNum[i/2]&((chrWICWorkBuf[j]<<4) | 0x0f);
				//for test
				//DebugContent[i/2] = DebugContent[i/2] & ((chrWICWorkBuf[j]<<4) | 0x0f);
			}
			else{	//odd
				SystemFile.SMTbl[item].chrOtherSideNum[i/2]
					= SystemFile.SMTbl[item].chrOtherSideNum[i/2]&(chrWICWorkBuf[j] | 0xf0);
				//for test
				//DebugContent[i/2] = DebugContent[i/2] & (chrWICWorkBuf[j] | 0xf0);
			}
			i++;
		}
		//process time
		j = Func_Search_Char(k+1,WICWorkBufPTR,'\"');
		k = Func_Search_Char(j+1,WICWorkBufPTR,'\"');
		j++;
		//
		SystemFile.SMTbl[item].Time.chrYear = (chrWICWorkBuf[j]&0x0f)*10;
		j++;
		SystemFile.SMTbl[item].Time.chrYear += chrWICWorkBuf[j]&0x0f;
		j++;
		j++;
		//
		SystemFile.SMTbl[item].Time.chrMonth = (chrWICWorkBuf[j]&0x0f)*10;
		j++;
		SystemFile.SMTbl[item].Time.chrMonth += chrWICWorkBuf[j]&0x0f;
		j++;
		j++;
		//
		SystemFile.SMTbl[item].Time.chrDate = (chrWICWorkBuf[j]&0x0f)*10;
		j++;
		SystemFile.SMTbl[item].Time.chrDate += chrWICWorkBuf[j]&0x0f;
		j++;
		j++;
		//
		SystemFile.SMTbl[item].Time.chrHour = (chrWICWorkBuf[j]&0x0f)*10;
		j++;
		SystemFile.SMTbl[item].Time.chrHour += chrWICWorkBuf[j]&0x0f;
		j++;
		j+=2;
		//
		SystemFile.SMTbl[item].Time.chrMinute = (chrWICWorkBuf[j]&0x0f)*10;
		j++;
		SystemFile.SMTbl[item].Time.chrMinute += chrWICWorkBuf[j]&0x0f;
		j++;
		j+=2;
		//
		SystemFile.SMTbl[item].Time.chrSecond = (chrWICWorkBuf[j]&0x0f)*10;
		j++;
		SystemFile.SMTbl[item].Time.chrSecond += chrWICWorkBuf[j]&0x0f;
		//The coding field
		i=0;
		for(;j<WICWorkBufPTR;j++){
			if(chrWICWorkBuf[j] == ',') i++;
			if(i==3)break;
		}
		j++;
		SystemFile.SMTbl[item].chrProperty = chrWICWorkBuf[j] & 0x0f;
		//the length field
		SystemFile.SMTbl[item].SMLength = len;
		//
		j=start;
		for(i=0; i<len; i++){
			SystemFile.SMTbl[item].SMContent[i] = chrWICWorkBuf[j];
			j++;
		}
		//
		SystemFile.SMTbl[item].Next = SystemFile.SMTblHead;
		SystemFile.SMTbl[item].Front = 0xff;
		if(SystemFile.SMTblTail >SMTBLLEN) SystemFile.SMTblTail = item;
		SystemFile.SMTblHead = item;
		//save SM and head pointer
		FileSave(SYS_FILE_ID,
				(INT16U)((INT24U)&(SystemFile.SMTbl[item]) - (INT24U)&SystemFile),
				&(SystemFile.SMTbl[item]),
				sizeof(SM_TABLE_ITEM));
		Save_Domain(79,&SystemFile.SMTblHead);
		return(0);
	}
	return(1);
}


*/

⌨️ 快捷键说明

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