Exemplo n.º 1
0
NITFPRIV(NITF_BOOL) toInt(nitf_Field * field,
                          NITF_DATA * outData,
                          size_t length, nitf_Error * error)
{
    /*  First we have to figure out what we are storing...
       See, its okay to convert a BCS-N to an int, and...
       its also okay to maintain a binary int...          */
    NITF_BOOL status = NITF_FAILURE;
    if (field->type == NITF_BINARY)
    {
        switch (field->length)
        {
            case 2:
                status = toInt16(field, (nitf_Int16 *) outData, error);
                break;
            case 4:
                status = toInt32(field, (nitf_Int32 *) outData, error);
                break;
            case 8:
                status = toInt64(field, (nitf_Int64 *) outData, error);
                break;
            default:
                nitf_Error_initf(error, NITF_CTXT,
                                 NITF_ERR_INVALID_PARAMETER,
                                 "Unexpected field size for int [%d]",
                                 field->length);
        }
    }
    else
    {
        status = fromStringToInt(field, outData, length, error);
    }
    return status;
}
static void lengthAttributeSetter(v8::Local<v8::Value> v8Value, const v8::FunctionCallbackInfo<v8::Value>& info)
{
    v8::Local<v8::Object> holder = info.Holder();
    ExceptionState exceptionState(ExceptionState::SetterContext, "length", "TestIntegerIndexed", holder, info.GetIsolate());
    TestIntegerIndexed* impl = V8TestIntegerIndexed::toImpl(holder);
    int cppValue = toInt16(info.GetIsolate(), v8Value, NormalConversion, exceptionState);
    if (exceptionState.throwIfNeeded())
        return;
    impl->setLength(cppValue);
}
Exemplo n.º 3
0
/* We may want to rethink this function a bit.
 * The NITF spec. has many fields with a BINARY_INTEGER type
 * This could mean that the field contains 3 8-bit binary integers
 * For that example, the length of the field is 3, which isn't an integer size
 * Thus, that wouldn't work here if we just assumed BINARY_INTEGER has ONE integer in the field
 */
NITFPRIV(NITF_BOOL) fromIntToString(nitf_Field * field, char *outValue,
                                    size_t length, nitf_Error * error)
{
    char buffer[256];
    size_t actualLength = 0;
    /*  These are all two-step processes 1) get native int 2) NITF_SNPRINTF */
    switch (field->length)
    {
        case 2:
        {
            nitf_Int16 int16;
            if (!toInt16(field, &int16, error))
                goto CATCH_ERROR;
            actualLength = NITF_SNPRINTF(buffer, 256, "%d", int16);
        }
        break;
        case 4:
        {
            nitf_Int32 int32;
            if (!toInt32(field, &int32, error))
                goto CATCH_ERROR;
            actualLength = NITF_SNPRINTF(buffer, 256, "%ld", (long) int32);
        }
        break;
        case 8:
        {
            nitf_Int64 int64;
            if (!toInt64(field, &int64, error))
                goto CATCH_ERROR;
            actualLength = NITF_SNPRINTF(buffer, 256, "%lld", int64);
        }
        break;
        default:
        {
            /* otherwise, it must not be an integer value */
            return fromStringToString(field, outValue, length, error);
        }
    }
    if (actualLength > length)
    {
        nitf_Error_initf(error, NITF_CTXT, NITF_ERR_INVALID_PARAMETER,
                         "Out value too small [%d] size required",
                         strlen(buffer));
        return NITF_FAILURE;
    }
    strcpy(outValue, buffer);
    return NITF_SUCCESS;

CATCH_ERROR:
    return NITF_FAILURE;
}
Exemplo n.º 4
0
//call periodically to keep serial console alive. Every call will produce a
//log on the dataflash
void logWriteLog(int16_t rightWingPWM,int16_t leftWingPWM,int16_t tailPWM,int16_t curThrottle){

    if(_enableLog == LOGGING_ENABLED){
    	//===================
		//gather data
		//===================
		_entry.header = LOG_PACKET_HEADER;
		_entry.time = micros(); //running time in useconds
		//AHRS values
		Vector3f drift  = _Ahrs->get_gyro_drift();
		_entry.roll   = toIntDeg(_Ahrs->roll,100);
		_entry.pitch  = toIntDeg(_Ahrs->pitch,100);
		_entry.yaw    = toIntDeg(_Ahrs->yaw,100);
		_entry.driftX = toIntDeg(drift.x,1000);
		_entry.driftY = toIntDeg(drift.y,1000);
		_entry.driftZ = toIntDeg(drift.z,1000);
		//Compass Heading Value
		_entry.heading = toInt16(100*ToDeg(_Compass->calculate_heading(_Ahrs->get_dcm_matrix())));
		//IMU raw values
		Vector3f accel = _IMU->get_accel();
		Vector3f gyro = _IMU->get_gyro();
		_entry.accX  = toInt16(100*accel.x);
		_entry.accY  = toInt16(100*accel.y);
		_entry.accZ  = toInt16(100*accel.z);
		_entry.gyroX = toIntDeg(gyro.x,100);
		_entry.gyroY = toIntDeg(gyro.y,100);
		_entry.gyroZ = toIntDeg(gyro.z,100);
		//servo / throttle outputs
		_entry.rightWingPWM = rightWingPWM;
		_entry.leftWingPWM = leftWingPWM;
		_entry.tailPWM = tailPWM;
		_entry.curThrottle = curThrottle;

		//write log
		logWriteEntry(&_entry);
    }//end active log check

}
Exemplo n.º 5
0
int16_t toInt16(v8::Handle<v8::Value> value)
{
    NonThrowableExceptionState exceptionState;
    return toInt16(value, NormalConversion, exceptionState);
}
 static inline int16_t toIntegral(v8::Handle<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
 {
     return toInt16(value, configuration, exceptionState);
 }
 static inline int16_t toIntegral(v8::Isolate* isolate, v8::Local<v8::Value> value, IntegerConversionConfiguration configuration, ExceptionState& exceptionState)
 {
     return toInt16(isolate, value, configuration, exceptionState);
 }