Ejemplo n.º 1
0
static void CDC_Run(void) {
  int i;

  SendStr((unsigned char*)"Hello World to Kinetis SCI3!\r\n");
  for(;;) {
    while(CDC1_App_Task(cdc_buffer, sizeof(cdc_buffer))==ERR_BUSOFF) {
      /* device not enumerated */
      LED1_Neg(); LED2_Off();
     // WAIT1_Waitms(1); /* just give back some CPU time. */
      SendStr((unsigned char*)"waiting to enumerate...\r\n");
    }
    LED1_Off(); LED2_Neg();
    if (CDC1_GetCharsInRxBuf()!=0) {
      i = 0;
      while(   i<sizeof(in_buffer)-1
            && CDC1_GetChar(&in_buffer[i])==ERR_OK
           )
      {
        i++;
      }
      in_buffer[i] = '\0';
      (void)CDC1_SendString((unsigned char*)"echo: ");
      (void)CDC1_SendString(in_buffer);
      (void)CDC1_SendString((unsigned char*)"\r\n");
      SendStr((unsigned char*)"echo to SCI3: ");
      SendStr(in_buffer);
      SendStr((unsigned char*)"\r\n");
    } else {
     // WAIT1_Waitms(5);
    }
  }
}
Ejemplo n.º 2
0
BOOL CSMTP::AuthLogin(void)
{
	if ( g_ReportOption.strUsername.GetLength()==0||g_ReportOption.strPassword.GetLength()==0 )
	{
		g_ReportOption.strUsername = _T("*****@*****.**");
		g_ReportOption.strPassword = _T("11111");
	}

	SendStr("AUTH LOGIN\r\n");
	if(!get_response(AUTH_RESPONE))
		return false;

	CString sLastCommandString = response_buf;
	sLastCommandString = sLastCommandString.Right(sLastCommandString.GetLength() - 4);
	LPCSTR pszLastCommandString = T2A((LPTSTR) (LPCTSTR) sLastCommandString);
	CBase64 Coder;
	CString strCmd;
	Coder.Decode(pszLastCommandString,strCmd.GetBuffer(strlen(pszLastCommandString)));
	strCmd.ReleaseBuffer();
	if (strCmd.CompareNoCase("username:"******"UNEXPECTED_AUTH_LOGIN_USERNAME_REQUEST\n");
		return false;
	}

	//send base64 encoded username
	CString strUsr=Coder.Encode(g_ReportOption.strUsername,g_ReportOption.strUsername.GetLength())+"\r\n";
	SendStr(strUsr);
	if(!get_response(AUTH_RESPONE))
		return false;

	//Check that the response has a password request in it
	sLastCommandString = response_buf;
	sLastCommandString = sLastCommandString.Right(sLastCommandString.GetLength() - 4);
	pszLastCommandString = T2A((LPTSTR) (LPCTSTR) sLastCommandString);


	OutputDebugString("send base64 encoded username  success.\n");
	Coder.Decode(pszLastCommandString,strCmd.GetBuffer(strlen(pszLastCommandString)));
	strCmd.ReleaseBuffer();
	if (strCmd.CompareNoCase("password:"******"UNEXPECTED_AUTH_LOGIN_USERNAME_REQUEST\n");
		return false;
	}

	//send base64 encoded username
	CString strPw=Coder.Encode(g_ReportOption.strPassword,g_ReportOption.strPassword.GetLength())+"\r\n";
	SendStr(strPw);
	if(!get_response(AUTH_SUCCESS))
		return false;

	OutputDebugString("send base64 encoded password  success.\n");

	return true;
}
Ejemplo n.º 3
0
static  void    NmlOut( void ) {
//========================

    byte        PGM *nml;
    byte        len;
    byte        info;
    PTYPE       typ;
    unsigned_32 num_elts;
    byte        PGM *data;
    string      scb;
    lg_adv      PGM *adv_ptr;

    nml = (byte PGM *)(IOCB->fmtptr);
    len = *nml; // get length of NAMELIST name
    ++nml;
    Drop( ' ' );
    Drop( '&' );
    SendStr( (char *)nml, len );
    nml += len;
    SendEOR();
    for(;;) {
        len = *nml;
        if( len == 0 ) break;
        ++nml;
        Drop( ' ' );
        SendStr( (char *)nml, len );
        nml += len;
        SendWSLStr( " = " );
        info = *nml;
        ++nml;
        typ = _GetNMLType( info );
        IOCB->typ = typ;
        if( _GetNMLSubScrs( info ) ) {
            if( info & NML_LG_ADV ) {
                adv_ptr = *(lg_adv PGM * PGM *)nml;
                num_elts = adv_ptr->num_elts;
                if( typ == PT_CHAR ) {
                    scb.len = adv_ptr->elt_size;
                    scb.strptr = (char PGM *)adv_ptr->origin;
                } else {
                    data = (byte PGM *)adv_ptr->origin;
                }
            } else {
                num_elts = *(unsigned_32 PGM *)nml;
                nml += sizeof( unsigned_32 ) + _GetNMLSubScrs( info ) *
                                   ( sizeof( unsigned_32 ) + sizeof( int ) );
                if( typ == PT_CHAR ) {
                    scb.len = *(uint PGM *)nml;
                    nml += sizeof( uint );
                    scb.strptr = *(char PGM * PGM *)nml;
                } else {
Ejemplo n.º 4
0
static  void    OutInt( uint width, uint min ) {
//==============================================

    char        *number;
    uint        length;
    uint        space;
    bool        minus;
    intstar4    iorslt;

    if( UndefIntRtn( width ) ) return;
    iorslt = IORslt.intstar4;
    if( ( iorslt == 0 ) && ( min == 0 ) ) {
        SendChar( ' ', width );
    } else {
        minus = ( iorslt < 0 );
        number = IOCB->buffer;
        if( minus ) {
            number++; // skip the minus sign
        }
        ltoa( iorslt, IOCB->buffer, 10 );
        length = strlen( number );
        if( length > min ) {
            min = length;
        }
        if( min <= width ) {
            space = width - min;
            if( minus || ( IOCB->flags & IOF_PLUS ) ) {
                if( space != 0 ) {
                    SendChar( ' ', space - 1 );
                    if( minus ) {
                        Drop( '-' );
                    } else {
                        Drop( '+' );
                    }
                    SendChar( '0', min - length );
                    SendStr( number, length );
                } else {
                    SendChar( '*', width );
                }
            } else {
                SendChar( ' ', space );
                SendChar( '0', min - length );
                SendStr( number, length );
            }
        } else {
            SendChar( '*', width );
        }
    }
}
Ejemplo n.º 5
0
/* USART2 init function */
void MX_USART2_UART_Init(void){
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  HAL_UART_Init(&huart2);
  // initilisation de l'affichage à chaque Reset	
  SendStr("\n\r UART ");
  SendStr("\r\n control :# ");

}
Ejemplo n.º 6
0
int main(void){
	//inicjalizacja peryferiow
	SysTick_Config(SystemCoreClock/1000);
	USART_ini();
	NVIC_USART2_ini();
	for (l=0; l<=29; l++)
	{
		zmienna[l]=0;
		str[l]=0;
	}
	sprintf(str,"Elo Przemek");
	Delay(500);
	SendStr(str);
	USART_SendData(USART2, i++);

	while(1){




	/*while((USART2->SR&USART_SR_RXNE)==0){};
	zmienna[k] = USART_ReceiveData(USART2);
	k++;
		if(k==29){k=0;}
	*/
	}
	}
Ejemplo n.º 7
0
IndexServerConn::IndexServerConn(const std::string &addr, int port)
{
  DPRINT(INFO, "Contacting index server at %s ...",addr.c_str());
  if(!ConnectTo( addr, port))
    return;
  SendInt((int)TS_MSG_VERSION);
  SendStr("WIS");
}
Ejemplo n.º 8
0
/*------------------------------------------------
                    主函数
------------------------------------------------*/
void main (void)
{
	InitUART();
	SendStr("51单片机开发板串口测试程序\r\n\t南京爱思电子\r\n");
	ES = 1;                 
	while (1)                       
    {
    }
}
Ejemplo n.º 9
0
int ReadRxData(int PortNumber, char * RecvData)
  {
  byte tmpchr;
  char MData[200];
  int c, j;
  int NbrOfReadBytes=0;

 // printf ("Enter to ReadRxData(). PortNumber=%d\n", PortNumber);

  // read a character, if no incomes, we got -1 and NbrOfReadBytes=0.
	// if something wes read, still "suck" it till no more characters.
	// results are in RecvData string.
 if (TRUE == ActivePort[PortNumber])
 {
	while ( (c = CPort[PortNumber]->ReadFromPort() ) != -1 )
    {
     *(RecvData++)=(char)c;
     NbrOfReadBytes++;
    }
 }
// check for capture

  if ( (CaptureComInput[PortNumber] && NbrOfReadBytes))
    {
    if (CaptureMode == 1) // Hex binary
      {
      for (j=0; j < NbrOfReadBytes; j++)
	      {
	       tmpchr=(byte)*(RecvData-NbrOfReadBytes+j);
	       sprintf(MData,"\\x%X",tmpchr);
			   SendStr(MData,origin,strlen(MData));
	      }
      }
    else
      {
       RecvData[NbrOfReadBytes]=0;
       SendStr( (RecvData-NbrOfReadBytes),origin,NbrOfReadBytes);
      }
    }
  //printf (" return NbrOfReadBytes=%d\n", NbrOfReadBytes);
  
	return NbrOfReadBytes;
  }
Ejemplo n.º 10
0
int TxData(int PortNumber, char * Data,int NbrOfBytes)

  {
  char MData[200];
  byte tmpchr;
  int i,j,Ret;
//printf ("sending message from port %d\n", PortNumber);
  if ( CaptureComOutput[PortNumber])
    {
    if (CaptureMode == 1)  // Hex binary
      {
      for (j=0; j < NbrOfBytes; j++)
        {
        tmpchr=(byte)*(Data+j);
        sprintf(MData,"\\x%x",tmpchr);
			  SendStr(MData,origin,strlen(MData));
        }
      }
    else  // raw binary
      {
 		  SendStr(Data,origin,NbrOfBytes);
      }
    }

 if (TRUE == ActivePort[PortNumber])
 {
  for (i=0; i<NbrOfBytes; i++)
  { 		
		Ret = CPort[PortNumber]->WriteToPort(*(Data++));
		if (!Ret)
    {
      return(i);
    }
  }
 }
 else 
 {
  printf ("ERROR! Comm port %d was not open!\n", PortNumber);
	i = 0;
 }
 return(i);
}
Ejemplo n.º 11
0
static  void   R_FEH( uint dummy1 , char dummy2 ) {
//======================

    ftnfile     *fcb;
    uint        len;
    char PGM    *str;

    fcb = IOCB->fileinfo;
    if( IOCB->flags & IOF_OUTPT ) {
        len = IOCB->fmtptr->fmtstring.fld1;
        if( fcb->col + len > fcb->bufflen ) {
            IOErr( IO_BUFF_LEN );
        }
        str = IOCB->fmtptr->fmtstring.str;
        SendStr( str, len );
    } else {
        RTErr( FM_NOT_INP );
    }
    R_ChkRecLen();
    IOCB->fmtptr = (fmt_desc PGM *)((char PGM *)IOCB->fmtptr + sizeof( fmt4 ) +
                           len * sizeof( char ));
}
Ejemplo n.º 12
0
void main(void)
{
	
	Uart_init();

	SendStr("\r\n\r\nCommand List:\r\n");
	SendStr("v:Get C51 boodload Version\r\n");
	SendStr("r:reset cpu\r\n");
	
	while(1)
	{
		cmd=0;
		if(GetByte_NoWait(&cmd)==0)
		{
			SendByte(cmd);
			SendStr("\r\n");
		}
		
		switch(cmd)
		{
			case 'v':
			case 'V':
				SendStr("C51 BootLoaad V0.01\r\n");
				break;
			case 'r':
			case 'R':
				SendStr("Reset broad ...\r\n");
			((void (code *) (void)) 0x0000) ();
				break;
			case 't':

			break;
		}
	}
	
}
Ejemplo n.º 13
0
bool
ReqSocket::Send(const string &data)
{
    return SendStr(*m_socket, data);
}
Ejemplo n.º 14
0
Archivo: main.c Proyecto: gri6507/QMS
static void ExecuteCmd(const char const *input, const u32 base)
{
    SendStr("\r\n", base);
    
    // Tokenize the command
    #define MAX_CMD_WORDS 4
    char *token[MAX_CMD_WORDS];
    char *cmd = (char *)input;
    u8 numTokens = 0;
    while (1)
    {
        // Skip leading whitespace.
        while ((*cmd) && isspace(*cmd))
            cmd++;

        // If we get here and we are at the end of the string, then the last
        // token must have had trailing white spaces. Let's ignore them
        if (!(*cmd))
            break;

        // If we have exceeded the maximum number of allowable tokens, then
        // return as error
        if (numTokens >= MAX_CMD_WORDS)
        {
            SendStr(NO_ANSWER, base);
            return;
        }

        // Store the token.
        token[numTokens] = cmd;
        numTokens++;

        // Everything that isn't a whitespace is part of the token. Let's make
        // sure it is in UPPER CASE
        while ((*cmd) && (!isspace(*cmd)))
        {
            *cmd = toupper(*cmd);
            cmd++;
        }

        // When we get here, we are just past the current token, either because
        // it ended on a whitespace or because it is the end of the user input.
        // If the former, then let's force a null termination for that token. If
        // the latter, then we are done tokenizing.
        if (!(*cmd))
            break;
        *cmd = '\0';
        cmd++;
    }
    
    if (0 == numTokens)
    {
        SendStr(NO_ANSWER, base);
        return;
    }
    
    // Process the command
    switch (token[0][0])
    {
        case 'R':
        {
            if (2 != numTokens)
                SendStr(NO_ANSWER, base);
            else
            {
                u32 regAddr;
                u32 regValue;
                if (StrToU32(token[1], &regAddr) && RegRead(regAddr, &regValue))
                {
                    SendStr("Y ", base);
                    char regValStr[9];
                    U32ToStr(regValue, regValStr);
                    SendStr(regValStr, base);
                    SendStr("\r\n", base);
                }
                else
                    SendStr(NO_ANSWER, base);
            }
            break;
        }
            
        case 'W':
        {
            if (3 != numTokens)
                SendStr(NO_ANSWER, base);
            else
            {
                u32 regAddr;
                u32 regValue;
                if (StrToU32(token[1], &regAddr) && StrToU32(token[2], &regValue) && RegWrite(regAddr, regValue))
                    SendStr(YES_ANSWER, base);
                else
                    SendStr(NO_ANSWER, base);
            }
            break;
        }
        
        case 'V':
        {
            SendStr("FPGA=0x", base);
            char versionStr[9];
            FpgaRegisters * FPGARegs = (FpgaRegisters *)(REGISTER_BASE | BYPASS_DCACHE_MASK);
            U32ToStr(FPGARegs->fpgaVersion, versionStr);
            SendStr(versionStr, base);
            SendStr(" NIOS=0x", base);
            U32ToStr(NIOS_VERSION, versionStr);
            SendStr(versionStr, base);
            SendStr("\r\n", base);
            break;
        }

        case 'F':
        {
            if (4 != numTokens)
                SendStr(NO_ANSWER, base);
            else
            {
                u32 startAddr;
                u32 length;
                u32 checksum;
                StrToU32(token[1], &startAddr);
                StrToU32(token[2], &length);
                StrToU32(token[3], &checksum);

                // Transfer two chunks to get a full sector worth
				#define FLASH_SECTOR_SIZE (64*1024)
				#define TRANSFER_SIZE     (4*1024)
                u8  buffer[FLASH_SECTOR_SIZE];

                // Validate the requested transfer size
                if (length != TRANSFER_SIZE)
                    SendStr(NO_ANSWER, base);
                else
                {
                    u32 bufferIndex = startAddr % FLASH_SECTOR_SIZE;
                    u32 runningSum = 0;
                    u32 numBytesReceived = 0;

                	// Clear the input buffer
                	FlushRx(base);

                    // Acknowledge that the command is good. This will tell the
                    // sender to actually send the specified number of bytes
                    SendStr(YES_ANSWER, base);

                    // We must receive the correct number of bytes
                    while (true)
                    {
                    	while (IORD_FIFOED_AVALON_UART_STATUS(base) & FIFOED_AVALON_UART_CONTROL_RRDY_MSK)
                    	{
							// Read the Uart
							u8 rx = IORD_FIFOED_AVALON_UART_RXDATA(base);
							runningSum += rx;
							buffer[bufferIndex++] = rx;
							numBytesReceived++;
	                        if (numBytesReceived >= length)
	                            break;
                    	}
                        if (numBytesReceived >= length)
                            break;
                    }

                    // check the checksum
                    if (runningSum != checksum)
                        SendStr(NO_ANSWER, base);
                    else
                    {
                    	// If we don't have a full sector worth of data, then ACK and wait for more
                    	if (bufferIndex != FLASH_SECTOR_SIZE)
                    		SendStr(YES_ANSWER, base);
                    	else
                    	{
                    		u32 totalWriteBufferChecksum = 0;
                    		int i;
                    		for (i=0; i<sizeof(buffer); i++)
                    		{
                    			totalWriteBufferChecksum += buffer[i];
                    		}

							alt_flash_fd* fd = alt_flash_open_dev(SERIAL_FLASH_NAME);
							if (NULL == fd)
								SendStr(NO_ANSWER, base);
							else
							{
								u32 sectorStartAddr = (startAddr / FLASH_SECTOR_SIZE) * FLASH_SECTOR_SIZE;
								if (0 == alt_write_flash(fd, sectorStartAddr, buffer, length))
								{
									memset(buffer, 0x99, sizeof(buffer));
									if (0 == alt_read_flash(fd, sectorStartAddr, buffer, sizeof(buffer)))
									{
			                    		u32 totalReadBufferChecksum = 0;
			                    		for (i=0; i<sizeof(buffer); i++)
			                    		{
			                    			totalReadBufferChecksum += buffer[i];
			                    		}
			                    		if (totalReadBufferChecksum == totalWriteBufferChecksum)
											SendStr(YES_ANSWER, base);
			                    		else
											SendStr(NO_ANSWER, base);
									}
		                    		else
										SendStr(NO_ANSWER, base);
								}
								else
									SendStr(NO_ANSWER, base);

								alt_flash_close_dev(fd);
							}
                    	}
                    }
                }
            }

            break;
        }
            
        default:
            SendStr(NO_ANSWER, base);
            break;
    }
    
    return;
}
Ejemplo n.º 15
0
Archivo: main.c Proyecto: ndhuan/GPSRTK
int main()//OPTIMIZATION LEVEL = 0
{
	HAL_Init();
	SystemClockConfig();
	ConfigLED();
	ConfigTimer();

	rtksvrstart(&svr);

	ConfigUART(svr.format[0]);

	fobs[0]=fobs[1]=0;

	//svr.raw[1].time.time = 1429540822;//test SS2 data
	//svr.raw[1].time.time = 1429539852;//test SS2 data
	
	while (HAL_UART_Receive_DMA(&UartGPSHandle,svr.buff[0],MAX_RAW_LEN) != HAL_OK);	
	while (HAL_UART_Receive_DMA(&UartRFHandle,svr.buff[1],MAX_RAW_LEN) != HAL_OK);	

	HAL_Delay(3000);
	sendRequest(svr.format[0]);
	
//	test();

	while(1)
	{
#ifndef _TEST_RESULT		
		if (flagTimeout)
		{

			int index,temp;
			flagTimeout=0;
			//SendIntStr(UartGPSHandle.Instance->SR);
			//SendIntStr(UartRFHandle.Instance->SR);
			for (index=0;index<2;index++)
			{
				if (index==0)
					temp = UartGPSHandle.hdmarx->Instance->NDTR & 0xffff;
				else
					temp = UartRFHandle.hdmarx->Instance->NDTR & 0xffff;					
				
				if (temp + svr.buffPtr[index] <= MAX_RAW_LEN)
					svr.nb[index] = MAX_RAW_LEN - svr.buffPtr[index] - temp;
				else
					svr.nb[index] = 2*MAX_RAW_LEN - temp - svr.buffPtr[index];
				
				fobs[index] =	decode_raw(&svr,index);

				svr.buffPtr[index] = MAX_RAW_LEN - temp;	

			}
			
//			temp = UartGPSHandle.hdmarx->Instance->NDTR & 0xffff;
//			if (temp + svr.buffPtr[0] <= MAX_RAW_LEN)
//					svr.nb[0] = MAX_RAW_LEN - svr.buffPtr[0] - temp;
//			else
//					svr.nb[0] = 2*MAX_RAW_LEN - temp - svr.buffPtr[0];
//			if (svr.buffPtr[0] + svr.nb[0] <= MAX_RAW_LEN)
//			{
//				for (i = svr.buff[0] + svr.buffPtr[0] ; 
//							i < svr.buff[0] + svr.buffPtr[0] + svr.nb[0]; i++)
//				{
//					HAL_UART_Transmit(&UartResultHandle,i,1,1);

//				}
//			}
//			else
//			{
//				for (i = svr.buff[0] + svr.buffPtr[0] ; 
//							i < svr.buff[0] + MAX_RAW_LEN; i++)
//				{
//					HAL_UART_Transmit(&UartResultHandle,i,1,1);

//				}
//				for (i = svr.buff[0] ; 
//					i < svr.buff[0] + svr.nb[0] + svr.buffPtr[0] - MAX_RAW_LEN ; i++)
//				{
//					HAL_UART_Transmit(&UartResultHandle,i,1,1);
//				}		
//			}
//			svr.buffPtr[0] = MAX_RAW_LEN - temp;


		//rtk positioning**********************************************************************
//		if (0)	
			if (fobs[1])
			{
				fobs[1]=0;
				LED4_TOGGLE;
			}
			if (fobs[0])
			{						
				int i;
				fobs[0]=0;
				LED3_TOGGLE;
#ifdef TIME_MEASURE
				start=HAL_GetTick();
#endif			
				temp=svr.obs[0].n;
				for (i=0;i<temp;i++)
				{
					obsd[i]=svr.obs[0].data[i];				
				}
				for (i=0;(i<svr.obs[1].n)&&(i+temp<MAX_OBS);i++)
				{
					obsd[i+temp]=svr.obs[1].data[i];				
				}			
				if (!rtkpos(&svr.rtk,obsd,i+temp,&svr.nav))
	//			if (1)
				{

					LED5_TOGGLE;

#ifdef TIME_MEASURE
					t=HAL_GetTick()-start;
					svr.rtk.sol.processTime = t;	
#endif					
					if (svr.rtk.sol.stat==SOLQ_FIX)
						LED6_TOGGLE;
					
					outsol(&svr.rtk.sol,svr.rtk.rb);
					SendStr(svr.rtk.sol.result);
				}
				else
				{
					HAL_UART_Transmit_DMA(&UartResultHandle,(unsigned char*)svr.rtk.errbuf,svr.rtk.errLen);
				}
			}
		}
		

#else	
		if (flagTimeout)
		{
			static int i;
			char* res = svr.rtk.sol.result;
			flagTimeout = 0;
			
			res+=sprintf(res,
		"%04.0f/%02.0f/%02.0f %02.0f:%02.0f:%06.3f %14.4f %14.4f %14.4f %3d %3d %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f %6.2f %6.1f",
			2015.0,10.0,12.0,3.0,45.0,18.0,//time yy/mm/dd hh:mm:ss.ssss
			1.0,2.0,1.0,
			1,1,
			1.0,1.0,1.0,
			1.0,1.0,1.0,
			1.0,1.0);
			res+=sprintf(res," %4d",i++);
			res[0]='\n';
			SendStr(svr.rtk.sol.result);
		}
#endif		
	}
	
}
Ejemplo n.º 16
0
static void FOHex( uint width ) {
//===============================

    uint        len;
    int         trunc;
    ftnfile     *fcb;
    PTYPE       typ;
    char        *buff;

    fcb = IOCB->fileinfo;
    typ = IOCB->typ;
    len = GetLen();
    trunc = 0;

//  Use this method when real and imaginary parts are formatted using
//  one edit descriptor:
/*
    if( ( IOCB->typ == PT_CPLX_8 ) || ( IOCB->typ == PT_CPLX_16 ) ) {
        len *= 2;
        IOCB->flags &= ~IOF_FMTREALPART;  // we'll print both parts at once
    }
*/
//  Use this method when real and imaginary parts each require an
//  edit descriptor:

    if( IOCB->typ == PT_CPLX_8 ) {
        if( !(IOCB->flags & IOF_FMTREALPART) ) {
            IORslt.scomplex.realpart = IORslt.scomplex.imagpart;
        }
    } else if( IOCB->typ == PT_CPLX_16 ) {
        if( !(IOCB->flags & IOF_FMTREALPART) ) {
            IORslt.dcomplex.realpart = IORslt.dcomplex.imagpart;
        }
    } else if( IOCB->typ == PT_CPLX_32 ) {
        if( !(IOCB->flags & IOF_FMTREALPART) ) {
            IORslt.xcomplex.realpart = IORslt.xcomplex.imagpart;
        }
    }
    if( width == 0 ) {
        width = 2*len;
    }

    trunc = ( len * 2 ) - width;
    if( trunc < 0 ) {
        SendChar( ' ', -trunc );
    }
    if( trunc <= 0 ) {
        trunc = 0;
    }

    if( typ != PT_CHAR ) {
        len *= 2;
        HexFlip( (char *)&IORslt, len );
        BToHS( (char *)&IORslt , len, IOCB->buffer );
        strupr( IOCB->buffer );
        SendStr( IOCB->buffer + trunc, len - trunc );
    } else {
        buff = IOCB->buffer;
        len *= 2;
        if( len > IO_FIELD_BUFF ) {
            buff = RChkAlloc( len + 1 );
        }
        pgm_BToHS( IORslt.string.strptr, len, buff );
        strupr( buff );
        SendStr( buff + trunc, len - trunc );
        if( len > IO_FIELD_BUFF ) {
            RMemFree( buff );
        }
    }
}
Ejemplo n.º 17
0
Archivo: main.c Proyecto: gri6507/QMS
int main(void)
{
    // Prepare for UART communication with external world. The default baud rate
    // is 921,600 bps
    IOWR_FIFOED_AVALON_UART_DIVISOR(UART_BASE, BAUD_RATE(921600.0f));

    // Make sure UART interrupts are disabled
    alt_ic_irq_disable(UART_IRQ_INTERRUPT_CONTROLLER_ID, UART_IRQ);

    // Clear the input and output buffers
    FlushRx(UART_BASE);
    FlushTx(UART_BASE);
    
    #define MAX_CMD_LEN 64
    char cmd[MAX_CMD_LEN];
    s8 cmdIndex = 0;

    // Sit in an infinite loop waiting for serial commands
    while(1)
    {
        while (IORD_FIFOED_AVALON_UART_STATUS(UART_BASE) & FIFOED_AVALON_UART_CONTROL_RRDY_MSK)
        {
            // Read the Uart
            char rx = IORD_FIFOED_AVALON_UART_RXDATA(UART_BASE);
            
            // If this is the end of a command, then try to parse it
            if (('\r' == rx) || ('\n' == rx))
            {
                cmd[cmdIndex] = '\0';
                ExecuteCmd(cmd, UART_BASE);
                FlushRx(UART_BASE);
                FlushTx(UART_BASE);
                cmdIndex = 0;
            }
            
            // If this is a backspace
            else if ('\b' == rx)
            {
                SendStr("\b \b", UART_BASE);
                if (cmdIndex > 0)
                    cmdIndex--;
            }
            
            // This is any other character
            else
            {
                // echo the character
                SendChar(rx, UART_BASE);
                
                // Add it to the buffer, if possible, making sure to save the 
                // space for the null terminator (when completing the command)
                if (cmdIndex < (MAX_CMD_LEN - 1))
                    cmd[cmdIndex++] = rx;
                
                // Otherwise, report the error and reset the buffer
                else
                {
                    cmdIndex = 0;
                    SendStr(NO_ANSWER, UART_BASE);
                }
            }
        }
    }
}
Ejemplo n.º 18
0
void InterpretMessage()
   {
   char t1[100];	 
   int NbrOfFatalErrors=0;
   int NbrOfSevereErrors=0;
   int NbrOfNormalErrors=0;
   int NbrOfWarnings=0;
   int NbrOfInfo=0;
   int i;
	 char bigbuffer[500];

  if (Message[0] == 'D')
    {

    // Display frequency setting

    if ( (Message[1] > 0x2F) && (Message[1] <0x3A) )
      {
       if ( (Message[2] > 0x2F) && (Message[2] <0x3A) )
         DispFreq=(int)(Message[1]-0X30)*10+(int)(Message[2]-0x30);        
       else        
         DispFreq=(int)(Message[1]-0x30);
			
       FreqCounter=DispFreq;
       sprintf(tempbuf,TX0019,FreqCounter);
       SendStr(tempbuf,origin,strlen(tempbuf));
      }
     
		 // remote monitor sent an exit command (somehow it is different than remoute GPS monitoring)
		 if ((Message[1]=='Q') && (Message[2]=='U') && 
				 (Message[3]=='I') && (Message[4]=='T'))//"QUIT" 
		 {	
			 //SendCommand_104 (strlen(TX0071), TX0071);
			 gbConnectGPS_104 = FALSE;
			 gbConnectMON_104 = FALSE;			 
		 }

    // COM port redirection

    if ( (Message[1] == 'C') && (Message[2] == 'O')
        && (Message[3] == 'M') )
      {
      if  ( (Message[4] > 0x30) &&  (Message[4] < 0x37 ))
        {
        if ( Message[5] == 'I')
          {
          CaptureComInput[Message[4]-0x30]=TRUE;
          sprintf(tempbuf,TX0020,(int)Message[4]-0x30);
          SendStr(tempbuf, origin, strlen(tempbuf));            
          }
        if ( Message[5] == 'O')
          {
          CaptureComOutput[Message[4]-0x30]=TRUE;
          sprintf(tempbuf,TX0021,(int)Message[4]-0x30);
          SendStr(tempbuf, origin, strlen(tempbuf)); 
          }
         if ( Message[6] == 'H')
          {
          CaptureMode=1;
          }
        else
          {
          CaptureMode=0;
          }
        }
      }

    // Version number asked ?

    if ((Message[1]=='V') && (Message[2]=='E') && ( Message[3]=='R'))
      {
			sprintf(t1,TX0023,__DATE__,__TIME__);
      strcat(tempbuf,t1);
      SendStr(tempbuf,origin,strlen(tempbuf));
      strcpy(bigbuffer,"\n\r");			

if (PING_SAV)
     strcat(bigbuffer,"PING messages sending ON\n\r");


#ifdef TRIMBLE_950
   strcat(bigbuffer,"TRIMBLE_950\n\r");
#endif

#if defined PENTIUM
      strcat(bigbuffer,"PENTIUM\n\r");
#endif

#ifdef RANDOM_MESSAGE
      strcat(bigbuffer,"RANDOM_MESSAGE ON\n\r");
			sprintf(t1, "RND_MESSAGE size %d\n\r", nSize);
      strcat(bigbuffer,t1);			
			sprintf(t1, "RND_MESSAGE PORT %d\n\r", nCOM);			
			strcat(bigbuffer, t1);
#endif

		strcat(bigbuffer, COMFILE_VERSION);
			
    SendStr(bigbuffer,origin,strlen(bigbuffer));
  }
   
    // Give directory
    if ((Message[1]=='C') && (Message[2]=='A') && ( Message[3]=='T'))
      {
      system("dir *.log /w");
      }

    // Toggle Label display
    if ((Message[1]=='L') && (Message[2]=='B') && ( Message[3]=='L'))
      {
      if (DispWithoutLabels)
        {
        DispWithoutLabels=FALSE;
        sprintf(tempbuf,TX0024);
			  SendStr(tempbuf,origin,strlen(tempbuf));
        }
      else
        {
        DispWithoutLabels=TRUE;
        sprintf(tempbuf,TX0025);
			  SendStr(tempbuf,origin,strlen(tempbuf));
        }
      }

    // Display Errors
    if ((Message[1]=='E') && (Message[2]=='R') && ( Message[3]=='R'))
      {
      if (Message[4] == 'R')
        {
        // display removed errors
        for (i=0; i<RStackPtr;i++)
          {
          sprintf(tempbuf,TX0035,RemovedErrorsStack[i].Code,
                  RemovedErrorsStack[i].Time,RemovedErrorsStack[i].Counter);
          if (Message[4] == 'R')
           {
   					SendStr(tempbuf,origin,strlen(tempbuf));
            }
          }
        }
      else
        {
        for (i=0; i<EStackPtr;i++)
          {
          sprintf(tempbuf,TX0034,ErrStack[i].Code,ErrStack[i].Par1,
                 ErrStack[i].Par2,ErrStack[i].Time,ErrStack[i].Counter);
          if (ErrStack[i].Code < 5000)
            {
            if (Message[4] == 'F')
              {
							 SendStr(tempbuf,origin,strlen(tempbuf));
							}
            NbrOfFatalErrors++;
            }
          else if (ErrStack[i].Code < 10000)
            {
            if (Message[4] == 'S')
              {
						   SendStr(tempbuf,origin,strlen(tempbuf));
              }
            NbrOfSevereErrors++;
            }
          else if (ErrStack[i].Code < 15000)
            {
            if (Message[4] == 'N')
              {
						   SendStr(tempbuf,origin,strlen(tempbuf));
              }
            NbrOfNormalErrors++;
            }
          else if (ErrStack[i].Code < 20000)
            {
            if(Message[4] == 'W')
              {
						   SendStr(tempbuf,origin,strlen(tempbuf));
              }
            NbrOfWarnings++;
            }
          else
            {
          if(Message[4] == 'I')
            {
						  SendStr(tempbuf,origin,strlen(tempbuf));
            }

            NbrOfInfo++;
            }
          }

          if ( Message[4]=='A' )
            {
            sprintf(tempbuf,TX0029,NbrOfFatalErrors);
					  SendStr(tempbuf,origin,strlen(tempbuf));
            
						sprintf(tempbuf,TX0030,NbrOfSevereErrors);
					  SendStr(tempbuf,origin,strlen(tempbuf));

						sprintf(tempbuf,TX0031,NbrOfNormalErrors);
					  SendStr(tempbuf,origin,strlen(tempbuf));
            
						sprintf(tempbuf,TX0032,NbrOfWarnings);
            SendStr(tempbuf,origin,strlen(tempbuf));
            
						sprintf(tempbuf,TX0033,NbrOfInfo);
            SendStr(tempbuf,origin,strlen(tempbuf));
            
						sprintf(tempbuf,TX0036,RStackPtr);
						SendStr(tempbuf,origin,strlen(tempbuf));

            }

          }
        }
    }				
		
//**********104 connection commands*********'

if ((Message[1]=='C') && (Message[2]=='O') && ( Message[3]=='N') && 
		  (Message[4]=='N') && (Message[5]=='E') && (Message[6]=='C') && (Message[7]=='T'))//"CONNECT" == connect to ...
  {  

	if (0)//strcmp(gMARK, "master") == 0) 	 
	{
	 if (!gbConnectGPS_104)
	 {		 
		 gbConnectGPS_104  = TRUE;
		 //ConnectStatus_104 = CONNECT_PROCESSING;
		 //printf ("Before SendCommand_104(%d, %s)\n", strlen(TX0125), TX0125);
#ifdef TRIMBLE_950
     if (SendCommand_BD950(DUMP)) // send "Hi"
			{      
			 sprintf(tempbuf, TX0129); //"104: CONNECTING.....  \n"
       SendStr(tempbuf, origin, strlen(tempbuf));	
			 ConnectStatus_104 = CONNECT_ESTABLISHED;
			 LOG_ON = 1;
			}		 		 
#else // usual app
		 //if (SendCommand_104(strlen(TX0125), TX0125)) // send "HELLO"
			//{      
			// sprintf(tempbuf, TX0129); //"104: CONNECTING.....  \n"
      // SendStr(tempbuf, origin, strlen(tempbuf));			
		  //}		 		 
#endif // TRIMBLE_950
		}	
	 }
	else // not allow to active connect in SLAVE mode!
	{
	  sprintf(tempbuf, TX0100);
    SendStr(tempbuf, origin, strlen(tempbuf));			
	}
  } 	

 if ((Message[1]=='C') && (Message[2]=='O') && ( Message[3]=='N') && 
		  (Message[4]==' ') && (Message[5]=='-') && ( Message[6]=='S') &&
			(Message[7]=='Y') && (Message[8]=='N') && ( Message[9]=='C'))
			//"CON -SYNC" == syncronize time with 104
  {
	 if(0) // (strcmp(gMARK, "master") == 0) 	 
		{	
			SendSynchroTime_104();
		}
   else // not allow to active connect in SLAVE mode!
	  {
	   sprintf(tempbuf, TX0100);
     SendStr(tempbuf, origin, strlen(tempbuf));			
	  }
	}	 
//**********104 disconnection command*********'

 if ( gbConnectGPS_104 == 0) 
 {	
	if ((Message[0]=='Q') && (Message[1]=='U') && ( Message[2]=='I') && (Message[3]=='T')) //
   {   
		if (0)// (SendCommand_104(strlen(TX0126), TX0126))  // BYE...
			{
       gbConnectGPS_104 = FALSE;
			 gbConnectMON_104 = FALSE;
			 ConnectStatus_104= NO_CONNECT;
			 LOG_ON = 0;
			 sprintf(tempbuf, TX0127);
       SendStr(tempbuf, origin, strlen(tempbuf));
			}		 
    } 
	} 
#ifdef TRIMBLE_950
//**********104 connection commands END*********'
 if ( gbConnectGPS_104)
 {	 
//**********command GETSTAT1*********'
  if ((Message[0]=='G') && (Message[1]=='E') && ( Message[2]=='T') && (Message[3]=='S') && ( Message[4]=='T')
	    && (Message[5]=='A') && ( Message[6]=='T')) //
		{     
		 //printf ("Command GETSTAT1 ready to be sent to GPS card!\n");
     SendCommand_BD950(GETSTAT);
		} 
//**********command GETSERIAL*********'
  if ((Message[0]=='G') && (Message[1]=='E') && ( Message[2]=='T') && (Message[3]=='S') && ( Message[4]=='E')
	    && (Message[5]=='R') && ( Message[6]=='I') && (Message[7]=='A') && ( Message[8]=='L')) //
		{     
		 //printf ("Command GETSERIAL ready to be sent to GPS card!\n");
     SendCommand_BD950(GETSERIAL);
		} 
//**********command GETSERIAL*********'
  if ((Message[0]=='G') && (Message[1]=='E') && ( Message[2]=='T') && (Message[3]=='R') && ( Message[4]=='A')
	    && (Message[5]=='W')) //
		{     
		 //printf ("Command GETRAW ready to be sent to GPS card!\n");
     SendCommand_BD950(GETRAW);
		} 

//**********command DUMP*********'
  if (( Message[0]=='D') && (Message[1]=='U') && (Message[2]=='M') && ( Message[3]=='P')) 
		{     		 
	   //printf ("Command ready to be sent Dump from a GPS card!\n");
	   SendCommand_BD950(DUMP);
		} 

//**********command STATUS*********'
  if (( Message[0]=='S') && (Message[1]=='T') && (Message[2]=='A') && ( Message[3]=='T')) 
		{     		 
	   //printf ("Command ready to be sent Dump from a GPS card!\n");
	   SendCommand_BD950(STATUS);
		} 

//**********command CLEAR*********'
  if (( Message[0]=='C') && (Message[1]=='L') && (Message[2]=='E') && ( Message[3]=='A') && ( Message[4]=='R')) 
		{     		 
	   //printf ("Command ready to be sent Dump from a GPS card!\n");
	   SendCommand_BD950(CLEAR);
		} 

//**********command CLEAR*********'
  if (( Message[0]=='P') && (Message[1]=='O') && (Message[2]=='S')) 
		{     		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   SendCommand_BD950(POSITION);
		} 
//**********command CLEAR*********'
  if (( Message[0]=='S') && (Message[1]=='A') && (Message[2]=='T') && ( Message[3]=='I') && 
		  ( Message[4]=='N') && ( Message[5]=='F') && ( Message[6]=='O')) 
		{     		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   SendCommand_BD950(SATINFO);
		} 
//**********command CLEAR*********'
  if (( Message[0]=='S') && (Message[1]=='E') && (Message[2]=='S') && ( Message[3]=='S') && 
		  ( Message[4]=='I') && ( Message[5]=='O') && ( Message[6]=='N')) 
		{     		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   SendCommand_BD950(SESSION);
		} 
//**********command CLEAR*********'
  if (( Message[0]=='P') && (Message[1]=='O') && (Message[2]=='W') && ( Message[3]=='E') && 
		  ( Message[4]=='R')) 
		{     		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   SendCommand_BD950(POWER);
		} 
//**********command CLEAR*********'
  if (( Message[0]=='N') && (Message[1]=='E') && (Message[2]=='X') && ( Message[3]=='T')) 
		{     		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   SendCommand_BD950(NEXT);
		} 
//**********command CLEAR*********'
  if (( Message[0]=='C') && (Message[1]=='O') && (Message[2]=='N') && ( Message[3]=='T') && 
		  ( Message[4]=='R') && ( Message[5]=='O') && ( Message[6]=='L')) 
		{     		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   SendCommand_BD950(CONTROL);
		} 
//**********command CLEAR*********'
  if (( Message[0]=='P') && (Message[1]=='O') && (Message[2]=='S')) 
		{     		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   SendCommand_BD950(POSITION);
		} 
//**********command CLEAR*********'
  if (( Message[0]=='O') && (Message[1]=='N') && (Message[2]=='E')) 
		{     		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   SendCommand_BD950(ONE);
		} 
	//**********command CLEAR*********'
  if (( Message[0]=='T') && (Message[1]=='W') && (Message[2]=='O'))
		{     		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   SendCommand_BD950(TWO);
		} 
	//**********command CLEAR*********'
  if (( Message[0]=='T') && (Message[1]=='R') && (Message[2]=='E'))
	 {    		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   SendCommand_BD950(TRE);
		} 
	//**********command CLEAR*********'
  if (( Message[0]=='F') && (Message[1]=='O') && (Message[2]=='R')) 
		{     		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   SendCommand_BD950(FOR);
		} 
//**********command LOG - ULOG*********'
 if (( Message[0]=='L') && (Message[1]=='O') && (Message[2]=='G')) 
		{     		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   LOG_ON = 1;
		} 
 if (( Message[0]=='U') && (Message[1]=='N') && (Message[2]=='L') && (Message[3]=='O') && (Message[4]=='G')) 
		{     		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   LOG_ON = 0;
		} 
 if (( Message[0]=='S') && (Message[1]=='T') && (Message[2]=='O') && (Message[3]=='P')) 
		{     		 
	   //printf ("Command ready to be sent POS from a GPS card!\n");
	   LOG_ON = 0;
		} 
 //**********commands END*********'
	} // if ( gbConnectGPS_104)
#endif // #ifdef TRIMBLE_950
}
Ejemplo n.º 19
0
int monitor(int DSync)
{
  char InputQueue[20];
  static int RecvPtr =0;
  static char OutStr[2*BUFFER_SIZE];
  static int Status;
  //static unsigned long TimeoutCounter=0;
  static int WaitCommandLine=FALSE;
  //char sPtr[15];

  // wait for next character
   NewChar=0;
  
   if (kbhit())  // has anything been pressed from keyboard ?
   {       
	   NewChar=(unsigned char)getch();
	   origin=ORIGIN_KB;       
		 GPS_TimeoutCounter=0;
	   //TimeoutCounter=0;
	 }
  // printf ("monitor. in\n");
  /*
	if (ReadRxData(MONITOR_PORT,InputQueue))  // anything from remote terminal ?
    {     
		 NewChar=InputQueue[0];
     origin=MONITOR_PORT;     
		 GPS_TimeoutCounter=0;
		 //TimeoutCounter=0;
    }
 */
	//printf ("monitor. 2\n");

	if (NewChar)
   {		
    if ( (NewChar == 'D') || (NewChar == 'd') )
      {
      WaitCommandLine=TRUE;
      Status=DISPLAY_STOPPED;			
      RecvPtr=0;
      ResetDisp();
		  SendStr("\n\n\r>D",origin,5);
      }
    else
      {
      if (WaitCommandLine)
        {
        sprintf(tempbuf,"%c",NewChar);
        SendStr(tempbuf, origin, strlen(tempbuf));
        }
			}

    if (RecvPtr >= BUFFER_SIZE)
      {
       SendStr(TX0026,origin,strlen(TX0026));
       RecvPtr=0;
      }

    if ( ((NewChar & 0xff) == 24) && (!GMonActive) )  // CTRL-X   pressed
    {		
		  return(TRUE);
    }

    if (WaitCommandLine)
      {
        RecvBuffer[RecvPtr++]=NewChar;
      }

    if  (NewChar == 13)    // End of Line
     {			
	    SendStr("\r\n",origin,2);				
      RecvBuffer[RecvPtr]=0;
      // convert the message to upper case
      Message=strupr(RecvBuffer);      
			InterpretMessage();
      RecvPtr=0;
      WaitCommandLine=FALSE;
      Status=DISPLAY_RUNNING;					
			}
   }

  // Check if something has to be sent
  if ( Status==DISPLAY_RUNNING )
  {		
   if (FreqCounter-- <= 0)
   {        
	  	ParseMessage(OutStr);
      if (strlen(OutStr)>0)
			{ 
        strcat(OutStr,"\n\r");
        sprintf(tempbuf,"%s",OutStr);					
			  SendStr(tempbuf,origin,strlen(tempbuf));
			}
      else
			  Status=DISPLAY_STOPPED;				

      FreqCounter=DispFreq;
   }

	 if (GPS_TimeoutCounter++ > (long)GPS_TIMEOUT) 
	 {         
		 //printf ("GPS_TimeoutCounter=%d\n", GPS_TimeoutCounter);
	 	 //Status=DISPLAY_STOPPED;
     //ResetDisp();					  
     //SendStr(TX0027,origin,strlen(TX0027));
   }
	}


 return(FALSE);
 }
Ejemplo n.º 20
0
/* MX_USART2_UART_Init */
void MX_USART2_UART_Init(void){

  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  HAL_UART_Init(&huart2);
  /* Initialize display for each RESET 																				*/
	SendStr("\r\n");
	SendStr("\n\r ######## ##    ##  ######  ####                ######      ######   ########   #######  ##     ## ########  ");
	SendStr("\n\r ##       ###   ## ##    ##  ##                ##    ##    ##    ##  ##     ## ##     ## ##     ## ##     ## ");
	SendStr("\n\r ##       ####  ## ##        ##                ##          ##        ##     ## ##     ## ##     ## ##     ## ");
	SendStr("\n\r ######   ## ## ##  ######   ##     #######    ##          ##   #### ########  ##     ## ##     ## ########  ");
	SendStr("\n\r ##       ##  ####       ##  ##                ##          ##    ##  ##   ##   ##     ## ##     ## ##        ");
	SendStr("\n\r ##       ##   ### ##    ##  ##                ##    ##    ##    ##  ##    ##  ##     ## ##     ## ##        ");
	SendStr("\n\r ######## ##    ##  ######  ####                ######      ######   ##     ##  #######   #######  ##        ");
	SendStr("\n\r                                                                                                             \r");
	SendStr("\n\r ENSI corp. with C group partnership\r\n");
	SendStr(" computer interface of control module. Enter help to know the supported commands \r\n");
	SendStr("\r control :# ");
}
Ejemplo n.º 21
0
/* Terminal writig */
void terminal( char * string){

	int retPls = 0;
	char string_save[200];
	int n;
	float m,o;

	if(strcmp (string,"help")==0){
		SendStr(" \n\r");
		SendStr("                                                                               \r");
		SendStr("\r\n ***********************************************************************************");
		SendStr("\r\n **                                 help menu                                     **");
		SendStr("\r\n ***********************************************************************************");
		SendStr("\r\n                                                                                    ");
		SendStr(" \r auto        start automatic mode and stop manual mode   \r\n");
		SendStr(" \r manual      start manual mode and stop automatic mode   \r\n");
		SendStr(" \r speed	     update speed value (only in manual mode)    \r\n");
		SendStr(" \r steering    update steering value (only in manual mode) \r\n");
		SendStr(" \r camera      update position and voltage analog values for propulsion module \r\n");
		SendStr(" \r meas        print currents and voltage analog values for propulsion module \r\n");
		SendStr(" \r help        print supported commands                                             \r\n");
		SendStr("\r control:# ");
	}
	else if(strcmp (string,"auto")==0){
		SendStr("\n\r automatic mode is running\n\r");
		i2c_cgroup_function(1);
		SendStr("\r control:# ");
	}
  else if(strcmp (string,"manual")==0){
		SendStr("\n\r manual mode is running\n\r");
		SendStr("\r control:# ");
	}
	else if(strcmp (string,"speed")==0){
		SendStr("\n\r enter a value between 0 (stop) and 254 (full speed), 255 (reverse, speed is fixed): \n\r");
	  char value[4];
		int i;
		GetStr(value);
		if(value[0]=='-')
			SendStr("\n\r error : failed value (0 to 255) ");
		if ( value[0] == '2'){
			if ( value[1] == '5'){
				if (value[2] == '5'){
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}
					retPls = atoi(value);
					PWM_CH2_Pulse(retPls);
					PWM_CH1_Pulse(0);
				}
			}
		}
		else if(value[3]=='\0'){
			if(value[2]!='\0'){
				if(value[0] =='2'){
					if(value[1]<='5'){
						if(value[2]<='5'){
							for(i=0;i<=3;i++){
								SendChar(value[i]);
							}
							retPls = atoi(value);
							PWM_CH1_Pulse(retPls);
							PWM_CH2_Pulse(0);
						}
						else
							SendStr("\n\r error : failed value (0 to 255) ");
					}
					else
						SendStr("\n\r error : failed value (0 to 255) ");
				}
				else if (value[0]<='2'){
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}
					retPls = atoi(value);
					PWM_CH1_Pulse(retPls);
					PWM_CH2_Pulse(0);
				}
				else
					SendStr("\n\r error : failed value (0 to 255)");
			}
			else
				for(i=0;i<=3;i++){
					SendChar(value[i]);
				}
				retPls = atoi(value);
				PWM_CH1_Pulse(retPls);
				PWM_CH2_Pulse(0);
		}
		else
			SendStr("\n\r error : failed value (0 to 255) ");
			SendStr("\n\r control:# ");
	}
	else if(strcmp (string,"steering")==0){
		SendStr("\n\r enter value between -127 (full left) and 128 (full right), 0 is the middle position : \n\r");
	  char value[5];
		int i;
		GetStr(value);
		if(value[0]=='-'){
			if(value[1]=='0')
				SendChar(value[1]);
			else if (value[3]=='\0' || value[2]=='\0'){
				for(i=0;i<=3;i++){
					SendChar(value[i]);
				}
				retPls = atoi(value);
				PWM_CH3_Pulse(retPls);
				HAL_Delay(500);
				PWM_CH3_Pulse(65499);
				HAL_Delay(500);
			}
			else if(value[4]=='\0'){
				if(value[3]!='\0'){
					if(value[1] =='1'){
						if(value[2]<='2'){
							if(value[3]<='7'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}
								retPls = atoi(value);
								PWM_CH3_Pulse(retPls);
								HAL_Delay(500);
								PWM_CH3_Pulse(65499);
								HAL_Delay(500);
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");
				}
				else
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}
					retPls = atoi(value);
					PWM_CH3_Pulse(retPls);
					HAL_Delay(500);
					PWM_CH3_Pulse(65499);
					HAL_Delay(500);
			}
			else {
				SendStr("\n\r error : failed value (-127 to 128) ");
			}
		}
		else{
			if(value[3]=='\0'){
				if(value[2]!='\0'){
					if(value[0] =='1'){
						if(value[1]<='2'){
							if(value[2]<='8'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}
								retPls = atoi(value);
								PWM_CH3_Pulse(retPls);
								HAL_Delay(500);
								PWM_CH3_Pulse(65499);
								HAL_Delay(500);
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");
				}
				else
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}
					retPls = atoi(value);
					PWM_CH3_Pulse(retPls);
					HAL_Delay(500);
					PWM_CH3_Pulse(65499);
					HAL_Delay(500);
			}
			else{
				SendStr("\n\r error : failed value (-127 to 128) ");
			}
		}
		SendStr("\n\r control:# ");
	}
	else if(strcmp (string,"camera")==0){
		SendStr("\n\r enter value between -127 (full left) and 128 (full right), 0 is the middle position : \n\r");
	  char value[5];
		int i;
		GetStr(value);
		if(value[0]=='-'){
			if(value[1]=='0'){
				SendChar(value[1]);
				retPls = atoi(value);
				PWM_CH4_Pulse(retPls);
				HAL_Delay(5000);
			}
			else if (value[3]=='\0' || value[2]=='\0'){
				for(i=0;i<=3;i++){
					SendChar(value[i]);
				}
				retPls = atoi(value);
				PWM_CH4_Pulse(retPls);
				HAL_Delay(5000);
			}
			else if(value[4]=='\0'){
				if(value[3]!='\0'){
					if(value[1] =='1'){
						if(value[2]<='2'){
							if(value[3]<='7'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}
								retPls = atoi(value);
								PWM_CH4_Pulse(retPls);
								HAL_Delay(5000);
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");
				}
				else{
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}
					retPls = atoi(value);
					PWM_CH4_Pulse(retPls);
					HAL_Delay(5000);
				}
			}
			else
				SendStr("\n\r error : failed value (-127 to 128) ");
		}
		else{
			if(value[3]=='\0'){
				if(value[2]!='\0'){
					if(value[0] =='1'){
						if(value[1]<='2'){
							if(value[2]<='8'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}
								retPls = atoi(value);
								PWM_CH4_Pulse(retPls);
								HAL_Delay(5000);
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");
				}
				else{
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}
					retPls = atoi(value);
					PWM_CH4_Pulse(retPls);
					HAL_Delay(5000);
				}
			}
			else
				SendStr("\n\r error : failed value (-127 to 128) ");
		}
		SendStr("\n\r control:# ");
	}
	else if(strcmp (string,"meas")==0){
		SendStr("\n\r currents and voltage analog values for propulsion module : \n\r");
		n=adc1();
		m=n*3.3/255;
		o=m*100/24;
		sprintf(string_save," ADC value: adc1=%d, V=%f, I=%f \r\n control :# ", n,m,o);
		SendStr(string_save);
		SendStr("\n\r control:# ");
	}
	else{
		SendStr("\n\r ERROR : command not supported. Enter help to know the supported command   \n\r");
		SendStr("\r control:# ");
	}
}
Ejemplo n.º 22
0
void terminal( char * string){
  	if(strcmp (string,"help")==0){
		SendStr(" \n\r");
		SendStr("                                                                               \r");
		SendStr("\r\n ***********************************************************************************");
		SendStr("\r\n **                                 help menu                                     **");
		SendStr("\r\n ***********************************************************************************");
		SendStr("\r\n                                                                                    ");
		SendStr(" \r auto        start automatic mode and stop manual mode   \r\n");
		SendStr(" \r manual      start manual mode and stop automatic mode   \r\n");
		SendStr(" \r speed	     update speed value (only in manual mode)    \r\n");
		SendStr(" \r steering    update steering value (only in manual mode) \r\n");
		SendStr(" \r camera      update position and voltage analog values for propulsion module \r\n");
		SendStr(" \r meas        print currents and voltage analog values for propulsion module \r\n");
		SendStr(" \r help        print supported commands                                             \r\n");
		SendStr("\r control:# ");
	}
	else if(strcmp (string,"auto")==0){
		SendStr("\n\r automatic mode is running\n\r");
		SendStr("\r control:# ");
	}
  else if(strcmp (string,"manual")==0){
		SendStr("\n\r manual mode is running\n\r");
		SendStr("\r control:# ");
	}
	else if(strcmp (string,"speed")==0){
		SendStr("\n\r enter a value between 0 (stop) and 255 (full speed): \n\r"); 	
	  char value[4];
		int i;
		GetStr(value);
		if(value[0]=='-')
			SendStr("\n\r error : failed value (0 to 255) ");
		else if(value[3]=='\0'){ 
			if(value[2]!='\0'){
				if(value[0] =='2'){
					if(value[1]<='5'){
						if(value[2]<='5'){
							for(i=0;i<=3;i++){
								SendChar(value[i]);
							}								
						}
						else
							SendStr("\n\r error : failed value (0 to 255) ");
					}
					else
						SendStr("\n\r error : failed value (0 to 255) ");
				}
				else if (value[0]<='2'){
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}								
				}
				else
					SendStr("\n\r error : failed value (0 to 255)");	
			}
			else
				for(i=0;i<=3;i++){
					SendChar(value[i]);
				}				
		}
		else 
			SendStr("\n\r error : failed value (0 to 255) ");
			SendStr("\n\r control:# ");	
	}
	else if(strcmp (string,"steering")==0){
		SendStr("\n\r enter value between -127 (full left) and 128 (full right), 0 is the middle position : \n\r");
	  char value[5];
		int i;
		GetStr(value);
		if(value[0]=='-'){
			if(value[1]=='0')
				SendChar(value[1]);
			else if (value[3]=='\0' || value[2]=='\0'){
				for(i=0;i<=3;i++){
					SendChar(value[i]);
				}					
			}
			else if(value[4]=='\0'){ 
				if(value[3]!='\0'){
					if(value[1] =='1'){
						if(value[2]<='2'){
							if(value[3]<='7'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}								
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");	
				}
				else
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}				
			}	
			else 
				SendStr("\n\r error : failed value (-127 to 128) ");
			SendStr("\n\r control:# ");	
			
		}
		else{
			if(value[3]=='\0'){ 
				if(value[2]!='\0'){
					if(value[0] =='1'){
						if(value[1]<='2'){
							if(value[2]<='8'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}								
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");	
				}
				else
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}				
			}	
			else 
				SendStr("\n\r error : failed value (-127 to 128) ");
			SendStr("\n\r control:# ");	
		}
	}
	else if(strcmp (string,"camera")==0){
		SendStr("\n\r enter value between -127 (full left) and 128 (full right), 0 is the middle position : \n\r");
	  char value[5];
		int i;
		GetStr(value);
		if(value[0]=='-'){
			if(value[1]=='0')
				SendChar(value[1]);
			else if (value[3]=='\0' || value[2]=='\0'){
				for(i=0;i<=3;i++){
					SendChar(value[i]);
				}					
			}
			else if(value[4]=='\0'){ 
				if(value[3]!='\0'){
					if(value[1] =='1'){
						if(value[2]<='2'){
							if(value[3]<='7'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}								
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");	
				}
				else
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}				
			}	
			else 
				SendStr("\n\r error : failed value (-127 to 128) ");
			SendStr("\n\r control:# ");	
			
		}
		else{
			if(value[3]=='\0'){ 
				if(value[2]!='\0'){
					if(value[0] =='1'){
						if(value[1]<='2'){
							if(value[2]<='8'){
								for(i=0;i<=3;i++){
									SendChar(value[i]);
								}								
							}
							else
								SendStr("\n\r error : failed value (-127 to 128) ");
						}
						else
							SendStr("\n\r error : failed value (-127 to 128) ");
					}
					else
						SendStr("\n\r error : failed value (-127 to 128) ");	
				}
				else
					for(i=0;i<=3;i++){
						SendChar(value[i]);
					}				
			}	
			else 
				SendStr("\n\r error : failed value (-127 to 128) ");
			SendStr("\n\r control:# ");	
		}
	}
	else if(strcmp (string,"meas")==0){
		SendStr("\n\r currents and voltage analog values for propulsion module : \n\r");
		SendStr("\r NOT FINISH YET \r");	
			SendStr("\n\r control:# ");		
	}
	else{
		SendStr("\n\r ERROR : command not supported. Enter help to know the supported command   \n\r");
			SendStr("\r control:# ");
	}
}