Ejemplo n.º 1
0
Uint32		convGetMeasuredSpeed()
{
	Uint32 	unDeltaMs;
	Uint32	unTempDeltaTicks;
	Uint32	unTempDeltaMs;
	Uint32	fpTriggersPerSecond;
	Uint32	fpLastSpeed;
	
		
	// Calculate the last interval in ms.
	unDeltaMs = timeToMs( convObject.unLastDeltaTicks );
	if ( unDeltaMs == 0 )
		return 0;	
	
	// And convert to speed (note: speed is Q.16 format and m/s).
	fpTriggersPerSecond = (1 << DRVCONV_FRACTIONAL_BITS) * 1000  / unDeltaMs;
	fpLastSpeed = fpTriggersPerSecond * convObject.unMillimetersPerTrigger / 1000;	
	
	// If standing, the speed is 0.
	if ( convObject.bStanding )
		return 0;

	// Determine delta time since last trigger.
	unTempDeltaTicks = timeGetHighResTime() - convObject.unLastTicks;
	
	// If delta is too big, the conveyor is declared to be standing and thus its speed
	// is 0 as well.
	if ( timeToMs(unTempDeltaTicks) > convHal.unTimeout )
	{
		//dbgLog("Set to standing because toMs(%ud)=%d > %d", unTempDeltaTicks, timeToMs(unTempDeltaTicks), convHal.unTimeout );
		//dbgLog(" unLastTicks = %ud, curTime= %ud", convObject.unLastTicks, timeGetHighResTime() );
		convObject.bStanding = TRUE;
		return 1;
	}
	
	/*
	// If speed*tempDelta is greater than the distance between two triggers,
	// reduce speed so that speed = distance / curDeltaTime.
	unTempDeltaMs = timeToMs(unTempDeltaTicks);
	
	if ( ( (unTempDeltaMs * fpLastSpeed)>> DRVCONV_FRACTIONAL_BITS ) > CONV_MILLIMETERS_PER_TRIGGER)
	{		
		dbgLog("Time: %ud, deltaMs: %u", timeGetHighResTime(), unTempDeltaMs );
		dbgLog("Reduced speed because %d > %d. From %f to %f",
			(unTempDeltaMs * fpLastSpeed) >> DRVCONV_FRACTIONAL_BITS, 
			CONV_MILLIMETERS_PER_TRIGGER,
			(float)fpLastSpeed / 65536.0,
			(float)(((1<< DRVCONV_FRACTIONAL_BITS ) * CONV_MILLIMETERS_PER_TRIGGER) / unTempDeltaMs) / 65536.0 );
			
		if ( unTempDeltaMs == 0 )
			return 1;
			
		fpLastSpeed = ((1<< DRVCONV_FRACTIONAL_BITS ) * CONV_MILLIMETERS_PER_TRIGGER) / unTempDeltaMs;
	}
	*/	
	
	return fpLastSpeed;
}
Ejemplo n.º 2
0
 TimeInPeriod TimerManagerClass::isTimeInPeriod(const char *startc, const char* endc) {
   int32_t  now   = getGMTime();
   if (now < 0) return TP_UNDEFINED;
   //if (DEBUG) Serial << F("now(): ") << msToStr(now) << endl;
   now += PropertyList.readLongProperty(PROP_TZOFFSET) * 60 * 1000;
   //if (DEBUG) Serial << F("now(tz adjusted): ") << msToStr(now) << endl;
   if (now < 0) now += ONE_DAY_MS;
   uint32_t start = timeToMs(startc);
   uint32_t end   = timeToMs(endc);
   if (start > end) end += ONE_DAY_MS;
   if ( (now > start && now < end) ||
        (now + ONE_DAY_MS > start && now + ONE_DAY_MS < end)) return TP_IN;
   return TP_OUT;
 }
