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

📄 jbmcomm.c

📁 电话PSTN线路上FSK处理软件。。。。。。。。。
💻 C
📖 第 1 页 / 共 3 页
字号:
	TxCmd(EQ);
}
// End function: NewDayTotal()

/***************************************************************
 *
 *		函	数: NewPowerOnOff()
 *		说	明: NEW模式上传开关机记录
 *
 **************************************************************/
void NewPowerOnOff(void)
{
	TxCmd(NEW_POWERONOFF);
	if(!RxCmd())
		return;
	if(bRecSBUF!=OK){
		bErrorCode=ERR_05;
		return;
	}
	bPaBuf=NEW_POWERONOFF_PA;			// 0x03;
	bNeBuf=NEW_POWERONOFF_NE;			// 0x00;
	if(!TxPaNe())
		return;
	GeneralReadData(1,NEW_POWERONOFF_ADDR,iPaNeNum,&aDataBuf);
	if(!TxData())
		return;
	TxCmd(EQ);
}
// End function: NewPowerOnOff()

/***************************************************************
 *
 *		函	数: NewSystem()
 *		说	明: NEW模式接收系统参数
 *
 **************************************************************/
void NewSystem(void)
{
	TxCmd(OK);
	if(!RxPaNe())
		return;
	if(iPaNeNum>NEW_SYSTEM_LIMIT){
		bErrorCode=ERR_05;				// 参数越限
		return;
	}
	if(!RxData())
		return;
	GeneralWriteData(NEW_SYSTEM_ADDR);
	// 计算并写入检验和
	bParaByte=CalcCSSubA(NEW_SYSTEM_ADDR,iPaNeNum);
	AutoWritePara(90);
	AutoWritePara(100);
	TxCmd(OK);
}
// End function: NewSystem()

/***************************************************************
 *
 *	函	数: NewCallStation()
 *	说	明: NEW模式接收寻呼台参数
 *
 **************************************************************/
void NewCallStation(void)
{
	TxCmd(OK);
	if(!RxPaNe())
		return;
	if(iPaNeNum>NEW_CALLSTATION_LIMIT){
		bErrorCode=ERR_05;				// 参数越限
		return;
	}
	if(!RxData())
		return;
	GeneralWriteData(NEW_CALLSTATION_ADDR);
	bParaByte=CalcCSSubA(NEW_CALLSTATION_ADDR,iPaNeNum);
	AutoWritePara(92);
	AutoWritePara(102);
	TxCmd(OK);
}
// End function: NewCallStation()

/***************************************************************
 *
 *		函	数: NewDiscount()
 *		说	明: NEW模式接收折扣参数
 *
 **************************************************************/
void NewDiscount(void)
{
	TxCmd(OK);
	if(!RxPaNe())
		return;
	if(iPaNeNum>NEW_DISCOUNT_LIMIT){
		bErrorCode=ERR_05;				// 参数越限
		return;
	}
	if(!RxData())
		return;
	GeneralWriteData(NEW_DISCOUNT_ADDR);
	bParaByte=CalcCSSubA(NEW_DISCOUNT_ADDR,iPaNeNum);
	AutoWritePara(91);
	AutoWritePara(101);
	TxCmd(OK);
}
// End function: NewDiscount()

/***************************************************************
 *
 *		函	数: NewIDDClass()
 *		说	明: NEW模式接收国际级数表
 *				命令代码:IDD_CLASS_NEW=0x34.
 *
 **************************************************************/
void NewIDDClass(void)
{
	TxCmd(OK);
	if(!RxPaNe())
		return;
	if(iPaNeNum>NEW_IDD_CLASS_LIMIT){
		bErrorCode=ERR_05;
		return;
	}
	if(!RxData())
		return;
	GeneralWriteData(NEW_IDD_CLASS_ADDR);
	bParaByte=CalcCSSubA(NEW_IDD_CLASS_ADDR,iPaNeNum);
	AutoWritePara(93);
	AutoWritePara(103);
	TxCmd(OK);
}
// End function: NewIDDClass()

