Hi all,
I know alot of people had asked question about structs and why does the size of them doesnt match the expected size, so why it doesnt match i know! I use C2D 64bits processor.
Those are my structs:
Code:
#include <stdint.h>
#define u1 uint8_t
#define u2 uint16_t
#define u4 uint32_t
#define i2 int16_t
#define i4 int32_t
Code:
typedef struct{
// SV status [bitfield], or
// Delta pseudo-range [0.02 meters].
// SV status [bitfield]:
u1 NavStatus:6; // 5...0: SV navigation status
// Delta pseudo-range [0.02 meters]:
// [full pseudo-range for given slot]-[refrange]
u1 ChannelNum:5; // 10...6: Channel number [0...31], 31 - unavailable
u1 GLONASS_Slot_num:5; // 15...11: GLONASS slot number (for GPS SV the field
// is undefined), [0...24], 0 - unknown
} SV_Status_;
typedef struct { // Packed data 1 [bitfield]:
u1 SNR:6; // 5...0: Signal-to-noise ratio [dB*Hz]
u1 LockTime:1; // 6: lock time is available
u1 SLL_Flag:1; // 7: signal lock loop flags are available
u1 Reserved:1; // 8: reserved
u1 SlotID:3; // 11...9: slot ID:
// 0 - C/A L1; 1 - P1; 2 - P2; 3 - C/A L2;
// 4 - L5; 5,6,7 - reserved
i4 CarrierPhaseDelta:20;// 31...12: [carrier phase] - [refrange]
// [-2^19...(2^19-1)] [0.0005 meters]
} PackedData1_;
typedef struct __attribute__((__packed__)) {
// Note: The zeroth element of the array Slot[i],i=0,...,M-1,
// unlike the other elements, does not contain corrections
// to the reference pseudo-range from the Header structure.
// To provide the user with additional information, the flag
// ?svst? is used for ?delrange? in the zeroth slot.
union __attribute__((__packed__)) {
i2 Delrange;
SV_Status_ Svst;
};
// SV status [bitfield], or
// Delta pseudo-range [0.02 meters].
// SV status [bitfield]:
// 15...11: GLONASS slot number (for GPS SV the field
// is undefined), [0...24], 0 - unknown
// 10...6: Channel number [0...31], 31 - unavailable
// 5...0: SV navigation status
// Delta pseudo-range [0.02 meters]:
// [full pseudo-range for given slot]-[refrange]
PackedData1_ word1; // Packed data 1 [bitfield]:
// 31...12: [carrier phase] - [refrange]
// [-2^19...(2^19-1)] [0.0005 meters]
// 11...9: slot ID:
// 0 - C/A L1; 1 - P1; 2 - P2; 3 - C/A L2;
// 4 - L5; 5,6,7 - reserved
// 8: reserved
// 7: signal lock loop flags are available
// 6: lock time is available
// 5...0: Signal-to-noise ratio [dB*Hz]
u2 flags; // Signal lock loop flags (see [FC] message)
u2 lock; // Packed data 2 [bitfield]:
// 15...12: fractional part of Signal-to-noise
// ratio [0.1 dB*Hz]
// 11...10: reserved
// 9...0: lock time [0.1 second]. Tracking time since
// last loss of lock. Varies between 0 and
// 102.3 seconds. ?Gets stuck? at 102.3s after
// the actual tracking time exceeds this value
// (until another loss of lock occurs).
u4 word2; // Packed data 3. Only present for ?version? 0 [bitfield]:
// 31...7: Doppler [-224...(224-1)], [0.001 Hz]
// 6...0: reserved
} SlotRec_14_;
WIth out
__attribute__((__packed__)) the size of
SlotRec_14_ would have bin 16 and with it, it is only 15, but it should have been 14 bytes.
Because the size of
SlotRec_14_ is wrong, i get wrong values in my struct when i debug the data! I cant explain why in other structs with bits separation there were no problems.
For my question, i am not so advance C programmer and i would like to know how would advance programer would have write such kind of decoder. If he\she would have used bitwise operators to decode this data or structs? Or is there another way in C?
Thanks