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

📄 hs.cpp

📁 这是一个手机校准程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	SioSendString(buf);
  }


//*******************************************************************************
// 6/27/00
// Modified so that Diana radios will exit the sub-cmd level after
// setting the Tx power. Diana has 2-level commands for Tx.
void hs::HS_SetTxLev(UInt16 TxPwrIndex)
  {
	Int8 buf[30];

	if(pac_cal_type==INFINEON || pac_cal_type==CONEXANT)
    {
    sprintf(buf,"ramp %d\n",TxPwrIndex);
	  SioSendString(buf);
    }
  else  
    {
    }
  }


//*******************************************************************************
void hs::HS_SetDacVal(UInt16 DacVal)
  {
	Int8 buf[30];

	sprintf(buf,"DACVAL %d\n",DacVal);
	SioSendString(buf);
  }

//*******************************************************************************
void hs::HS_SetPeakDAC(UInt16 TxLevel, UInt16 Peak)
  {
  char buf[256];

	sprintf(buf,"RAMP_SELECT %d\n",TxLevel);
	SioSendString(buf);
  Sleep(10);

  sprintf(buf,"PEAK %d\n",Peak);
  SioSendString(buf);
  Sleep(10);

  sprintf(buf,"EXIT\n");
  SioSendString(buf);
  Sleep(10);
  }

//*******************************************************************************
void hs::HS_SetRamp(UInt16 *RampTable)
  {
	Int8 buf[200];
	UInt16 *p;

	p = RampTable;
	sprintf(buf,"RAMPUP %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",p[0],
		p[1],p[2],p[3],p[4],p[5],p[6],
		p[7],p[8],p[9],p[10],p[11],p[12],
		p[13],p[14],p[15]);
	SioSendString(buf);

	sprintf(buf,"RAMPDOWN %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",p[16],
		p[17],p[18],p[19],p[20],p[21],p[22],
		p[23],p[24],p[25],p[26],p[27],p[28],
		p[29],p[30],p[31]);
	SioSendString(buf);
  }

//*******************************************************************************
void hs::HS_SetRxAgc(UInt16 TargetRxLevDb)
  {
	Int8 buf[30];

	sprintf(buf,"agc %d\n",TargetRxLevDb);
	SioSendString(buf);
  }

//*******************************************************************************
void hs::HS_SetStart(void)	
  {
	Int8 buf[30];

	sprintf(buf,"start 0\n");
	SioSendString(buf);
  }

//*******************************************************************************
void hs::HS_SetStop(void)
  {
	Int8 buf[30];

	sprintf(buf,"stop\n");
	SioSendString(buf);
  }

//*******************************************************************************
void hs::HS_SendOneLine(Int8 *cmd)
  {
	Int8 *p;
	UInt16 i;

	p = cmd;
	for(i=0; i<50; i++)
    {
		if(*p++ == NULL) break;
    }
	p--;
	*p = '\n';
	p++;
	*p = NULL;

	SioSendString(cmd);
  }

//******************************************************************************
//--- send one char to UART when Tx buffer empty
BOOL hs::SioSendString(Int8	*ch_p)
  {
	DWORD SentLength;
	UInt8 ch;
	DWORD dwBytesSent = 0;
	DWORD ErrorFlags;
	COMSTAT	ComStat;
	Int8	buf[256];
  Int8  buf1[256];
	
	ch = strlen(ch_p);
	
	while(!WriteFile( CommDesc.Sio, ch_p, strlen(ch_p), &SentLength, &(CommDesc.olWrite) ))
    {
		if( GetLastError() == ERROR_IO_PENDING)
      {
			while ( !GetOverlappedResult( CommDesc.Sio, &(CommDesc.olWrite), &SentLength, TRUE) )
        {
				if( GetLastError() == ERROR_IO_INCOMPLETE ) 
          {
					continue;
          }
				else
          {
					ClearCommError( CommDesc.Sio, &ErrorFlags, &ComStat);
					break;
          }
        }
			break;
      }
		else
      {
			ClearCommError( CommDesc.Sio, &ErrorFlags, &ComStat);
      }
    }
// Jan 15, 2000
// Bin Lu reports that in Calibrate mmode the phone Rx buffer overflows
// so add delay after transmission to prevent closely spaced bursts
	Sleep(100);

// log the string
  strcpy(buf,"SIO Tx: ");
  strcpy(buf1,ch_p);
// strip off the trailing cr
  if(strlen(buf1)>1)
    {
    *(buf1+strlen(buf1)-1)=0x00;
    }
  strcat(buf,buf1);
  HS_LogSIO(buf);

	return SentLength;
  }

