コード例 #1
0
ファイル: Utilities.c プロジェクト: flamon/digitales
void PrintByteOnHexFormatBlocking(uint8_t u8Byte, bool_t bPrintComma, uartPortNumber_t port)
{
  static uint8_t HexString[4] = {0};
    
  HexString[0] = HexToAscii(u8Byte>>4);
  HexString[1] = HexToAscii(u8Byte);
  if(bPrintComma){
    HexString[2] = ',';  
  }else{
    HexString[2] = 0;      
  }
  HexString[3] = 0;      
  
  (void)Uart_BlockingStringTx(HexString, port);
}
コード例 #2
0
ファイル: reserveip.c プロジェクト: jeremyd2019/r6300v2
u_int32_t find_reserved_ip(u_int8_t *chaddr)
{
    int i;

    for (i=0; i<num_of_reservedIP; i++)
    {
        unsigned char tempMac[32], mac[7];
        sprintf(tempMac, "%s", resrvMacAddr[i]);
        trimMacAddr(tempMac);
        HexToAscii(tempMac, mac);
        if ( memcmp(chaddr, mac, 6) == 0 )
        {
            /*reserved ip found for this mac*/
            return ntohl(inet_addr(resrvIpAddr[i]));
        }
    }

    return 0;   /* Sorry, no reserved ip found */
}
コード例 #3
0
/*
*********************************************************************************************************
*	函 数 名: CheckXor
*	功能说明: 检查0183数据包的校验和是否正确
*	形    参:  _ucaBuf  收到的数据
*			 _usLen    数据长度
*	返 回 值: TRUE 或 FALSE.
*********************************************************************************************************
*/
uint8_t CheckXor(uint8_t *_ucaBuf, uint16_t _usLen)
{
	uint8_t ucXorSum;
	uint8_t ucaBuf[2];
	uint16_t i;

	if (_usLen < 3)
	{
		return FALSE;
	}

	/* 如果没有校验字节,也认为出错 */
	if (_ucaBuf[_usLen - 3] != '*')
	{
		return FALSE;
	}


	/* 不允许出现非ASCII字符 */
	for (i = 0; i < _usLen - 3; i++)
	{
		if ((_ucaBuf[i] & 0x80) || (_ucaBuf[i] == 0))
		{
			return FALSE;
		}
	}

	ucXorSum = _ucaBuf[0];
	for (i = 1; i < _usLen - 3; i++)
	{
		ucXorSum = ucXorSum ^ _ucaBuf[i];
	}

	HexToAscii(&ucXorSum, ucaBuf, 2);

	if (memcmp(&_ucaBuf[_usLen - 2], ucaBuf, 2) == 0)
	{
		return TRUE;
	}

	return FALSE;
}
コード例 #4
0
ファイル: reserveip.c プロジェクト: jeremyd2019/r6300v2
int check_reserved_ip(u_int32_t req_ip, u_int8_t *chaddr)
{
    u_int32_t reserved_ip=0;
    int i=0;

    /*  added start by EricHuang, 02/01/2007 */
    //if ( ntohl(req_ip) == server_config.server ) // modified, wenchia, 2007/09/10
    if ( ntohl(req_ip) == ntohl(server_config.server) )
    {
        return 0; /* requested ip is router's ip */
    }
    /*  added end by EricHuang, 02/01/2007 */

    for (i=0; i<num_of_reservedIP; i++)
    {
        reserved_ip = inet_addr(resrvIpAddr[i]);
        /* modify start,Zz Shan@Reserved ip 05/07/2008*/
        //if ( reserved_ip == ntohl(req_ip) )
        if ( reserved_ip == (req_ip) )
        /* modify end,Zz Shan@Reserved ip 05/07/2008*/
        {
            unsigned char tempMac[32], mac[7];
            sprintf(tempMac, "%s", resrvMacAddr[i]);
            trimMacAddr(tempMac);
            HexToAscii(tempMac, mac);
            if ( memcmp(chaddr, mac, 6) == 0 )
            {
                return 1; /*reserved ip and the ip reserved for this mac*/
            }

            return 0; /*reserved ip but not for this mac*/
        }
    }

    return 1; /*not a reserved ip*/
}
コード例 #5
0
ファイル: controller_min.c プロジェクト: run1c/Master
int main(void)
{
	// init all needed services
	cli();
	timer_init();
	USART_init();
	ADC_init();
	sei(); 
	
	// set up enable port
	ENA_DDR = /*(1 << ENA_LED) |*/ (1 << ENA_PIN);
//	ENA_PORT = (1 << ENA_LED);
	
	// init condition is receiving
	driverReceive();
	
	// string, char and ascii buffers for serial comm.
	uint8_t read_buf = 0x00, ascii_bufh = 0x00, ascii_bufl = 0x00;
	char str_buf[10];
	
	// send own address on startup
	HexToAscii(str_buf, 3, own_addr);
	sendString(str_buf);
	sendString(EOM);
	
    while(1) {
		// check if there is something to be read (non blocking...)
		if ( USART_dataAvaliable() ){
			read_buf = 0x00;
			read_buf = USART_readByte();
			switch(MPPC_status){
				
				/* no start delimiter, awaits start delimiter */
				
				case IDLE:
				if (read_buf == '<'){
					MPPC_status = LISTENING;
				} else {
					MPPC_status = IDLE;
					sleep_ms(2);
				}
				break;
	
				/* received a start delimiter, awaits adress */
				
				case LISTENING:
				// check wether there are characters or ASCII numbers beeing send
				if ( ((read_buf >= '0') && (read_buf <= '9')) ||
				((read_buf >= 'A') && (read_buf <= 'F')) ) {
					// a ASCII number has been sent, we need another digit
					str_buf[0] = read_buf;
					str_buf[1] = USART_receiveByte();
					// convert both ascii numbers into a 'real' hex number
					read_buf = AsciiToHex(str_buf, 2);
					HexToAscii(str_buf, 3, read_buf);
				} else {
					// in this stage we need an address; if there are no numbers beeing sent, we are not interested anymore!
					MPPC_status = IDLE;
					break;
				}
				// We received an address, converted it to hex and now want to check, if it is our's
				if (read_buf == own_addr){
					MPPC_status = ADDRESSED;
					// SEL_LED on -> module has been selected + echo
					sendString(str_buf);
//					ENA_PORT&= ~(1 << ENA_LED);
					// echo in ASCII
				} else {
					MPPC_status = IDLE;
				}
				break;

				/* received it's own address, awaits command */
				
				case ADDRESSED:
				if (read_buf == '>'){	// stop delimiter
					MPPC_status = IDLE;
//					ENA_PORT |= (1 << ENA_LED);	// SEL_LED off -> module has been deselected
				} else {
					command_handler(read_buf);	// yet another switch/case stucture...
				}
				break;

			} // end switch

		} // end if
		
		// apply bias voltages
		setBiasVoltage();
	}
}
コード例 #6
0
ファイル: controller_min.c プロジェクト: run1c/Master
void command_handler(uint8_t command){
	uint16_t wbuf;
	uint8_t bufh, bufl;
	float fbuf;
	char sbuf[10];
	switch(command){

		/* read temperature in human readable form */

		case READ_TEMP:
		sendByte(command);
		fbuf = getTemperature( ADC_read() );
		floatToString(fbuf, sbuf);
		sendString(sbuf);
		sendString(EOM);
		break;

		/* read temperature in raw ADC counts */
		case READ_TEMP_RAW:
		sendByte(command);
		wbuf = ADC_read();
		HexToAscii(sbuf, 4, wbuf);
		sendString(sbuf);
		sendString(EOM);
		break;

		/* set operational voltage @25°C */

		case SET_UBIAS_A:
		// echo the command
		sendByte(command);
		// waiting for a 4 character string
		receiveString(sbuf, 4);
		sendString(EOM);
		// set ADC register to given value
		wbuf = AsciiToHex(sbuf, 4);
		// max 0x7FF
		ADC_REG = 0x7FF & wbuf;
		break;

		/* set the temperature progression coefficient */

		case SET_COEFF:
		// echo...
		sendByte(command);
		// waiting for a 2 character string
		receiveString(sbuf, 2);
		sendString(EOM);
//		Vcoef = AsciiToHex(sbuf, 2);
		// max value = 0x7F
//		Vcoef &= 0x7F;		
		break;

		/* read the calculated adjusted operational voltage */

		case READ_UADJ_A:
		sendByte(command);
		// get temperature
		fbuf = getTemperature( ADC_read() );
		// calculate temperature adjusted voltage
		wbuf = calcAdjustedBiasVoltage(fbuf);
		// create string
		HexToAscii(sbuf, 5, wbuf);
		sendString(sbuf);
		sendString(EOM);
		break;

		/* read temperature coefficient */

		case READ_COEFF:
		sendByte(command);
		sendString(EOM);
		break;

		/* print help */

		case PRINT_HELP:
		sendByte(command);
		sendString("HW Version x.x SW Version 2.0");
		sendString(EOM);
		break;

		/* print sipm info of module */
		case SIPM_INFO:
		sendByte(command);
		sendString(EOM);
		break;
		
		case DAC_CAL:
		sendByte(command);
		sendString(EOM);
		break;
	
		default:
		MPPC_status = ADDRESSED;
	}


}
コード例 #7
0
ファイル: conversion.c プロジェクト: AlexisDanizan/Scripts
int main(int argc, char *argv[])
{
		int input=6, output=6;
		char octal_buff[SIZE];
		char hexa_buff[SIZE];
		char ascii_buff[SIZE];
		char char_buff[SIZE];
		char buffer[SIZE];
		while (input > 5)
		{
			puts("-------------------------------------------------------");
			puts("\tSelect input:\t");
			puts("\t\t1 - Octal");
			puts("\t\t2 - Hexadecimal");
			puts("\t\t3 - ASCII Char");
			puts("\t\t4 - Char\n");
			puts("-------------------------------------------------------");
		
			printf("Choice Input: ");
			scanf("%d",&input);
			EmptyBuffer();
		}
		while (output > 5)
		{
			puts("-------------------------------------------------------");
			puts("\tSelect output:\t");
			puts("\t\t1 - Octal");
			puts("\t\t2 - Hexadecimal");
			puts("\t\t3 - ASCII Char");
			puts("\t\t4 - Char\n");
			puts("-------------------------------------------------------");
		
			printf("Choice Output: ");
			scanf("%d",&output);
			EmptyBuffer();
		
		}
		
		//Octal Input
		if(input ==1)
		{
			if(output == 1)
			{
				puts("Bitche I do not convert it !");
			}
			
			printf("Input octal: ");
			read(buffer);
			strcpy(octal_buff,buffer);
			if(output==2)
			{
				OcToHex(octal_buff,hexa_buff);
			}
			if(output==3)
			{
				OcToAscii(octal_buff,ascii_buff);
			}
			if(output==4)
			{
				OcToChar(octal_buff,char_buff);
			}
		}
		//Hexadecimal Input
		if(input == 2)
		{
			if(output==2)
			{
				puts("You want to suck ?");
			}
			
			printf("Input Hexadecimal: ");
			read(buffer);
			strcpy(hexa_buff,buffer);
			if(output==1)
			{
				HexToOct(hexa_buff,octal_buff);
			}
			if(output==3)
			{
				HexToAscii(hexa_buff,ascii_buff);
			}
			if(output==4)
			{
				HexToChar(hexa_buff,char_buff);
			}
		}
		//Ascii Input
		if(input == 3)
		{
			if(output==3)
			{
				puts("Kill yourself -->[-]");
			}
			
			printf("Input Ascii: ");
			read(buffer);
			strcpy(ascii_buff,buffer);
			
			if(output==1)
			{
				AsciiToOct(ascii_buff,octal_buff);
			}
			if(output==2)
			{
				AsciiToHex(ascii_buff,hexa_buff);
			}
			if(output==4)
			{
				AsciiToChar(ascii_buff,char_buff);
			}
		}
		//Char Input
		if(input == 4)
		{
			if(output==4)
			{
				puts("Exile you in /dev/null !!!");
			}
			
			printf("Input Char: ");
			read(buffer);
			strcpy(char_buff,buffer);
			
			if(output==1)
			{
				CharToOct(char_buff,octal_buff);
			}
			if(output==2)
			{
				CharToHex(char_buff,hexa_buff);
			}
			if(output==3)
			{
				CharToAscii(char_buff,ascii_buff);
			}
		}

	return 0;
}	
コード例 #8
0
ファイル: main.c プロジェクト: Ahamedjee/PSoC-4-BLE
/*******************************************************************************
* Function Name: main
********************************************************************************
* Summary:
*        System entry point. This calls the user SFlash write API when switch SW2
* is pressed during system bootup.
*
* Parameters:
*  void
*
* Return:
*  int
*
*******************************************************************************/
int main()
{
    uint32 data[USER_SFLASH_ROW_SIZE/4];
    uint8 *sflashPtr;
    uint8 rowIndex;
    uint32 dataIndex;
            
    CyGlobalIntEnable; /* Enable system interrupts required for UART operation */
    
    UART_Console_Start(); /* UART is used for UI on the serial port terminal */
    
    if(Write_Switch_Read() == SWITCH_PRESSED) /* If SW2 on BLE pioneer kit baseboard is pressed during startup */
    {
        for(dataIndex = 0; dataIndex < (USER_SFLASH_ROW_SIZE/4); dataIndex++)
        {
            data[dataIndex] = SFLASH_STARTING_VALUE + dataIndex;  /* Fill the user SFlash write buffer with known data */
        }
        
        for(rowIndex = 0; rowIndex < USER_SFLASH_ROWS; rowIndex++) /* Continuously write all the 4 user FLASH rows */
        {
            uint32 status;
            
            UART_Console_UartPutString("\r\nWriting user SFlash row");
            UART_Console_UartPutChar('0' + rowIndex);
            
            /* User SFlash write API will change the IMO frequency to 48MHz internally (which is not desired for any
             * peripherals that are operating on IMO based clock (UART in this example). Wait for UART data transfer
             * to complete before calling the user SFlash write API */
            while((UART_Console_SpiUartGetTxBufferSize() + UART_Console_GET_TX_FIFO_SR_VALID) != 0u);
            
            status  = WriteUserSFlashRow(rowIndex, &data[0]);
            
            if(status == USER_SFLASH_WRITE_SUCCESSFUL)
            {
                UART_Console_UartPutString(" successful");
            }
            else
            {
                UART_Console_UartPutString(" failed - ");
                UART_Console_UartPutChar(HexToAscii(HI8(HI16(status)),1));
                UART_Console_UartPutChar(HexToAscii(HI8(HI16(status)),0));
                UART_Console_UartPutChar(HexToAscii(LO8(HI16(status)),1));
                UART_Console_UartPutChar(HexToAscii(LO8(HI16(status)),0));
            }
        }
        
        UART_Console_UartPutString("\r\nUser SFlash write complete\r\n");
    }
    
    sflashPtr = (uint8 *)USER_SFLASH_BASE_ADDRESS; /* User SFlash read is direct memory read using pointers */

    /* Read all the 512 bytes of user configurable SFlash content and display on UART console */
    for(rowIndex = 0; rowIndex < USER_SFLASH_ROWS; rowIndex++)
    {
        UART_Console_UartPutString("\r\n\nUser SFlash row ");
        UART_Console_UartPutChar('0' + rowIndex);
        UART_Console_UartPutString(" data:\r\n");
        
        for(dataIndex = 0; dataIndex < USER_SFLASH_ROW_SIZE; dataIndex++)
        {
            uint8 readData;
            
            readData = *sflashPtr++;
            
            UART_Console_UartPutChar(HexToAscii(readData,1));
            UART_Console_UartPutChar(HexToAscii(readData,0));
            UART_Console_UartPutChar(' ');
        }
    }

    while(1); /* halt the system */
}
コード例 #9
0
ファイル: main.c プロジェクト: Ahamedjee/PSoC-4-BLE
/*******************************************************************************
* Function Name: StackEventHandler()
********************************************************************************
* Summary:
* Event handler function for the BLE events processing.
*
* Parameters:
* uint32 eventCode: The event to be processed
* void * eventParam: Pointer to hold the additional information associated 
*                    with an event
*
* Return:
* None
*
* Theory:
* The function is responsible for handling the events generated by the stack.
* In addition to handling general events for BLE advertisement, connection, 
* and disconnection, this function handles the events related to L2CAP CBFC 
* connection-oriented channel connection and disconnection.
*
* For details on L2CAP connection-oriented channels, refer to Bluetooth 4.1 
* specification, Volume 3, Part A, section 3.4.
*
* Side Effects:
* None
*
*******************************************************************************/
void StackEventHandler(uint32 eventCode, void * eventParam)
{
    CYBLE_L2CAP_CBFC_CONN_CNF_PARAM_T cbfcResponse;
    uint8 counter; 
    
    switch(eventCode)
    {
        /* Stack initialized; ready for advertisement */
        case CYBLE_EVT_STACK_ON:
            UART_UartPutString("\n\rAdvertising with Address: ");
            for(counter = 6; counter > 0; counter--)
            {
                UART_UartPutChar(HexToAscii(cyBle_deviceAddress.bdAddr[counter - 1], 1));
                UART_UartPutChar(HexToAscii(cyBle_deviceAddress.bdAddr[counter - 1], 0));
                UART_UartPutChar(' ');
            }
            CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
            break;
        
        /* Advertisement timed out; Restart advertisement */
        case CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP:
            if(CyBle_GetState() == CYBLE_STATE_DISCONNECTED)
            {
                CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
            }
            break;
        
        case CYBLE_EVT_GAP_DEVICE_CONNECTED:
            UART_UartPutString("\n\rConnected. ");
            break;
            
        /* Device disconnected */
        case CYBLE_EVT_GAP_DEVICE_DISCONNECTED:
            /* The L2CAP channel is disconnected but the PSM is already 
             * registered. Update the state machine.
             */
            channelState = CHANNEL_PSM_REGISTERED;
            previousDataTransmitted = true;
            
            /* Restart advertisement */
            UART_UartPutString("\n\n\rDisconnected. ");
            UART_UartPutString("\n\rAdvertising again. ");
            UART_UartPutString("Address: ");
            for(counter = 6; counter > 0; counter--)
            {
                UART_UartPutChar(HexToAscii(cyBle_deviceAddress.bdAddr[counter - 1], 1));
                UART_UartPutChar(HexToAscii(cyBle_deviceAddress.bdAddr[counter - 1], 0));
                UART_UartPutChar(' ');
            }
            CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
            break;
        
        /* CBFC connection response is received */
        case CYBLE_EVT_L2CAP_CBFC_CONN_CNF:
            cbfcResponse = *(CYBLE_L2CAP_CBFC_CONN_CNF_PARAM_T *)eventParam;
            
            /* If the connection request was accepted */
            if(cbfcResponse.response == CYBLE_L2CAP_CONNECTION_SUCCESSFUL)
            {
                UART_UartPutString("\n\rL2CAP channel connection request accepted. Sending data. ");
                
                /* Cache the connection parameters and channel ID */
                cbfcPeerParameters = cbfcResponse.connParam;
                l2capCid = cbfcResponse.lCid;

                /* Update the state machine to indicate that the channel 
                 * is created.
                 */
                channelState = CHANNEL_CREATED;
            }
            break;
        
        /* Peer device requested for CBFC channel disconnection */
        case CYBLE_EVT_L2CAP_CBFC_DISCONN_IND:
            if(*(uint16 *)eventParam == l2capCid)
            {
                /* L2CAP channel disconnected but the PSM is still registered */
                channelState = CHANNEL_PSM_REGISTERED;
                previousDataTransmitted = true;
            }
            break;
            
        /* Invalid credits received from peer device; initiate disconnect */
        case CYBLE_EVT_L2CAP_CBFC_TX_CREDIT_IND:
            if(((CYBLE_L2CAP_CBFC_LOW_TX_CREDIT_PARAM_T *)eventParam)->result != CYBLE_L2CAP_RESULT_SUCCESS)
            {
                CyBle_L2capDisconnectReq(l2capCid);
                channelState = CHANNEL_PSM_REGISTERED;
            }
            break;

        /* Previous data transmission completed */
        case CYBLE_EVT_L2CAP_CBFC_DATA_WRITE_IND:
            previousDataTransmitted = true;
            break;
            
        default:
            break;
    }
}