我正在尝试构建 RTCM SC104 v3 消息。该标准仅要求使用最小位数将数据传输到最大定义范围。因此,要加入数据,我将使用工会。但是如何将奇数大小的工会联合到以前的奇数工会?例如,消息 1002 每个卫星需要 74 位。直到消息完成并显示 n 个卫星的所有数据之前,没有填充位。我可以建立以前工会的工会吗?
typedef union headerGPS
{
struct
{
unsigned int msgNo :12; // creates a 12 bit wide integral field
unsigned int baseID :12; //base index number
unsigned int tow :30; //time of measurement
unsigned int syncFlg :1; //1 if all GNSS readings same time
unsigned int no_gps :5; //number of gps readings
unsigned int smoothInd :1; //smoothing indicator
unsigned int smoothInt :3; //smoothing int rep
} fields;
unsigned char header[8];
} headerGPS;
typedef union data1002
{
struct //74 bits / 9.25 bytes per SV
{
INT8U satID :6; //sat ID 6 bit
INT8U L1ind :1; //L1 indicator 1 bit set 1
INT32U L1range :24; //L1 psuedorange uint24
int diff :20; //L1 phaserange - psuedorange int20
INT8U lockInd :7; //L1 locktime indicator uint7
INT8U ambi :8; //L1 int ambiguity uint8
INT8U cnr :8; //L1 CNR uint8
}fields;
INT8U data[];
}data1002;
bool encode1002( int baseNumber, int gpsEpoch , int numberGpsSV, int numberGloSV, int numberGalSV )
{
std::string message1002;
headerGPS h1002; //create header object
h1002.fields.msgNo = 1002;
h1002.fields.baseID = baseNumber;
h1002.fields.tow = gpsEpoch;
if(numberGloSV > 0 || numberGalSV > 0)
{
h1002.fields.syncFlg = 1;
}
else
{
h1002.fields.syncFlg = 0;
}
h1002.fields.no_gps = numberGpsSV;
h1002.fields.smoothInd = 0;
h1002.fields.smoothInt = 0;
for(int n=0; n<8; n++)
{
message1002 += h1002.header[n];
}//1002 header is complete
return true;
}
好的,所以我正在尝试设置一个位集来准备要发送的数据。我正在使用这种状态以所需的顺序填充位集,而无需添加额外的填充位。这是在“for”语句和“if channel data good”语句中。
for(varPos = 0; varPos < 6; varPos ++) //start on 0, end on 5
{
data_1002.set(bitPos,datastream[baseNumber].channel[n].satID & (1<<varPos)); //test bit
bitPos++;
}
data_1002.set(bitPos,1);
bitPos++;
for(varPos = 0; varPos < 24; varPos ++) //start on 0, end on 5
{
data_1002.set(bitPos,codeRange & (1<<varPos)); //test bit
bitPos++;
}
我想将 bitset 中的所有位值复制到字节数组中,以使用以下命令发送 TCP/IP 端口:
int noBytes = (bitPos+7)/8; //number of data bytes to copy to array
if(noBytes <=0)
{
noBytes = 0;
}
cout << "number of bytes to process= " << noBytes <<endl;
cout <<"completed bitset size= " << bitPos << endl;
//convert bits to bytes
bitPos = 0;
int byteCount;
for (int w=0; w<noBytes; w++) //bitPos/8 = number of bytes; w+8 because 8 bytes in header
{
for(int q=0; q<8; q++)
{
if(data_1002.test(bitPos+q) == 1)
{
BUFFER[(w+8)] = BUFFER[(w+8)] | (1<<q);
}
else
{
BUFFER[(w+8)] = BUFFER[(w+8)] & (0xFF & (0<<q));
}
}
bitPos = bitPos +8;
byteCount = w+8;
}
cout << "bytecounter= " << byteCount << endl;
cout<<"number btes processed plus header= "<< noBytes+8 <<endl;
for(int w=0; w<noBytes+8; w++)
{
output += BUFFER[w];
}
这似乎应该可以工作,但是如果我在编码中遗漏了一个错误,我将不胜感激。还有没有更简单的方法可以将位集传输到字节数组中发送出去?我阅读并尝试在字符串流中插入一个位集,但它将每个位插入为一个字符而不是一个位。