//*******************************************************************************
BOOL hs::SioReadOneLine(Cmd_t *cmd_string,UInt8 *num_parm,Parm_t *parm)
  {
	UInt8 ch;
	UInt8 buf[160];
	UInt8 *buf_p;
	Int8 *p;	
	Int16 value;
	BOOL is_valid;
	BOOL	is_lineend;
	Int8	buf1[100];
	*num_parm = 0;
	//Save one line command characters into buf.
	buf_p = buf;

	for(;;)
    {
		if(ReceiveChar(&ch) )
      {
			if( (ch == LINE_FEED) || (ch == CARRIAGE_RETURN ) ) 
        {
				*buf_p = STRING_END;
				break;
        }
			else if(ch == BACKSPACE_KEY) //BackSpace key
        {
				buf_p--;
        }
			else
        {
				*buf_p++ = ch;
        }
      }
		else
      {
			//waiting time is over
			return FALSE;
      }
    }

	sprintf(buf1,"SIO Rx: %s", buf);
  HS_LogSIO(buf1);

	//Receive command from the input buffer first.
	buf_p = buf;
	p = *cmd_string;
	for(;;)
    {
		ch = *buf_p++;

		if( ( ch >= 'A' ) && ( ch <= 'Z') ){}
		else if( ( ch >= 'a' ) && ( ch <= 'z' ) )
      {
			ch -= 32;
      }
		else if(( ch >='0' ) && (ch <= '9'))
      {
      }
		else if(( ch == SPACE_KEY ) || ( ch == TAB_KEY ) )
      {	//Command has been received successfully
			*p = STRING_END;
			break;
      }
		else if( ch == STRING_END)
      {
			*p = STRING_END;
			return TRUE;
      }
		else
      {
      }

		*p++ = ch;
    }

	//Receive parameters
	for(;;)
    {
		if(!GetOneNum(&buf_p, &is_valid, &value, &is_lineend) )
      {
      }
		else
      {
			if(is_valid)
        {
				(*parm)[*num_parm] = value;
				(*num_parm)++;
				if(is_lineend) break;
        }
			else if(is_lineend) break;
      }
    }

	return TRUE;
  }

//******************************************************************************

BOOL hs::GetOneNum(UInt8 **string_p, BOOL	*is_valid, Int16 *value, BOOL *is_lineend)
  {
	UInt16 d = 0;
	UInt16 cnt = 0;
	UInt16 ch;
	BOOL hex_mode = FALSE;
	BOOL negtive	 = FALSE;	

	*is_valid = FALSE;
	*is_lineend = FALSE;
	//Get rid of all space characters.
	do
    {
		ch = **string_p;
		(*string_p)++;
    }
	while (( ch == SPACE_KEY ) || ( ch == TAB_KEY ) );
	
	//check if it is '-' '0x' or '+'
	if ( ch == '0')
    {
		ch = **string_p;
		if( ( ch == 'x' )|| ( ch == 'X' ))
      {
			hex_mode = TRUE;
			(*string_p)++;
      }
		else 
      {  
		  (*string_p)--;
      }	
    }
	else if( ch =='-')
    {
		negtive = TRUE;
    }
	else if( ch == '+') {}
	else { (*string_p)--; }


	for(;;)
    {
		ch = **string_p;
		(*string_p)++;
		if( hex_mode)
      {
			if( (ch >= 'a') && ( ch <= 'f'))
        {
				d = ( d * 16 ) + ( ch - 'a' + 10 );
				cnt++;
        }
			else if( ( ch >='A') && ( ch <= 'F') )
        {
				d = ( d * 16 ) + ( ch -'A' + 10 );
				cnt++;
        }
			else if( ( ch >= '0' ) && ( ch <= '9'))
        {
				d = ( d * 16 ) + ( ch -'0');
				cnt++;
        }
			else if( ( ch == SPACE_KEY ) || ( ch == TAB_KEY ) )
        {
				if(cnt !=0)	*is_valid = TRUE;
				break;
        }
			else if( ch == STRING_END )
        {
				*is_lineend = TRUE;
				break;
        }
			else
        {
				return FALSE;
        }
      }
		else 
      {  // decimal mode 
			if( ( ch >= '0' ) && ( ch <= '9'))
        {
				d = ( d * 10 ) + ( ch -'0');
				cnt++;
        }
			else  if( ch == STRING_END) 
        {
				*is_lineend = TRUE;
				break;
        }
			else if(( ch == SPACE_KEY ) || ( ch == TAB_KEY ) )
        {
				if(cnt !=0)	*is_valid = TRUE;
				break;
        }
			else return FALSE; 
      }
    }

	if(*is_lineend)
    {
		if(cnt !=0)		*is_valid = TRUE;
    }

	if(*is_valid)
    {
		if(negtive)
      {
			*value = 0 - d;
      }
		else
      {
			*value = d;
      }
    }
	return TRUE;
}

//*******************************************************************************
BOOL hs::SioPurge()
  {
  return PurgeComm( CommDesc.Sio, PURGE_RXCLEAR ) ;
  }

//*******************************************************************************
void hs::SioSendCR()
  {
	SioSendString("\n");
  }

⌨️ 快捷键说明

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