/***************************************************************
 *
 *		函	数: NewDDDClass()
 *		说	明: NEW模式接收国内级数表
 *				命令代码:DDD_CLASS_NEW=0x37.
 *
 **************************************************************/
void NewDDDClass(void)
{
	TxCmd(OK);
	if(!RxPaNe())
		return;
	if(iPaNeNum>NEW_DDD_CLASS_LIMIT){
		bErrorCode=ERR_05;
		return;
	}
	if(!RxData())
		return;
	GeneralWriteData(NEW_DDD_CLASS_ADDR);
	bParaByte=CalcCSSubA(NEW_DDD_CLASS_ADDR,iPaNeNum);
	AutoWritePara(94);
	AutoWritePara(104);
	TxCmd(OK);
}
// End function: NewDDDClass()

/***************************************************************
 *
 *		函	数: NewLOCALClass()
 *		说	明: NEW模式接收本地级数表
 *				命令代码:LOCAL_CLASS_NEW=0x38.
 *
 **************************************************************/
void NewLOCALClass(void)
{
	TxCmd(OK);
	if(!RxPaNe())
		return;
	if(iPaNeNum>NEW_LOCAL_CLASS_LIMIT){
		bErrorCode=ERR_05;
		return;
	}
	if(!RxData())
		return;
	GeneralWriteData(NEW_LOCAL_CLASS_ADDR);
	bParaByte=CalcCSSubA(NEW_LOCAL_CLASS_ADDR,iPaNeNum);
	AutoWritePara(95);
	AutoWritePara(105);
	TxCmd(OK);
}
// End function: NewLOCALClass()

/***************************************************************
 *
 *		函	数: NewIDDTariff()
 *		说	明: NEW模式接收国际区号表
 *
 **************************************************************/
void NewIDDTariff(void)
{
	TxCmd(OK);
	if(!RxPaNe())
		return;
	if(iPaNeNum>NEW_IDD_TARIFF_LIMIT){
		bErrorCode=ERR_05;				// 参数越限
		return;
	}
	if(!RxData())
		return;
	GeneralWriteData(NEW_IDD_TARIFF_ADDR);
	bParaByte=CalcCSSubA(NEW_IDD_TARIFF_ADDR,iPaNeNum);
	AutoWritePara(96);
	AutoWritePara(106);
	TxCmd(OK);
}
// End function: NewIDDTariff()

/***************************************************************
 *
 *		函	数: NewDDDTariff()
 *		说	明: NEW模式接收国内区号表
 *				命令代码:DDD_TARIFF_NEW=0x34.
 *
 **************************************************************/
void NewDDDTariff(void)
{
	TxCmd(OK);
	if(!RxPaNe())
		return;
	if(iPaNeNum>NEW_DDD_TARIFF_LIMIT){
		bErrorCode=ERR_05;				// 参数越限
		return;
	}
	if(!RxData())
		return;
	GeneralWriteData(NEW_DDD_TARIFF_ADDR);
	bParaByte=CalcCSSubA(NEW_DDD_TARIFF_ADDR,iPaNeNum);
    AutoWritePara(97);
	AutoWritePara(107);
	TxCmd(OK);
}
// End function: NewDDDTariff()

/***************************************************************
 *
 *		函	数: NewLocalTariff()
 *		说	明: NEW模式接收本地区号表
 *				命令代码:LOCAL_TARIFF_NEW=0x35.
 *
 **************************************************************/
void NewLocalTariff(void)
{
	TxCmd(OK);
	if(!RxPaNe())
		return;
	if(iPaNeNum>NEW_LOCAL_TARIFF_LIMIT){
		bErrorCode=ERR_05;				// 参数越限
		return;
	}
	if(!RxData())
		return;
	GeneralWriteData(NEW_LOCAL_TARIFF_ADDR);
	bParaByte=CalcCSSubA(NEW_LOCAL_TARIFF_ADDR,iPaNeNum);
	AutoWritePara(98);
	AutoWritePara(108);
	TxCmd(OK);
}
// End function: NewLocalTariff()

