Ejemplo n.º 1
0
void MATLABPLOTTER::savedata(std::vector <double> &timeVector, std::vector <double> &signalVector)
{
	//generic data saving
	std::ofstream myfile;
	std::string filename_raw_data;

	filename_raw_data = "AM Spectrum on " + generateDate() + ".csv"; 
	std::string path = "\\\\atomsrv1\\EP\\Data\\sagnacAmplitudeModulator\\";

	std::string fullPath = path + filename_raw_data;

	myfile.open(const_cast<char*>( fullPath.c_str()) );
	
	/*
	myfile << "Pull Amplifier: 10-4200 MHz" << std::endl;
	myfile << "Push Amplifier: 700-4200 MHz" << std::endl;
	myfile << "Push NLTL: 7113-110" << std::endl;
	myfile << "Pull NLTL: 7112-110" << std::endl;
	myfile << "Push Function generator frequency: " << pushFrequency << " MHz" << std::endl;
	myfile << "Pull Function generator frequency: " << pullFrequency << " MHz" << std::endl;
	myfile << "Push Function generator power: " << pushPower << " dBm" << std::endl;
	myfile << "Pull Function generator power: " << pullPower << " dBm" << std::endl;
	myfile << "push pull low frequency serrodyne" << std::endl;
	*/
	myfile << "timeVector, signalVector" << std::endl;
	for(unsigned int i = 0; i < timeVector.size(); i++)
	{
		myfile << timeVector.at(i) << ", " << signalVector.at(i) << std::endl;
	}
	myfile.close();
}
Ejemplo n.º 2
0
void MATLABPLOTTER::savedata(unsigned int number, double pushFrequency,double pullFrequency, double pushPower, double pullPower, std::vector <double> &timeVectorOff, std::vector <double> &signalVectorOff,
							 std::vector <double> &timeVectorSerrodyne, std::vector <double> &signalVectorSerrodyne)
{
	std::ofstream myfile;
	std::string filename_raw_data;

	std::string numberString;
	std::stringstream convert;
	convert << number;
	convert >> numberString;

	filename_raw_data = "serrodyneRawData on " + generateDate() + " " + numberString + ".csv"; 
	std::string path = "\\\\atomsrv1\\EP\\Data\\SerrodynePushPull\\";

	//std::string save_command_raw_data = "csvwrite('" + path + filename_raw_data + "',[dataTime(:), dataSignal(:)]);";

	//engEvalString(ep, save_command_raw_data.c_str());

	std::string fullPath = path + filename_raw_data;

	myfile.open(const_cast<char*>( fullPath.c_str()) );
	//myfile << "Function generator frequency: " << frequency << " MHz" << std::endl;
	//myfile << "Function generator output power: " << power << " dBM" << std::endl;
	//myfile << "7113-110 PSPL Comb Generator" << std::endl;
	//myfile << "0dB output attenuator" << std::endl;
	//myfile << "700 - 4200 MHz input amplifier" << std::endl;
	//myfile << "no output amplifier" << std::endl;
	//myfile << "no output phase shifter" << std::endl;
	
	myfile << "Pull Amplifier: 10-4200 MHz" << std::endl;
	myfile << "Push Amplifier: 700-4200 MHz" << std::endl;
	myfile << "Push NLTL: 7113-110" << std::endl;
	myfile << "Pull NLTL: 7112-110" << std::endl;
	myfile << "Push Function generator frequency: " << pushFrequency << " MHz" << std::endl;
	myfile << "Pull Function generator frequency: " << pullFrequency << " MHz" << std::endl;
	myfile << "Push Function generator power: " << pushPower << " dBm" << std::endl;
	myfile << "Pull Function generator power: " << pullPower << " dBm" << std::endl;
	myfile << "push pull low frequency serrodyne" << std::endl;
	myfile << "timeVector, signalVector" << std::endl; //, timeVectorSerrodyne, signalVectorSerrodyne" << std::endl;
	for(unsigned int i = 0; i < timeVectorOff.size(); i++)
	{
		myfile << timeVectorOff.at(i) << ", " << signalVectorOff.at(i) << std::endl; //<< ", " << timeVectorSerrodyne.at(i) << ", " << signalVectorSerrodyne.at(i) << std::endl;
	}
	myfile.close();

}
Ejemplo n.º 3
0
void DateFormatRoundTripTest::test(DateFormat *fmt, const Locale &origLocale, UBool timeOnly) 
{
    UnicodeString pat;
    if(fmt->getDynamicClassID() != SimpleDateFormat::getStaticClassID()) {
        errln("DateFormat wasn't a SimpleDateFormat");
        return;
    }
    
    UBool isGregorian = FALSE;
    UErrorCode minStatus = U_ZERO_ERROR;
    UDate minDate = CalendarTest::minDateOfCalendar(*fmt->getCalendar(), isGregorian, minStatus);
    if(U_FAILURE(minStatus)) {
      errln((UnicodeString)"Failure getting min date for " + origLocale.getName());
      return;
    } 
    //logln(UnicodeString("Min date is ") + fullFormat(minDate)  + " for " + origLocale.getName());

    pat = ((SimpleDateFormat*)fmt)->toPattern(pat);

    // NOTE TO MAINTAINER
    // This indexOf check into the pattern needs to be refined to ignore
    // quoted characters.  Currently, this isn't a problem with the locale
    // patterns we have, but it may be a problem later.

    UBool hasEra = (pat.indexOf(UnicodeString("G")) != -1);
    UBool hasZoneDisplayName = (pat.indexOf(UnicodeString("z")) != -1) || (pat.indexOf(UnicodeString("v")) != -1) 
        || (pat.indexOf(UnicodeString("V")) != -1);

    // Because patterns contain incomplete data representing the Date,
    // we must be careful of how we do the roundtrip.  We start with
    // a randomly generated Date because they're easier to generate.
    // From this we get a string.  The string is our real starting point,
    // because this string should parse the same way all the time.  Note
    // that it will not necessarily parse back to the original date because
    // of incompleteness in patterns.  For example, a time-only pattern won't
    // parse back to the same date.

    //try {
        for(int i = 0; i < TRIALS; ++i) {
            UDate *d                = new UDate    [DEPTH];
            UnicodeString *s    = new UnicodeString[DEPTH];

            if(isGregorian == TRUE) {
              d[0] = generateDate();
            } else {
              d[0] = generateDate(minDate);
            }

            UErrorCode status = U_ZERO_ERROR;

            // We go through this loop until we achieve a match or until
            // the maximum loop count is reached.  We record the points at
            // which the date and the string starts to match.  Once matching
            // starts, it should continue.
            int loop;
            int dmatch = 0; // d[dmatch].getTime() == d[dmatch-1].getTime()
            int smatch = 0; // s[smatch].equals(s[smatch-1])
            for(loop = 0; loop < DEPTH; ++loop) {
                if (loop > 0)  {
                    d[loop] = fmt->parse(s[loop-1], status);
                    failure(status, "fmt->parse", s[loop-1]+" in locale: " + origLocale.getName() + " with pattern: " + pat);
                    status = U_ZERO_ERROR; /* any error would have been reported */
                }

                s[loop] = fmt->format(d[loop], s[loop]);
                
                // For displaying which date is being tested
                //logln(s[loop] + " = " + fullFormat(d[loop]));
                
                if(s[loop].length() == 0) {
                  errln("FAIL: fmt->format gave 0-length string in " + pat + " with number " + d[loop] + " in locale " + origLocale.getName());
                }

                if(loop > 0) {
                    if(smatch == 0) {
                        UBool match = s[loop] == s[loop-1];
                        if(smatch == 0) {
                            if(match) 
                                smatch = loop;
                        }
                        else if( ! match) 
                            errln("FAIL: String mismatch after match");
                    }

                    if(dmatch == 0) {
                        // {sfb} watch out here, this might not work
                        UBool match = d[loop]/*.getTime()*/ == d[loop-1]/*.getTime()*/;
                        if(dmatch == 0) {
                            if(match) 
                                dmatch = loop;
                        }
                        else if( ! match) 
                            errln("FAIL: Date mismatch after match");
                    }

                    if(smatch != 0 && dmatch != 0) 
                        break;
                }
            }
            // At this point loop == DEPTH if we've failed, otherwise loop is the
            // max(smatch, dmatch), that is, the index at which we have string and
            // date matching.

            // Date usually matches in 2.  Exceptions handled below.
            int maxDmatch = 2;
            int maxSmatch = 1;
            if (dmatch > maxDmatch) {
                // Time-only pattern with zone information and a starting date in PST.
                if(timeOnly && hasZoneDisplayName) {
                    int32_t startRaw, startDst;
                    fmt->getTimeZone().getOffset(d[0], FALSE, startRaw, startDst, status);
                    failure(status, "TimeZone::getOffset");
                    // if the start offset is greater than the offset on Jan 1, 1970
                    // in PST, then need one more round trip.  There are two cases
                    // fall into this category.  The start date is 1) DST or
                    // 2) LMT (GMT-07:52:58).
                    if (startRaw + startDst > -28800000) {
                        maxDmatch = 3;
                        maxSmatch = 2;
                    }
                }
            }

            // String usually matches in 1.  Exceptions are checked for here.
            if(smatch > maxSmatch) { // Don't compute unless necessary
                UBool in0;
                // Starts in BC, with no era in pattern
                if( ! hasEra && getField(d[0], UCAL_ERA) == GregorianCalendar::BC)
                    maxSmatch = 2;
                // Starts in DST, no year in pattern
                else if((in0=fmt->getTimeZone().inDaylightTime(d[0], status)) && ! failure(status, "gettingDaylightTime") &&
                         pat.indexOf(UnicodeString("yyyy")) == -1)
                    maxSmatch = 2;
                // If we start not in DST, but transition into DST
                else if (!in0 &&
                         fmt->getTimeZone().inDaylightTime(d[1], status) && !failure(status, "gettingDaylightTime"))
                    maxSmatch = 2;
                // Two digit year with no time zone change,
                // unless timezone isn't used or we aren't close to the DST changover
                else if (pat.indexOf(UnicodeString("y")) != -1
                        && pat.indexOf(UnicodeString("yyyy")) == -1
                        && getField(d[0], UCAL_YEAR)
                            != getField(d[dmatch], UCAL_YEAR)
                        && !failure(status, "error status [smatch>maxSmatch]")
                        && ((hasZoneDisplayName
                         && (fmt->getTimeZone().inDaylightTime(d[0], status)
                                == fmt->getTimeZone().inDaylightTime(d[dmatch], status)
                            || getField(d[0], UCAL_MONTH) == UCAL_APRIL
                            || getField(d[0], UCAL_MONTH) == UCAL_OCTOBER))
                         || !hasZoneDisplayName)
                         )
                {
                    maxSmatch = 2;
                }
                // If zone display name is used, fallback format might be used before 1970
                else if (hasZoneDisplayName && d[0] < 0) {
                    maxSmatch = 2;
                }
            }

            /*
             * Special case for Japanese and Buddhist (could have large negative years)
             * Also, Hebrew calendar need help handling leap month.
             */
            if(dmatch > maxDmatch || smatch > maxSmatch) {
              const char *type = fmt->getCalendar()->getType();
              if(!strcmp(type,"japanese") || (!strcmp(type,"buddhist"))) {
                maxSmatch = 4;
                maxDmatch = 4;
              } else if(!strcmp(type,"hebrew")) {
                  maxSmatch = 3;
                  maxDmatch = 3;
                }
            }

            // Use @v to see verbose results on successful cases
            UBool fail = (dmatch > maxDmatch || smatch > maxSmatch);
            if (optionv || fail) {
                if (fail) {
                    errln(UnicodeString("\nFAIL: Pattern: ") + pat +
                          " in Locale: " + origLocale.getName());
                } else {
                    errln(UnicodeString("\nOk: Pattern: ") + pat +
                          " in Locale: " + origLocale.getName());
                }
                
                logln("Date iters until match=%d (max allowed=%d), string iters until match=%d (max allowed=%d)",
                      dmatch,maxDmatch, smatch, maxSmatch);

                for(int j = 0; j <= loop && j < DEPTH; ++j) {
                    UnicodeString temp;
                    FieldPosition pos(FieldPosition::DONT_CARE);
                    errln((j>0?" P> ":"    ") + fullFormat(d[j]) + " F> " +
                          escape(s[j], temp) + UnicodeString(" d=") + d[j] + 
                          (j > 0 && d[j]/*.getTime()*/==d[j-1]/*.getTime()*/?" d==":"") +
                          (j > 0 && s[j] == s[j-1]?" s==":""));
                }
            }
            delete[] d;
            delete[] s;
        }
    /*}
    catch (ParseException e) {
        errln("Exception: " + e.getMessage());
        logln(e.toString());
    }*/
}
Ejemplo n.º 4
0
/// Check the signature and parse the identity
bool SipXauthIdentity::decode(const UtlString& identityValue,
                              const UtlString& callId,
                              const UtlString& fromTag,
                              DialogRule       bindRule
                              )
{
  /**
   * See SipXauthIdentity Encoding comment at the top of the file
   */
   Os::Logger::instance().log(FAC_SIP, PRI_DEBUG,
                 "SipXauthIdentity::decode "
                 "parse '%s'",
                 identityValue.data()
                 );
   mIdentity.remove(0);
   mIsValidIdentity = FALSE;

   bool decodeError = false; // false iff the identity was correctly signed and successfully parsed
   UtlString decodedIdentity;
   unsigned long epochTimestamp = 0;
   UtlString timestamp;
   UtlString actualSignatureHash;
   bool isBound = false;

   Url encodedUrl(identityValue, Url::NameAddr);
   if (Url::SipUrlScheme == encodedUrl.getScheme())
   {
      // Only proceed if the URL parsing succeeded
      // Extract the identity
      encodedUrl.getIdentity(decodedIdentity);

      // Extract signature parameter
      UtlString signatureParamValue;
      if (encodedUrl.getUrlParameter(SignatureUrlParamName, signatureParamValue))
      {
         // only proceed if signature parameter was found
         RegEx signatureRegEx(SignatureRegEx);

         if (signatureRegEx.Search(signatureParamValue))
         {
            UtlString secondSeparator;

            isBound = (   signatureRegEx.MatchString(&secondSeparator,2)
                       && secondSeparator.isNull()); // there is only one ':' separator

            if (   (requireDialogBinding == bindRule) // must be bound
                && ! isBound
                )
            {
               decodeError = true;
               Os::Logger::instance().log(FAC_SIP, PRI_WARNING,
                             "SipXauthIdentity::decode "
                             "'%s' is an unbound identity",
                             identityValue.data()
                             );
            }
            else
            {
               // extract timestamp
               if (   !signatureRegEx.MatchString(&timestamp,1)
                   || !from_string(epochTimestamp, timestamp)
                   )
               {
                  decodeError = true;
                  Os::Logger::instance().log(FAC_SIP, PRI_WARNING,
                                "SipXauthIdentity::decode "
                                "'%s' invalid timestamp",
                                identityValue.data()
                                );
               }
               // extract signature
               else if (!signatureRegEx.MatchString(&actualSignatureHash,3))
               {
                  decodeError = true;
                  Os::Logger::instance().log(FAC_SIP, PRI_WARNING,
                                "SipXauthIdentity::decode '%s' missing hash",
                                identityValue.data()
                                );
               }
            }
         }
         else
         {
            decodeError = true;
            Os::Logger::instance().log(FAC_SIP, PRI_WARNING,
                          "SipXauthIdentity::decode "
                          "'%s' invalid signature format",
                          identityValue.data()
                          );
         }
      }
      else
      {
         decodeError = true;
         Os::Logger::instance().log(FAC_SIP, PRI_WARNING,
                       "SipXauthIdentity::decode "
                       "'%s' missing '%s' param",
                       identityValue.data(), SignatureUrlParamName
                       );
      }
   }
   else
   {
      decodeError = true;
      Os::Logger::instance().log(FAC_SIP, PRI_WARNING,
                    "SipXauthIdentity::decode "
                    "'%s' URL parsing failed",
                     identityValue.data()
                    );
   }

   // validate timestamp
   if (!decodeError && !sSignatureValidityInterval.isNoWait())
   {
      // timestamp validity check
      if (epochTimestamp + sSignatureValidityInterval.seconds() < OsDateTime::getSecsSinceEpoch())
      {
         decodeError = true;
         OsDateTime generateDate(OsTime(epochTimestamp,0));
         UtlString generateTimeString;
         generateDate.getIsoTimeStringZ(generateTimeString);
         Os::Logger::instance().log(FAC_SIP, PRI_WARNING,
                       "SipXauthIdentity::decode(%s)"
                       " timestamp '%lX' from '%s' too old with interval of '%d' seconds",
                       identityValue.data(), epochTimestamp, generateTimeString.data(),
                       sSignatureValidityInterval.seconds()
                       );
      }
   }

   // validate signature hash
   if (!decodeError)
   {
      UtlString validSignature;

      // signature-hash=MD5(<timestamp><secret><from-tag><call-id><identity>)
      NetMd5Codec signatureHash;
      signatureHash.hash(timestamp);
      signatureHash.hash(sSignatureSecret);
      if (isBound)
      {
         signatureHash.hash(fromTag);
         signatureHash.hash(callId);
      }
      signatureHash.hash(decodedIdentity);
      signatureHash.appendHashValue(validSignature);

      if (validSignature.compareTo(actualSignatureHash) == 0)
      {
         // the signature checks out
         mIdentity = decodedIdentity;
         mIsValidIdentity = TRUE;
      }
      else
      {
         Os::Logger::instance().log(FAC_SIP, PRI_WARNING,
                       "SipXauthIdentity::decode "
                       "'%s' invalid signature '%s' != '%s'",
                       identityValue.data(), actualSignatureHash.data(), validSignature.data()
                       );
      }
   }

   return mIsValidIdentity;
}