Exemplo n.º 1
0
//============================================================================
//		NCFNumber::GetObject : Get the object.
//----------------------------------------------------------------------------
NCFObject NCFNumber::GetObject(void) const
{	float64_t		valueFloat64;
	float32_t		valueFloat32;
	int64_t			valueInt64;
	NCFObject		theObject;



	// Get the object
	switch (GetPrecision()) {
		case kNPrecisionInt8:
		case kNPrecisionInt16:
		case kNPrecisionInt32:
		case kNPrecisionInt64:
			valueInt64 = GetInt64();
			theObject.SetObject(CFNumberCreate(kCFAllocatorNano, kCFNumberLongLongType, &valueInt64));
			break;
		
		case kNPrecisionFloat32:
			valueFloat32 = GetFloat32();
			theObject.SetObject(CFNumberCreate(kCFAllocatorNano, kCFNumberFloatType,    &valueFloat32));
			break;
		
		case kNPrecisionFloat64:
			valueFloat64 = GetFloat64();
			theObject.SetObject(CFNumberCreate(kCFAllocatorNano, kCFNumberDoubleType,   &valueFloat64));
			break;
		
		default:
			NN_LOG("Unable to convert '%@' to CFNumber", GetString());
			break;
		}

	return(theObject);
}
Exemplo n.º 2
0
//============================================================================
//		NNumber::Compare : Compare the value.
//----------------------------------------------------------------------------
NComparison NNumber::Compare(const NNumber &theValue) const
{	Float64				valueFloat64_1, valueFloat64_2;
	Float32				valueFloat32_1, valueFloat32_2;
	SInt64				valueInt64_1,  valueInt64_2;
	NComparison			theResult;



	// Compare equal types
	if (mPrecision == theValue.mPrecision || (IsInteger() && theValue.IsInteger()))
		{
		switch (mPrecision) {
			case kNPrecisionInt8:
			case kNPrecisionInt16:
			case kNPrecisionInt32:
			case kNPrecisionInt64:
				theResult = GetComparison(mValue.integer, theValue.mValue.integer);
				break;
			
			case kNPrecisionFloat32:
				valueFloat32_1 = (Float32)          mValue.real;
				valueFloat32_2 = (Float32) theValue.mValue.real;
				theResult      = GetComparison(valueFloat32_1, valueFloat32_2);
				break;

			case kNPrecisionFloat64:
				theResult = GetComparison(mValue.real, theValue.mValue.real);
				break;

			default:
				NN_LOG("Unknown precision: %d", mPrecision);
				theResult = kNCompareLessThan;
				break;
			}
		}


	// Compare dis-similar types
	else
		{
		switch (mPrecision) {
			case kNPrecisionInt8:
			case kNPrecisionInt16:
			case kNPrecisionInt32:
			case kNPrecisionInt64:
				valueInt64_1 =          GetSInt64();
				valueInt64_2 = theValue.GetSInt64();
				theResult    = GetComparison(valueInt64_1, valueInt64_2);
				break;

			case kNPrecisionFloat32:
				valueFloat32_1 =          GetFloat32();
				valueFloat32_2 = theValue.GetFloat32();
				theResult      = GetComparison(valueFloat32_1, valueFloat32_2);
				break;

			case kNPrecisionFloat64:
				valueFloat64_1 =          GetFloat64();
				valueFloat64_2 = theValue.GetFloat64();
				theResult      = GetComparison(valueFloat64_1, valueFloat64_2);
				break;

			default:
				NN_LOG("Unknown precision: %d", mPrecision);
				theResult = kNCompareLessThan;
				break;
			}
		}

	return(theResult);
}
Exemplo n.º 3
0
uint8_t	Set_param(uint8_t *buf)
{
  	int16_t i;
	
	switch(*(buf + 1))
	{
	  	case	1:
		  	pre_commutation = GetUint16(buf + 2);
			flash_update = true;
		break;
		case	2:	
		  	Vel_reg.Kp = GetFloat32(buf + 2);
			flash_update = true;
		break;
		case	3:
		  	Vel_reg.Ki = GetFloat32(buf + 2);
			flash_update = true;
		break;
		case	4:
		  	Vel_reg.Kd = GetFloat32(buf + 2);
			flash_update = true;
		break;
		case	5:
		  	add_Uin = GetInt16(buf + 2);
			flash_update = true;
		break;
		case	6:
		  	limit_dec_f_force_comm = GetUint16(buf + 2);
			flash_update = true;
		break;
		case	7:	
		  	current_protection = GetFloat32(buf + 2);
			flash_update = true;
		break;
		case	8:
		  	level_pwm_start = GetUint16(buf + 2);
			flash_update = true;
		break;
		case	9:
		  	cnt_on_reg_speed = GetUint16(buf + 2);
			flash_update = true;
		break;
		case	10:
		  	level_correct_speed = GetUint16(buf + 2);
			flash_update = true;
		break;
		case	11:
		  	step_add_velocity = GetFloat32(buf + 2);
			flash_update = true;
		break;
		case	12:	
		  	step_dec_velocity = GetFloat32(buf + 2);
			flash_update = true;
		break;
		case	13:
		  	level_detect_stop = GetUint16(buf + 2);
			flash_update = true;
		break;
		case	14:
		  	add_force_time = GetUint32(buf + 2);
			flash_update = true;
		break;
		case	15:	
		  	step_dec_f_force_comm = GetUint16(buf + 2);
			flash_update = true;
		break;
		case	16:
		  	level_on_feedback = GetUint16(buf + 2);
			flash_update = true;
		break;
		case	17:
		  	level_pause_detect_ZC = GetUint16(buf + 2);
			flash_update = true;
		break;
		case	18:
		  	n_pair_polus = GetUint16(buf + 2);
			flash_update = true;
		break;
		case	19:
		  	drive_mode = GetUint16(buf + 2);
			flash_update = true;
		break;
		case	20:
		  	Unom = GetFloat32(buf + 2);
			flash_update = true;
		break;
		case	21:
		  	current_protect_avg = GetFloat32(buf + 2);
			flash_update = true;
		break;
		case	22:
		  	slave_addr = GetFloat32(buf + 2);
			flash_update = true;
		break;
		default:
	 	break;
	}
	
	i = 2;
	
	return i;
}