/***************************************************************
 *
 *		函	数: NewQueryBills()
 *		说	明: NEW模式接收指定话单数据
 *
 **************************************************************/
void NewQueryBills(void)
{
	TxCmd(OK);						// 应答接收到的命令
	if(!RxPaNe())
		return;
	if((bPaBuf!=NEW_QUERYBILL_PA)||(bNeBuf!=NEW_QUERYBILL_NE)){
		bErrorCode=ERR_05;
		return;
	}
	if(!RxData())
		return;
	memcpy(&aNumBuf,&aDataBuf,8);		// 缓存匹配号码数组
	TxCmd(OK);
}
// End function: NewQueryBills()

/***************************************************************
 *
 *		函	数: NewReportQueryBills()
 *		说	明: NEW模式发送指定话单数据
 *				命令代码:REPORT_QUERYBILLS_NEW=0x41.
 *
 **************************************************************/
void NewReportQueryBills(void)
{
	byte j,bTemp;
	uint i,iAddr,ciBills;
	TxCmd(NEW_REPORT_QUERYBILLS);
	if(!RxCmd())
		return;
	if(bRecSBUF!=OK){
		bErrorCode=ERR_05;
		return;
	}
	// 计算欲回报话单的Pa.Ne
	ciBills=0;
	iAddr=NEW_BILLS_ADDR;
	for(i=0;i<500;i++,iAddr+=NEW_BILL_LEN){
		if(!SelectBill(iAddr))
			continue;
		for(j=0;j<NEW_BILL_LEN;j++){			// 存储找到的话单入aDataBuf
			Page(1);
			bTemp=XBYTE[iAddr+j];
			Page(5);
			if(j==0){
				if(bTemp==0xcc);				// 被叫号码
				else if(bTemp>0xb9)				// 异常号码
					break;
			}
			aDataBuf[ciBills++]=bTemp;
		}
	}
	if(ciBills==0){
		bPaBuf=0;
		bNeBuf=0;
	}
	else{
		bPaBuf=(byte)(ciBills/128);
		bNeBuf=(byte)(ciBills%128);
		if(bNeBuf==0){
			bNeBuf=128;
			--bPaBuf;
		}
	}
	if(!TxPaNe())
		return;
	if(ciBills!=0){
		if(!TxData())
			return;
	}
	TxCmd(EQ);
}
// End function: NewReportQueryBills()

/***************************************************************
 *
 *		函	数: NewExpandPara()
 *		说	明: NEW模式接收管理机下传的扩充参数
 *
 **************************************************************/
void NewExpandPara(void)
{
	TxCmd(OK);
	if(!RxPaNe())
		return;
	if(iPaNeNum>NEW_EXPAND_LIMIT){
		bErrorCode=ERR_05;				// 参数越限
		return;
	}
	if(!RxData())
		return;
	GeneralWriteData(NEW_EXPAND_ADDR);
	AutoWritePara(109);
	TxCmd(OK);
}
// End function: NewExpandPara()

/***************************************************************
 *
 *		函	数: NewQueryPara()
 *		说	明: NEW模式接收管理机下传的扩充参数
 *
 **************************************************************/
void NewQueryPara(void)
{
	TxCmd(NEW_QUERY_PARA);
	if(!RxCmd())
		return;
	if(bRecSBUF!=OK){
		bErrorCode=ERR_05;
		return;
	}
	PrepareQueryPara();
	if(!TxPaNe())
		return;
	if(iPaNeNum!=0){
		if(!TxData())
			return;
	}
	TxCmd(EQ);
}
// End function: NewQueryPara()

void PrepareQueryPara(void)
{
	bPaBuf=0x00;
	bNeBuf=0x00;
	iPaNeNum=bPaBuf*128+bNeBuf;
}
// End function: PrepareExpandPara()

/************************************************************
 *
 *
 *		函	数: SendTelNum()
 *		说	明: 根据系统模式,向系统发送相应格式的本机电话号码
 *
 *
 *************************************************************/
