コード例 #1
0
ファイル: LimitBox.cpp プロジェクト: alod83/IS-MOOS
bool CLimitBox::OnNewMail(MOOSMSG_LIST &NewMail)
{
    CMOOSMsg Msg;
    if(PeekMail(NewMail,"NAV_X",Msg))
    {
        if(!Msg.IsSkewed(GetTimeNow()))
        {
            m_XDOF.SetCurrent(Msg.m_dfVal,Msg.m_dfTime);
        }
    }
    if(PeekMail(NewMail,"NAV_Y",Msg))
    {
        if(!Msg.IsSkewed(GetTimeNow()))
        {
            m_YDOF.SetCurrent(Msg.m_dfVal,Msg.m_dfTime);
        }
    }
    if(PeekMail(NewMail,"NAV_DEPTH",Msg))
    {
        if(!Msg.IsSkewed(GetTimeNow()))
        {
            m_DepthDOF.SetCurrent(Msg.m_dfVal,Msg.m_dfTime);
        }
    }

    //always call base class version
    CMOOSBehaviour::OnNewMail(NewMail);

    return true;
}
コード例 #2
0
ファイル: ZPatternTask.cpp プロジェクト: alod83/IS-MOOS
bool CZPatternTask::OnNewMail(MOOSMSG_LIST &NewMail)
{
    CMOOSMsg Msg;
    
    if(PeekMail(NewMail,"NAV_DEPTH",Msg))
    {
        if(!Msg.IsSkewed(GetTimeNow()))
        {
        m_DepthDOF.SetCurrent(Msg.m_dfVal,Msg.m_dfTime);
        }
    }

    if(PeekMail(NewMail,"NAV_PITCH",Msg))
    {
        if(!Msg.IsSkewed(GetTimeNow()))
        {
        m_PitchDOF.SetCurrent(Msg.m_dfVal,Msg.m_dfTime);
        }
    }


    //always call base class version
    CMOOSBehaviour::OnNewMail(NewMail);

    return true;
}
コード例 #3
0
ファイル: ARec.cpp プロジェクト: deardaniel/PizzaTest
// Send a marker packet to output
void ARec::SendMarkerPkt(string marker)
{
  AStringData *sd = new AStringData(cname+"::"+marker);
  APacket mkrpkt(sd);
  mkrpkt.SetStartTime(GetTimeNow());
  mkrpkt.SetEndTime(GetTimeNow());
  out->PutPacket(mkrpkt);
  if (trace&T_OUT)mkrpkt.Show();
}
コード例 #4
0
ファイル: ASyn.cpp プロジェクト: deardaniel/PizzaTest
// ChkAckBuf: check acks coming from sink and update host on status
void ASyn::ChkAckBuf()
{
   if (!ackbuf->IsEmpty()){
      // first unpack the incoming packet which has the form
      //   cmd(ss,playedSamps,totalSamps)
      APacket p = ackbuf->GetPacket();
      if (p.GetKind() != CommandPacket) {
         HRError(12002,"ASyn:ChkAckBuf - non-command pkt in ackbuf\n");
         throw ATK_Error(12002);
      }
      ACommandData * cd = (ACommandData *) p.GetData();
      string ack = cd->GetCommand();
      int ss = cd->GetInt(0);
      int played = cd->GetInt(1);
      int total = cd->GetInt(2);
      // next construct reply command
      cd = new ACommandData(ack);
      // if intermediate state, then figure out what has been played
      string word;
      if (ack=="aborted" || ack=="muted" || ack=="unmuted"){
         int idx;
         float percent;
         if (ss==seqnum) {  // still current output utterance
               //printf("********* p=%d,t=%d,nw=%d,b1=%d,b2=%d\n",
               //played,total,syn->GetNumWords(),
               //syn->GetBoundary(1),syn->GetBoundary(2));
            idx = syn->GetNumWords();
            while (idx>0 && syn->GetBoundary(idx)>played) --idx;
            word = "";
            if (idx>0) word = syn->GetWord(idx);
            percent = 100.0*played/total;
         }else{
            idx=0; percent=100.0; word=".";
         }
         cd->AddArg(ss); cd->AddArg(idx);
         cd->AddArg(word); cd->AddArg(percent);
         if (ack=="aborted") syn->EndUtterance();
         if (trace&T_ABT)
            printf("ASyn: syn interrupted: ss=%d,played=%d,total=%d,idx=%d[%s]\n",
                    ss,played,total,idx,word.c_str());
      }else if (ack == "started") {
         cd->AddArg(ss); cd->AddArg(total);
      }else if (ack == "error" || ack == "finished") {
         cd->AddArg(ss); syn->EndUtterance();
      }
      APacket reppkt(cd);
      reppkt.SetStartTime(GetTimeNow());
      reppkt.SetEndTime(GetTimeNow());
      repbuf->PutPacket(reppkt);
      if (trace&T_TOP){
         printf("ASyn: reply sent - "); cd->Show(); printf("\n");
      }
   }
}
コード例 #5
0
ファイル: cdb_dump_util.c プロジェクト: PengJi/gpdb-comments
/* Simple error logging to stderr with msg caching for later re-use */
void
mpp_err_msg_cache(const char *loglevel, const char *prog, const char *fmt,...)
{
	va_list		ap;
	char		szTimeNow[18];
	int			len;

	va_start(ap, fmt);
	fprintf(stderr, "%s|%s-[%s]:-", GetTimeNow(szTimeNow), prog, loglevel);
	vfprintf(stderr, gettext(fmt), ap);
	va_end(ap);

	/* cache a copy of the message - we may need it for a report */
	va_start(ap, fmt);
	len = vsnprintf(predump_errmsg, sizeof(predump_errmsg), gettext(fmt), ap);
	va_end(ap);

	/*
	 * If the passed error string exceeds the size of the buffer, indicate that
	 * by suffixing the string with ".."
	 */
	if (len > sizeof(predump_errmsg))
	{
		int		i;
		for (i = sizeof(predump_errmsg) - 3; predump_errmsg[i]; i++)
			predump_errmsg[i] = '.';
	}
}
コード例 #6
0
ファイル: ASyn.cpp プロジェクト: deardaniel/PizzaTest
// TalkCmd: synthesise the string and start playing it
void ASyn::TalkCmd()
{
   AWaveData *wd;
   char cbuf[100];
   short *wave,*p;
   int size,n;
   string text;

   if (!GetStrArg(text))
      HPostMessage(HThreadSelf(),"TalkCmd: synthesis string expected\n");
   if (trace&T_TOP)
      printf("ASyn: talk request = %s\n",text.c_str());   // convert text to waveform
   syn->StartUtterance(text);
   n = syn->GetNumSamples();
   if (n==0){
      string err="TalkCmd: cannot synthesise "+text+"\n";
      HPostMessage(HThreadSelf(),err.c_str());
   }
   // packet up the wave and send it to ASource
   // - first create header
   ++seqnum;
   sprintf(cbuf,"%d:%d",seqnum,n);
   AStringData *sd = new AStringData(string(cbuf));
   APacket hdrpkt(sd);
   hdrpkt.SetStartTime(GetTimeNow());
   hdrpkt.SetEndTime(GetTimeNow());
   audbuf->PutPacket(hdrpkt);
   // - then chop wave into packets
   p = syn->GetWave();
   while (n>0){
      size = n;
      if (size>WAVEPACKETSIZE) size = WAVEPACKETSIZE;
      wd = new AWaveData(size,p);
      n -= size; p += size;
      APacket wavpkt(wd);
      audbuf->PutPacket(wavpkt);
   }
   // - finally send command to start playback
   sprintf(cbuf,"startout(%d)",seqnum);
   sink->SendMessage(string(cbuf));
   state = synth_talking;
}
コード例 #7
0
ファイル: cdb_dump_util.c プロジェクト: PengJi/gpdb-comments
/* Simple error logging to stdout  */
void
mpp_msg(const char *loglevel, const char *prog, const char *fmt,...)
{
	va_list		ap;
	char		szTimeNow[18];

	va_start(ap, fmt);
	fprintf(stdout, "%s|%s-[%s]:-", GetTimeNow(szTimeNow), prog, loglevel);
	vfprintf(stdout, gettext(fmt), ap);
	va_end(ap);
}
コード例 #8
0
ファイル: ARec.cpp プロジェクト: deardaniel/PizzaTest
// Flush  a single observation
Boolean ARec::FlushObservation()
{
   APacket pkt;
   AStringData *sd;
   AObsData *od;
   PacketKind kind;
   Boolean flushing = TRUE;

   stTime = -1.0;  // ensure -ve before switching to runstate
   if (runmode&RUN_IMMED) // no flushing
      return TRUE;

   while (in->NumPackets()>0){
      pkt = in->PeekPacket(); kind = pkt.GetKind();

      if (kind==StringPacket) {
         in->PopPacket(); StoreMarker(pkt);
         sd = (AStringData *)pkt.GetData();
         if (sd->data.find("TERMINATED")!=string::npos) terminated=TRUE;
         if (runmode&FLUSH_TOMARK) {
            // if start or endoflist marker found, flushing complete
            string::size_type posn = sd->data.find("ENDOFLIST");
            if (posn != string::npos ) {
               OutPacket(Start_PT, "","ENDOFLIST",0,0,0.0,0.0,0.0,-1,0.0,0.0,0.0);
               terminated = TRUE;
               return TRUE;
            }
            posn = sd->data.find("START");
            if (posn != string::npos) {
               string::size_type pos1 = sd->data.find("(");
               string::size_type pos2 = sd->data.find(")");
               if (pos1<1 || pos2<pos1) return TRUE;
               fname = string(sd->data,pos1+1,pos2-pos1-1);
               return TRUE;
            }
         }
         OutMarkers(GetTimeNow());
      } else
         if (kind==ObservationPacket){
            // if speech flagged observation, flushing complete
            if (runmode&FLUSH_TOSPEECH) {
               od = (AObsData *)pkt.GetData();
               if (od->data.vq[0]) return TRUE;
            }
            in->PopPacket();
         } else {
            in->PopPacket();	// ignore non-string or -obs packets
         }
   }
   return FALSE;
}
コード例 #9
0
ファイル: ThirdPartyTask.cpp プロジェクト: alod83/IS-MOOS
bool CThirdPartyTask::Run(CPathAction &DesiredAction)
{

    if(!m_bInitialised)
    {
        Initialise();
    }

    if(!m_bEnabled)
        return true;


    if(m_Rudder.GetAge(GetTimeNow())<THIRDPARTY_STALE)
    {
        DesiredAction.Set(  ACTUATOR_RUDDER,
                            m_Rudder.GetDoubleVal(),
                            m_nPriority,
                            m_sJob.c_str());
    }

    if(m_Elevator.GetAge(GetTimeNow())<THIRDPARTY_STALE)
    {
        DesiredAction.Set(  ACTUATOR_ELEVATOR,
                            m_Elevator.GetDoubleVal(),
                            m_nPriority,
                            m_sJob.c_str());
    }

    if(m_Thrust.GetAge(GetTimeNow())<THIRDPARTY_STALE)
    {
        DesiredAction.Set(  ACTUATOR_THRUST,
                            m_Thrust.GetDoubleVal(),
                            m_nPriority,
                            m_sJob.c_str());
    }

    return true;
}
コード例 #10
0
ファイル: ThirdPartyTask.cpp プロジェクト: alod83/IS-MOOS
bool CThirdPartyTask::OnNewMail(MOOSMSG_LIST &NewMail)
{
    CMOOSMsg Msg;

    if(PeekMail(NewMail,m_sJob,Msg) && Msg.m_sSrc==m_sClient)
    {
        if(!Msg.IsSkewed(GetTimeNow()))
        {
            return OnNewInstruction(Msg.m_sVal,Msg.m_dfTime);
        }
    }

    return true;
}
コード例 #11
0
ファイル: cdb_dump_util.c プロジェクト: hellower/gpdb
/* Simple error logging to stderr with msg caching for later re-use */
void
mpp_err_msg_cache(const char *loglevel, const char *prog, const char *fmt,...)
{
	va_list		ap;
	char		szTimeNow[18];

	va_start(ap, fmt);
	fprintf(stderr, "%s|%s-[%s]:-", GetTimeNow(szTimeNow), prog, loglevel);
	vfprintf(stderr, gettext(fmt), ap);
	va_end(ap);

	/* cache a copy of the message - we may need it for a report */
	va_start(ap, fmt);
	vsprintf(predump_errmsg, gettext(fmt), ap);
	va_end(ap);
}
コード例 #12
0
ファイル: FileOutputer.cpp プロジェクト: ArkEngine/flexse
void FileOutputer :: FileCheckOpen()
{
    char  curpath[FileNameMaxLen];
    uint32_t daynow = GetTimeNow();
    if (daynow != mLastDay)
    {
        close(m_fd);
        snprintf(curpath, sizeof(curpath), "%s.%d", m_path, daynow);
        m_fd = open(curpath, O_WRONLY|O_CREAT|O_APPEND, S_IRWXU|S_IRWXG|S_IRWXO);
        if (m_fd < 0)
        {
            fprintf(stderr, "FILE[%s:%u] create logfile[%s] fail. msg[%m]\n", __FILE__, __LINE__, curpath);
            while(0 != raise(SIGKILL)){}
        }
        mLastDay = daynow;
    }
}
コード例 #13
0
ファイル: project2.c プロジェクト: tmathmeyer/Networks
void init( ) {
    int      i;
    double   sum, avg;
    double   TimeNow;
    char     TempString[50];
  
    printf("-----  Network Simulator Version 2.30 -------- \n\n");
    if ( CallingArgc  >= 9 ) {
        MaxMsgsToSimulate      = atoi( CallingArgv[1] );
        LossProb               = atof( CallingArgv[2] );
        CorruptProb            = atof( CallingArgv[3] );
        OutOfOrderProb         = atof( CallingArgv[4] );
        AveTimeBetweenMsgs     = atof( CallingArgv[5] );
        TraceLevel             = atoi( CallingArgv[6] );
        RandomizationRequested = atoi( CallingArgv[7] );
        Bidirectional          = atoi( CallingArgv[8] );
    }
    else {
        printf("Enter the number of messages to simulate: ");
        scanf( "%d", &MaxMsgsToSimulate);
        printf("Packet loss probability [enter number between 0.0 and 1.0]: ");
        scanf( "%s", &TempString );
        LossProb = atof( TempString );
        printf("Packet corruption probability [0.0 for no corruption]: ");
        scanf( "%s", &TempString );
        CorruptProb = atof( TempString );
        printf("Packet out-of-order probability [0.0 for no out-of-order]: ");
        scanf( "%s", &TempString );
        OutOfOrderProb = atof( TempString );
        printf("Average time between messages from sender's layer5 [ > 0.0]: ");
        scanf( "%s", &TempString );
        AveTimeBetweenMsgs     = atof( TempString );
        printf("Enter Level of tracing desired: ");
        scanf( "%d", &TraceLevel);
        printf("Do you want actions randomized: (1 = yes, 0 = no)? " );
        scanf( "%d", &RandomizationRequested);
        printf("Do you want Bidirectional: (1 = yes, 0 = no)? " );
        scanf( "%d", &Bidirectional);
    }
    //  Do sanity checking on inputs:
    if (   LossProb < 0 || LossProb> 1.0 || CorruptProb < 0 
                        || CorruptProb > 1.0 || OutOfOrderProb < 0 
                        || OutOfOrderProb > 1.0 || AveTimeBetweenMsgs <= 0.0 )
    {
         printf( "One of your input parameters is out of range\n");
         exit(0);
    }
    printf( "Input parameters:\n");
    printf( "Number of Messages = %d", MaxMsgsToSimulate );
    printf( "  Lost Packet Prob. =  %6.3f\n", LossProb );
    printf( "Corrupt Packet Prob. =  %6.3f", CorruptProb );
    printf( "  Out Of Order Prob. =  %6.3f\n", OutOfOrderProb );
    printf( "Ave. time between messages = %8.2f", AveTimeBetweenMsgs );
    printf( "  Trace level = %d\n", TraceLevel );
    printf( "Randomize = %d", RandomizationRequested );
    printf( "  Bi-directional = %d\n\n", Bidirectional );

    if ( RandomizationRequested == 1 )   {
        GetTimeNow( &TimeNow );
        SetRandomSeed( (long)TimeNow );
    }
    // test random number generator for students 
    // GetRandomNumber() should be uniform in [0,1] 
    sum = 0.0;               
    for (i = 0; i < 1000; i++)
        sum = sum + GetRandomNumber();  
    avg = sum/1000.0;
    if (avg < 0.25 || avg > 0.75) {
        printf("It is likely that random number generation on your machine\n" );
        printf("is different from what this emulator expects.  Please look\n");
        printf("at the routine GetRandomNumber() in the emulator. Sorry. \n");
        exit(0);
    }

    NumMsgs4To3        = 0;              /* Initialize Counters    */
    NumMsgsLost        = 0;
    NumMsgsCorrupt     = 0;
    NumSimutaneousMsgs = 0;

    CurrentSimTime = 0.0;                  /* initialize time to 0.0 */
    GenerateNextArrival();     /* initialize event list */
}                               /*  End of init()   */