int main(int argc, char *argv[]) { (void) argc; (void) argv; // NOTE: don't use unbuffered IO - it crashes the threads lib //setlinebuf(stdout); //setlinebuf(stderr); // thread_init(); // FIXME: doing a fork() seems to completely hose aio. if( 0 ) { system_test(); sockio_test(); exit(0); } system_test(); sockio_test(); diskio_test(); syscall_mapping_test(); readdir_test(); malloc_test(); // malloc(10); // output("after malloc()\n"); // strdup("abc"); // output("after strdup()\n"); output("DONE\n\n"); if( 0 ) { sleep(2); output("sending USR1 to pid=%d\n", getpid()); kill(getpid(), SIGUSR1); sleep(2); output("exiting\n"); } return 0; }
void system_init() { DEBUG_PRINTF(V_MESSAGE, "Initializing WirePi.\n"); wiringPiSetup() ; pinMode(LED, OUTPUT); LED_ON; // Turn red led ON on initialization. DEBUG_PRINTF(V_MESSAGE, "Initializing timers.\n"); init_photo_timer(); if((operation_type == OPERATION_A) || (operation_type == OPERATION_B)) { init_accelgyro_timer(); } init_operation_timer(); init_led_timer(); DEBUG_PRINTF(V_MESSAGE, "Initializing accelgyro.\n"); accelgyro.initialize(); if(operation_type == OPERATION_A) // PLAN A { accelgyro_handler = &accelgyro_handler_planA; accelgyro.getAcceleration(&x, &y,&z); accel_low.x = accel_low.x * gravity_alpha + x * (1 - gravity_alpha); accel_low.y = accel_low.y * gravity_alpha + y * (1 - gravity_alpha); accel_low.z = accel_low.z * gravity_alpha + z * (1 - gravity_alpha); last_angle = accel_low.getAngleTo(gravity); max_angle = last_angle; start_accelgyro_timer(0, ACCELGYRO_TICK); } else if(operation_type == OPERATION_B) // PLAN B { accelgyro_handler = &accelgyro_handler_planB; start_accelgyro_timer(0, ACCELGYRO_TICK); } DEBUG_PRINTF(V_MESSAGE, "Initializing TCP socket.\n"); socket_tcp = TCP_Socket(host_ip, socket_port); DEBUG_PRINTF(V_MESSAGE, "Starting Timers.\n"); start_led_timer(TIMER_LED_TICK, 0); DEBUG_PRINTF(V_MESSAGE, "Initialization sleep!\n"); sleep(INITIAL_DELAY); DEBUG_PRINTF(V_MESSAGE, "System initialized!\n"); if((operation_test == TEST_NO_TCP) || (operation_test == FULL_TEST)) { DEBUG_PRINTF(V_MESSAGE, "System test!\n"); if(system_test() == false) { signalize(ERROR); DEBUG_PRINTF(V_ERROR, "Failed on System Test!\n"); while(1); } else { DEBUG_PRINTF(V_MESSAGE, "Passed on system test!\n"); } } return; }