Ejemplo n.º 3
0
Uint32		convGetPosition()
{
	Uint32 pos;
	Uint32 deltaTimeMs;	
	Uint32 speed;
	Uint32 offset;
	
	pos = convObject.unNumTotalTriggerSignals * CONV_MILLIMETERS_PER_TRIGGER;
	
	// if standing, the conveyor's position is right before the next
	// trigger point.
	if ( convObject.bStanding )
	{
		pos += CONV_MILLIMETERS_PER_TRIGGER;
		return pos;
	}
	
	
	// determine current delta time since last trigger signal
	// conveyor position is at speed * deltatime + last trigger's
	// position.
	deltaTimeMs = timeToMs( timeGetHighResTime() - convObject.unLastTicks );
	speed = convGetMeasuredSpeed();
	offset = ( speed * deltaTimeMs) >> DRVCONV_FRACTIONAL_BITS;
	
	//dbgLog("pos %d: deltaMs: %d, speed: %d, pos+:%d", pos, deltaTimeMs, speed, offset );
	
	pos += offset;
	
	return pos;	
}
Ejemplo n.º 4
0
void stdLogger(int level, string_view msg) noexcept
{
  const auto now = UnixClock::now();
  const auto t = UnixClock::to_time_t(now);
  const auto ms = timeToMs(now);

  struct tm tm;
  localtime_r(&t, &tm);

  // The following format has an upper-bound of 42 characters:
  // "%b %d %H:%M:%S.%03d %-7s [%d]: "
  //
  // Example:
  // Mar 14 00:00:00.000 WARNING [0123456789]: msg...
  // <---------------------------------------->
  char head[42 + 1];
  size_t hlen = strftime(head, sizeof(head), "%b %d %H:%M:%S", &tm);
  hlen += sprintf(head + hlen, ".%03d %-7s [%d]: ", static_cast<int>(ms % 1000), logLabel(level),
                  static_cast<int>(getpid()));
  char tail = '\n';
  iovec iov[] = {
    {head, hlen}, //
    {const_cast<char*>(msg.data()), msg.size()}, //
    {&tail, 1} //
  };

  int fd{level > LogWarning ? STDOUT_FILENO : STDERR_FILENO};
// Best effort given that this is the logger.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
  writev(fd, iov, sizeof(iov) / sizeof(iov[0]));
#pragma GCC diagnostic pop
}
Ejemplo n.º 5
0
/*
 * Watches socket to find a response for the given title
 * using TIMEOUT as maximum time to wait
 * returns adress:port string
 */
char* discoverHost(int sock, char* title)
{
	struct timeval timeout;
	int found = 0;
	fd_set fds;
	char message[MESSAGE_SIZE];
	int titleLen = strlen(title);

	msToTime(TIMEOUT, &timeout); //set up the timeout

	while(timeToMs(&timeout) > 0){
		//use select() to wait on socket up to timeout
		FD_ZERO(&fds);
		FD_SET(sock, &fds);
		select(sock+1, &fds, NULL, NULL, &timeout);

		if(FD_ISSET(sock, &fds)) {
			mrecv(sock, message, MESSAGE_SIZE); //read next message from socket
			//check if its the right title
			if(strncmp(title, message, titleLen) == 0){
				//get second line, which will have address:port
				char* host = (char*) calloc(strlen(message)-titleLen, sizeof(char));
				strcpy(host, &message[titleLen+1]);
				return host;
			}
		}
	}

	//matching host was not found, return NULL
	return NULL;
}
Ejemplo n.º 6
0
void AsyncJourn::doCreateExec(const Exec& exec, More more)
{
  pipe_.write([&exec, more](Msg& msg) {
    msg.type = MsgType::CreateExec;
    auto& body = msg.createExec;
    setCString(body.accnt, exec.accnt());
    body.marketId = exec.marketId();
    setCString(body.contr, exec.contr());
    body.settlDay = exec.settlDay();
    body.id = exec.id();
    body.orderId = exec.orderId();
    setCString(body.ref, exec.ref());
    body.state = exec.state();
    body.side = exec.side();
    body.lots = exec.lots();
    body.ticks = exec.ticks();
    body.resd = exec.resd();
    body.exec = exec.exec();
    body.cost = exec.cost();
    body.lastLots = exec.lastLots();
    body.lastTicks = exec.lastTicks();
    body.minLots = exec.minLots();
    body.matchId = exec.matchId();
    body.liqInd = exec.liqInd();
    setCString(body.cpty, exec.cpty());
    body.created = timeToMs(exec.created());
    body.more = more;
  });
}
Ejemplo n.º 7
0
 int32_t TimerManagerClass::updateLastTime() {
   String googleTime;
   getTimeFromGoogle(googleTime);
   const char *d1 = googleTime.c_str();
   if (strlen(d1) < 20) return -1;
   //if (DEBUG) Serial << F("Time From Google: ") << d1 << endl;
   int32_t tg = timeToMs(d1 + strlen(d1) - 12);
   rtcMemStore.setGenData(GEN_LASTTIME, tg); //in case the format of the time changes 01 vs 1
   //Serial << "  time google: " << msToStr(tg) << endl;
   return tg;
 }