void SendTelNum(bool fSelect)
{
	byte i;
	byte bCheckSum;
	memset(&aParaBuf,0xcc,8);
	AutoReadPara(47);
	if(bParaByte==0x88)
		AutoReadPara(210);					// 按OLD模式传电话号码
	else
		AutoReadPara(2);
	if(fWorkMode){
		if(fSelect)
			memcpy(&aDataBuf,&aParaBuf,8);
		else
			memset(aDataBuf,0x11,9);
	}
	else{
		if(!fSelect){
			for(i=0;i<4;i++){
				aDataBuf[2*i]=aParaBuf[i]>>4;
				aDataBuf[2*i+1]=aParaBuf[i]&0x0f;
			}
		}
		else{
			memcpy(&aDataBuf,&aParaBuf,4);
			memset(&aDataBuf[4],0xcc,4);
		}
	}
	//
	for(i=0,bCheckSum=0;i<8;i++){
		TxByte(aDataBuf[i]);
		bCheckSum+=aDataBuf[i];
	}
	if(fSelect)
		TxByte(~bCheckSum);
	else{
		if(fWorkMode)
			TxByte(0x11);
		else
			TxByte(bCheckSum);
	}
}
// End function: SendTelNum()

/*********************************************************
 *
 *	函	数: ExitPro()
 *	说	明: CML644A设为低功耗
 *			显示出错代码或成功提示
 *			最后转入硬件初始化过程
 *
 ********************************************************/
void ExitPro(void)
{
	ResetModem();
	if(bErrorCode!=ERR_NO){
		if((bErrorCode==ERR_04)||(bErrorCode==ERR_05)||(bErrorCode==ERR_08)||(bErrorCode==ERR_02)){
			Close(MLD);						//判断退出是否是拔线导致
			Close(RLY);
			Delay5MS(10);
			InBuf=ReadByte(IN_CE,6);
			Open(RLY);
			if((InBuf&0x08)!=0){
				AutoReadPara(77);
				if(bParaByte>=5)
					bParaByte=0;
				if(bParaByte==5){
					AutoReadPara(57);
					if(bParaByte==1);
					else{
						bParaByte=1;
						AutoWritePara(57);
					}
				}
				else
					bParaByte++;
				AutoWritePara(77);
			}
		}
		DispErrorCode();
		bFailTimes++;
		if((bErrorCode==ERR_21)||			//管理系统无此用户时,不重复呼叫
		  (bErrorCode==ERR_31))
			bFailTimes=24;
	}
	else{
		Page(6);
		XBYTE[PARA_76]=0;
		Page(5);
		DispOK(3);
		bParaByte=0;
		AutoWritePara(77);
		CheckSumTest();						//检查各种重要参数检验和
		if(bErrorCode!=ERR_NO){
			if(bCallReason==NEW_TEST)
				WriteData(1,PARA_90,9,&aNumBuf);
			else if(bCallReason==OLD_TEST)
				WriteData(1,PARA_223,9,&aNumBuf);
			bFailTimes++;
		}
		else
			bFailTimes=0;
	}
	Close(MLD);
	Close(POWER_ON);
	bStatusWord=S_HARDWAREINIT;
}
// End function: ExitPro()

byte SearchCmd(byte bCmd)
{
	byte i;
	for(i=0;i<40;i++){
		if(bCmd==CmdDisp[2*i])
			return CmdDisp[2*i+1];
	}
	bErrorCode=ERR_33;					// 通讯异常命令
	return 0xff;
}
// End function: SearchCmd()

/*********************************************************
 *
 *	函	数: FlashComm()
 *	说	明: 通信过程中闪烁FLASH符号.
 *
 ********************************************************/
void FlashComm(void)
{
	fFlash=~fFlash;
	if(fFlash)
		DispSymbol(LARGE_FLASH);
	else
		DispSymbol(LARGE_UNFLASH);
}
// End function: FlashComm()

//
//The End of jbMcomm.c
//



