本文整理汇总了C++中ArTime::mSecTo方法的典型用法代码示例。如果您正苦于以下问题:C++ ArTime::mSecTo方法的具体用法?C++ ArTime::mSecTo怎么用?C++ ArTime::mSecTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArTime
的用法示例。
在下文中一共展示了ArTime::mSecTo方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
AREXPORT int ArTcpConnection::read(const char *data, unsigned int size,
unsigned int msWait)
{
ArTime timeDone;
unsigned int bytesRead = 0;
int n;
if (getStatus() != STATUS_OPEN)
{
ArLog::log(ArLog::Terse,
"ArTcpConnection::read: Attempt to use port that is not open.");
return -1;
}
int timeToWait;
timeDone.setToNow();
timeDone.addMSec(msWait);
do
{
timeToWait = timeDone.mSecTo();
if (timeToWait < 0)
timeToWait = 0;
n = mySocket->read(const_cast<char *>(data) + bytesRead, size - bytesRead,
timeToWait);
/*if (n == -1)
{
ArLog::log("ArTcpConnection::read: read failed.");
return -1;
} */
//printf("%ld %d %d\n", timeDone.mSecTo(), n, size);
if (n != -1)
bytesRead += n;
if (bytesRead >= size)
return bytesRead;
} while (timeDone.mSecTo() >= 0);
return bytesRead;
}
示例2: read
AREXPORT int ArSerialConnection::read(const char *data, unsigned int size,
unsigned int msWait)
{
struct timeval tp; /* time interval structure for timeout */
fd_set fdset; /* fd set ??? */
int n;
long timeLeft;
unsigned int bytesRead = 0;
ArTime timeDone;
if (myPort >= 0)
{
if (msWait >= 0)
{
timeDone.setToNow();
if (!timeDone.addMSec(msWait)) {
ArLog::log(ArLog::Normal,
"ArSerialConnection::read() error adding msecs (%i)",
msWait);
}
while ((timeLeft = timeDone.mSecTo()) >= 0)
{
tp.tv_sec = (timeLeft) / 1000; /* we're polling */
tp.tv_usec = (timeLeft % 1000) * 1000;
FD_ZERO(&fdset);
FD_SET(myPort,&fdset);
if (select(myPort+1,&fdset,NULL,NULL,&tp) <= 0)
return bytesRead;
if ((n = ::read(myPort, const_cast<char *>(data)+bytesRead,
size-bytesRead)) == -1)
{
ArLog::logErrorFromOS(ArLog::Terse, "ArSerialConnection::read: Blocking read failed.");
return bytesRead;
}
bytesRead += n;
if (bytesRead >= size)
return bytesRead;
}
return bytesRead;
}
else
{
n = ::read(myPort, const_cast<char *>(data), size);
if (n == -1)
ArLog::logErrorFromOS(ArLog::Terse, "ArSerialConnection::read: Non-Blocking read failed.");
return n;
}
}
ArLog::log(ArLog::Normal, "ArSerialConnection::read: Connection invalid.");
return -1;
}
示例3: read
AREXPORT int ArSerialConnection::read(const char *data, unsigned int size,
unsigned int msWait)
{
COMSTAT stat;
unsigned long ret;
unsigned int numToRead;
ArTime timeDone;
if (myPort != INVALID_HANDLE_VALUE && myStatus == STATUS_OPEN)
{
if (msWait > 0)
{
timeDone.setToNow();
if (!timeDone.addMSec(msWait)) {
ArLog::log(ArLog::Normal,
"ArSerialConnection::read() error adding msecs (%i)",
msWait);
}
while (timeDone.mSecTo() >= 0)
{
if (!ClearCommError(myPort, &ret, &stat))
return -1;
if (stat.cbInQue < size)
ArUtil::sleep(2);
else
break;
}
}
if (!ClearCommError(myPort, &ret, &stat))
return -1;
if (stat.cbInQue == 0)
return 0;
if (stat.cbInQue > size)
numToRead = size;
else
numToRead = stat.cbInQue;
if (ReadFile( myPort, (void *)data, numToRead, &ret, NULL))
{
return (int)ret;
}
else
{
ArLog::logErrorFromOS(ArLog::Terse, "ArSerialConnection::read: Read failed.");
return -1;
}
}
ArLog::log(ArLog::Terse, "ArSerialConnection::read: Connection invalid.");
return -1;
}
示例4: ArRobotPacket
/**
@param msWait how long to block for the start of a packet, nonblocking if 0
@return NULL if there are no packets in alloted time, otherwise a pointer
to the packet received, if allocatePackets is true than the place that
called this function owns the packet and should delete the packet when
done... if allocatePackets is false then nothing must store a pointer to
this packet, the packet must be used and done with by the time this
method is called again
*/
AREXPORT ArRobotPacket *ArRobotPacketReceiver::receivePacket(
unsigned int msWait)
{
ArRobotPacket *packet;
unsigned char c;
char buf[256];
int count = 0;
// state can be one of the STATE_ enums in the class
int state = STATE_SYNC1;
//unsigned int timeDone;
//unsigned int curTime;
long timeToRunFor;
ArTime timeDone;
ArTime lastDataRead;
ArTime packetReceived;
int numRead;
if (myAllocatePackets)
packet = new ArRobotPacket(mySync1, mySync2);
else
packet = &myPacket;
if (packet == NULL || myDeviceConn == NULL ||
myDeviceConn->getStatus() != ArDeviceConnection::STATUS_OPEN)
{
if (myAllocatePackets)
delete packet;
return NULL;
}
timeDone.setToNow();
timeDone.addMSec(msWait);
// check for log file connection, return assembled packet
if (dynamic_cast<ArLogFileConnection *>(myDeviceConn))
{
packet->empty();
packet->setLength(0);
packetReceived = myDeviceConn->getTimeRead(0);
packet->setTimeReceived(packetReceived);
numRead = myDeviceConn->read(buf, 255, 0);
if (numRead > 0)
{
packet->dataToBuf(buf, numRead);
packet->resetRead();
return packet;
}
else
{
if (myAllocatePackets)
delete packet;
return NULL;
}
}
do
{
timeToRunFor = timeDone.mSecTo();
if (timeToRunFor < 0)
timeToRunFor = 0;
if (myDeviceConn->read((char *)&c, 1, timeToRunFor) == 0)
{
if (state == STATE_SYNC1)
{
if (myAllocatePackets)
delete packet;
return NULL;
}
else
{
//ArUtil::sleep(1);
continue;
}
}
switch (state) {
case STATE_SYNC1:
if (c == mySync1) // move on, resetting packet
{
state = STATE_SYNC2;
packet->empty();
packet->setLength(0);
packet->uByteToBuf(c);
packetReceived = myDeviceConn->getTimeRead(0);
packet->setTimeReceived(packetReceived);
}
else
{
//printf("Bad sync1 %d\n", c);
//.........这里部分代码省略.........
开发者ID:eilo,项目名称:Evolucion-Artificial-y-Robotica-Autonoma-en-Robots-Pioneer-P3-DX,代码行数:101,代码来源:ArRobotPacketReceiver.cpp
示例5: if
AREXPORT ArNetPacketReceiverTcp::Ret ArNetPacketReceiverTcp::readPacket(int msWait)
{
long timeToRunFor = -1;
int numRead = 0;
bool printing = true;
int ret = 0;
unsigned char c = 0;
ArTime timeDone;
timeDone.setToNow();
timeDone.addMSec(msWait);
//printf("Read packet!\n");
do
{
timeToRunFor = timeDone.mSecTo();
if (timeToRunFor < 0)
timeToRunFor = 0;
if (myState != STATE_ACQUIRE_DATA)
{
c = 0;
if ((ret = mySocket->read((char *)&c, 1, 0/*timeToRunFor*/)) == -1)
{
if (myState == STATE_SYNC1)
{
return RET_FAILED_READ;
}
else
{
//ArUtil::sleep(1);
continue;
}
}
else if (ret == 0)
{
return RET_CONN_CLOSED;
}
}
/*
if (myState != STATE_ACQUIRE_DATA)
{
printf("%d", myState);
printf(" %d\n", c);
}
*/
//else
//{
//printf("\n");
//}
switch (myState) {
case STATE_SYNC1:
if (c == mySync1) // move on, resetting packet
{
myState = STATE_SYNC2;
myPacket.empty();
myPacket.setLength(0);
myPacket.uByteToBuf(c);
}
else
{
if (printing)
ArLog::log(ArLog::Verbose, "%sBad char in sync1 %d", myLoggingPrefix.c_str(), c);
return RET_BAD_PACKET;
}
break;
case STATE_SYNC2:
if (c == mySync2) // move on, adding this byte
{
myState = STATE_LENGTH1;
myPacket.uByteToBuf(c);
}
else // go back to beginning, packet hosed
{
if (printing)
ArLog::log(ArLog::Verbose, "%sBad char in sync2 %d, returning to sync1", myLoggingPrefix.c_str(), c);
myState = STATE_SYNC1;
return RET_BAD_PACKET;
}
break;
case STATE_LENGTH1:
myState = STATE_LENGTH2;
myReadLength = ((unsigned int)c & 0xff);
myPacket.uByteToBuf(c);
break;
case STATE_LENGTH2:
myState = STATE_ACQUIRE_DATA;
myReadLength += ((unsigned int)c & 0xff) << 8;
myPacket.uByteToBuf(c);
myReadCount = 0;
break;
case STATE_ACQUIRE_DATA:
if (myReadLength > ArNetPacket::MAX_LENGTH ||
myReadLength < myPacket.getHeaderLength() + myPacket.getFooterLength())
{
if (!myQuiet)
ArLog::log(ArLog::Normal,
"%sArNetPacketReceiverTcp::readPacket: bad packet length, it is %d which is more than max length of %d bytes or less than the minimum %d",
myLoggingPrefix.c_str(), myReadLength,
//.........这里部分代码省略.........
示例6: if
/**
@param msWait how long to block for the start of a packet, nonblocking if 0
@return NULL if there are no packets in alloted time, otherwise a pointer
to the packet received, if allocatePackets is true than the place that
called this function owns the packet and should delete the packet when
done... if allocatePackets is false then nothing must store a pointer to
this packet, the packet must be used and done with by the time this
method is called again
*/
AREXPORT ArLMS2xxPacket *ArLMS2xxPacketReceiver::receivePacket(
unsigned int msWait)
{
ArLMS2xxPacket *packet;
unsigned char c;
char buf[2048];
long count = 0;
// state can be one of the STATE_ enums in the class
int state = STATE_START;
//unsigned int timeDone;
//unsigned int curTime;
long timeToRunFor;
long packetLength;
ArTime timeDone;
ArTime lastDataRead;
ArTime packetReceived;
int numRead;
if (myDeviceConn == NULL ||
myDeviceConn->getStatus() != ArDeviceConnection::STATUS_OPEN)
{
return NULL;
}
timeDone.setToNow();
timeDone.addMSec(msWait);
do
{
timeToRunFor = timeDone.mSecTo();
if (timeToRunFor < 0)
timeToRunFor = 0;
if (myDeviceConn->read((char *)&c, 1, timeToRunFor) == 0)
{
if (state == STATE_START)
{
return NULL;
}
else
{
//ArUtil::sleep(1);
continue;
}
}
//printf("%x\n", c);
switch (state) {
case STATE_START:
if (c == 0x02) // move on, resetting packet
{
//printf("###############\n");
state = STATE_ADDR;
myPacket.empty();
myPacket.setLength(0);
myPacket.uByteToBuf(c);
packetReceived = myDeviceConn->getTimeRead(0);
myPacket.setTimeReceived(packetReceived);
}
/*else
{
//printf(" BAD\n");
}*/
break;
case STATE_ADDR:
// if this is correct move on, adding this byte... this is taken
// out in favor of a more inclusive approach, if someone ever
// wnats to drive multiple robots off of one serial port just
// put this back in, or I don't know, punt
//if (c == ((unsigned char)0x80 + myReceivingAddress))
if (!myUseBase0Address && c >= 0x80 && c <= 0x84)
{
state = STATE_START_COUNT;
myPacket.uByteToBuf(c);
}
// c will always be >= 0 since its unsigned
else if (myUseBase0Address && c <= 0x4)
{
state = STATE_START_COUNT;
myPacket.uByteToBuf(c);
}
else // go back to beginning, packet hosed
{
ArLog::log(ArLog::Terse,
"ArLMS2xxPacketReceiver::receivePacket: wrong address (0x%x instead of 0x%x)", c, (unsigned) 0x80 + myReceivingAddress);
state = STATE_START;
}
break;
case STATE_START_COUNT:
packetLength = c;
myPacket.uByteToBuf(c);
//.........这里部分代码省略.........
示例7: msecs
ArSZSeriesPacket *ArSZSeriesPacketReceiver::receivePacket(unsigned int msWait,
bool startMode) {
ArSZSeriesPacket *packet;
unsigned char c;
long timeToRunFor;
ArTime timeDone;
ArTime lastDataRead;
ArTime packetReceived;
int i;
if (myConn == NULL || myConn->getStatus()
!= ArDeviceConnection::STATUS_OPEN) {
return NULL;
}
timeDone.setToNow();
if (!timeDone.addMSec(msWait)) {
ArLog::log(ArLog::Terse, "%s::receivePacket() error adding msecs (%i)",
myName, msWait);
}
//msWait = 100;
do {
timeToRunFor = timeDone.mSecTo();
if (timeToRunFor < 0)
timeToRunFor = 0;
/*
ArLog::log(ArLog::Terse,
"%s::receivePacket() timeToRunFor = %d",
myName, timeToRunFor);
*/
myPacket.empty();
myPacket.setLength(0);
myReadCount = 0;
unsigned char firstbytelen;
unsigned char secondbytelen;
unsigned char temp[4];
unsigned char crcbuf[10000];
memset(crcbuf, 0, 10000);
memset(myReadBuf, 0, 100000);
int n = 0;
#if 0
bool nonzero = true;
int zerocnt = 0;
char prev_c = 0x30;
while (nonzero)
{
if ((myConn->read((char *) &c, 1, msWait)) > 0)
{
if (((c == 0x00) && (zerocnt == 0)) || ((c == 0x00) && (prev_c == 0x00)))
{
zerocnt++;
prev_c = c;
if (zerocnt == 4)
nonzero = false;
}
else
{
zerocnt = 0;
prev_c = 0x30;
}
}
} // endwhile
//printf("WE FOUND A 4 ZERO's\n");
packetReceived = myConn->getTimeRead(0);
myPacket.setTimeReceived(packetReceived);
#endif
//#if 0
// look for initial sequence 0x00 0x00 0x00 0x00
for (i = 0; i < 4; i++) {
if ((myConn->read((char *) &c, 1, msWait)) > 0) {
if (c != 0x00) {
//printf("char = %x\n",c);
//ArLog::log(ArLog::Terse,
// "ArSZSeries::receivePacket() error reading first 4 bytes of header");
break;
}
if (i == 0) {
packetReceived = myConn->getTimeRead(0);
//ArTime previousTime = myPacket.getTimeReceived();
myPacket.setTimeReceived(packetReceived);
//ArLog::log(ArLog::Normal,
// "ms since = %d",
// packetReceived.mSecSince(previousTime));
}
} else {
/* don't log this if we are in starting mode, means laser is not connecting */
if (startMode)
ArLog::log(ArLog::Terse,
"%s::receivePacket() myConn->read error (header)",
myName);
return NULL;
}
} // end for
//.........这里部分代码省略.........
示例8: if
ArLMS1XXPacket *ArLMS1XXPacketReceiver::receivePacket(unsigned int msWait,
bool scandataShortcut)
{
ArLMS1XXPacket *packet;
unsigned char c;
long timeToRunFor;
ArTime timeDone;
ArTime lastDataRead;
ArTime packetReceived;
int numRead;
int i;
if (myConn == NULL ||
myConn->getStatus() != ArDeviceConnection::STATUS_OPEN)
{
return NULL;
}
timeDone.setToNow();
timeDone.addMSec(msWait);
do
{
timeToRunFor = timeDone.mSecTo();
if (timeToRunFor < 0)
timeToRunFor = 0;
//printf("%x\n", c);
if (myState == STARTING)
{
if ((numRead = myConn->read((char *)&c, 1, timeToRunFor)) <= 0)
return NULL;
if (c == '\002')
{
myState = DATA;
myPacket.empty();
myPacket.setLength(0);
myPacket.rawCharToBuf(c);
myReadCount = 0;
packetReceived = myConn->getTimeRead(0);
myPacket.setTimeReceived(packetReceived);
}
else
{
ArLog::log(ArLog::Normal,
"ArLMS1XXPacketReceiver: Failed read (%d)",
numRead);
}
}
else if (myState == DATA)
{
numRead = myConn->read(&myReadBuf[myReadCount],
sizeof(myReadBuf) - myReadCount,
5);
// trap if we failed the read
if (numRead < 0)
{
ArLog::log(ArLog::Normal,
"ArLMS1XXPacketReceiver: Failed read (%d)",
numRead);
myState = STARTING;
return NULL;
}
// see if we found the end of the packet
for (i = myReadCount; i < myReadCount + numRead; i++)
{
if (myReadBuf[i] == '\002')
{
ArLog::log(ArLog::Verbose, "ArLMS1XXPacketReceiver: Data found start of new packet...",
myReadCount);
myPacket.empty();
myPacket.setLength(0);
memmove(myReadBuf, &myReadBuf[i], myReadCount + numRead - i);
numRead -= (i - myReadCount);
myReadCount -= i;
i = 0;
continue;
}
if (myReadBuf[i] == '\003')
{
myPacket.dataToBuf(myReadBuf, i + 1);
myPacket.resetRead();
packet = new ArLMS1XXPacket;
packet->duplicatePacket(&myPacket);
myPacket.empty();
myPacket.setLength(0);
// if it's the end of the data just go back to the beginning
if (i == myReadCount + numRead - 1)
{
//ArLog::log(ArLog::Verbose, "ArLMS1XXPacketReceiver: Starting again");
myState = STARTING;
}
// if it isn't move the data up and start again
else
{
memmove(myReadBuf, &myReadBuf[i+1], myReadCount + numRead - i - 1);
myReadCount = myReadCount + numRead - i - 1;
myState = REMAINDER;
ArLog::log(ArLog::Verbose, "ArLMS1XXPacketReceiver: Got remainder, %d bytes beyond one packet ...",
myReadCount);
//.........这里部分代码省略.........
示例9: threadStarted
AREXPORT void * ArSyncLoop::runThread(void *arg)
{
threadStarted();
long timeToSleep;
ArTime loopEndTime;
std::list<ArFunctor *> *runList;
std::list<ArFunctor *>::iterator iter;
ArTime lastLoop;
bool firstLoop = true;
bool warned = false;
if (!myRobot)
{
ArLog::log(ArLog::Terse, "ArSyncLoop::runThread: Trying to run the synchronous loop without a robot.");
return(0);
}
if (!myRobot->getSyncTaskRoot())
{
ArLog::log(ArLog::Terse, "ArSyncLoop::runThread: Can not run the synchronous loop without a task tree");
return(0);
}
while (myRunning)
{
myRobot->lock();
if (!firstLoop && !warned && !myRobot->getNoTimeWarningThisCycle() &&
myRobot->getCycleWarningTime() != 0 &&
myRobot->getCycleWarningTime() > 0 &&
lastLoop.mSecSince() > (signed int) myRobot->getCycleWarningTime())
{
ArLog::log(ArLog::Normal,
"Warning: ArRobot cycle took too long because the loop was waiting for lock.");
ArLog::log(ArLog::Normal,
"\tThe cycle took %u ms, (%u ms normal %u ms warning)",
lastLoop.mSecSince(), myRobot->getCycleTime(),
myRobot->getCycleWarningTime());
}
myRobot->setNoTimeWarningThisCycle(false);
firstLoop = false;
warned = false;
lastLoop.setToNow();
loopEndTime.setToNow();
loopEndTime.addMSec(myRobot->getCycleTime());
myRobot->incCounter();
myRobot->unlock();
// note that all the stuff beyond here should maybe have a lock
// but it should be okay because its just getting data
myInRun = true;
myRobot->getSyncTaskRoot()->run();
myInRun = false;
if (myStopRunIfNotConnected && !myRobot->isConnected())
{
if (myRunning)
ArLog::log(ArLog::Normal, "Exiting robot run because of lost connection.");
break;
}
timeToSleep = loopEndTime.mSecTo();
// if the cycles chained and we're connected the packet handler will be
// doing the timing for us
if (myRobot->isCycleChained() && myRobot->isConnected())
timeToSleep = 0;
if (!myRobot->getNoTimeWarningThisCycle() &&
myRobot->getCycleWarningTime() != 0 &&
myRobot->getCycleWarningTime() > 0 &&
lastLoop.mSecSince() > (signed int) myRobot->getCycleWarningTime())
{
ArLog::log(ArLog::Normal,
"Warning: ArRobot sync tasks too long at %u ms, (%u ms normal %u ms warning)",
lastLoop.mSecSince(), myRobot->getCycleTime(),
myRobot->getCycleWarningTime());
warned = true;
}
if (timeToSleep > 0)
ArUtil::sleep(timeToSleep);
}
myRobot->lock();
myRobot->wakeAllRunExitWaitingThreads();
myRobot->unlock();
myRobot->lock();
runList=myRobot->getRunExitListCopy();
myRobot->unlock();
for (iter=runList->begin();
iter != runList->end(); ++iter)
(*iter)->invoke();
delete runList;
threadFinished();
return(0);
}
示例10: main
int main(void)
{
printf("\nTesting platform localtime (broken-down) struct:\n");
//struct tm t;
//ArUtil::localtime(&t);
struct tm t;
ArUtil::localtime(&t);
printf("ArUtil::localtime() returned: year=%d mon=%d mday=%d hour=%d min=%d sec=%d\n",
t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
time_t yesterday = time(NULL) - (24*60*60) ;
ArUtil::localtime(&yesterday, &t);
printf("ArUtil::localtime(time(NULL) - 24hours, struct tm*) returned: year=%d mon=%d mday=%d hour=%d min=%d sec=%d\n",
t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
printf("\nCurrent time as strings:\n");
char year[5], month[3], day[3], hour[3], min[3], sec[3];
ArUtil::putCurrentYearInString(year, 5);
ArUtil::putCurrentMonthInString(month, 3);
ArUtil::putCurrentDayInString(day, 3);
ArUtil::putCurrentHourInString(hour, 3);
ArUtil::putCurrentMinuteInString(min, 3);
ArUtil::putCurrentSecondInString(sec, 3);
printf(" Year:%s, Month:%s, Day:%s, Hour:%s, Min:%s, Sec:%s\n",
year, month, day, hour, min, sec);
printf("\nTesting ArTime:\n");
ArTime start, test;
printf("Setting an ArTime object \"start\" to now...\n");
start.setToNow();
start.log();
printf("Sleeping 4 secs\n");
ArUtil::sleep(4000);
printf("Setting an ArTime object \"test\" to now...\n");
test.setToNow();
test.log();
printf("ms of \"test\" since start %ld\n", test.mSecSince(start));
printf("seconds \"test\" since start %ld\n", test.secSince(start));
printf("ms of start since \"test\" %ld\n", start.mSecSince(test));
printf("seconds \"start\" test %ld\n", start.secSince(test));
printf("\"start\" is before \"test\"? %d\n", test.isBefore(start));
printf("\"start\" is after \"test\"? %d\n", test.isAfter(start));
printf("\"test\" is before \"start\"? %d\n", start.isBefore(test));
printf("\"test\" is after \"start\"? %d\n", start.isAfter(test));
printf("ms from \"start\" to now %ld\n", start.mSecTo());
printf("s from \"start\" to now %ld\n", start.secTo());
printf("ms since \"start\" %ld\n", start.mSecSince());
printf("s since \"start\" %ld\n", start.secSince());
printf("ms from \"test\" stamp to now %ld\n", test.mSecTo());
printf("s from \"test\" stamp to now %ld\n", test.secTo());
printf("Testing addMSec, adding 200 mSec\n");
test.addMSec(200);
printf("ms from \"test\" stamp to now %ld\n", test.mSecTo());
printf("Testing addMSec, subtracting 300 mSec\n");
test.addMSec(-300);
printf("ms from \"test\" stamp to now %ld\n", test.mSecTo());
printf("Testing addMSec, adding 20.999 seconds\n");
test.addMSec(20999);
printf("ms from \"test\" stamp to now %ld\n", test.mSecTo());
printf("Testing addMSec, subtracting 23.5 seconds\n");
test.addMSec(-23500);
printf("ms from \"test\" stamp to now %ld\n", test.mSecTo());
ArTime timeDone;
printf("Setting ArTime object \"done\" to now.\n");
timeDone.setToNow();
timeDone.addMSec(1000);
printf("Making sure the add works in the right direction, adding a second to a timestamp set now\n");
printf("Reading: %ld\n", timeDone.mSecTo());
printf("Sleeping 20 ms\n");
ArUtil::sleep(20);
printf("Reading: %ld\n", timeDone.mSecTo());
printf("Sleeping 2 seconds\n");
ArUtil::sleep(2000);
printf("Reading: %ld\n", timeDone.mSecTo());
puts("\nslamming ArUtil::localtime() from a bunch of threads with the same input time...");
time_t now = time(NULL);
class LocaltimeTestThread : public virtual ArASyncTask
{
private:
time_t time;
public:
LocaltimeTestThread(time_t t) : time(t) {}
virtual void *runThread(void *) {
struct tm t;
ArUtil::localtime(&time, &t);
printf("ArUtil::localtime() returned: year=%d mon=%d mday=%d hour=%d min=%d sec=%d\n", t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
return 0;
}
};
for(int i = 0; i < 200; ++i)
(new LocaltimeTestThread(now))->runAsync();
ArUtil::sleep(5000);
printf("test is done.\n");
//.........这里部分代码省略.........