int xTime::getMin(time_t time) { struct tm tm; getLocalTime(tm, time); return tm.tm_min; }
time_t xTime::getDayStart(time_t time) { struct tm tm; getLocalTime(tm, time); return time - (tm.tm_hour * 60 + tm.tm_min) * 60 - tm.tm_sec;//直接计算比使用mktime函数效率更高 }
int xTime::getWeek(time_t time) { struct tm tm; getLocalTime(tm, time); return tm.tm_wday; }
int xTime::getHour(time_t time) { struct tm tm; getLocalTime(tm, time); return tm.tm_hour; }
int xTime::getMonth(time_t time) { struct tm tm; getLocalTime(tm, time); return tm.tm_mon+1; }
int xTime::getYear(time_t time) { struct tm tm; getLocalTime(tm, time); return tm.tm_year+1900; }
long getLocalMsTime() { return (long)(1000*getLocalTime()); }
void applyRotation(int actuator) { float t = getLocalTime(); //int pos = dynamixelApi_getPositionEstimate(actuator, rotations[actuator].dir); int pos = dynamixelApi_getPosition(actuator); float f = rotations[actuator].frequency; float pd = rotations[actuator].phaseDiff/6.28f; //0-1 float dt = controllers[actuator].lastUpdateTime-t; //if(actuator==1) printf("%f sec\n",t); float percentPos; percentPos = f*t+pd; int goalPos = ((int)(percentPos*DYNAMIXEL_MAX_POS_FULL))%DYNAMIXEL_MAX_POS_FULL; if(rotations[actuator].dir) goalPos = DYNAMIXEL_MAX_POS_FULL-goalPos; if(goalPos>DYNAMIXEL_MAX_POS_VALID) goalPos =DYNAMIXEL_MAX_POS_VALID; if(goalPos<0) goalPos = 0; int error = (goalPos-pos); int speed; bool atValidAngle = dynamixelApi_isAtValidAngle(actuator, rotations[actuator].dir); if(atValidAngle) { if(rotations[actuator].dir == true) { if(error>512) { error = error-DYNAMIXEL_MAX_POS_VALID; } if(error<0 && error>-512) { controllers[actuator].integral = controllers[actuator].integral + myAbs(error)*dt; float derivative = (myAbs(error) - controllers[actuator].previousError)/dt; speed = controllers[actuator].P*myAbs(error) + controllers[actuator].I*controllers[actuator].integral + controllers[actuator].D*derivative; speed += controllers[actuator].avrSpeed; controllers[actuator].previousError = myAbs(error); } else { speed = -controllers[actuator].P*myAbs(error); speed += controllers[actuator].avrSpeed; } } else if(rotations[actuator].dir == false) { if(error<-512) { error = error+DYNAMIXEL_MAX_POS_VALID; } if(error>0&&error<512) { controllers[actuator].integral = controllers[actuator].integral + myAbs(error)*dt; float derivative = (myAbs(error) - controllers[actuator].previousError)/dt; speed = controllers[actuator].P*myAbs(error) + controllers[actuator].I*controllers[actuator].integral + controllers[actuator].D*derivative; speed += controllers[actuator].avrSpeed; controllers[actuator].previousError = myAbs(error); } else { speed = -controllers[actuator].P*myAbs(error); speed += controllers[actuator].avrSpeed; } } if(speed>1023) speed = 1023; if(speed<=150) speed = 150; controllers[actuator].previousError = myAbs(error); rotations[actuator].speed = speed; rotations[actuator].changed = true; } else { speed = controllers[actuator].avrSpeed;// controllers[actuator].avrSpeed; if(speed<150) { speed = 150; } controllers[actuator].integral = 0; controllers[actuator].previousError = 0; rotations[actuator].speed = speed; rotations[actuator].changed = true; error = 0; } controllers[actuator].lastUpdateTime = t; if(!rotations[actuator].pause) { controllers[actuator].avrSpeed = (1.0-0.05)*controllers[actuator].avrSpeed+0.05*speed; if(rotations[actuator].changed ) { dynamixelApi_wheelMove(actuator, rotations[actuator].speed, rotations[actuator].dir); rotations[actuator].changed = false; } } else { float periodeTime = 1.0f/rotations[actuator].frequency; if(t-rotations[actuator].pauseStart > periodeTime) { rotations[actuator].pause = false; } dynamixelApi_wheelMove(actuator, 0, rotations[actuator].dir); } int loopTimeMs=1000*(getLocalTime()-t); if(actuator==0||actuator==0) { //printf("%i: avr speed = %f, error = %i\n",actuator,controllers[actuator].avrSpeed, error); } if(loopTimeMs>20) { printf("%i: %i ms loop time (warning)\n",actuator,loopTimeMs); } //printf("{%i, %li, %i, %i, %i, %i, %i},\n",actuator,getLocalMsTime(),dynamixelApi_getPosition(actuator),dynamixelApi_getPositionEstimate(actuator,rotations[actuator].dir),goalPos,error,speed); //fprintf(posLog, "%i %li %i %i %i %i %i %i %f\n",actuator,getLocalMsTime(),dynamixelApi_getPosition(actuator),dynamixelApi_getPositionEstimate(actuator,rotations[actuator].dir),goalPos,error,speed,1023*(int)atValidAngle,controllers[actuator].avrSpeed); //fflush(posLog); //ase_printf("%i: Dynamixel at %i \n", i, pos); }
int HGameTime::getServerTime() { return getLocalTime()-m_deltaTime; }
PassRefPtr<SharedBuffer> MHTMLArchive::generateMHTMLData(Page* page, bool useBinaryEncoding) { Vector<PageSerializer::Resource> resources; PageSerializer pageSerializer(&resources); pageSerializer.serialize(page); String boundary = generateRandomBoundary(); String endOfResourceBoundary = makeString("--", boundary, "\r\n"); String dateString; time_t localTime = time(0); tm localTM; getLocalTime(&localTime, &localTM); dateString = makeRFC2822DateString(localTM.tm_wday, localTM.tm_mday, localTM.tm_mon, 1900 + localTM.tm_year, localTM.tm_hour, localTM.tm_min, localTM.tm_sec, calculateUTCOffset() / (1000 * 60)); StringBuilder stringBuilder; stringBuilder.append("From: <Saved by WebKit>\r\n"); stringBuilder.append("Subject: "); // We replace non ASCII characters with '?' characters to match IE's behavior. stringBuilder.append(replaceNonPrintableCharacters(page->mainFrame()->document()->title())); stringBuilder.append("\r\nDate: "); stringBuilder.append(dateString); stringBuilder.append("\r\nMIME-Version: 1.0\r\n"); stringBuilder.append("Content-Type: multipart/related;\r\n"); stringBuilder.append("\ttype=\""); stringBuilder.append(page->mainFrame()->document()->suggestedMIMEType()); stringBuilder.append("\";\r\n"); stringBuilder.append("\tboundary=\""); stringBuilder.append(boundary); stringBuilder.append("\"\r\n\r\n"); // We use utf8() below instead of ascii() as ascii() replaces CRLFs with ?? (we still only have put ASCII characters in it). ASSERT(stringBuilder.toString().containsOnlyASCII()); CString asciiString = stringBuilder.toString().utf8(); RefPtr<SharedBuffer> mhtmlData = SharedBuffer::create(); mhtmlData->append(asciiString.data(), asciiString.length()); for (size_t i = 0; i < resources.size(); ++i) { const PageSerializer::Resource& resource = resources[i]; stringBuilder.clear(); stringBuilder.append(endOfResourceBoundary); stringBuilder.append("Content-Type: "); stringBuilder.append(resource.mimeType); const char* contentEncoding = useBinaryEncoding ? binary : base64; stringBuilder.append("\r\nContent-Transfer-Encoding: "); stringBuilder.append(contentEncoding); stringBuilder.append("\r\nContent-Location: "); stringBuilder.append(resource.url); stringBuilder.append("\r\n\r\n"); asciiString = stringBuilder.toString().utf8(); mhtmlData->append(asciiString.data(), asciiString.length()); if (!strcmp(contentEncoding, binary)) { const char* data; size_t position = 0; while (size_t length = resource.data->getSomeData(data, position)) { mhtmlData->append(data, length); position += length; } } else { // FIXME: ideally we would encode the content as a stream without having to fetch it all. const char* data = resource.data->data(); size_t dataLength = resource.data->size(); Vector<char> encodedData; if (!strcmp(contentEncoding, quotedPrintable)) { quotedPrintableEncode(data, dataLength, encodedData); mhtmlData->append(encodedData.data(), encodedData.size()); mhtmlData->append("\r\n", 2); } else { ASSERT(!strcmp(contentEncoding, base64)); // We are not specifying insertLFs = true below as it would cut the lines with LFs and MHTML requires CRLFs. base64Encode(data, dataLength, encodedData); const size_t maximumLineLength = 76; size_t index = 0; size_t encodedDataLength = encodedData.size(); do { size_t lineLength = std::min(encodedDataLength - index, maximumLineLength); mhtmlData->append(encodedData.data() + index, lineLength); mhtmlData->append("\r\n", 2); index += maximumLineLength; } while (index < encodedDataLength); } } } asciiString = makeString("--", boundary, "--\r\n").utf8(); mhtmlData->append(asciiString.data(), asciiString.length()); return mhtmlData.release(); }
void HGameTime::setServerTime(int stime) { m_deltaTime = getLocalTime() -stime; }
static int32_t calculateUTCOffset() { #if OS(WINDOWS) TIME_ZONE_INFORMATION timeZoneInformation; DWORD rc = 0; if (callGetTimeZoneInformationForYear_t timeZoneFunction = timeZoneInformationForYearFunction()) { // If available, use the Windows API call that takes into account the varying DST from // year to year. SYSTEMTIME systemTime; ::GetSystemTime(&systemTime); rc = timeZoneFunction(systemTime.wYear, nullptr, &timeZoneInformation); if (rc == TIME_ZONE_ID_INVALID) return 0; } else { rc = ::GetTimeZoneInformation(&timeZoneInformation); if (rc == TIME_ZONE_ID_INVALID) return 0; } int32_t bias = timeZoneInformation.Bias; if (rc == TIME_ZONE_ID_DAYLIGHT) bias += timeZoneInformation.DaylightBias; else if (rc == TIME_ZONE_ID_STANDARD || rc == TIME_ZONE_ID_UNKNOWN) bias += timeZoneInformation.StandardBias; return -bias * 60 * 1000; #else time_t localTime = time(0); tm localt; getLocalTime(&localTime, &localt); // Get the difference between this time zone and UTC on the 1st of January of this year. localt.tm_sec = 0; localt.tm_min = 0; localt.tm_hour = 0; localt.tm_mday = 1; localt.tm_mon = 0; // Not setting localt.tm_year! localt.tm_wday = 0; localt.tm_yday = 0; localt.tm_isdst = 0; #if HAVE(TM_GMTOFF) localt.tm_gmtoff = 0; #endif #if HAVE(TM_ZONE) localt.tm_zone = 0; #endif #if HAVE(TIMEGM) time_t utcOffset = timegm(&localt) - mktime(&localt); #else // Using a canned date of 01/01/2009 on platforms with weaker date-handling foo. localt.tm_year = 109; time_t utcOffset = 1230768000 - mktime(&localt); #endif return static_cast<int32_t>(utcOffset * 1000); #endif }
double getLocalTime(const Arguments& arguments, http::server::reply& reply) { return getLocalTime(getTimeStamp(arguments, reply)); }
//以周一早上0点为起始时间 time_t xTime::getWeekStart(time_t time) { struct tm tm; getLocalTime(tm, time); return time - ((((tm.tm_wday + 6) % 7) * 24 + tm.tm_hour) * 60 + tm.tm_min) * 60 - tm.tm_sec; }
int xTime::getDay(time_t time) { struct tm tm; getLocalTime(tm, time); return tm.tm_mday; }
time_t xTime::getMonthStart(time_t time) { struct tm tm; getLocalTime(tm, time); return time - (((tm.tm_mday - 1) * 24 + tm.tm_hour) * 60 + tm.tm_min) * 60 - tm.tm_sec; }
void *listenForKeyInput() { while(1) { char command; printf("Type in a command: \n"); printf(" p - pause for one period\n"); printf(" q - turn left (pause left for one period)\n"); printf(" e - turn right (pause right for one period)\n"); printf(" f - Increase frequency\n"); printf(" g - Decrease frequency\n"); printf(" h - Increase lift modules phase-shift\n"); printf(" j - Decrease lift modules phase-shift\n"); printf(" k - Increase stride modules phase-shift\n"); printf(" l - Decrease stride modules phase-shift\n"); scanf("%c", &command); printf("The command you typed was %c\n", command); int i; if(command=='p') { for(i=0; i<getNumberOfActuators(); i++) { rotations[i].pause = true; rotations[i].pauseStart = getLocalTime(); } } //6,7,8,9 if(command=='q') { for(i=0; i<getNumberOfActuators(); i++) { if(i==4||i==5||i==6||i==7) { rotations[i].pause = true; rotations[i].pauseStart = getLocalTime(); } } } if(command=='e') { for(i=0; i<getNumberOfActuators(); i++) { if(i==0||i==1||i==2||i==3) { rotations[i].pause = true; rotations[i].pauseStart = getLocalTime(); } } } if(command=='f'||command=='g') { for(i=0; i<getNumberOfActuators(); i++) { if(command=='f') rotations[i].frequency += 0.1f; if(command=='g') rotations[i].frequency -= 0.1f; } printf("New frequency = %f\n",rotations[0].frequency); } //stride modules: 4=>2,3=>1,8=>6,7=>5 //lift modules: 2=>0,5=>3,6=>4,9=>7 if(command=='h'||command=='j') { for(i=0; i<getNumberOfActuators(); i++) { if(i==0||i==3||i==4||i==7) { if(command=='h') rotations[i].phaseDiff += 0.1f; if(command=='j') rotations[i].phaseDiff -= 0.1f; } } printf("New phase-shift for lift modules = %f\n",rotations[0].phaseDiff); } if(command=='k'||command=='l') { for(i=0; i<getNumberOfActuators(); i++) { if(i==2||i==1||i==6||i==5) { if(command=='k') rotations[i].phaseDiff += 0.1f; if(command=='l') rotations[i].phaseDiff -= 0.1f; } } printf("New phase-shift for stride modules = %f\n",rotations[0].phaseDiff); } } }