Example #1
0
int main()
{
    int x = 123;
    cout<<x<<endl;
    char *str = int2ascii(x);
    cout<<str<<endl;
}
Example #2
0
quint8 SetCANConfig(CANConfigInfo info, quint8 * SerialBuffer, quint8 BufferSize, quint8 * ConvertSize){
	quint8 len;
	quint8 ind;
	unsigned char buf[30];
	quint8 function;
	function =0;


	buf[0] = 'W';
	buf[1] = 'C';
	switch (info.Spec){
	case CAN_A: buf[2] = 'A'; break;
	case CAN_B: buf[2] = 'B'; break;
	default: return Invalid_Arg;
	}
	buf[3] = ',';

	len = int2ascii(info.Baudrate,&buf[4],4);
	if(len ==0 ){
		return Invalid_Arg;
	}
	buf[len+4] = ',';
	ind=len+5;

	len = hex2ID(info.ID,info.Spec,&buf[ind],8);
	if(len ==0 ){
		return Invalid_Arg;
	}
	buf[len+ind] = ',';
	ind=len+ind+1;

	len = hex2ID(info.Mask,info.Spec,&buf[ind],8);
	if(len ==0 ){
		return Invalid_Arg;
	}
	buf[len+ind] = ',';
	ind=len+ind+1;

	if(info.DAR)
		SETDAR(function);
	if(info.ABOR)
		SETABOR(function);

	buf[ind++] = toASCII_HEX(function);
	buf[ind++] = CR;


	if(ind > BufferSize)
		return Invalid_Arg;
	
	*ConvertSize = ind;
	memcpy(SerialBuffer,buf,ind);
	

	return No_Error;

}
Example #3
0
/**
 * @brief	Read CAN Setting function
 * @param	command	: Serial command buffer without command header
 * @param	size	: Serial command buffer size without command header
 * @return	0 of the successful, error code if else
 * @note	ex) A,500,700,000,1<0x0d>  -> baudrate 500, Spec A, ID: 0x700, Mask: 0x000, function: 1
 *
 * 				function 0000 00xx
 * 				1 bit: DAR(Disable Automatic Retransmit)
 * 				2 bit: ABOR(Auto Bus-Off Recorvery)
 *
 */
uint32_t RC_Command(uint8_t *command, uint32_t size) {
	volatile uint32_t len;
	uint8_t tmp[30];
	volatile uint32_t ind;
	volatile uint8_t function;
	function =0;

	memset(tmp, 0, 30);
	switch (can.Spec) {
	case CAN_A:
		tmp[0] = 'A';
		tmp[1] = ',';
		break;
	case CAN_B:
		tmp[0] = 'B';
		tmp[1] = ',';
		break;
	default:
		return 0;
	}

	len = int2ascii(can.Baudrate, &tmp[2], 4);
	if (len == 0) {
		return 0;
	}
	tmp[len + 2] = ',';
	ind = len + 3;
	len = hex2ID(can.ID, can.Spec, &tmp[ind], 8);
	if (len == 0) {
		return 0;
	}
	tmp[can.Spec + ind] = ',';
	ind = can.Spec + ind + 1;

	len = hex2ID(can.Mask, can.Spec, &tmp[ind], 8);
	if (len == 0) {
		return 0;
	}

	tmp[len + ind] = ',';
	ind = can.Spec + ind;
	ind = ind + 1;

	if(can.DAR)
		SETDAR(function);
	if(can.ABOR)
		SETABOR(function);

	tmp[ind++] = hex2ascii(function);
	tmp[ind++] = 0x0d;


	memcpy(ReadSetting, tmp, ind);

	return 1;
}
Example #4
0
quint8 SetSerialConfig(SerialConfigInfo info, quint8 * SerialBuffer, quint8 BufferSize, quint8 * ConvertSize){
	
	quint8 len;
	unsigned char buf[20];

	buf[0] = 'W';
	buf[1] = 'S';
	switch (info.flow){
	case NoFlowControl:  buf[2] = 'N'; break;
	case HardwareControl: buf[2] = 'H'; break;
	default: return Invalid_Arg;
	}

	switch (info.data){
	case Data8:  buf[3] = '8'; break;
	default: return Invalid_Arg;
	}

	switch (info.parity){
	case NoParity:		buf[4] = 'N'; break;
	case EvenParity:	buf[4] = 'E'; break;
	case OddParity:		buf[4] = 'O'; break;
	case SpaceParity:	buf[4] = 'S'; break;
	case MarkParity:	buf[4] = 'M'; break;
	default: return Invalid_Arg;
	}

	switch (info.stop){
	case OneStop:  buf[5] = '1'; break;
	case TwoStop:  buf[5] = '2'; break;
	default: return Invalid_Arg;
	}
	len = int2ascii(info.Baudrate,&buf[6],20-6);
	if(len ==0 ){
		return Invalid_Arg;
	}
	buf[6+len] = CR;


	if((len+7) > BufferSize)
		return Invalid_Arg;

	*ConvertSize = len+7;
	memcpy(SerialBuffer,buf,len+7);

	return No_Error;


}
Example #5
0
/**
 * @brief	Read Option Setting function
 * @param	command	: Serial command buffer without command header
 * @param	size	: Serial command buffer size without command header
 * @return	0 of the successful, error code if else
 * @note	ex) C,10,tTeE --> Converter Mode: deley: 10, Setting to the command header of active mode
 * 				first parameter: Select for active mode
 * 				                 C--> Converter Mode
 * 				                 P--> Pair Mode (not yet supported)
 * 				second parameter: delay,,,	"delay" mean is can to serial, serial to can of delay
 * 				third parameter: Change the command header
 *
 */
