void setOperationalMode(int newmode) { extern void buildMyStatsCSV(); if(newmode == (int)P_WAIT) { // stop(); --- should we see if we can WAIT while paused in an audio file? SysIntoWaitMode(); // when leaving wait mode, next instruction is executed, so we return here return; } else { // assume calling for sleep or halt if (newmode == (int)P_HALT) logString((char *)"Halting",BUFFER,LOG_NORMAL); else // newmode == (int)P_SLEEP logString((char *)"Sleeping",BUFFER,LOG_NORMAL); housekeeping(); shutdown(); if (newmode == (int)P_HALT) { SysIntoHaltMode(); } else { // newmode == (int)P_SLEEP _SystemOnOff(); } while(1); // cpu reset on exiting halt/sleep mode, so nothing below here executes } }
// possibly stop running driver if allowed by config void IDAStealth::StealthSession::stopDrivers() { const HideDebuggerConfig& config = HideDebuggerConfig::getInstance(); if (config.getUnloadRDTSC()) { try { bool wasRunning = rdtscDriver_.isRunning(); rdtscDriver_.stopDriver(); if (wasRunning) logString("Successfully unloaded RDTSC emulation driver"); } catch (const std::exception& e) { logString("RDTSC driver: " + std::string(e.what())); } } if (config.getUnloadStealth()) { try { bool wasRunning = stealthDriver_.isRunning(); stealthDriver_.stopDriver(); if (wasRunning) logString("Successfully unloaded stealth driver"); } catch (const std::exception& e) { logString("Stealth driver: " + std::string(e.what())); } } }
void rtcAlarmFired(unsigned long alarm) { char buffer[48], wrk[12]; void setNextAlarm(); void removeAlarm(unsigned long); APP_IRAM static unsigned long lastActivity; strcpy(buffer,"rtcAlarmFired() alarm="); unsignedlongToHexString((long)alarm, (char *)wrk); strcat(buffer, wrk); logString(buffer,ASAP,LOG_ALWAYS); removeAlarm(alarm); // remove from table if present if((alarm & 0x00ffffffL) == 0) { // if(*P_Hour == 0 && *P_Minute == 0) { // bump systemcounters incrementCumulativeDays(); // loadSystemCounts(); //TODO:Redundant with Flash system counter // systemCounts.poweredDays += 1; // systemCounts.monthday++; // fixBadDate(&systemCounts); // saveSystemCounts(); // logRTC(); // remove while(*P_Second == 0) wait(100); strcpy(buffer,"poweredDays="); longToDecimalString(getCumulativeDays(), buffer+12, 4); logString(buffer,ASAP,LOG_ALWAYS); lastActivity = 0; // if up when rollover prevent shutdown // resetRTC(); // resetRTC23(); // test, really set rtc to 0,0,1sec // setRTCalarm(0, 0, 0); } setNextAlarm(); }
BOOL isCategoryLocked(char *cat) { char buffer[READ_LENGTH+1]; char filepath[PATH_LENGTH]; char *line; int handle, locked; cpyListPath(filepath,LIST_MASTER); // gets the right path using the current system language strcat(filepath,(char *)LIST_MASTER); strcat(filepath,(char *)".txt"); handle = tbOpen(filepath, O_RDONLY); if(handle < 0) { logString("isCategoryLocked: unable to open following path:",BUFFER,LOG_DETAIL); logString(filepath, BUFFER,LOG_DETAIL); return(FALSE); } getLine(-1,0); // reset in case at end from prior use for(locked = 0; line = getLine(handle,buffer); locked = 0) { if(*line == '!') { line++; locked = 1; } if(!strcmp(line, cat)) break; } close(handle); return(locked == 1); }
void rtcAlarmFired(unsigned long alarm) { char buffer[48], wrk[12]; void setNextAlarm(); void removeAlarm(unsigned long); APP_IRAM static unsigned long lastActivity; strcpy(buffer,"rtcAlarmFired alarm="); unsignedlongToHexString((long)alarm, (char *)wrk); strcat(buffer, wrk); logString(buffer,ASAP,LOG_ALWAYS); // any rtc alarm not on hour 0 minute 0 will not reset an alarm if(curAlarmSet) { removeAlarm(curAlarmSet); curAlarmSet = 0; } if((alarm & 0xffff) == 0) { // if(*P_Hour == 0 && *P_Minute == 0) { // bump systemcounters loadSystemCounts(); systemCounts.poweredDays += 1; systemCounts.monthday++; fixBadDate(&systemCounts); saveSystemCounts(); // logRTC(); // remove while(*P_Second == 0) wait(100); strcpy(buffer,"poweredDays="); longToDecimalString(systemCounts.poweredDays, buffer+12, 4); logString(buffer,ASAP,LOG_ALWAYS); lastActivity = 0; // if up when rollover prevent shutdown // resetRTC(); // resetRTC23(); // test, really set rtc to 0,0,1sec // setRTCalarm(0, 0, 0); } setNextAlarm(); }
void setLockCat(char *cat, int newlock_value) { char buffer[READ_LENGTH+1]; char filepath[PATH_LENGTH]; char *lineStart, *lineCat, tempLine[80]; int handle, wHandle, i, locked, bytesToWrite, ret; char wFilepath[PATH_LENGTH]; ListItem *list; cpyListPath(filepath,LIST_MASTER); // gets the right path using the current system language strcat(filepath,(char *)LIST_MASTER); strcat(filepath,(char *)".txt"); handle = tbOpen(filepath, O_RDONLY); if(handle < 0) { logString("lockCat: unable to open following path:",LOG_NORMAL,LOG_DETAIL); logString(filepath, BUFFER,LOG_DETAIL); return(FALSE); } strcpy(wFilepath,"temp.txt"); wHandle = tbOpen((LPSTR)wFilepath,O_CREAT|O_TRUNC|O_WRONLY); getLine(-1,0); // reset in case at end from prior use for(;(lineStart = lineCat = getLine(handle,buffer));) { locked = 0; if(*lineStart == '!') { lineCat++; locked = 1; } if(!strcmp(lineCat, cat)) { // the category we want if(locked == newlock_value) { // nothing to do close(handle); close(wHandle); unlink(wFilepath); return; } if(newlock_value) { bytesToWrite = convertDoubleToSingleChar(tempLine,"!",FALSE); ret = write(wHandle,(unsigned long)tempLine<<1,1); } else { // need to unlock this category lineStart = lineCat; // skips the '!' } } bytesToWrite = convertDoubleToSingleChar(tempLine,lineStart,TRUE); ret = write(wHandle,(unsigned long)tempLine<<1,bytesToWrite); } close(handle); close(wHandle); i = unlink((LPSTR)filepath); if (i != -1) { i = rename((LPSTR)wFilepath,(LPSTR)filepath); } list = &pkgSystem.lists[context.package->idxMasterList]; if(!strcmp(list->currentString, cat)) { list->isLocked = newlock_value; } }
void DebugManager::logCommandLine(const std::vector<UString> &argv) { logString("Full command line:"); for (std::vector<UString>::const_iterator arg = argv.begin(); arg != argv.end(); ++arg) { logString(" "); logString(*arg); } logString("\n"); }
void setOperationalMode(int newmode) { extern void buildMyStatsCSV(); extern void saveLogFile(int); if(newmode == (int)P_WAIT) { // stop(); --- should we see if we can WAIT while paused in an audio file? SysIntoWaitMode(); // when leaving wait mode, next instruction is executed, so we return here return; } else { // give visual feedback of shutting down (aural feedback when user causes shutdown in takeAction()) setLED(LED_ALL,TRUE); buildMyStatsCSV(); buildExchgOstats(); clearDeleteQueue(); write_config_bin(); // build a config.bin writeVersionToDisk(SYSTEM_PATH); // make sure the version file is correct confirmSNonDisk(); // make sure the serial number file is correct //cleanUpOldRevs(); // cleanup any old revs // assume calling for sleep or halt *P_Clock_Ctrl |= 0x200; //bit 9 KCEN enable IOB0-IOB2 key change interrupt if (newmode == (int)P_HALT) logString((char *)"Halting",BUFFER,LOG_NORMAL); else // newmode == (int)P_SLEEP logString((char *)"Sleeping",BUFFER,LOG_NORMAL); saveLogFile(0); Snd_Stop(); // no logging setLED(LED_ALL,FALSE); turnAmpOff(); disk_safe_exit(0); // try to get the sd card in a safe state - reversw what we do on startup _deviceunmount(0); fs_uninit(); SD_Uninitial(); turnSDoff(); turnNORoff(); if (newmode == (int)P_HALT) { /* setRTCalarmSeconds(61); // device should come back on in 61 seconds */ SysIntoHaltMode(); } else { // newmode == (int)P_SLEEP disk_safe_exit(0); _SystemOnOff(); } while(1); // cpu reset on exiting halt/sleep mode, so nothing below here executes } }
void logException(unsigned int errorCode, const char * pStrError, int takeAction) { // errorcode == 1 means memory error from BodyInit() and ucBSInit() int i; char errorString[160]; if(vCur_1 < V_MIN_SDWRITE_VOLTAGE) { } if (takeAction || LOG_WARNINGS) { strcpy(errorString,"\x0d\x0a" "*** ERROR! (cycle "); //cycle number longToDecimalString(systemCounts.powerUpNumber,(char *)(errorString+strlen(errorString)),4); strcat(errorString," - version " VERSION ")\x0d\x0a*** #"); longToDecimalString((long)errorCode,(char *)(errorString+strlen(errorString)),3); if (takeAction) { strcat(errorString,"-fatal"); stop(); } else strcat(errorString,"-warning"); if (LOG_FILE) { logString(errorString,ASAP); if (pStrError) { LBstrncpy(errorString,pStrError,80); logString(errorString,ASAP); } } else { appendStringToFile(ERROR_LOG_FILE,errorString); if (pStrError) { LBstrncpy(errorString,pStrError,80); appendStringToFile(ERROR_LOG_FILE,errorString); } } } //todo: put a parameter in fct to return instead of reset or USB //maybe a choice of the three RETURN, RESET, USB if (takeAction) { // commenting out code to alert user of error -- just use lights and auto-reset to welcome msg // if (errorCode != 10 && errorCode != 14) // can't access config or system boot // insertSoundFile(ERROR_SOUND_FILE_IDX); // if (errorCode != 14) // LED_GREEN and LED_RED are not assigned without config file for (i=0; i < 5; i++) { setLED(LED_GREEN,FALSE); setLED(LED_RED,TRUE); wait(500); setLED(LED_RED,FALSE); setLED(LED_GREEN,TRUE); wait(500); } if (takeAction == USB_MODE) // can't load config setUSBDevice (TRUE); else if (takeAction == RESET) resetSystem(); else if (takeAction == SHUT_DOWN) setOperationalMode((int)P_SLEEP); } }
// possibly start both, the RDTSC and the stealth driver void IDAStealth::StealthSession::startDrivers() { HideDebuggerConfig& config = HideDebuggerConfig::getInstance(); try { // RDTSC driver if (config.getUseRDTSC()) { ResourceItem drvResource = getRDTSCDriverResource(); // empty driver name means: randomize name! std::string driverName = config.getRandRDTSCName() ? "" : "RDTSCEMU"; rdtscDriver_.startDriver(drvResource, driverName); RDTSCMode mode = config.getRDTSCMode(); unsigned int param = mode == constant ? 0 : config.getRDTSCIncrDelta(); DWORD ioctlCode = mode == constant ? (DWORD)IOCTL_RDTSCEMU_METHOD_ALWAYS_CONST : (DWORD)IOCTL_RDTSCEMU_METHOD_INCREASING; rdtscDriver_.setMode(ioctlCode, ¶m, sizeof(param)); std::ostringstream oss; oss << "Successfully started RDTSC emulation driver from " << rdtscDriver_.getDriverPath().c_str(); logString(oss.str()); } } catch (const std::exception& e) { logString(e.what()); } try { // stealth driver if (config.getUseStealthDriver()) { ResourceItem stealthDrvResource = getStealthDriverResource(); stealthDriver_.startDriver(stealthDrvResource, "STEALTHDRIVER"); std::ostringstream oss; oss << "Successfully started stealth driver from " << stealthDriver_.getDriverPath().c_str(); logString(oss.str()); StealthHook mode; if (config.getStealthNtSetInfoThread()) { mode = SH_NtSetInformationThread; stealthDriver_.setMode(IOCTL_STEALTHDRIVER_ENABLE_HOOKS, &mode, sizeof(StealthHook)); } if (config.getStealthNtQueryInfoProcess()) { mode = SH_NtQueryInformationProcess; stealthDriver_.setMode(IOCTL_STEALTHDRIVER_ENABLE_HOOKS, &mode, sizeof(StealthHook)); } } } catch (const std::exception& e) { logString(e.what()); } }
static int getFileHandle (CtnrFile *newFile) { int ret = 0; char sTemp[PATH_LENGTH]; CtnrPackage *pkg; pkg = getPackageFromFile(newFile); // get package that applied to file, rather than context package // This is necessary for user packages inserting system sounds. switch (pkg->pkg_type) { case PKG_SYS: case SYS_MSG: strcpy(sTemp,LANGUAGES_PATH); if (pkg->transList.mode == '1') strcat(sTemp,TRANSLATE_TEMP_DIR); else strcat(sTemp,pkg->strHeapStack + pkg->idxName); strcat(sTemp,"/"); if (newFile->idxFirstBlockInFile == -1) // check for list strcat(sTemp,TOPICS_SUBDIR); else strcat(sTemp,UI_SUBDIR); break; case PKG_APP: strcpy(sTemp, USER_PATH); strcat(sTemp,pkg->strHeapStack + pkg->idxName); strcat(sTemp,"/"); //USERS CAN'T USE LISTS YET - ONLY THE SYSTEM PACKAGE //if (newFile->idxFirstBlockInFile == -1) // check for list // strcat(sTemp,LISTS_SUBDIR); break; case PKG_MSG: strcpy(sTemp, USER_PATH); break; } strcat(sTemp,pkg->strHeapStack + newFile->idxFilename); strcat(sTemp,AUDIO_FILE_EXT); ret = tbOpen((LPSTR)sTemp,O_RDONLY); if (DEBUG_MODE) { logString(sTemp,BUFFER); if (ret == -1) { strcpy(sTemp,"last file not found"); logString(sTemp,ASAP); } } if ((ret >= 0)/* && (pkg->pkg_type > PKG_SYS)*/) { recordStats(sTemp, (long)ret, STAT_OPEN, pkg->pkg_type); } // logString(sTemp,ASAP); return ret; }
bool Shader::compile() { m_program = glCreateProgram(); glCompileShader(m_vertex); GLint status; glGetShaderiv(m_vertex, GL_COMPILE_STATUS, &status); if(status != GL_TRUE) { GLint length; glGetShaderiv(m_vertex, GL_INFO_LOG_LENGTH, &length); char* log = new char[length]; glGetShaderInfoLog(m_vertex, length, 0, log); std::string logString(log); delete [] log; Util::LogManager::error("Error while compiling vertex shader "+ m_vertFile +": "+logString); return false; } else m_vertexLoaded = true; glCompileShader(m_fragment); glGetShaderiv(m_fragment, GL_COMPILE_STATUS, &status); if(status != GL_TRUE) { GLint length; glGetShaderiv(m_fragment, GL_INFO_LOG_LENGTH, &length); char* log = new char[length]; glGetShaderInfoLog(m_fragment, length, 0, log); std::string logString(log); delete [] log; Util::LogManager::error("Error while compiling vertex shader "+ m_fragFile +": "+logString); return false; } else m_fragmentLoaded = true; glAttachShader(m_program, m_vertex); glAttachShader(m_program, m_fragment); glLinkProgram(m_program); glGetProgramiv(m_program, GL_LINK_STATUS, &status); if(status != GL_TRUE) { GLint length; glGetProgramiv(m_program, GL_INFO_LOG_LENGTH, &length); char* log = new char[length]; glGetProgramInfoLog(m_program, length, 0, log); std::string logString(log); delete [] log; Util::LogManager::error("Error while linking shader: "+logString); return false; } else m_programLoaded = true; return true; }
Status logQueryLogItem(const QueryLogItem& results, const std::string& receiver) { if (FLAGS_disable_logging) { return Status(0, "Logging disabled"); } std::vector<std::string> json_items; Status status; if (FLAGS_log_result_events) { status = serializeQueryLogItemAsEventsJSON(results, json_items); } else { std::string json; status = serializeQueryLogItemJSON(results, json); json_items.push_back(json); } if (!status.ok()) { return status; } for (auto& json : json_items) { if (!json.empty() && json.back() == '\n') { json.pop_back(); status = logString(json, "event", receiver); } } return status; }
int main(int argc, char *argv[]) { char inputSequenceFile[100], log_desc[1000] ; int ret ; if(argc != 2) { printf("Usage: %s <input-transaction-file-path>\n", argv[0]) ; return 0 ; } strcpy(inputSequenceFile, argv[1]) ; ret = checkFileExists(inputSequenceFile) ; if(ret == -1) { printf("main: File %s does not exist or is an empty file. Exiting\n", inputSequenceFile) ; return 0 ; } FILE *fp = fopen("repcrec.log", "w") ; if(fp == NULL) { printf("main: failed to open log file in write mode. Error: %s\n", (char *)strerror(errno)) ; } else { fclose(fp) ; } initializeTransactionManager() ; initializeSiteData() ; ret = parseInput(inputSequenceFile) ; if(ret == -1) { printf("main: parseInput could not parse file %s. Exiting\n", inputSequenceFile) ; return 0 ; } startTransactionManager() ; sprintf(log_desc, "main: Transaction Manager exiting\n") ; logString(log_desc) ; return 0 ; }
TEST_F(LoggerTests, test_log_string) { // So far, tests have only used the logger registry/plugin API. EXPECT_TRUE(logString("{\"json\": true}", "event")); ASSERT_EQ(LoggerTests::log_lines.size(), 1U); EXPECT_EQ(LoggerTests::log_lines.back(), "{\"json\": true}"); // Expect the logString method to fail if we explicitly request a logger // plugin that has not been added to the registry. EXPECT_FALSE(logString("{\"json\": true}", "event", "does_not_exist")); // Expect the plugin to receive logs if status logging is disabled. FLAGS_disable_logging = true; EXPECT_TRUE(logString("test", "event")); EXPECT_EQ(LoggerTests::log_lines.size(), 2U); FLAGS_disable_logging = false; }
void IDAStealth::StealthSession::handleRtlGetNtGlobalFlags(unsigned int processID) { HideDebuggerConfig& config = HideDebuggerConfig::getInstance(); if (!config.getRtlGetNtGlobalFlags()) return; // assumes that ntdll is loaded to the IBA across processes // on ASLR systems, each image is randomized once and is // mapped to the same IBA until reboot HMODULE hNtDll = LoadLibrary("ntdll.dll"); LPVOID address = GetProcAddress(hNtDll, "RtlGetNtGlobalFlags"); if (address) { // xor eax, eax; retn unsigned char opcodes[] = { 0x31, 0xC0, 0xC3 }; try { Process process(processID); process.writeMemory(address, opcodes, 3); } catch (MemoryAccessException& e) { logString("Error while trying to patch RtlGetNtGlobalFlags: " + std::string(e.what())); } } FreeLibrary(hNtDll); }
void Logger::logBinary(uint32_t style, const void* data, size_t size) { static const char prefix[] = ".data "; static const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; const uint8_t* s = static_cast<const uint8_t*>(data); size_t i = size; char buffer[128]; ::memcpy(buffer, prefix, ASMJIT_ARRAY_SIZE(prefix) - 1); while (i) { uint32_t n = static_cast<uint32_t>(IntUtil::iMin<size_t>(i, 16)); char* p = buffer + ASMJIT_ARRAY_SIZE(prefix) - 1; i -= n; do { uint32_t c = s[0]; p[0] = hex[c >> 4]; p[1] = hex[c & 15]; p += 2; s += 1; } while (--n); *p++ = '\n'; logString(style, buffer, static_cast<size_t>(p - buffer)); } }
void saveSystemCounts() { int handle, ret, i; if(vCur_1 < V_MIN_SDWRITE_VOLTAGE) { refuse_lowvoltage(0); return; } i = 0; do { ret = unlink((LPSTR)(SYSTEM_VARIABLE_FILE)); if (ret) wait(100); } while (ret && ++i < 3); handle = tbOpen((LPSTR)(SYSTEM_VARIABLE_FILE),O_CREAT|O_RDWR); if (handle != -1) ret = write(handle, (unsigned long)&systemCounts<<1, sizeof(SystemCounts)<<1); else { if (ret) logString((char *)"failed unlink of system var file",BUFFER,LOG_ALWAYS); close(handle); logException(17,SYSTEM_VARIABLE_FILE,RESET); //can't save SYSTEM_VARIABLE_FILE; } close(handle); }
void resetSystem(void) { // set watchdog timer to reset device; 0x780A (Watchdog Reset Control Register) // see GPL Programmer's Manual (V1.0 Dec 20,2006), Section 3.5, page 18 checkVoltage(); // USB may have been supplying sole power -- need to check if voltage dropping fast stop(); if (PLEASE_WAIT_IDX && context.package) { // prevents trying to insert this sound before config & control files are loaded. insertSound(&pkgSystem.files[PLEASE_WAIT_IDX],NULL,TRUE); } checkVoltage(); // USB may have been supplying sole power -- need to check if voltage dropping fast saveVolumeProfile(); logString((char *)"* RESET *",ASAP,LOG_ALWAYS); saveLogFile(0); fs_safexit(); // should close all open files disk_safe_exit(0); // try to get the sd card in a safe state - reverse what we do on startup _deviceunmount(0); fs_uninit(); SD_Uninitial(); turnSDoff(); playBip(); setLED(LED_ALL,FALSE); *P_WatchDog_Ctrl &= ~0x4001; // clear bits 14 and 0 for resetting system and time=0.125 sec *P_WatchDog_Ctrl |= 0x8004; // set bits 2 and 15 for 0.125 sec, system reset, and enable watchdog while(1); }
void setNextAlarm() { unsigned int i, hour, minute, second; unsigned long newAlarm; unsigned long curRTC = getRTCinSeconds(); curAlarmSet = 0; /* for now disable all alarma except the one at 0:0:0 */ /* for(i=0; i<N_RTC_ALARMS; i++) { if(rtcAlarm[i] > curRTC) { newAlarm = rtcAlarm[i]; hour = newAlarm / 3600; minute = (newAlarm % 3600) / 60; second = (newAlarm % 3600) % 60; setRTCalarm(hour, minute, second); logString("setRTCalarm(non-zero)",BUFFER,LOG_NORMAL); curAlarmSet = newAlarm; break; } } */ if(curAlarmSet == 0 ) { logString("setRTCalarm(0,0,0)",BUFFER,LOG_DETAIL); while(*P_Hour == 0 && *P_Minute == 0 && *P_Second == 0); setRTCalarm(0, 0, 0); // test setPlus10(); } }
TEST_F(TLSLoggerTests, test_database) { // Start a server. TLSServerRunner::start(); TLSServerRunner::setClientConfig(); auto forwarder = std::make_shared<TLSLogForwarder>(); std::string expected = "{\"new_json\": true}"; forwarder->logString(expected); StatusLogLine status; status.message = "{\"status\": \"bar\"}"; forwarder->logStatus({status}); // Stop the server. TLSServerRunner::unsetClientConfig(); TLSServerRunner::stop(); std::vector<std::string> indexes; scanDatabaseKeys(kLogs, indexes); EXPECT_EQ(2U, indexes.size()); // Iterate using an unordered search, and search for the expected string // that was just logged. bool found_string = false; for (const auto& index : indexes) { std::string value; getDatabaseValue(kLogs, index, value); found_string = (found_string || value == expected); deleteDatabaseValue(kLogs, index); } EXPECT_TRUE(found_string); }
void set_voltmaxvolume(BOOL forceLower) { int wrk = V_MIN_VOL_VOLTAGE - vCur_1; if (wrk <= 0 || forceLower) { if (forceLower) wrk = MAX_VOLUME - 1; else { wrk >>= 3; // for every .08 volt below V_MIN_VOL_VOLTAGE subtract 1 from MAX_VOLUME wrk = 16 - wrk; } if(wrk < 1) wrk = 1; if(wrk < MAX_VOLUME) { MAX_VOLUME = wrk; if (volume > MAX_VOLUME) { volume = MAX_VOLUME; SACM_Volume(volume); playBip(); } if (TRUE) { // logging voltage for all devices in the field (DEBUG_MODE) { char log[15] = "v---,MV--,CV--"; longToDecimalString(vCur_1, log+1, 3); log[4] = ','; longToDecimalString((long)MAX_VOLUME,log+7,2); log[9] = ','; longToDecimalString((long)volume,log+11,2); logString(log,BUFFER,LOG_NORMAL); } } } }
void logVoltage() { int i; unsigned int sample; char buffer[40]; unsigned long time = getRTCinSeconds(); APP_IRAM static unsigned long timeLastSample = -1; // if ((context.isStopped || context.isPaused) && (time > (timeInitialized + 2))) // 2-3 second delay) if (VOLTAGE_SAMPLE_FREQ_SEC && (context.isStopped || context.isPaused) && time > (timeLastSample+VOLTAGE_SAMPLE_FREQ_SEC)) { sample = getCurVoltageSample(); strcpy(buffer,"V:"); longToHexString(((long)vThresh_1 & 0xffff),buffer+strlen(buffer),1); strcat(buffer," | "); if(sample == 0xffff) { sample = getCurVoltageSample(); if(sample == 0xffff) return; } longToDecimalString((long)sample,buffer+strlen(buffer),3); i = strlen(buffer); buffer[i+1] = 0; buffer[i] = buffer[i-1]; buffer[i-1] = buffer[i-2]; buffer[i-2] = '.'; logString(buffer,ASAP,LOG_DETAIL); voltage = sample; timeLastSample = time; } }
static void logKeystroke(int intKey) { int i; char str[20]; if (LOG_KEYS) { longToDecimalString(keydown_counter,str,4); if(intKey & 0x8000) { // key up if(intKey & 0x4000) { strcat(str," LONG "); } else { strcat(str," UP "); } } else { strcat(str," DOWN "); } intKey &= 0x7fff; strcat(str,", "); i = strlen(str)-1; if (intKey == KEY_LEFT) str[i] = TEXT_EVENT_LEFT; else if (intKey == KEY_RIGHT) str[i] = TEXT_EVENT_RIGHT; else if (intKey == KEY_UP) str[i] = TEXT_EVENT_UP; else if (intKey == KEY_DOWN) str[i] = TEXT_EVENT_DOWN; else if (intKey == KEY_SELECT) str[i] = TEXT_EVENT_SELECT; else if (intKey == KEY_HOME) str[i] = TEXT_EVENT_HOME; else if (intKey == KEY_PLAY) str[i] = TEXT_EVENT_PLAY; else if (intKey == KEY_STAR) str[i] = TEXT_EVENT_STAR; else if (intKey == KEY_PLUS) str[i] = TEXT_EVENT_PLUS; else if (intKey == KEY_MINUS) str[i] = TEXT_EVENT_MINUS; logString(str,ASAP,LOG_ALWAYS); } }
TEST_F(FilesystemLoggerTests, test_log_string) { EXPECT_TRUE(logString("{\"json\": true}", "event")); std::string content; EXPECT_TRUE(readFile(results_path_, content)); EXPECT_EQ(content, "{\"json\": true}\n"); }
void Logger::logString( LogLevel::LogLevel level, const std::string& message ) { if ( level <= mLogLevel && !mIgnoreRank ) { logString( message ); } }
TEST_F(LoggerTests, test_multiple_loggers) { auto& rf = RegistryFactory::get(); auto second = std::make_shared<SecondTestLoggerPlugin>(); rf.registry("logger")->add("second_test", second); EXPECT_TRUE(rf.setActive("logger", "test,second_test").ok()); auto test_plugin = rf.registry("logger")->plugin("test"); auto test_logger = std::dynamic_pointer_cast<TestLoggerPlugin>(test_plugin); test_logger->shouldLogStatus = false; // With two active loggers, the string should be added twice. logString("this is a test", "added"); EXPECT_EQ(2U, LoggerTests::log_lines.size()); LOG(WARNING) << "Logger test is generating a warning status (4)"; // Refer to the above notes about status logs not emitting until the logger // it initialized. We do a 0-test to check for dead locks around attempting // to forward Glog-based sinks recursively into our sinks. EXPECT_EQ(0U, LoggerTests::statuses_logged); // Now try to initialize multiple loggers (1) forwards, (2) does not. initLogger("logger_test"); LOG(WARNING) << "Logger test is generating a warning status (5)"; // Now that the "test" logger is initialized, the status log will be // forwarded. EXPECT_EQ(1U, LoggerTests::statuses_logged); // Multiple logger plugins have a 'primary' concept. auto flag_default = FLAGS_logger_secondary_status_only; FLAGS_logger_secondary_status_only = true; logString("this is another test", "added"); // Only one log line will be appended since 'second_test' is secondary. EXPECT_EQ(3U, LoggerTests::log_lines.size()); // Only one status line will be forwarded. LOG(WARNING) << "Logger test is generating another warning (6)"; EXPECT_EQ(2U, LoggerTests::statuses_logged); FLAGS_logger_secondary_status_only = flag_default; logString("this is a third test", "added"); EXPECT_EQ(5U, LoggerTests::log_lines.size()); // Reconfigure the second logger to forward status logs. test_logger->shouldLogStatus = true; initLogger("logger_test"); LOG(WARNING) << "Logger test is generating another warning (7)"; EXPECT_EQ(4U, LoggerTests::statuses_logged); }
void setNextAlarm() { unsigned int i, hour, minute, second; unsigned long newAlarm; unsigned long curRTC = getRTCinSeconds(); char buf[64], strbuf[12]; curAlarmSet = 0; for(i=0; i<N_RTC_ALARMS; i++) { if(rtcAlarm[i] > curRTC) { newAlarm = rtcAlarm[i]; hour = newAlarm / 3600; while(hour >= 24) hour = hour - 24; minute = (newAlarm % 3600) / 60; while(minute >= 60) minute = minute - 60; second = (newAlarm % 3600) % 60; setRTCalarm(hour, minute, second); newAlarm = (long)((long)hour * 3600L) + (long)((long)minute * 60L) + (long)second; strcpy(buf,"setRTCalarm to "); unsignedlongToHexString((unsigned long)newAlarm, (char *)strbuf); strcat(buf, strbuf); logString(buf,BUFFER,LOG_DETAIL); strcpy(buf," RTC = "); unsignedlongToHexString(curRTC, (char *)strbuf); strcat(buf, strbuf); logString(buf,BUFFER,LOG_DETAIL); curAlarmSet = newAlarm; break; } } if(curAlarmSet == 0 ) { logString("setRTCalarm(0,0,0)",BUFFER,LOG_DETAIL); while(*P_Hour == 0 && *P_Minute == 0 && *P_Second == 0); setRTCalarm(0, 0, 0); // test setPlus10(); } }
const std::string Program::getInfoLog() const { GLint length; glGetProgramiv(m_nGLId, GL_INFO_LOG_LENGTH, &length); char* log = new char[length]; glGetProgramInfoLog(m_nGLId, length, 0, log); std::string logString(log); delete [] log; return logString; }
void quitProgram(int returnValue) { #ifdef SOUND_ENABLED Mix_FadeOutMusic(700); #endif if(unpacked) { logString("Quitting\n"); remove("textures/CRYSTAL.BMP"); remove("textures/FLY.BMP"); remove("textures/JOHN.BMP"); remove("textures/MARS1.BMP"); remove("textures/MARS2.BMP"); remove("textures/METAL.BMP"); remove("textures/MOON1.BMP"); remove("textures/MOON2.BMP"); remove("textures/SAND.BMP"); remove("textures/STEIN1.BMP"); remove("textures/STEIN.BMP"); remove("textures/STONE53.BMP"); remove("textures/STONE54.BMP"); remove("sounds/bg.ogg"); remove("sounds/boom.wav"); remove("sounds/crystal.wav"); remove("sounds/fanfare.wav"); remove("gfx/font.bmp"); remove("gfx/particle.bmp"); remove("gfx/loading.bmp"); remove("textures"); remove("sounds"); remove("gfx"); } hiScores = fopen(hsFName, "w"); if (!hiScores) fprintf(stderr, "Couldn't write Hall of Fame\n"); else { int i; for(i=0; i<10; i++) { fprintf(hiScores, "%s = %d %d %d\n", scores[i].Name, scores[i].mins, scores[i].secs, scores[i].dsec); } fclose(hiScores); } free(camBase); free(shipBase); #ifdef SOUND_ENABLED while(Mix_FadingMusic() == MIX_FADING_OUT){}; #endif SDL_Quit(); if(!debug && unpacked) fclose(logfile); exit(returnValue); }