59 parityStatus(psUnknown),
68 const ObsID& obsIDArg,
71 parityStatus(psUnknown),
83 const ObsID& obsIDArg,
84 const std::string rxString,
87 parityStatus(psUnknown),
100 const ObsID& obsIDArg,
101 const NavID& navIDArg,
102 const std::string rxString,
105 parityStatus(psUnknown),
120 const ObsID& obsIDArg,
121 const NavID& navIDArg,
122 const std::string rxString,
126 : parityStatus(psUnknown),
131 transmitTime(transmitTimeArg),
132 bits(numBits, fillValue),
247 const int numBits )
const
251 size_t stop = startBit + numBits;
252 if (stop>
bits.size())
254 InvalidParameter exc(
"Requested bits not present.");
257 for (
size_t i=startBit; i<stop; ++i)
267 const int scale )
const
270 unsigned long ulong = (
unsigned long)
temp;
276 const int scale)
const
279 return( (
long) (s * scale ) );
283 const int power2)
const
285 uint64_t uint =
asUint64_t( startBit, numBits );
288 double dval = (double) uint;
289 dval *= pow(
static_cast<double>(2), power2);
294 const int power2 )
const
299 double dval = (double) s;
300 dval *= pow(
static_cast<double>(2), power2);
305 const int power2)
const
315 const int scale)
const
318 int startBitMag = startBit + 1;
319 int numBitsMag = numBits - 1;
320 unsigned long mag =
asUnsignedLong(startBitMag, numBitsMag, scale);
325 long smag = (long) mag;
326 if (uint==1) smag *= -1;
333 const int power2)
const
335 int startBitMag = startBit + 1;
336 int numBitsMag = numBits - 1;
337 uint64_t mag =
asUint64_t(startBitMag, numBitsMag);
339 int64_t smag = (int64_t)mag;
345 return ldexp((
double)smag, power2);
351 const int power2)
const
362 int currentStart = startBit;
363 for (
int i = 0; i < numChars; ++i)
366 char ch = (char)
temp;
368 currentStart += CHAR_SIZE;
375 const unsigned numBits[],
377 const int scale )
const
380 unsigned long ulong = (
unsigned long)
asUint64_t(startBits[0], numBits[0]);
382 for(
unsigned int i = 1; i < len; i++){
384 ulong <<= numBits[i];
400 const unsigned numBits1,
401 const unsigned startBit2,
402 const unsigned numBits2,
403 const int scale )
const
405 uint64_t temp1 =
asUint64_t( startBit1, numBits1 );
406 uint64_t temp2 =
asUint64_t( startBit2, numBits2 );
407 unsigned long ulong = (
unsigned long) temp1;
416 const unsigned numBits[],
418 const int scale )
const
421 int64_t s =
SignExtend(startBits[0], numBits[0]);
423 for(
unsigned int i = 1; i < len; i++){
434 return( (
long) (s * scale ) );
439 const unsigned numBits1,
440 const unsigned startBits2,
441 const unsigned numBits2,
442 const int scale )
const
450 return( (
long) (s * scale ) );
455 const unsigned numBits[],
457 const int power2)
const
460 unsigned long ulong = (
unsigned long)
asUint64_t(startBits[0], numBits[0]);
462 for(
unsigned int i = 1; i < len; i++){
464 ulong <<= numBits[i];
476 double dval = (double) ulong;
477 dval *= pow(
static_cast<double>(2), power2);
483 const unsigned numBits1,
484 const unsigned startBit2,
485 const unsigned numBits2,
486 const int power2)
const
488 uint64_t temp1 =
asUint64_t( startBit1, numBits1 );
489 uint64_t temp2 =
asUint64_t( startBit2, numBits2 );
490 unsigned long ulong = (
unsigned long) temp1;
494 double dval = (double) ulong;
495 dval *= pow(
static_cast<double>(2), power2);
501 const unsigned numBits[],
503 const int power2)
const
505 int64_t s =
SignExtend(startBits[0], numBits[0]);
507 for(
unsigned int i = 1; i < len; i++){
519 double dval = (double) s;
520 dval *= pow(
static_cast<double>(2), power2);
527 const std::vector<unsigned>& numBits,
528 const std::vector<unsigned>& whichSF,
529 const std::vector<PackedNavBitsPtr>& bits,
532 int64_t s =
bits[whichSF[0]]->SignExtend(startBits[0], numBits[0]);
534 for (
unsigned int i = 1; i < startBits.size(); i++)
536 temp =
bits[whichSF[i]]->asUint64_t(startBits[i], numBits[i]);
542 return ldexp((
double)s, power2);
548 const std::vector<unsigned>& numBits,
549 const std::vector<unsigned>& whichSF,
550 const std::vector<PackedNavBitsPtr>& bits,
553 uint64_t ulong =
bits[whichSF[0]]->asUint64_t(startBits[0], numBits[0]);
555 for (
unsigned int i = 1; i < startBits.size(); i++)
557 temp =
bits[whichSF[i]]->asUint64_t(startBits[i], numBits[i]);
558 ulong <<= numBits[i];
563 return ldexp((
double)ulong, power2);
568 const unsigned numBits1,
569 const unsigned startBit2,
570 const unsigned numBits2,
571 const int power2)
const
574 uint64_t temp2 =
asUint64_t( startBit2, numBits2 );
579 double dval = (double) s;
580 dval *= pow(
static_cast<double>(2), power2);
586 const unsigned numBits[],
588 const int power2)
const
596 const unsigned numBits1,
597 const unsigned startBit2,
598 const unsigned numBits2,
599 const int power2)
const
617 uint64_t out = (uint64_t) value;
620 uint64_t test = pow(
static_cast<double>(2),numBits) - 1;
623 InvalidParameter exc(
"Scaled value too large for specifed bit length");
636 out = (int64_t) value;
639 int64_t test = pow(
static_cast<double>(2),numBits-1) - 1;
640 if ( ( out > test ) || ( out < -( test + 1 ) ) )
642 InvalidParameter exc(
"Scaled value too large for specifed bit length");
651 uint64_t out = (uint64_t)
ScaleValue(value, power2);
652 uint64_t test = pow(
static_cast<double>(2),numBits) - 1;
655 InvalidParameter exc(
"Scaled value too large for specifed bit length");
671 int64_t test = pow(
static_cast<double>(2),numBits-1) - 1;
672 if ( ( out > test ) || ( out < -( test + 1 ) ) )
674 InvalidParameter exc(
"Scaled value too large for specifed bit length");
690 int64_t test = pow(
static_cast<double>(2), numBits-1) - 1;
691 if ( ( out > test ) || ( out < -( test + 1 ) ) )
693 InvalidParameter exc(
"Scaled value too large for specifed bit length");
701 int numPadBlanks = 0;
703 if (numChars <
int(String.length()))
706 numToCopy = numChars;
708 else if (numChars >
int(String.length()))
710 numToCopy = String.length();
711 numPadBlanks = numChars - numToCopy;
715 numToCopy = numChars;
718 for (i = 0; i < numToCopy; ++i)
720 const unsigned char ch = String[i];
722 if ( (
'A' <= ch && ch <=
'Z') || (
'0' <= ch && ch <=
':') || (
' ' == ch) ||
723 (
'"' == ch) || (
'\'' == ch) || (
'+' == ch) || (
'-' <= ch && ch <=
'/') ||
724 (0xF8 == ch) )
valid =
true;
728 InvalidParameter exc(
"Invalid character '<< ch <<' in text string. ");
731 uint64_t out = (uint64_t) ch;
734 uint64_t space = 0x00000020;
735 for (i = 0; i < numPadBlanks; ++i)
743 if (numBits >
data.size()*8)
745 gnsstk::InvalidParameter exc(
"Requested more bits than are available");
748 unsigned numBytes = numBits >> 3;
749 unsigned rem = numBits % 8;
752 for (
unsigned long i = 0; i < numBytes; i++)
759 unsigned bitsToAdd = 8;
760 unsigned shiftRight = 0;
761 if ((i+1)*8 >= numBits)
779 bits[i+old_bits_used] = right.
bits[i];
786 uint64_t mask = 0x0000000000000001L;
787 mask <<= (numBits-1);
789 for (
int i=0; i<numBits; ++i)
822 if (
bits.size()<right.
bits.size())
return true;
826 for (
int i=0;i<
bits.size();i++)
828 if (
bits[i]==
false && right.
bits[i]==
true)
833 if (
bits[i]==
true && right.
bits[i]==
false)
853 for (
int i=0;i<
bits.size();i++)
865 const short startBit,
871 ss <<
"PackedNavBits::copyBits( ) may only be called on two";
872 ss <<
" objects with the same number of packed bits.";
873 InvalidParameter ip(ss.str());
877 short finalBit = endBit;
878 if (finalBit==-1) finalBit =
bits_used - 1;
880 for (
short i=startBit; i<=finalBit; i++)
897 ss <<
"insertUnsignedLong called with startBit+numBits > bits_used.";
898 InvalidParameter ip(ss.str());
902 uint64_t out = (uint64_t) value;
905 uint64_t test = pow(
static_cast<double>(2),numBits) - 1;
908 InvalidParameter exc(
"Scaled value too large for specifed bit length");
912 size_t ndx = startBit;
913 uint64_t mask = 0x0000000000000001L;
915 mask <<= (numBits-1);
916 for (
int i=0; i<numBits; i++)
960 temp /= pow(
static_cast<double>(2), power2);
969 ios::fmtflags oldFlags = s.flags();
971 s.setf(ios::fixed, ios::floatfield);
972 s.setf(ios::right, ios::adjustfield);
973 s.setf(ios::uppercase);
977 s <<
"****************************************************************"
978 <<
"************" << endl
979 <<
"Packed Nav Bits" << endl
981 <<
"SatID: " << getsatSys() << endl
985 <<
"NavID: " << navID << endl;
987 s <<
" RxID: " << rxID << endl;
989 <<
"Number Of Bits: " << dec << getNumBits() << endl
992 s <<
" Week(10bt) SOW UTD SOD"
993 <<
" MM/DD/YYYY HH:MM:SS\n";
996 s <<
printTime( transmitTime,
"%4F(%4G) %6.0g %3j %5.0s %02m/%02d/%04Y %02H:%02M:%02S");
999 s << endl <<
"Packed Bits, Left Justified, 32 Bits Long:\n";
1000 int numBitInWord = 0;
1003 for(
size_t i = 0; i < bits.size(); ++i)
1006 if (bits[i])
word++;
1009 if (numBitInWord >= 32)
1011 s <<
" 0x" << setw(8) << setfill(
'0') << hex <<
word << dec << setfill(
' ');
1015 if (word_count %5 == 0) s << endl;
1018 word <<= 32 - numBitInWord;
1019 if (numBitInWord > 0 ) s <<
" 0x" << setw(8) << setfill(
'0') << hex <<
word << dec << setfill(
' ');
1020 s.setf(ios::fixed, ios::floatfield);
1029 const short numPerLine,
1030 const char delimiter,
1031 const short numBitsPerWord )
const
1033 ios::fmtflags oldFlags = s.flags();
1035 s.setf(ios::uppercase);
1036 int rollover = numPerLine;
1038 int numBitInWord = 0;
1042 for(
size_t i = 0; i <
bits.size(); ++i)
1048 if (numBitInWord >= numBitsPerWord)
1050 s << delimiter <<
" 0x" << setw(8) << setfill(
'0') << hex <<
word << dec << setfill(
' ');
1058 word_count % rollover == 0 &&
1059 (i+1) <
bits.size()) s << endl;
1063 word <<= 32 - numBitInWord;
1066 s << delimiter <<
" 0x" << setw(8) << setfill(
'0') << hex <<
word << dec << setfill(
' ');
1069 return(
bits.size());
1076 return match(right);
1080 const short startBit,
1082 const unsigned flagBits)
const
1085 if (!
matchBits(right,startBit,endBit))
return false;
1090 const unsigned flagBits)
const
1098 diffSec = fabs(diffSec);
1099 if (diffSec>0.001)
return false;
1109 if ((flagBits &
mmRX) &&
rxID.compare(right.
rxID)!=0)
return false;
1117 const short startBitA,
1118 const short endBitA)
const
1122 if (
bits.size()!=right.
bits.size())
return false;
1124 short startBit = startBitA;
1125 short endBit = endBitA;
1128 endBit>=
int(
bits.size())) endBit =
bits.size()-1;
1129 if (startBit<0) startBit=0;
1130 if (startBit>=
int(
bits.size())) startBit =
bits.size()-1;
1132 for (
int i=startBit;i<=endBit;i++)
1151 string whiteSpace=
" \t,";
1152 string::size_type begin = inString.find_first_not_of(whiteSpace);
1153 if (begin==string::npos)
1155 InvalidParameter exc(
"Did not find #bits at beginning of input string.");
1158 string::size_type end = inString.find_first_of(whiteSpace,begin);
1159 if (end==string::npos)
1161 InvalidParameter exc(
"Did not find space after #bits at beginning of input string.");
1164 string textBitCount = inString.substr(begin,end);
1172 int numWordsExpected = (( bitsExpected-1)/32) + 1;
1176 for (
int i = 0; i<numWordsExpected; ++i)
1180 begin = inString.find_first_not_of(whiteSpace,end+1);
1181 if (begin==string::npos)
1183 InvalidParameter exc(
"Did not find expected number of hex words.");
1186 end = inString.find_first_of(whiteSpace,begin);
1187 string::size_type length = end - begin;
1188 string hexWord = inString.substr(begin,length);
1191 if (hexWord.substr(0,2)!=
"0x" &&
1192 hexWord.substr(0,2)!=
"0X" )
1194 InvalidParameter exc(
"Expected hex data did not being with '0x'");
1206 int numBitsToAdd = bitsExpected - bitsRead;
1207 if (numBitsToAdd>32) numBitsToAdd = 32;
1213 bitsRead += numBitsToAdd;