uint32_t RO_Command(uint8_t *command, uint32_t size) {
	volatile uint32_t len;
	uint8_t tmp[30];
	volatile uint32_t ind;

	memset(tmp, 0, 30);
	switch (option.ActiveMode) {
	case ACTIVE_CONVERTER_MODE:
		tmp[0] = 'C';
		tmp[1] = ',';
		break;
	case ACTIVE_PAIR_MODE:
		tmp[0] = 'P';
		tmp[1] = ',';
		break;
	default:
		return 0;
	}
	len = int2ascii(option.intDelay, &tmp[2], 3);
	if (len == 0) {
		return 0;
	}
	tmp[len + 2] = ',';
	ind = len + 3;



#ifdef dd
	len = int2ascii(can.Baudrate, &tmp[2], 4);
	if (len == 0) {
		return 0;
	}
	tmp[len + 2] = ',';
	ind = len + 3;
	len = hex2ID(can.ID, can.Spec, &tmp[ind], 8);
	if (len == 0) {
		return 0;
	}
	tmp[can.Spec + ind] = ',';
	ind = can.Spec + ind + 1;

	len = hex2ID(can.Mask, can.Spec, &tmp[ind], 8);
	if (len == 0) {
		return 0;
	}

	tmp[len + ind] = ',';
	ind = can.Spec + ind;
	ind = ind + 1;

	if(can.DAR)
		SETDAR(function);
	if(can.ABOR)
		SETABOR(function);

	tmp[ind++] = hex2ascii(function);
	tmp[ind++] = 0x0d;
#endif

	memcpy(ReadSetting, tmp, ind);

	return 1;
}
Example #6
0
/**
 * @brief	Read Serial Setting function
 * @param	command	: Serial command buffer without command header
 * @param	size	: Serial command buffer size without command header
 * @return	0 of the successful, error code if else
 * @note	ex) H8N19600<0x0d>  -> baudrate 9600, 8N1, Hardware flowcontrol
 */
uint32_t RS_Command(uint8_t *command, uint32_t size) {
	uint32_t len;
	uint8_t tmp[30];

	switch (serial.FlowControl) {
	case UART_HARDWARE_FLOW_CONTROL:
		tmp[0] = 'H';
		break;
	case UART_NONE_FLOW_CONTROL:
		tmp[0] = 'N';
		break;
	default:
		return 0;
	}

	switch (serial.DataBit) {
	case UART_LCR_WLEN5:
		tmp[1] = '5';
		break;
	case UART_LCR_WLEN6:
		tmp[1] = '6';
		break;
	case UART_LCR_WLEN7:
		tmp[1] = '7';
		break;
	case UART_LCR_WLEN8:
		tmp[1] = '8';
		break;
	default:
		return 0;
	}

	switch (serial.ParityBit) {
	case UART_LCR_PARITY_DIS:
		tmp[2] = 'N';
		break;
	case UART_LCR_PARITY_EN | UART_LCR_PARITY_ODD:
		tmp[2] = 'O';
		break;
	case UART_LCR_PARITY_EN | UART_LCR_PARITY_EVEN:
		tmp[2] = 'E';
		break;
	case UART_LCR_PARITY_EN | UART_LCR_PARITY_F_1:
		tmp[2] = 'M';
		break;
	case UART_LCR_PARITY_EN | UART_LCR_PARITY_F_0:
		tmp[2] = 'S';
		break;
	default:
		return 0;
	}

	switch (serial.StopBit) {
	case UART_LCR_SBS_1BIT:
		tmp[3] = '1';
		break;
	case UART_LCR_SBS_2BIT:
		tmp[3] = '2';
		break;
	default:
		return 0;
	}
	len = int2ascii(serial.Baudrate, &tmp[4], size - 4);
	if (len == 0) {
		return 0;
	}
	tmp[len + 4] = 0x0d;
	memcpy(ReadSetting, tmp, len + 5);

	return 1;
}