/***********************************************************************
*
*		函数名:byte RxFskByte(byte rxfsk)
*		说  明:从FSK接收缓存区内提取数据。接收缓存区为aCallID[],
*               aCallID[97]是前指针,aCallID[98]是后指针,
*               aCallID[99]是当前接收缓存区中的数据个数。
*		入口值:
*		返回值:
*		日  期:
*
***********************************************************************/

byte RxFskByte(byte * rxfsk)
{
	byte btemp;
	btemp=0;
	if(aCallID[99]>0){
		*rxfsk=aCallID[aCallID[97]];
		aCallID[97]=(aCallID[97]+1)%97;
		aCallID[99]--;
		btemp=1;
	}
	return btemp;
}




/***********************************************************************
*
*		函数名:void Fsk_0_1_Modu(byte binar)
*		说  明:将‘1’调制为1300Hz三角波,将‘0’调制为2100Hz三角波
*				波形维持时间为字节中的一位,即833us(1200bps的速度)
*		入口值:bBinar!=0代表调制‘1’,bBinar==0代表调制‘0’
*		返回值:
*		日  期:
*
***********************************************************************/
byte code aVoltage[12]={
						 0, 5,10,15,20,25,
						30,25,20,15,10, 5};
void Fsk_0_1_Modu(byte bBinar)
{
	byte cycl=0;
	//------‘1’调制------//				//769us
	if(bBinar){
		while(1){							//1300Hz,一周期一共要1418条指令,每级70条指令
			XBYTE[PR_CE]=aVoltage[bCurrentVoltage];
			if(bCurrentVoltage++>10){		//在bCurrentVoltage=20处会比别的级多2个指令
				bCurrentVoltage=0;
			}
			_nop_();					//766.5us,每级63.875us
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			_nop_();
			cycl++;
			if(cycl==13){
				MD_CLK=~MD_CLK;
				break;
			}
		}
	}
	//------‘0’调制------//				//476.2us
	else{
		while(1){							//2100Hz,一周期一共要878条指令,每级43条指令
			XBYTE[PR_CE]=aVoltage[bCurrentVoltage];

			if(bCurrentVoltage++>10){		//在bCurrentVoltage=20处会比别的级多2个指令
				bCurrentVoltage=0;
			}
			_nop_();					//473.6us,每级39.47us
			_nop_();
			_nop_();
			cycl++;
			if(cycl==21){
				MD_CLK=~MD_CLK;
				break;
			}
		}
	}
}


/***********************************************************************
*
*		函数名:void TxFskByte(void)
*		说  明:1-1300Hz 分为10级 每个周期(1/1300)/20=76.9us/2=34us
*               0-210Hz  分为10级 每个周期(1/2100)/20=47.6us/2=24us
*               波特率12000bps  每位周期 1/1200=833us;
*		入口值:
*		返回值:
*		日  期:
*
***********************************************************************/



void TxFskByte(byte bByte)
{
	byte i,bTemp;

	bTemp=0x01;
	Fsk_0_1_Modu(1);

	// 发送起始位 //
	Fsk_0_1_Modu(0);

	// 发送8位数据 //
	for(i=0;i<8;i++){
		Fsk_0_1_Modu(bByte&bTemp);
		bTemp<<=1;
	}

	// 发送停止位 //
	Fsk_0_1_Modu(1);

//	if(bByte==0x80||bByte<4){
//		for(i=0;i<7;i++){
			Fsk_0_1_Modu(1);
//		}
//	}
}

void Fsk_2225Hz(void)
{
	byte cycl=0;
	//------‘2225’调制------//				//1/2225=449.4us
	while(1){
		XBYTE[PR_CE]=aVoltage[bCurrentVoltage];
		if(bCurrentVoltage++>10){		//在bCurrentVoltage=20处会比别的级多2个指令
			bCurrentVoltage=0;
		}
		_nop_();					//449.4us,每级37.5us
		_nop_();

		cycl++;
		if(cycl==22){				//833us/37.5=22
			MD_CLK=~MD_CLK;
			break;
		}
	}
}

⌨️ 快捷键说明

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