/* See Porting Layer Definition - p. 57 */ void ddxGiveUp (void) { int i; #if CYGDEBUG winDebug ("ddxGiveUp\n"); #endif /* Perform per-screen deinitialization */ for (i = 0; i < g_iNumScreens; ++i) { /* Delete the tray icon */ if (!g_ScreenInfo[i].fNoTrayIcon && g_ScreenInfo[i].pScreen) winDeleteNotifyIcon (winGetScreenPriv (g_ScreenInfo[i].pScreen)); } #ifdef XWIN_MULTIWINDOW /* Notify the worker threads we're exiting */ winDeinitMultiWindowWM (); #endif #ifdef HAS_DEVWINDOWS /* Close our handle to our message queue */ if (g_fdMessageQueue != WIN_FD_INVALID) { /* Close /dev/windows */ close (g_fdMessageQueue); /* Set the file handle to invalid */ g_fdMessageQueue = WIN_FD_INVALID; } #endif if (!g_fLogInited) { g_pszLogFile = LogInit (g_pszLogFile, NULL); g_fLogInited = TRUE; } LogClose (); /* * At this point we aren't creating any new screens, so * we are guaranteed to not need the DirectDraw functions. */ if (g_hmodDirectDraw != NULL) { FreeLibrary (g_hmodDirectDraw); g_hmodDirectDraw = NULL; g_fpDirectDrawCreate = NULL; g_fpDirectDrawCreateClipper = NULL; } /* Unload our TrackMouseEvent funtion pointer */ if (g_hmodCommonControls != NULL) { FreeLibrary (g_hmodCommonControls); g_hmodCommonControls = NULL; g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA; } /* Free concatenated command line */ free(g_pszCommandLine); g_pszCommandLine = NULL; /* Remove our keyboard hook if it is installed */ winRemoveKeyboardHookLL (); /* Tell Windows that we want to end the app */ PostQuitMessage (0); }
static void logging_format(void) { const char *log_file_path = "/tmp/Xorg-logging-test.log"; const char *str = "%s %d %u %% %p %i"; char buf[1024]; int i; unsigned int ui; long li; unsigned long lui; FILE *f; char read_buf[2048]; char *logmsg; uintptr_t ptr; /* set up buf to contain ".....end" */ memset(buf, '.', sizeof(buf)); strcpy(&buf[sizeof(buf) - 4], "end"); LogInit(log_file_path, NULL); assert(f = fopen(log_file_path, "r")); #define read_log_msg(msg) \ fgets(read_buf, sizeof(read_buf), f); \ msg = strchr(read_buf, ']') + 2; /* advance past [time.stamp] */ /* boring test message */ LogMessageVerbSigSafe(X_ERROR, -1, "test message\n"); read_log_msg(logmsg); assert(strcmp(logmsg, "(EE) test message\n") == 0); /* long buf is truncated to "....en\n" */ LogMessageVerbSigSafe(X_ERROR, -1, buf); read_log_msg(logmsg); assert(strcmp(&logmsg[strlen(logmsg) - 3], "en\n") == 0); /* same thing, this time as string substitution */ LogMessageVerbSigSafe(X_ERROR, -1, "%s", buf); read_log_msg(logmsg); assert(strcmp(&logmsg[strlen(logmsg) - 3], "en\n") == 0); /* strings containing placeholders should just work */ LogMessageVerbSigSafe(X_ERROR, -1, "%s\n", str); read_log_msg(logmsg); assert(strcmp(logmsg, "(EE) %s %d %u %% %p %i\n") == 0); /* literal % */ LogMessageVerbSigSafe(X_ERROR, -1, "test %%\n"); read_log_msg(logmsg); assert(strcmp(logmsg, "(EE) test %\n") == 0); /* character */ LogMessageVerbSigSafe(X_ERROR, -1, "test %c\n", 'a'); read_log_msg(logmsg); assert(strcmp(logmsg, "(EE) test a\n") == 0); /* something unsupported % */ LogMessageVerbSigSafe(X_ERROR, -1, "test %Q\n"); read_log_msg(logmsg); assert(strstr(logmsg, "BUG") != NULL); LogMessageVerbSigSafe(X_ERROR, -1, "\n"); fseek(f, 0, SEEK_END); /* string substitution */ LogMessageVerbSigSafe(X_ERROR, -1, "%s\n", "substituted string"); read_log_msg(logmsg); assert(strcmp(logmsg, "(EE) substituted string\n") == 0); /* Invalid format */ LogMessageVerbSigSafe(X_ERROR, -1, "%4", 4); read_log_msg(logmsg); assert(strcmp(logmsg, "(EE) ") == 0); LogMessageVerbSigSafe(X_ERROR, -1, "\n"); fseek(f, 0, SEEK_END); /* %hld is bogus */ LogMessageVerbSigSafe(X_ERROR, -1, "%hld\n", 4); read_log_msg(logmsg); assert(strstr(logmsg, "BUG") != NULL); LogMessageVerbSigSafe(X_ERROR, -1, "\n"); fseek(f, 0, SEEK_END); /* number substitution */ ui = 0; do { char expected[30]; sprintf(expected, "(EE) %u\n", ui); LogMessageVerbSigSafe(X_ERROR, -1, "%u\n", ui); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); sprintf(expected, "(EE) %x\n", ui); LogMessageVerbSigSafe(X_ERROR, -1, "%x\n", ui); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); if (ui == 0) ui = 1; else ui <<= 1; } while(ui); lui = 0; do { char expected[30]; sprintf(expected, "(EE) %lu\n", lui); LogMessageVerbSigSafe(X_ERROR, -1, "%lu\n", lui); read_log_msg(logmsg); sprintf(expected, "(EE) %lld\n", (unsigned long long)ui); LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (unsigned long long)ui); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); sprintf(expected, "(EE) %lx\n", lui); printf("%s\n", expected); LogMessageVerbSigSafe(X_ERROR, -1, "%lx\n", lui); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); sprintf(expected, "(EE) %llx\n", (unsigned long long)ui); LogMessageVerbSigSafe(X_ERROR, -1, "%llx\n", (unsigned long long)ui); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); if (lui == 0) lui = 1; else lui <<= 1; } while(lui); /* signed number substitution */ i = 0; do { char expected[30]; sprintf(expected, "(EE) %d\n", i); LogMessageVerbSigSafe(X_ERROR, -1, "%d\n", i); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); sprintf(expected, "(EE) %d\n", i | INT_MIN); LogMessageVerbSigSafe(X_ERROR, -1, "%d\n", i | INT_MIN); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); if (i == 0) i = 1; else i <<= 1; } while(i > INT_MIN); li = 0; do { char expected[30]; sprintf(expected, "(EE) %ld\n", li); LogMessageVerbSigSafe(X_ERROR, -1, "%ld\n", li); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); sprintf(expected, "(EE) %ld\n", li | LONG_MIN); LogMessageVerbSigSafe(X_ERROR, -1, "%ld\n", li | LONG_MIN); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); sprintf(expected, "(EE) %lld\n", (long long)li); LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (long long)li); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); sprintf(expected, "(EE) %lld\n", (long long)(li | LONG_MIN)); LogMessageVerbSigSafe(X_ERROR, -1, "%lld\n", (long long)(li | LONG_MIN)); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); if (li == 0) li = 1; else li <<= 1; } while(li > LONG_MIN); /* pointer substitution */ /* we print a null-pointer differently to printf */ LogMessageVerbSigSafe(X_ERROR, -1, "%p\n", NULL); read_log_msg(logmsg); assert(strcmp(logmsg, "(EE) 0x0\n") == 0); ptr = 1; do { char expected[30]; #ifdef __sun /* Solaris doesn't autoadd "0x" to %p format */ sprintf(expected, "(EE) 0x%p\n", (void*)ptr); #else sprintf(expected, "(EE) %p\n", (void*)ptr); #endif LogMessageVerbSigSafe(X_ERROR, -1, "%p\n", (void*)ptr); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); ptr <<= 1; } while(ptr); for (i = 0; i < sizeof(float_tests)/sizeof(float_tests[0]); i++) { double d = float_tests[i]; char expected[30]; sprintf(expected, "(EE) %.2f\n", d); LogMessageVerbSigSafe(X_ERROR, -1, "%f\n", d); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); /* test for length modifiers, we just ignore them atm */ LogMessageVerbSigSafe(X_ERROR, -1, "%.3f\n", d); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); LogMessageVerbSigSafe(X_ERROR, -1, "%3f\n", d); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); LogMessageVerbSigSafe(X_ERROR, -1, "%.0f\n", d); read_log_msg(logmsg); assert(strcmp(logmsg, expected) == 0); } LogClose(EXIT_NO_ERROR); unlink(log_file_path); #undef read_log_msg }
/** * Robot-wide initialization code should go here. * * Use this method for default Robot-wide initialization which will * be called when the robot is first powered on. It will be called exactly 1 time. */ void RobotInit() { printf(">>> RobotInit\n"); LogInit(); #ifdef HAVE_COMPRESSOR compressor = new Compressor(1, 1); #endif #ifdef HAVE_TOP_WHEEL #ifdef HAVE_TOP_CAN1 topWheel1 = new CANJaguar(1); topWheel1->SetSafetyEnabled(false); // motor safety off while configuring topWheel1->SetSpeedReference( CANJaguar::kSpeedRef_Encoder ); topWheel1->ConfigEncoderCodesPerRev( 1 ); #endif #ifdef HAVE_TOP_PWM1 topWheel1 = new Victor(1); topWheel1->SetSafetyEnabled(false); // motor safety off while configuring #endif #ifdef HAVE_TOP_CAN2 topWheel2 = new CANJaguar(2); topWheel2->SetSafetyEnabled(false); // motor safety off while configuring topWheel2->SetSpeedReference( CANJaguar::kSpeedRef_Encoder ); topWheel2->ConfigEncoderCodesPerRev( 1 ); #endif topTach = new Tachometer(2); #endif #ifdef HAVE_BOTTOM_WHEEL #ifdef HAVE_BOTTOM_CAN1 bottomWheel1 = new CANJaguar(3); bottomWheel1->SetSafetyEnabled(false); // motor safety off while configuring bottomWheel1->SetSpeedReference( CANJaguar::kSpeedRef_Encoder ); bottomWheel1->ConfigEncoderCodesPerRev( 1 ); #endif #ifdef HAVE_BOTTOM_PWM1 bottomWheel1 = new Victor(2); bottomWheel1->SetSafetyEnabled(false); // motor safety off while configuring #endif #ifdef HAVE_BOTTOM_CAN2 bottomWheel2 = new CANJaguar(4); bottomWheel2->SetSafetyEnabled(false); // motor safety off while configuring bottomWheel2->SetSpeedReference( CANJaguar::kSpeedRef_Encoder ); bottomWheel2->ConfigEncoderCodesPerRev( 1 ); #endif bottomTach = new Tachometer(3); #endif #ifdef HAVE_ARM arm = new DoubleSolenoid(2, 1); #endif #ifdef HAVE_INJECTOR injectorL = new DoubleSolenoid(5, 3); injectorR = new DoubleSolenoid(6, 4); #endif #ifdef HAVE_EJECTOR ejector = new Solenoid(7); #endif #ifdef HAVE_LEGS legs = new Solenoid(8); #endif ds = DriverStation::GetInstance(); eio = &ds->GetEnhancedIO(); gamepad = new Joystick(1); LiveWindow *lw = LiveWindow::GetInstance(); #ifdef HAVE_COMPRESSOR lw->AddActuator("K9", "Compressor", compressor); #endif #ifdef HAVE_TOP_WHEEL #ifdef HAVE_TOP_CAN1 lw->AddActuator("K9", "Top1", topWheel1); #endif #ifdef HAVE_TOP_PWM1 lw->AddActuator("K9", "Top1", topWheel1); #endif #ifdef HAVE_TOP_CAN2 lw->AddActuator("K9", "Top2", topWheel2); #endif #endif #ifdef HAVE_BOTTOM_WHEEL #ifdef HAVE_BOTTOM_CAN1 lw->AddActuator("K9", "Bottom1", bottomWheel1); #endif #ifdef HAVE_BOTTOM_PWM1 lw->AddActuator("K9", "Bottom1", bottomWheel1); #endif #ifdef HAVE_BOTTOM_CAN2 lw->AddActuator("K9", "Bottom2", bottomWheel2); #endif #endif #ifdef HAVE_ARM lw->AddActuator("K9", "Arm", arm); #endif #ifdef HAVE_INJECTOR lw->AddActuator("K9", "InjectorL", injectorL); lw->AddActuator("K9", "InjectorR", injectorR); #endif #ifdef HAVE_EJECTOR lw->AddActuator("K9", "Ejector", ejector); #endif #ifdef HAVE_LEGS lw->AddActuator("K9", "Legs", legs); #endif SmartDashboard::PutNumber("Shooter P", kP); SmartDashboard::PutNumber("Shooter I", kI); SmartDashboard::PutNumber("Shooter D", kD); spinFastNow = false; #ifdef HAVE_TOP_WHEEL SmartDashboard::PutNumber("Top Set ", topSpeed); #ifdef HAVE_TOP_CAN1 SmartDashboard::PutNumber("Top Current 1", 0.0); #endif #ifdef HAVE_TOP_CAN2 SmartDashboard::PutNumber("Top Current 2", 0.0); SmartDashboard::PutNumber("Top Jag ", 0.0); #endif SmartDashboard::PutNumber("Top Tach ", 0.0); #endif #ifdef HAVE_BOTTOM_WHEEL SmartDashboard::PutNumber("Bottom Set ", bottomSpeed); #ifdef HAVE_BOTTOM_CAN1 SmartDashboard::PutNumber("Bottom Current 1", 0.0); #endif #ifdef HAVE_BOTTOM_CAN2 SmartDashboard::PutNumber("Bottom Current 2", 0.0); SmartDashboard::PutNumber("Bottom Jag ", 0.0); #endif SmartDashboard::PutNumber("Bottom Tach ", 0.0); #endif SetPeriod(0); //Set update period to sync with robot control packets (20ms nominal) printf("<<< RobotInit\n"); }
int main(void) { //******************************************************************* Init(); TMRInit(2); // Initialize Timer interface with Priority=2 BLIInit(); // Initialize Signal interface //******************************************************************* //_T1IE = 0; // Temporarily disable Timer1 interrupt //******************************************************************* LogInit(); // Initialize Data Logger //******************************************************************* //------------------------------------------------------------------- #define MaxRec 60 //------------------------------------------------------------------- struct { DWORD TS; WORD Index; char filler[506]; } Data; //------------------------------------------------------------------- uint i; for (i = 0; i < sizeof(Data.filler); i++) { Data.filler[i] = 0; } //------------------------------------------------------------------- DWORD TimeStart; float TimePoints[MaxRec]; // WORD TimeIndex[MaxRec]; //------------------------------------------------------------------- char pFN[15]; WORD RC; uint ReadCnt; FSFILE File; //******************************************************************* BLISignalON(); //------------------------------ // Create (Open) Log file for Writing and Reading //------------------------------ RC = LogNewFile(&File); while ( RC != LE_GOOD ); //------------------------------ // Retrieve and save for future new log file name //------------------------------ RC = FS_GetName(pFN, 15, &File); while ( RC != LE_GOOD ); //------------------------------ // Write sample data to file //------------------------------ for (i=0; i < MaxRec; i++) { Data.Index = i; Data.TS = TMRGetTS(); RC = FS_WriteSector(&File, &Data); while (CE_GOOD != RC); } //------------------------------ // Check position in the file //------------------------------ i = FS_GetPosition (&File); while (i != 512*MaxRec); //------------------------------ // Close the file - save changes //------------------------------ RC = FS_Flush(&File); while ( RC != CE_GOOD ); //------------------------------ //------------------------------ // Open file for Reading //------------------------------ RC = FS_CreateFile(pFN, FS_READ_ONLY, &File); while ( RC != CE_GOOD ); //------------------------------ // Reed records //------------------------------ for (i=0; i < MaxRec; i++) { RC = FS_Read (&File, &Data, sizeof(Data), &ReadCnt); while (CE_GOOD != RC); //-------------------------- // TimeIndex[i] = Data.Index; //-------------------------- if (0 == i) TimeStart = Data.TS; //-------------------------- TimePoints[i] = (Data.TS - TimeStart) * TMRGetTSRate() * 1000.0; // in msec //-------------------------- TimeStart = Data.TS; } //------------------------------ // Close the file - save changes //------------------------------ RC = FS_Flush(&File); while ( RC != CE_GOOD ); //******************************************************************* BLISignalOFF(); //------------------------------ i = 1 + i; //------------------------------ while(1); return 0; }
void OsInit(void) { static Bool been_here = FALSE; static char* devnull = "/dev/null"; char fname[PATH_MAX]; if (!been_here) { struct sigaction act, oact; int i; int siglist[] = { SIGSEGV, SIGQUIT, SIGILL, SIGFPE, SIGBUS, SIGSYS, SIGXCPU, SIGXFSZ, #ifdef SIGEMT SIGEMT, #endif 0 /* must be last */ }; sigemptyset(&act.sa_mask); #ifdef SA_SIGINFO act.sa_sigaction = OsSigHandler; act.sa_flags = SA_SIGINFO; #else act.sa_handler = OsSigHandler; act.sa_flags = 0; #endif for (i = 0; siglist[i] != 0; i++) { if (sigaction(siglist[i], &act, &oact)) { ErrorF("failed to install signal handler for signal %d: %s\n", siglist[i], strerror(errno)); } } #ifdef HAVE_BACKTRACE /* * initialize the backtracer, since the ctor calls dlopen(), which * calls malloc(), which isn't signal-safe. */ do { void *array; backtrace(&array, 1); } while (0); #endif #ifdef RTLD_DI_SETSIGNAL /* Tell runtime linker to send a signal we can catch instead of SIGKILL * for failures to load libraries/modules at runtime so we can clean up * after ourselves. */ int failure_signal = SIGQUIT; dlinfo(RTLD_SELF, RTLD_DI_SETSIGNAL, &failure_signal); #endif #if !defined(__CYGWIN__) fclose(stdin); fclose(stdout); #endif /* * If a write of zero bytes to stderr returns non-zero, i.e. -1, * then writing to stderr failed, and we'll write somewhere else * instead. (Apparently this never happens in the Real World.) */ if (write (2, fname, 0) == -1) { FILE *err; if (strlen (display) + strlen (ADMPATH) + 1 < sizeof fname) sprintf (fname, ADMPATH, display); else strcpy (fname, devnull); /* * uses stdio to avoid os dependencies here, * a real os would use * open (fname, O_WRONLY|O_APPEND|O_CREAT, 0666) */ if (!(err = fopen (fname, "a+"))) err = fopen (devnull, "w"); if (err && (fileno(err) != 2)) { dup2 (fileno (err), 2); fclose (err); } #if defined(SYSV) || defined(SVR4) || defined(WIN32) || defined(__CYGWIN__) { static char buf[BUFSIZ]; setvbuf (stderr, buf, _IOLBF, BUFSIZ); } #else setlinebuf(stderr); #endif } if (getpgrp () == 0) setpgid (0, 0); #ifdef RLIMIT_DATA if (limitDataSpace >= 0) { struct rlimit rlim; if (!getrlimit(RLIMIT_DATA, &rlim)) { if ((limitDataSpace > 0) && (limitDataSpace < rlim.rlim_max)) rlim.rlim_cur = limitDataSpace; else rlim.rlim_cur = rlim.rlim_max; (void)setrlimit(RLIMIT_DATA, &rlim); } } #endif #ifdef RLIMIT_STACK if (limitStackSpace >= 0) { struct rlimit rlim; if (!getrlimit(RLIMIT_STACK, &rlim)) { if ((limitStackSpace > 0) && (limitStackSpace < rlim.rlim_max)) rlim.rlim_cur = limitStackSpace; else rlim.rlim_cur = rlim.rlim_max; (void)setrlimit(RLIMIT_STACK, &rlim); } } #endif #ifdef RLIMIT_NOFILE if (limitNoFile >= 0) { struct rlimit rlim; if (!getrlimit(RLIMIT_NOFILE, &rlim)) { if ((limitNoFile > 0) && (limitNoFile < rlim.rlim_max)) rlim.rlim_cur = limitNoFile; else rlim.rlim_cur = rlim.rlim_max; (void)setrlimit(RLIMIT_NOFILE, &rlim); } } #endif LockServer(); been_here = TRUE; } TimerInit(); OsVendorInit(); /* * No log file by default. OsVendorInit() should call LogInit() with the * log file name if logging to a file is desired. */ LogInit(NULL, NULL); SmartScheduleInit (); }
int main( int argc, char **argv ) { int sig; sigset_t termSig; pthread_t readSerialThreadId; pthread_t readStdinThreadId; int rc; int opt; const char *baudStr = NULL; #if defined( linux ) const char *portStr = "ttyS0"; #else const char *portStr = "com1"; #endif #if USE_I2C PKT_TextChar = PacketTextChar; PKT_SendChar = PacketSendChar; PKT_PacketReceived = PacketReceived; #endif // signal( SIGINT, ControlC ); // signal( SIGTERM, ControlC ); LogInit( stdout ); while (( opt = getopt_long( argc, argv, "b:dhmp:sv", gLongOption, NULL )) > 0 ) { switch ( opt ) { case 'b': { baudStr = optarg; break; } case 'd': { gDebug = true; break; } case 'g': { gDongle = true; break; } case 'm': { gMegaLoad = true; break; } case 'p': { portStr = optarg; break; } case 'r': { gUseRtsToReset = true; break; } case 's': { gStk500 = true; break; } case 'v': { gVerbose = true; break; } #if USE_I2C case OPT_DEBUG_DONGLE: { gSerialDongle.m_debugDongle = true; break; } case OPT_DEBUG_DONGLE_DATA: { gSerialDongle.m_debugDongleData = true; break; } #endif case '?': case 'h': { Usage(); return 1; } } } if ( optind < argc ) { if (( optind + 1 ) != argc ) { fprintf( stderr, "Only one download file supported\n" ); return 1; } gDownloadFileName = argv[ optind ]; } // Open the file to download if ( gDownloadFileName != NULL ) { // If we are asked to download a file, then read the entire file // into memory. if (( gDownloadInfo = ReadFile( gDownloadFileName )) == NULL ) { return 1; } } if ( !gSerialPort.Open( portStr, baudStr )) { return 1; } gSerialPort.UseRTStoReset( gUseRtsToReset ); gSerialPort.ResetTarget(); // Put stdin in raw mode setbuf( stdin, NULL ); setbuf( stdout, NULL ); #if defined( unix ) sigemptyset( &termSig ); sigaddset( &termSig, SIGINT ); sigaddset( &termSig, SIGTERM ); pthread_sigmask( SIG_BLOCK, &termSig, NULL ); struct termios tio_new; if ( tcgetattr( fileno( stdin ), &gTio_org ) < 0 ) { LogError( "Unable to retrieve terminal settings\n" ); return 1; } tio_new = gTio_org; tio_new.c_lflag &= ~( ICANON | ECHO ); tio_new.c_cc[VMIN] = 1; tio_new.c_cc[VTIME] = 0; if ( tcsetattr( fileno( stdin ), TCSANOW, &tio_new ) < 0 ) { LogError( "Unable to update terminal settings\n" ); return 1; } #endif const char *bootLoaderType = "*** Unknown ***"; if ( gDongle ) { bootLoaderType = "Serial Dongle"; } else if ( gMegaLoad ) { bootLoaderType = "MegaLoad v2.3"; } else if ( gStk500 ) { bootLoaderType = "STK500"; } gLogFs2 = fopen( "BootHost.log", "wb" ); Log( "BootHost - BootLoader: %s\n", bootLoaderType ); // Kick off the serial port reader thread. rc = pthread_create( &readSerialThreadId, NULL, ReadSerialThread, &gSerialPort ); if ( rc != 0 ) { fprintf( stderr, "Error creating ReadSerialThread: %d\n", rc ); return 1; } // Kick off the stdin reader thread. rc = pthread_create( &readStdinThreadId, NULL, ReadStdinThread, NULL ); if ( rc != 0 ) { fprintf( stderr, "Error creating ReadSerialThread: %d\n", rc ); return 1; } #if defined( unix ) // Wait for a termmination signal if (( rc = sigwait( &termSig, &sig )) != 0 ) { fprintf( stderr, "sigwait failed\n" ); } else { fprintf( stderr, "Exiting...\n" ); } pthread_cancel( readSerialThreadId ); pthread_cancel( readStdinThreadId ); // Restore stdin back to the way it was when we started if ( tcsetattr( fileno( stdin ), TCSANOW, &gTio_org ) == -1 ) { LogError( "Unable to restore terminal settings\n" ); } #endif #if defined( __CYGWIN__ ) // Under Windows closing the serial port and stdin will cause the reads // to unblock. Under linux, this isn't required, but it doesn't hurt // either. gSerialPort.Close(); fclose( stdin ); #endif // Unblock the termination signals so the user can kill us if we hang up // waiting for the reader threads to exit. #if defined( unix ) pthread_sigmask( SIG_UNBLOCK, &termSig, NULL ); #endif pthread_join( readSerialThreadId, NULL ); pthread_join( readStdinThreadId, NULL ); #if !defined( __CYGWIN__ ) gSerialPort.Close(); fclose( stdin ); #endif if ( gVerbose ) { printf( "Done\n" ); } return 0; } // main
/*++ DbInit Initializes the procedure table and database connection pool. Arguments: getProc - Pointer to ioFTPD's GetProc function. Return Values: If the function succeeds, the return value is nonzero (true). If the function fails, the return value is zero (false). --*/ BOOL FCALL DbInit(Io_GetProc *getProc) { DWORD result; #if 0 // Wait for debugger to be attached before proceeding WaitForDebugger(); #endif TRACE("refCount=%d", refCount); // Only initialize the database pool once if (InterlockedIncrement(&refCount) > 1) { TRACE("Already initialized, returning."); return TRUE; } // Initialize procedure table result = ProcTableInit(getProc); if (result != ERROR_SUCCESS) { TRACE("Unable to initialize procedure table (error %lu).", result); return FALSE; } // Initialize configuration structures result = ConfigInit(); if (result != ERROR_SUCCESS) { TRACE("Unable to initialize configuration system (error %lu).", result); return FALSE; } // Initialize logging system result = LogInit(); if (result != ERROR_SUCCESS) { TRACE("Unable to initialize logging system (error %lu).", result); return FALSE; } // // Now that the logging system has been initialized, the LOG_* macros are // available for use. Prior to this point, the TRACE macro must be used. // // Load configuration options result = ConfigLoad(); if (result != ERROR_SUCCESS) { TRACE("Unable to load configuration (error %lu).", result); DbFinalize(); return FALSE; } // Create connection pool result = PoolCreate(&dbPool, dbConfigPool.minimum, dbConfigPool.average, dbConfigPool.maximum, dbConfigPool.timeoutMili, ConnectionOpen, ConnectionCheck, ConnectionClose, NULL); if (result != ERROR_SUCCESS) { LOG_ERROR("Unable to initialize connection pool (error %lu).", result); DbFinalize(); return FALSE; } LOG_INFO("nxMyDB v%s loaded, using MySQL Client Library v%s.", STRINGIFY(VERSION), mysql_get_client_info()); return TRUE; }
s32 CALLBACK DEV9init() { #ifdef DEV9_LOG_ENABLE LogInit(); DEV9_LOG("DEV9init\n"); #endif memset(&dev9, 0, sizeof(dev9)); DEV9_LOG("DEV9init2\n"); DEV9_LOG("DEV9init3\n"); FLASHinit(); hEeprom = CreateFile( "eeprom.dat", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_WRITE_THROUGH, NULL ); if(hEeprom==INVALID_HANDLE_VALUE) { dev9.eeprom=(u16*)eeprom; } else { mapping=CreateFileMapping(hEeprom,NULL,PAGE_READWRITE,0,0,NULL); if(mapping==INVALID_HANDLE_VALUE) { CloseHandle(hEeprom); dev9.eeprom=(u16*)eeprom; } else { dev9.eeprom = (u16*)MapViewOfFile(mapping,FILE_MAP_WRITE,0,0,0); if(dev9.eeprom==NULL) { CloseHandle(mapping); CloseHandle(hEeprom); dev9.eeprom=(u16*)eeprom; } } } { int rxbi; for(rxbi=0;rxbi<(SMAP_BD_SIZE/8);rxbi++) { smap_bd_t *pbd = (smap_bd_t *)&dev9.dev9R[SMAP_BD_RX_BASE & 0xffff]; pbd = &pbd[rxbi]; pbd->ctrl_stat = SMAP_BD_RX_EMPTY; pbd->length = 0; } } DEV9_LOG("DEV9init ok\n"); return 0; }
/* * SpyWindowProc - handle messages for the spy appl. */ LRESULT CALLBACK SpyWindowProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ) { int check; HWND selwin; HWND hinthwnd; WORD cmdid = 0; RECT area; BOOL pausestate; BOOL spyallstate; about_info ai; HMENU mh; switch ( msg ) { case WM_CREATE: GetClientRect( hwnd, &area ); mh = GetMenu( hwnd ); area.top = area.bottom - statusHite; StatusHdl = HintWndCreate( hwnd, &area, Instance, NULL ); statusHite = SizeHintBar( StatusHdl ); SetHintText( StatusHdl, (MenuItemHint *)menuHints, sizeof( menuHints ) / sizeof( MenuItemHint ) ); if( SpyMainWndInfo.show_hints ) { CheckMenuItem( mh, SPY_SHOW_HELP, MF_CHECKED | MF_BYCOMMAND ); } else { hinthwnd = GetHintHwnd( StatusHdl ); ShowWindow( hinthwnd, SW_HIDE ); } CreateSpyBox( hwnd ); SET_WNDINFO( hwnd, (LONG_PTR)SpyListBox ); CreateSpyTool( hwnd ); ShowSpyTool( SpyMainWndInfo.show_toolbar ); if( SpyMainWndInfo.show_toolbar ) { CheckMenuItem( mh, SPY_SHOW_TOOLBAR, MF_CHECKED | MF_BYCOMMAND ); } LogInit( hwnd, Instance, SpyLogTitle ); CheckMenuItem( SpyMenu, SPY_AUTO_SCROLL, MF_CHECKED ); EnableMenuItem( SpyMenu, SPY_ADD_WINDOW, MF_GRAYED ); EnableMenuItem( SpyMenu, SPY_STOP, MF_GRAYED ); EnableMenuItem( SpyMenu, SPY_OFFON, MF_GRAYED ); if( SpyMainWndInfo.on_top ) { CheckMenuItem( mh, SPY_TOP, MF_CHECKED | MF_BYCOMMAND ); SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); } break; case WM_TIMER: // See comment on setUpForPick KillTimer( hwnd, wparam ); switch( wparam ) { case SPY_ADD_WINDOW: selwin = DoPickDialog( wparam ); if( selwin != NULL ) { setMultipleWindows( hwnd ); AddSelectedWindow( selwin ); } break; case SPY_PEEK_WINDOW: DoPickDialog( wparam ); break; case SPY_WINDOW: selwin = DoPickDialog( cmdid ); if( selwin != NULL ) { ClearSelectedWindows(); setSingleWindow( hwnd, selwin ); enableSpy(); AddSelectedWindow( selwin ); } break; } break; #ifdef __NT__ case WM_COPYDATA: HandleMessage( (LPMSG)((COPYDATASTRUCT *)lparam)->lpData ); break; #endif case WM_MENUSELECT: hinthwnd = GetHintHwnd( StatusHdl ); HintMenuSelect( StatusHdl, hwnd, wparam, lparam ); break; case WM_COMMAND: cmdid = LOWORD( wparam ); switch( cmdid ) { case SPY_SHOW_HELP: SpyMainWndInfo.show_hints = !SpyMainWndInfo.show_hints; mh = GetMenu( hwnd ); hinthwnd = GetHintHwnd( StatusHdl ); if( SpyMainWndInfo.show_hints ) { CheckMenuItem( mh, SPY_SHOW_HELP, MF_CHECKED | MF_BYCOMMAND ); showHintBar( hwnd ); } else { CheckMenuItem( mh, SPY_SHOW_HELP, MF_UNCHECKED | MF_BYCOMMAND ); ShowWindow( hinthwnd, SW_HIDE ); } GetClientRect( hwnd, &area ); ResizeSpyBox( area.right - area.left, area.bottom - area.top ); break; case SPY_SHOW_TOOLBAR: SpyMainWndInfo.show_toolbar = !SpyMainWndInfo.show_toolbar; mh = GetMenu( hwnd ); if( SpyMainWndInfo.show_toolbar ) { CheckMenuItem( mh, SPY_SHOW_TOOLBAR, MF_CHECKED | MF_BYCOMMAND ); } else { CheckMenuItem( mh, SPY_SHOW_TOOLBAR, MF_UNCHECKED | MF_BYCOMMAND ); } ShowSpyTool( SpyMainWndInfo.show_toolbar ); GetClientRect( hwnd, &area ); ResizeSpyBox( area.right - area.left, area.bottom - area.top ); break; case SPY_TOP: SpyMainWndInfo.on_top = !SpyMainWndInfo.on_top; mh = GetMenu( hwnd ); if( SpyMainWndInfo.on_top ) { CheckMenuItem( mh, SPY_TOP, MF_CHECKED | MF_BYCOMMAND ); SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); } else { CheckMenuItem( mh, SPY_TOP, MF_UNCHECKED | MF_BYCOMMAND ); SetWindowPos( hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); } break; case SPY_MARK: pausestate = SpyMessagesPaused; SpyMessagesPaused = FALSE; /* make sure marks are * always added */ ProcessMark( hwnd, Instance, markCallback ); SpyMessagesPaused = pausestate; break; case SPY_SET_FONT: if( ChooseMonoFont( hwnd ) ) { statusHite = SizeHintBar( StatusHdl ); ResetSpyListBox(); showHintBar( hwnd ); } break; case SPY_SAVE_AS: SaveListBox( SLB_SAVE_AS, SaveExtra, "", SpyName, hwnd, SpyListBox ); break; case SPY_SAVE: SaveListBox( SLB_SAVE_TMP, SaveExtra, ".\\wspy.txt", SpyName, hwnd, SpyListBox ); break; case SPY_LOG: if( LogToggle() ) { CheckMenuItem( SpyMenu, SPY_LOG, MF_BYCOMMAND | MF_CHECKED ); } else { CheckMenuItem( SpyMenu, SPY_LOG, MF_BYCOMMAND | MF_UNCHECKED ); CheckMenuItem( SpyMenu, SPY_PAUSE_LOG, MF_BYCOMMAND | MF_UNCHECKED ); } break; case SPY_CONFIG_LOG: LogConfigure(); break; case SPY_EXIT: ClearFilter(); DestroyWindow( hwnd ); break; case SPY_LIST_BOX: switch( GET_WM_COMMAND_CMD( wparam, lparam ) ) { case LBN_ERRSPACE: ClearSpyBox(); break; case LBN_DBLCLK: DoMessageSelDialog( hwnd ); break; } break; case SPY_SHOW_SELECTED_WINDOWS: spyallstate = spyAll; DoShowSelectedDialog( hwnd, &spyallstate ); if( spyallstate ) { doSpyAll( hwnd, spyallstate ); if( spyAll ) { SetSpyState( ON ); } break; } if( WindowCount == 0 ) { SetWindowText( hwnd, SpyName ); disableSpy(); break; } if( WindowCount == 1 ) { setSingleWindow( hwnd, WindowList[0] ); } else { setMultipleWindows( hwnd ); } if( SpyState == NEITHER ) { enableSpy(); } break; case SPY_HELP_CONTENTS: if( !WHtmlHelp( hwnd, "spy.chm", HELP_CONTENTS, 0 ) ) { WWinHelp( hwnd, "spy.hlp", HELP_CONTENTS, 0 ); } break; case SPY_HELP_SRCH: if( !WHtmlHelp( hwnd, "spy.chm", HELP_PARTIALKEY, (HELP_DATA)"" ) ) { WWinHelp( hwnd, "spy.hlp", HELP_PARTIALKEY, (HELP_DATA)"" ); } break; case SPY_HELP_ON_HELP: WWinHelp( hwnd, "winhelp.hlp", HELP_HELPONHELP, 0 ); break; case SPY_ABOUT: ai.owner = hwnd; ai.inst = Instance; ai.name = AllocRCString( STR_ABOUT_NAME ); ai.version = AllocRCString( STR_ABOUT_VERSION ); ai.first_cr_year = "1993"; ai.title = AllocRCString( STR_ABOUT_TITLE ); DoAbout( &ai ); FreeRCString( ai.name ); FreeRCString( ai.version ); FreeRCString( ai.title ); break; case SPY_AUTO_SCROLL: if( SpyMessagesAutoScroll ) { SpyMessagesAutoScroll = FALSE; CheckMenuItem( SpyMenu, SPY_AUTO_SCROLL, MF_UNCHECKED ); } else { SpyMessagesAutoScroll = TRUE; CheckMenuItem( SpyMenu, SPY_AUTO_SCROLL, MF_CHECKED ); } break; case SPY_PAUSE_LOG: if( SpyLogPauseToggle() ) { CheckMenuItem( SpyMenu, SPY_PAUSE_LOG, MF_BYCOMMAND | MF_CHECKED ); } else { CheckMenuItem( SpyMenu, SPY_PAUSE_LOG, MF_BYCOMMAND | MF_UNCHECKED ); } break; case SPY_PAUSE_MESSAGES: SpyMessagePauseToggle(); break; case SPY_CLEAR_MESSAGES: ClearSpyBox(); ClearMessageCount(); break; case SPY_MESSAGES_ASCFG: if( AutoSaveConfig ) { check = MF_UNCHECKED; AutoSaveConfig = FALSE; } else { AutoSaveConfig = TRUE; check = MF_CHECKED; } CheckMenuItem( SpyMenu, SPY_MESSAGES_ASCFG, check ); break; case SPY_MESSAGES_SAVE: DoSaveSpyConfig(); break; case SPY_MESSAGES_LOAD: DoLoadSpyConfig(); break; case SPY_MESSAGES_WATCH: case SPY_MESSAGES_STOP: DoMessageDialog( hwnd, cmdid ); break; case SPY_OFFON: if( SpyState != NEITHER ) { SetSpyState( !SpyState ); } break; case SPY_STOP: disableSpy(); ClearSelectedWindows(); SetWindowText( hwnd, SpyName ); break; case SPY_ANOTHER_WINDOW: if( SpyState == NEITHER || spyAll ) { SendMessage( hwnd, WM_COMMAND, GET_WM_COMMAND_MPS( SPY_WINDOW, 0, 0 ) ); } else { SendMessage( hwnd, WM_COMMAND, GET_WM_COMMAND_MPS( SPY_ADD_WINDOW, 0, 0 ) ); } break; case SPY_PEEK_WINDOW: case SPY_ADD_WINDOW: case SPY_WINDOW: setUpForPick( hwnd, cmdid ); break; case SPY_ALL_WINDOWS: doSpyAll( hwnd, !spyAll ); if( spyAll ) { SetSpyState( ON ); } break; } break; #ifdef __NT__ case WM_NOTIFY: if( ((NMHDR *)lparam)->code == NM_DBLCLK && ((NMHDR *)lparam)->idFrom == SPY_LIST_BOX ) { DoMessageSelDialog( hwnd ); } break; #endif case WM_CLOSE: PostMessage( hwnd, WM_COMMAND, GET_WM_COMMAND_MPS( SPY_EXIT, 0, 0 ) ); break; case WM_ENDSESSION: if( wparam ) { SpyFini(); } break; case WM_DESTROY: HintWndDestroy( StatusHdl ); HintFini(); StatusWndFini(); DestroyMonoFonts(); DestroySpyTool(); WWinHelp( hwnd, "spy.hlp", HELP_QUIT, 0 ); PostQuitMessage( 0 ); break; case WM_MOVE: GetWindowRect( hwnd, &area ); if( !SpyMainWndInfo.minimized ) { SpyMainWndInfo.last_xpos = SpyMainWndInfo.xpos; SpyMainWndInfo.last_ypos = SpyMainWndInfo.ypos; SpyMainWndInfo.xpos = area.left; SpyMainWndInfo.ypos = area.top; } break; case WM_SIZE: if( wparam != SIZE_MAXIMIZED && wparam != SIZE_MINIMIZED ) { GetWindowRect( hwnd, &area ); SpyMainWndInfo.xsize = area.right - area.left; SpyMainWndInfo.ysize = area.bottom - area.top; } else { SpyMainWndInfo.xpos = SpyMainWndInfo.last_xpos; SpyMainWndInfo.ypos = SpyMainWndInfo.last_ypos; } SpyMainWndInfo.minimized = ( wparam == SIZE_MINIMIZED ); GetClientRect( hwnd, &area ); area.top = area.bottom - statusHite; hinthwnd = GetHintHwnd( StatusHdl ); MoveWindow( hinthwnd, area.left, area.top, area.right - area.left, statusHite, TRUE ); ResizeSpyBox( LOWORD( lparam ), HIWORD( lparam ) ); ResizeSpyTool( LOWORD( lparam ), HIWORD( lparam ) ); showHintBar( hwnd ); return( DefWindowProc( hwnd, msg, wparam, lparam ) ); break; #if defined( __NT__ ) case WM_ERASEBKGND: { static RECT r; GetClientRect( hwnd, &r ); FillRect( (HDC)wparam, &r, (HBRUSH)(COLOR_BTNFACE + 1) ); return 1; } #endif default: return( DefWindowProc( hwnd, msg, wparam, lparam ) ); } return( 0 ); } /* SpyWindowProc */
int main( int argc, char **argv ) { char shortOptsStr[ sizeof( gOption ) / sizeof( gOption[ 0 ] ) + 1 ]; char *shortOpts = shortOptsStr; struct option *scanOpt; int opt; const char *i2cDevName = "/dev/i2c-0"; int i2cDev; int cmdIdx; LogInit( stdout ); // Figure out the short options from our options structure for ( scanOpt = gOption; scanOpt->name != NULL; scanOpt++ ) { if (( scanOpt->flag == NULL ) && ( scanOpt->val < OPT_FIRST_LONG_OPT )) { *shortOpts++ = (char)scanOpt->val; if ( scanOpt->has_arg != no_argument ) { *shortOpts++ = ':'; } } } *shortOpts++ = '\0'; // Parse the command line options while (( opt = getopt_long( argc, argv, shortOptsStr, gOption, NULL )) != -1 ) { switch ( opt ) { case 0: { // getopt_long returns 0 for entries where flag is non-NULL break; } case OPT_BASE_DECIMAL: case OPT_BASE_HEX: { gBase = opt; break; } case OPT_VERSION: { printf( "i2c-io: SVN Revision: %d\n", SVN_REVISION ); exit( 0 ); } case '?': case OPT_HELP: default: { LogError( "opt:%d\n", opt ); Usage(); exit( 1 ); } } } argc -= optind; argv += optind; // Verify that an i2c-address was specified if ( argc < 1 ) { LogError( "Must specify an i2c address\n\n" ); Usage(); exit( 1 ); } gI2cAddr = strtol( argv[ 0 ], NULL, 0 ); if (( gI2cAddr <= 0 ) || ( gI2cAddr > 127 )) { LogError( "Expecting i2c address in the range of 1-127, Found: %d\n", gI2cAddr ); Usage(); exit( 1 ); } // Verify that a command has been specified if ( argc < 2 ) { LogError( "Must specify a command\n" ); Usage(); exit( 1 ); } gCmdStr = argv[ 1 ]; for ( cmdIdx = 0; cmdIdx < gNumCmds; cmdIdx++ ) { if ( strcasecmp( gCmdStr, gCmdMap[ cmdIdx ].cmdStr ) == 0 ) { gCmd = gCmdMap[ cmdIdx ].cmd; break; } } if ( gCmd == CMD_DEFAULT ) { LogError( "Unrecognized command '%s'\n", gCmdStr ); exit( 1 ); } // Process command specific arguments if ( gCmd == CMD_INFO ) { if ( argc != 2 ) { LogError( "Unexpected extra parameters\n" ); Usage(); exit( 1 ); } } else if (( gCmd == CMD_GET ) || ( gCmd == CMD_GET_DIR )) { if ( argc < 3 ) { LogError( "Expecting port.pin\n" ); Usage(); exit( 1 ); } gPortPinStr = argv[ 2 ]; } else if (( gCmd == CMD_SET ) || ( gCmd == CMD_SET_DIR )) { if ( argc < 4 ) { LogError( "port.pin followed by value\n" ); Usage(); exit( 1 ); } gPortPinStr = argv[ 2 ]; gValStr = argv[ 3 ]; } else if ( gCmd == CMD_READ_REG ) { if ( argc < 3 ) { LogError( "Expecting register index\n" ); Usage(); exit( 1 ); } gRegStr = argv[ 2 ]; } else if ( gCmd == CMD_WRITE_REG ) { if ( argc < 4 ) { LogError( "Expecting register index and value\n" ); Usage(); exit( 1 ); } gRegStr = argv[ 2 ]; gValStr = argv[ 3 ]; } if ( gDebug ) { Log( "i2cAddr:0x%02x Cmd: %s (%d)", gI2cAddr, gCmdStr, gCmd ); if ( gPortPinStr != NULL ) { Log( " Pin: %s", gPortPinStr ); } if ( gValStr != NULL ) { Log( " Val: %s", gValStr ); } Log( "\n" ); } // Try to open the i2c device if (( i2cDev = open( i2cDevName, O_RDWR )) < 0 ) { LogError( "Error opening '%s': %s\n", i2cDevName, strerror( errno )); exit( 1 ); } // Indicate which slave we wish to speak to I2cSetSlaveAddress( i2cDev, gI2cAddr, I2C_USE_CRC ); switch ( gCmd ) { case CMD_INFO: { ProcessInfoCommand( i2cDev ); break; } case CMD_GET: { ProcessGetCommand( i2cDev, gPortPinStr ); break; } case CMD_SET: { ProcessSetCommand( i2cDev, gPortPinStr, gValStr ); break; } case CMD_GET_DIR: { ProcessGetDirCommand( i2cDev, gPortPinStr ); break; } case CMD_SET_DIR: { ProcessSetDirCommand( i2cDev, gPortPinStr, gValStr ); break; } case CMD_READ_REG: { ProcessReadRegCommand( i2cDev, gRegStr ); break; } case CMD_WRITE_REG: { ProcessWriteRegCommand( i2cDev, gRegStr, gValStr ); break; } } close( i2cDev ); return 0; } // main
int main(int argc, char* argv[]) { int ret = 0; log_t* log_tLog = NULL; char* stringTmp = NULL; err_t err_tRet = 0; int i = 0; int intPid = 0; int j = 0; int N = 0; N = atoi(argv[1]); _GLOBAL_debug_level = 4; for( i=1; i<=N; i++ ) { err_tRet = LogInit( "client.conf", &log_tLog); if ( BMD_ERR( err_tRet )) { BMD_BTERR( err_tRet ); BMD_FREEERR( err_tRet ); } err_tRet = LogCreate(log_tLog); if ( BMD_ERR( err_tRet )) { BMD_BTERR( err_tRet ); BMD_FREEERR( err_tRet ); } asprintf(&stringTmp, "11:4"); err_tRet = LogSetParam( log_level, stringTmp, log_tLog ); if ( BMD_ERR( err_tRet )) { BMD_BTERR( err_tRet ); BMD_FREEERR( err_tRet ); } free( stringTmp); err_tRet = LogSetParam( log_owner, "Willow", log_tLog ); if ( BMD_ERR( err_tRet )) { BMD_BTERR( err_tRet ); BMD_FREEERR( err_tRet ); } err_tRet = LogSetParam( service, "SOP", log_tLog ); if ( BMD_ERR( err_tRet )) { BMD_BTERR( err_tRet ); BMD_FREEERR( err_tRet ); } err_tRet = LogSetParam( operation_type, "zażółć gęślą jaźń", log_tLog ); if ( BMD_ERR( err_tRet )) { BMD_BTERR( err_tRet ); BMD_FREEERR( err_tRet ); } err_tRet = LogSetParam( log_referto, "Sysytem obsługi eFaktur", log_tLog ); if ( BMD_ERR( err_tRet )) { BMD_BTERR( err_tRet ); BMD_FREEERR( err_tRet ); } err_tRet = LogSetParam( event_code, "345", log_tLog ); if ( BMD_ERR( err_tRet )) { BMD_BTERR( err_tRet ); BMD_FREEERR( err_tRet ); } err_tRet = LogSetParam( log_referto_event_visible, "1", log_tLog ); if ( BMD_ERR( err_tRet )) { BMD_BTERR( err_tRet ); BMD_FREEERR( err_tRet ); } err_tRet = LogSetParam( date_time_begin, "2010-02-12 09:28:54.413454", log_tLog ); if ( BMD_ERR( err_tRet )) { BMD_BTERR( err_tRet ); BMD_FREEERR( err_tRet ); } err_tRet = LogCommit(log_tLog); if ( BMD_ERR( err_tRet )) { BMD_BTERR( err_tRet ); BMD_FREEERR( err_tRet ); printf("Tutaj wlazlem\n"); } err_tRet = LogEnd(&log_tLog); if ( BMD_ERR( err_tRet )) { BMD_BTERR( err_tRet ); BMD_FREEERR( err_tRet ); } printf("\n LOG nr : \n %d \n", i); //sleep(1); } return 0; }
int main(void) { struct _tm timeCheck; WatchDogDisable(); NutDelay(100); SysInitIO(); SPIinit(); LedInit(); LcdLowLevelInit(); Uart0DriverInit(); Uart0DriverStart(); LogInit(); X12Init(); VsPlayerInit(); NtpInit(); NutThreadCreate("BackgroundThread", StartupInit, NULL, 1024); NutThreadCreate("BackgroundThread", AlarmSync, NULL, 2500); NutThreadCreate("BackgroundThread", AlarmCheck, NULL, 256); KbInit(); SysControlMainBeat(ON); // enable 4.4 msecs heartbeat interrupt /* * Increase our priority so we can feed the watchdog. */ NutThreadSetPriority(1); /* Enable global interrupts */ sei(); LcdBackLight(LCD_BACKLIGHT_ON); setCurrentDisplay(DISPLAY_DateTime, 5); X12RtcGetClock(&timeCheck); int hours; int mins; int secs; if(!NutNvMemLoad(100, &hours, sizeof(hours))) { printf("uren: %d", hours); } if(!NutNvMemLoad(105, &mins, sizeof(mins))) { printf(" minuten: %d", mins); } if(!NutNvMemLoad(110, &secs, sizeof(secs))) { printf(" seconden %d", secs); } printf("Welcome to Saltyradio.\nI'm using mac address: %s\n\n\n", getMacAdress()); for (;;) { //Key detecten if(KbGetKey() == KEY_01){ setCurrentDisplay(DISPLAY_DateTime, 5); } else if(KbGetKey() == KEY_OK) { if(getCurrentDisplay() == DISPLAY_MainMenu) { clickOk(); } else if(getCurrentDisplay() == DISPLAY_SettingsMenu) { clickOkSettings(); } else if(getCurrentDisplay() == DISPLAY_Play || getCurrentDisplay() == DISPLAY_Song) { clickOkPlay(); } else { setCurrentDisplay(DISPLAY_MainMenu, 10000); } } else if(KbGetKey() == KEY_LEFT) { switchLeft(); } else if(KbGetKey() == KEY_RIGHT) { switchItem(); } else if(KbGetKey() == KEY_DOWN){ setCurrentDisplay(DISPLAY_Volume, 5); volumeDown(); }else if(KbGetKey() == KEY_UP) { setCurrentDisplay(DISPLAY_Volume, 5); volumeUp(); } refreshScreen(); WatchDogRestart(); NutSleep(100); } return(0); }