コード例 #1
0
ファイル: scia.c プロジェクト: eunwho/dcPower
// read data format  "X40001.234e-3"
// write data format  "X60001.234e-3"
void scia_cmd_proc( int * sci_cmd, double * sci_ref)
{
	double data;
	int addr,check;
	 
	* sci_cmd = CMD_NULL;
	* sci_ref = 0.0;

	if( scia_rx_msg_flag == 0) return;

	scia_rx_msg_flag = 0;

	if ( scia_rx_msg_box[0] != 'X') return;
	
	addr =  (scia_rx_msg_box[2]- '0')* 100 +(scia_rx_msg_box[2]- '0')*10 + (scia_rx_msg_box[2]- '0');
	data =  atof( & scia_rx_msg_box[4]);
	
	// regist write function decoding
	if( scia_rx_msg_box[1] == '6'){
		if( addr == 900 ){ * sci_cmd = CMD_START; * sci_ref = data;}
		else if( addr == 901 ){ * sci_cmd = CMD_STOP;  * sci_ref = 0.0;}
		else{
			// registor_write_proc(addr,data);

			check = SaveDataProc(addr, data);
		}
	}
	else if(scia_rx_msg_box[1] == '4'){
		check = get_code_information( addr, CMD_READ_DATA , & code_inform);
		if( check != 0 ){
			if( code_inform.type == TYPE_DOUBLE ) data = code_inform.code_value.doubles;
			else 								  data = (double)(code_inform.code_value.ints);

			snprintf( gStr1,20,"read data =10.3%e \n",data);
			load_scia_tx_mail_box(gStr1);		
		}
		else{
			load_scia_tx_mail_box("Error Invalid Address");		
		}
	}
}
コード例 #2
0
ファイル: scib.c プロジェクト: eunwho/b2inv
// read data format   "9:4:123:x.xxxe-x"
// write data format  "9:6:123:1.234e-3"
void scib_cmd_proc( int * sci_cmd, double * sci_ref)
{
	double data,dbtemp;
	int addr,check,temp;
	char str[30]={0};

	TRIP_INFO * TripData;
	 
	* sci_cmd = CMD_NULL;
	* sci_ref = 0.0;

	if( scib_rx_msg_flag == 0) return;

	scib_rx_msg_flag = 0;

	if ( scib_rx_msg_box[0] != '9') return;
	
	addr =  (scib_rx_msg_box[4]- '0')* 100 +(scib_rx_msg_box[5]- '0')*10 + (scib_rx_msg_box[6]- '0');
	scib_rx_msg_box[16]=0;
	data =  atof( & scib_rx_msg_box[8]);
	
	// regist write function decoding
	
	if( scib_rx_msg_box[2] == '6'){
		if( addr == 900 ){
			check = (int)data;
			if(check == 10){
				* sci_cmd = CMD_START;
				* sci_ref = code_btn_start_ref;
				load_scib_tx_mail_box("UART CMD_START");		
			}
			else if( check == 20 ){
				* sci_cmd = CMD_STOP;  * sci_ref = 0.0;
				load_scib_tx_mail_box("UART CMD_STOP");		
			}
			else if( check == 30 ){
				* sci_cmd = CMD_RESET;  * sci_ref = 0.0;
				load_scib_tx_mail_box("UART CMD_RESET");		
			}
			else if( data == 40 ){
				* sci_cmd = CMD_SAVE;  * sci_ref = 0.0;
				load_scib_tx_mail_box("UART CMD_SAVE");		
			}
			else if( data == 80 ){
				* sci_cmd = CMD_NULL;  * sci_ref = 0.0;
				get_adc_offset();
			}
			else if( data == 90 ){
				* sci_cmd = CMD_NULL;  * sci_ref = 0.0;
				load_scib_tx_mail_box("EEPROM init Start");		
				check = init_eprom_data();		// 0이 아니면 address value
				if( check != 0) load_scib_tx_mail_box("EEPROM init Fail");		
				else		load_scib_tx_mail_box("EEPROM init Success");
			}
			else{
				load_scib_tx_mail_box("Illegal CMD data");		
			}
		}
		else{
			// registor_write_proc(addr,data);
			check = SaveDataProc(addr, data);
			Nop();
		}
	}

//==================
//   read routine
//====================
	else if(scib_rx_msg_box[2] == '4'){
	
		if(addr == 901){	//	monitor state
			check = (int)data;
			if(check == 0){
				switch(gMachineState){
					case STATE_POWER_ON:	load_scib_tx_mail_box("[POWE_ON] "); break;		
					case STATE_READY: 		load_scib_tx_mail_box("[READY]   "); break;		
					case STATE_RUN: 		load_scib_tx_mail_box("[RUN ]    "); break;		
					case STATE_TRIP: 		load_scib_tx_mail_box("[TRIP]    "); break;		
					case STATE_INIT_RUN: 	load_scib_tx_mail_box("[INIT]    "); break;		
					case STATE_GO_STOP: 	load_scib_tx_mail_box("[GO_STOP] "); break;		
					case STATE_WAIT_BREAK_OFF: load_scib_tx_mail_box("STATE_WAIT_BREAK_OFF"); break;	
					default: 				load_scib_tx_mail_box("Unknown State"); break;
				}
			}
			return;
		}
		else if(addr == 902){	//	내부 변수 read
			check = (int)data;

			switch( check ){
			case 0 :
				temp = (int)(floor(Freq_out +0.5));
				snprintf( str,10,"Fq=%3d[hz]",temp); load_scib_tx_mail_box(str);
				break;

			case 1 :
				temp = (int)(floor(rpm +0.5));
				snprintf( str,10,"RPM =%4d ",temp);	load_scib_tx_mail_box(str);
				break;
			case 2 :
				temp = (int)(floor(Vdc +0.5));
				snprintf( str,10," VDC =%4d",temp);	load_scib_tx_mail_box(str);
				break;
			case 3 :
				temp = (int)(floor( RMS_Ia * 10 + 0.5 ) );
				snprintf( str,10,"I1  =%2d.%d ",temp/10, temp%10); load_scib_tx_mail_box(str);
				break;
			case 4 :
				temp = (int)(floor( RMS_Ib * 10 + 0.5 ) );
				snprintf( str,10,"I2  =%2d.%d ",temp/10, temp%10); load_scib_tx_mail_box(str);
				break;
			case 5 : // Reset;
				gMachineState = STATE_POWER_ON;
				Nop();
				asm (" .ref _c_int00"); // ;Branch to start of boot.asm in RTS library
				asm (" LB _c_int00"); // ;Branch to start of boot.asm in RTS library
				break;
			default:
				break;
			}
			
			// check 에 따른 변수를 포인터로 두어서 처리 한다. 
		//	snprintf( str,30,"\n Vdc =%10.3e \n",Vdc);	load_scib_tx_mail_box(str); 
			return;
		}
		else if(addr == 903){	//	내부 변수 read // EEPROM TRIP DATA
			check = (int)data;

			if( data == 0 ){
				snprintf( str,4,"%03d:",TripInfoNow.CODE);
				load_scib_tx_mail_box(str); delay_msecs(180);

				load_scib_tx_mail_box(TripInfoNow.MSG); delay_msecs(220);
				load_scib_tx_mail_box(TripInfoNow.TIME); delay_msecs(180);

				dbtemp = TripInfoNow.HZ;
				temp = (int)(floor(dbtemp +0.5));				
				snprintf( str,10,"Fq=%3d[hz]",temp);	
				load_scib_tx_mail_box(str);	delay_msecs(180);

				dbtemp = TripInfoNow.VDC;
				temp = (int)(floor(dbtemp +0.5));
				snprintf( str,10," VDC =%4d",temp);	
				load_scib_tx_mail_box(str);	delay_msecs(180);

				dbtemp = TripInfoNow.CURRENT;
				temp = (int)(floor(dbtemp +0.5));
				snprintf( str,10,"I1  =%4d ",temp);	
				load_scib_tx_mail_box(str);	delay_msecs(180);

				dbtemp = TripInfoNow.DATA;
				temp = (int)(floor(dbtemp +0.5));
				snprintf( str,10," DATA=%4d",temp);	
				load_scib_tx_mail_box(str);	delay_msecs(180);
			}
			else{

		       TripData = (TRIP_INFO*)malloc(sizeof(TRIP_INFO));
		       GetTripInfo(check + 1,TripData);

				strncpy(gStr1,TripInfoNow.MSG,20);
			
				snprintf( str,4,"%03d:",TripData->CODE);
				load_scib_tx_mail_box(str); delay_msecs(180);

				load_scib_tx_mail_box(TripData->MSG); delay_msecs(220);
				load_scib_tx_mail_box(TripData->TIME); delay_msecs(180);

				dbtemp = TripData->HZ;
				temp = (int)(floor(dbtemp +0.5));				
				snprintf( str,10,"Fq=%3d[hz]",temp);	
				load_scib_tx_mail_box(str);	delay_msecs(180);

				dbtemp = TripData->VDC;
				temp = (int)(floor(dbtemp +0.5));
				snprintf( str,10," VDC =%4d",temp);	
				load_scib_tx_mail_box(str);	delay_msecs(180);

				dbtemp = TripData->CURRENT;
				temp = (int)(floor(dbtemp +0.5));
				snprintf( str,10,"I1  =%4d ",temp);	
				load_scib_tx_mail_box(str);	delay_msecs(180);

				dbtemp = TripData->DATA;
				temp = (int)(floor(dbtemp +0.5));
				snprintf( str,10," DATA=%4d",temp);	
				load_scib_tx_mail_box(str);	delay_msecs(180);

				free(TripData);
			}
			return;
		}
		else if(addr == 904){	 // DATE & TIME SET
			check = (int)data;

			switch( check ){
			case 0:
				TimeInput[0] = scib_rx_msg_box[10];
				TimeInput[1] = scib_rx_msg_box[11];
				TimeInput[2] = scib_rx_msg_box[12];
				TimeInput[3] = scib_rx_msg_box[13];
				TimeInput[4] = scib_rx_msg_box[14];
				TimeInput[5] = scib_rx_msg_box[15];
				break;
			case 1:
				TimeInput[6] = scib_rx_msg_box[10];
				TimeInput[7] = scib_rx_msg_box[11];
				TimeInput[8] = scib_rx_msg_box[12];
				TimeInput[9] = scib_rx_msg_box[13];
				TimeInput[10] = scib_rx_msg_box[14];
				TimeInput[11] = scib_rx_msg_box[15];
				delay_msecs(50);
				WriteTimeToDS1307(TimeInput);
				load_scib_tx_mail_box("Date & Time Saved");
				break;
			case 2:
		//		load_scib_tx_mail_box("WAIT FOR CLEAR DATA!");
		//		delay_msecs(180);
				ClearTripDataToEeprom();
				break;
			}
			return;
		}
		else if(addr == 905){	// RUN & STOP
			check = (int)data;
				
			switch( check ){
			case 0:
				* sci_cmd = CMD_START;
				* sci_ref = code_btn_start_ref;
				break;
			case 1:
				* sci_cmd = CMD_STOP;
				* sci_ref = 0.0;
				break;
			case 2:
				* sci_cmd = CMD_SPEED_UP;
				break;
			case 3:
				* sci_cmd = CMD_SPEED_DOWN;
				break;
			default:
				* sci_cmd = CMD_NULL;
				break;
			}
			return;
		}
		else if(addr == 906){
			GetTimeAndDateStr(str);
			load_scib_tx_mail_box(str);
			return;
		}
		else if (( addr > 979) && ( addr < 996)){
			check = addr - 980;
			snprintf( str,19,"adc =%4d",adc_result[check]);
			load_scib_tx_mail_box(str);
			delay_msecs(10);
			return;
		}

		check = get_code_information( addr, CMD_READ_DATA , & code_inform);
	
		if( check == 0 ){
			check = (int)data;

			switch(check)
			{
			case 0:
				snprintf( str,19,"CODE=%4d",addr);
				load_scib_tx_mail_box(str);
				 delay_msecs(10);
				break;
			case 1:
				load_scib_tx_mail_box(code_inform.disp);delay_msecs(10);
				break;
			case 2: 
				if( code_inform.type == TYPE_DOUBLE ){
					snprintf( str,20,"Data =%10.3e",code_inform.code_value.doubles);
				}
				else{
					snprintf( str,20,"Data =%10d",code_inform.code_value.ints);
				}
				load_scib_tx_mail_box(str);	delay_msecs(10);
				break;
			default:
				snprintf( str,19,"CODE=%4d",addr);
				load_scib_tx_mail_box(str);delay_msecs(10);
				load_scib_tx_mail_box(code_inform.disp);delay_msecs(10);

				if( code_inform.type == TYPE_DOUBLE )
					snprintf( str,20,"Data =%10.3e",code_inform.code_value.doubles);
				else
					snprintf( str,20,"Data =%10d",code_inform.code_value.ints);

				load_scib_tx_mail_box(str);	delay_msecs(10);				 
	
				break;
			}	
		}
		else{
			load_scib_tx_mail_box("Error Invalid Address");delay_msecs(10);		
		}
		return;
	}
}
コード例 #3
0
// read data format   "9:4:123:x.xxxe-x"
// write data format  "9:6:123:1.234e-3"
void scia_cmd_proc( int * sci_cmd, double * sci_ref)
{
	double data;
	int addr,check;
	char str[30]={0};
	 
	* sci_cmd = CMD_NULL;
	* sci_ref = 0.0;

	if( scia_rx_msg_flag == 0) return;

	scia_rx_msg_flag = 0;

	if ( scia_rx_msg_box[0] != '9') return;
	
	addr =  (scia_rx_msg_box[4]- '0')* 100 +(scia_rx_msg_box[5]- '0')*10 + (scia_rx_msg_box[6]- '0');
	scia_rx_msg_box[16]=0;
	data =  atof( & scia_rx_msg_box[8]);
	
	// regist write function decoding
	if( scia_rx_msg_box[2] == '6'){
		if( addr == 900 ){
			check = (int)data;
			if(check == 10){
				* sci_cmd = CMD_START; * sci_ref = data;
				load_scia_tx_mail_box("\n UART CMD_START");		
			}
			else if( check == 20 ){
				* sci_cmd = CMD_STOP;  * sci_ref = 0.0;
				load_scia_tx_mail_box("\n UART CMD_STOP");		
			}
			else if( check == 30 ){
				* sci_cmd = CMD_RESET;  * sci_ref = 0.0;
				load_scia_tx_mail_box("\n UART CMD_RESET");		
			}
			else if( data == 40 ){
				* sci_cmd = CMD_SAVE;  * sci_ref = 0.0;
				load_scia_tx_mail_box("\n UART CMD_SAVE");		
			}
			else if( data == 80 ){
				* sci_cmd = CMD_NULL;  * sci_ref = 0.0;
				get_adc_offset();
			}
			else if( data == 90 ){
				* sci_cmd = CMD_NULL;  * sci_ref = 0.0;
				load_scia_tx_mail_box("\n EEPROM init Start");		
				check = init_eprom_data();		// 0이 아니면 address value
				if( check != 0) load_scia_tx_mail_box("\n EEPROM init Fail");		
				else		load_scia_tx_mail_box("\n EEPROM init Success");
			}
			else{
				load_scia_tx_mail_box("\n Illegal CMD data");		
			}
		}
		else{
			// registor_write_proc(addr,data);
			check = SaveDataProc(addr, data);
			Nop();
		}
	}
	else if(scia_rx_msg_box[2] == '4'){
	
		if(addr == 901){	//	monitor state
			check = (int)data;
			if(check == 0){
				switch(gMachineState){
					case STATE_POWER_ON:	load_scia_tx_mail_box("\n POWER_ON"); break;		
					case STATE_READY: 		load_scia_tx_mail_box("\n STATE_READY"); break;		
					case STATE_RUN: 		load_scia_tx_mail_box("\n STATE_RUN"); break;		
					case STATE_TRIP: 		load_scia_tx_mail_box("\n STATE_TRIP"); break;		
					case STATE_INIT_RUN: 	load_scia_tx_mail_box("\n STATE_INIT_RUN"); break;		
					case STATE_GO_STOP: 	load_scia_tx_mail_box("\n STATE_GO_STOP"); break;		
					case STATE_WAIT_BREAK_OFF: load_scia_tx_mail_box("\n STATE_WAIT_BREAK_OFF"); break;	
					default: 				load_scia_tx_mail_box("\n Unknown State"); break;
				}
			}
			return;
		}
		else if(addr == 902){	//	내부 변수 read
			check = (int)data;
			
			// check 에 따른 변수를 포인터로 두어서 처리 한다. 
			snprintf( str,30,"\n Vdc =%10.3e \n",Vdc);	load_scia_tx_mail_box(str); 
			return;
		}

		check = get_code_information( addr, CMD_READ_DATA , & code_inform);
	
		if( check == 0 ){
			load_scia_tx_mail_box(code_inform.disp);		
			if( code_inform.type == TYPE_DOUBLE )
				snprintf( str,30," :: read data =%10.3e \n",code_inform.code_value.doubles);
			else
				snprintf( str,30," :: read data =%10d \n",code_inform.code_value.ints);
			
			load_scia_tx_mail_box(str);		
		}
		else{
			load_scia_tx_mail_box("Error Invalid Address");		
		}
	}
}