Esempio n. 1
0
void COM_txCMD_CHAN1(UINT8 deviceAddress, 
			UINT8 cmd, UINT8 *buffer , UINT8 length)
{
	UINT8 cmdPacket[25] = {0};
	UINT8 i,j,cs;

	i = 0;
	cmdPacket[i++]= CMD_SOP;
	cmdPacket[i++] = deviceAddress+2;
	cmdPacket[i++] = length;
	cmdPacket[i++] = cmd;
	for( j =0; j < length ; j++)
	{
		cmdPacket[i+j] = buffer[j];
	}
	i+= j;
 	cs = checksum(&cmdPacket[1], i - 1 );
	while((cs == CMD_SOP ) || (cs == CMD_EOP)) //if check sum matches sop or eop
	{
		cmdPacket[2]++; 						// change length
		cs = checksum(&cmdPacket[1], i - 1 ); //recalculate check sum
	}
	cmdPacket[i++] = cs;
	cmdPacket[i++] = CMD_EOP;

	for( j = 0 ; j < i ; j++)
	{
		UART1_write(cmdPacket[j]);
	}
	UART1_transmit();

}
Esempio n. 2
0
void COM_task()
{
	UINT8 uartData = 0;


#if(defined __18F8722_H) ||(defined __18F46K22_H)
	if( UART1_hasData() )
	{
		uartData = UART1_read();	

		UART1_write(uartData);
		UART1_transmit();
		return;

	}
#else
	if( UART_hasData() )
	{
		uartData = UART_read();	

		UART_write(uartData);
		UART_transmit();
		return;

	}

#endif

}
Esempio n. 3
0
void COM_txData()
{
	UINT8 bcc = 0;
	UINT8 i= 0;

	bcc = checksum(communication.txPacketBuffer, communication.txPacketLength);

#if(defined __18F8722_H) ||(defined __18F46K22_H)

	UART1_write(communication.tx_sop);

	for( i = 0; i < communication.txPacketLength; i++ )
	{
		UART1_write(communication.txPacketBuffer[i]);
	}

	UART1_write(bcc);
	UART1_write(communication.tx_eop);


#ifdef __RESPONSE_ENABLED__
	UART1_transmit();
#endif


#else 	//(defined __18F8722_H) ||(defined __18F46K22_H)
	
	UART_write(communication.tx_sop);

	for( i = 0; i < communication.txPacketLength; i++ )
	{
		UART_write(communication.txPacketBuffer[i]);
	}

	UART_write(bcc);
	UART_write(communication.tx_eop);


#ifdef __RESPONSE_ENABLED__
	UART_transmit();
#endif
	ClrWdt();

#endif
	
}
Esempio n. 4
0
void COM_txStr(rom UINT8 *str)
{
#if(defined __18F8722_H) ||(defined __18F46K22_H)

	while(*str)
	{
		UART1_write(*str);
		str++;
	}
	UART1_transmit();

#else

	while(*str)
	{
		UART_write(*str);
		str++;
	}
	UART_transmit();
#endif
}