Ejemplo n.º 8
0
void CClassification::GetStats( ClassificationStats * stats, Bool bReset )
{
#ifndef _WINDOWS // ------- Don't compile on windows -----

	// First, disable all SWI, so that we're not be disturbed here. There shouldn't
	// be any critical task running at the moment, since this function will mainly be
	// called from the control task.
	
//	SWI_disable();
	
	// copy all fields
	if ( stats != NULL )
	{
		stats->unElapsedTime = timeToMs( timeGetHighResTime() - m_sClassificationStats.unElapsedTime );
		stats->unNumProcessed = m_sClassificationStats.unNumProcessed;
		stats->unNumPossible = m_sClassificationStats.unNumPossible;
		stats->fp16ConveyorSpeed = convGetMeasuredSpeed();
		stats->unNumRejectedTotal = m_sClassificationStats.unNumRejectedTotal;
		stats->unNumRejectedSplit = m_sClassificationStats.unNumRejectedSplit;
		stats->unNumRejectedColor = m_sClassificationStats.unNumRejectedColor;
		stats->unNumRejectedGreen = m_sClassificationStats.unNumRejectedGreen;
		stats->unNumRejectedShape = m_sClassificationStats.unNumRejectedShape;
	}
	
	
	if ( bReset )
	{
		m_sClassificationStats.unElapsedTime = timeGetHighResTime();
		m_sClassificationStats.unNumProcessed = 0;
		m_sClassificationStats.unNumPossible = 0;
		m_sClassificationStats.unNumRejectedTotal = 0;
		m_sClassificationStats.unNumRejectedSplit = 0;
		m_sClassificationStats.unNumRejectedColor = 0;
		m_sClassificationStats.unNumRejectedGreen = 0;
		m_sClassificationStats.unNumRejectedShape = 0;
	}

	//	SWI_enable();

#endif // ------------------------------------------------

}
Ejemplo n.º 9
0
void AsyncJourn::doArchiveTrade(Id64 marketId, ArrayView<Id64> ids, Time modified, More more)
{
  assert(ids.size() <= MaxIds);
  pipe_.write([&marketId, ids, modified, more](Msg& msg) {
    msg.type = MsgType::ArchiveTrade;
    auto& body = msg.archiveTrade;
    body.marketId = marketId;
    // Cannot use copy and fill here because ArchiveBody is a packed struct:
    // auto it = copy(ids.begin(), ids.end(), begin(body.ids));
    // fill(it, end(body.ids), 0);
    size_t i{0};
    for (; i < ids.size(); ++i) {
      body.ids[i] = ids[i];
    }
    for (; i < MaxIds; ++i) {
      body.ids[i] = 0_id64;
    }
    body.modified = timeToMs(modified);
    body.more = more;
  });
}