Commit 7518c2a1 authored by Andrea Bulgarelli's avatar Andrea Bulgarelli
Browse files

management of real double precision (PartOfPacket)

parent b44aff88
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -103,6 +103,23 @@ public:
    /// \param index Represent the index of the field.
    virtual float getFieldValue_5_1(word index);
    
    /// Returns the value of a field in the list of fields of this part of packet.
    /// The value returned is interpreted as a real double precision (IEEE 754).
    /// The index of the argument is the first 16 bit field of the 4 fields that compound
    /// the 64 bit real double precision. The layout foreseen is the following:
    /// ---------------------------------
    /// -	float last 16 bits	-	the index passed as argument
    /// ---------------------------------
    /// -	float third 16 bits	-	the index + 1
    /// ---------------------------------
    /// -	float second 16 bits	-	the index + 1
    /// ---------------------------------
    /// -	float first 16 bits	-	the index + 1
    /// ---------------------------------
    /// This corresponds with the PTC=5, PFC = 2.
    /// \param index Represent the index of the field.
    virtual double getFieldValue_5_2(word index);

    /// Set the value of a field. The value is interpreted as a real single
    /// precision (IEEE 754).
    /// The index of the argument is the first 16 bit field of the 2 fields that compound
@@ -118,6 +135,25 @@ public:
    /// \param value The real single precision value
    virtual void setFieldValue_5_1(word index, float value);
    
    /// Set the value of a field. The value is interpreted as a real double
    /// precision (IEEE 754).
    /// The index of the argument is the first 16 bit field of the 4 fields that compound
    /// the 64 bit real double precision. The layout foreseen is the following:
 	/// ---------------------------------
    /// -	float last 16 bits	-	the index passed as argument
    /// ---------------------------------
    /// -	float third 16 bits	-	the index + 1
    /// ---------------------------------
    /// -	float second 16 bits	-	the index + 1
    /// ---------------------------------
    /// -	float first 16 bits	-	the index + 1
    /// ---------------------------------
    /// This corresponds with the PTC=5, PFC = 2.
    /// See setFieldValue(word index, word value) for general considerations.
    /// \param index Represent the index of the field.
    /// \param value The real double precision value
    virtual void setFieldValue_5_2(word index, double value);

    /// Returns the value of a field in the list of fields of this part of packet.
    /// The value returned is interpreted as a 32 bit signed integer.
    /// The index of the argument is the first 16 bit field of the 2 fields that compound
+787 −31

File changed.

Preview size limit exceeded, changes collapsed.

+49 −2
Original line number Diff line number Diff line
@@ -463,14 +463,33 @@ float PartOfPacket::getFieldValue_5_1(word index)
    union u_tag
    {
    	/// 32 bit
        unsigned long i;
        dword i;
        /// 32 bit single precision
        float f;	
    } u;
    u.i = (getFieldValue(index) << 16) | getFieldValue(index + 1);
    u.i =  ( (dword) getFieldValue(index) << 16) | ( (dword) getFieldValue(index + 1) );
    return u.f;
}

double PartOfPacket::getFieldValue_5_2(word index)
{
	if(sizeof(unsigned long) == 4) {
		//TODO
		cout << "this does not work in a 32 bit system" << endl;
		exit(0);
	}
		
    union u_tag
    {
    	/// 64 bit for 64 bit os)
        unsigned long i;
        /// 64 bit double precision
        double d;	
    } u;
    u.i = (unsigned long) ( (unsigned long)  getFieldValue(index) << (48)) | ( (unsigned long) getFieldValue(index + 1) << (32)) | ( (unsigned long) getFieldValue(index + 2) << (16)) | ( (unsigned long) getFieldValue(index + 3) );
    return u.d;
}

void PartOfPacket::setFieldValue_5_1(word index, float value)
{
    union u_tag
@@ -488,6 +507,34 @@ void PartOfPacket::setFieldValue_5_1(word index, float value)
    setFieldValue(index + 1, w);
}

void PartOfPacket::setFieldValue_5_2(word index, double value)
{
    if(sizeof(unsigned long) == 4) {
		//TODO
		cout << "this does not work in a 32 bit system" << endl;
		exit(0);
	}
		
    union u_tag
    {
    	/// 64 bit for 64 bit os)
        unsigned long i;
        /// 64 bit double precision
        double d;	
    } u;
    
    word w;
    u.d = value;
    w = (word)( (u.i >> 48) );
    setFieldValue(index, w);
    w = (word)( 0xFFFF &  (u.i >> 32) );
    setFieldValue(index + 1, w);
    w = (word)( 0xFFFF &  (u.i >> 16) );
    setFieldValue(index + 2, w);
    w = (word)(0xFFFF & u.i);
    setFieldValue(index + 3, w);
}

signed long PartOfPacket::getFieldValue_4_14(word index)
{
    long l;