int main( void )
{
    structInit();
    halInit();
    moduleInit();
    buttonIsr = &handleButtonPress;    
    printf("\r\n****************************************************\r\n");
    printf("Simple Application Example - COORDINATOR\r\n");
    
    routers[0].MAC_address[0] = 0x5E;
    routers[0].MAC_address[1] = 0xD2;
    routers[0].MAC_address[2] = 0x5D;
    routers[0].MAC_address[3] = 0x02;
    routers[0].MAC_address[4] = 0x00;
    routers[0].MAC_address[5] = 0x4B;
    routers[0].MAC_address[6] = 0x12;
    routers[0].MAC_address[7] = 0x00;
    
    routers[1].MAC_address[0] = 0xD3;
    routers[1].MAC_address[1] = 0xD3;
    routers[1].MAC_address[2] = 0x5D;
    routers[1].MAC_address[3] = 0x02;
    routers[1].MAC_address[4] = 0x00;
    routers[1].MAC_address[5] = 0x4B;
    routers[1].MAC_address[6] = 0x12;
    routers[1].MAC_address[7] = 0x00;
    
    HAL_ENABLE_INTERRUPTS();
    clearLeds();
    
    halRgbLedPwmInit();
    
    while (1) {
        stateMachine();    //run the state machine
        if (alarm_sounding == 1 && !alarm_silenced) {
          delayMs(2);
          toggleLed(0);
        }
    }
}
Example #2
0
int main(int argc, char *argv[])
{
	/* definition of basic variables */
	int state;

	/* Handle signals. This is useful to intercept accidental Ctrl+C
	 * which would otherwise just kill the process without any cleanup.
	 * This could also be useful when the process is managed by some
	 * other program, e.g. systemD.
	 * - SIGINT will be send by pressing Ctrl+C
	 * - SIGTERM will be send by process managers, e.g. systemD
	 *   wishing to stop the process
	 *
	 * Windows has its own ctrl handlers, we only really care about
	 * Ctrl+C, but others could be implemented as well (see above).
	 */
#ifdef POSIX
	struct sigaction sa, osa;
	memset(&sa, 0, sizeof(sa));
	sa.sa_handler = &stop_program;
	sigaction(SIGINT, &sa, &osa);
	sigaction(SIGTERM, &sa, &osa);
#else
	if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE)) {
		log_error("Control handler could not be installed, Ctrl+C won't work");
	}
#endif

	/* initiate the logfile and start logging */
	state = log_init();
	if (state != 0) {
		/*
		 * if creating a logfile fails we have to terminate the program.
		 * The error message then has to go directly to the screen
		 */
		printf("creating a logfile failed. Program is aborting...\n");
		stop_program(state);
		return state;
	}

	/*
	 * set default values, read config file and process cli arguments,
	 * which override settings in the config file
	 */
	config.dHistMinInterval = 350;
	config.dHistPercentage = 5;
	config.dInterFrameDelay = 10;
	config.dBufferlength = 1376256;

	state = load_config("configurations//SO2Config.conf", &config);
	if (state != 0) {
		log_error("loading configuration failed");
		stop_program(1);
		return 1;
	}

	state = process_cli_arguments(argc, argv, &config);
	if (state != 0) {
		log_error("Could not handle command line arguments");
		return state;
	}

	/* Initialise parameter structures */
	structInit(&sParameters_A, &config, 'a');
	structInit(&sParameters_B, &config, 'b');

	/* initialize IO */
	state = io_init(&config);
	if (state != 0) {
		log_error("io_init failed");
		stop_program(1);
		return state;
	}

	/* init filterwheel */
	state = filterwheel_init(&config);
	if (state != 0) {
		log_error("failed to initialize filterwheel");
		stop_program(1);
		return state;
	}
	log_message("filterwheel initialized");

	/* open filterwheel */
	state = filterwheel_send(FILTERWHEEL_OPENED_A);
	if (state != 0) {
		/* this is critical if this function fails no camera handle is returned */
		log_error("failed to open filterwheel");
		stop_program(1);
		return state;
	}
	log_message("filterwheel opened");

	/* initiate camera */
	state = camera_init(&sParameters_A);
	if (state != 0) {
		/* this is critical if this function fails no camera handle is returned */
		log_error("camera_init for Camera A failed");
		stop_program(1);
		return state;
	}
	log_message("camera A initialized");

	state = camera_init(&sParameters_B);
	if (state != 0) {
		/* this is critical if this function fails no camera handle is returned */
		log_error("camera_init for Camera B failed");
		stop_program(1);
		return state;
	}
	log_message("camera B initialized");

	/* configure camera */
	state = camera_config(&sParameters_A);
	if (state != 0) {
		log_error("config camera A failed");
		stop_program(1);
		return 1;
	}
	log_message("camera A configured");

	state = camera_config(&sParameters_B);
	if (state != 0) {
		log_error("config camera B failed");
		stop_program(1);
		return 1;
	}
	log_message("camera B configured");

	/* set exposure */
	state = setExposureTime(&sParameters_A, &config);
	if (state != 0) {
		log_error("setExposureTime for cam B failed");
		stop_program(1);
		return 1;
	}
	log_message("exposure time for cam A set");

	state = setExposureTime(&sParameters_B, &config);
	if (state != 0) {
		log_error("setExposureTime for cam B failed");
		stop_program(1);
		return 1;
	}
	log_message("exposure time for cam B set");

	/*
	 * Starting the acquisition with the exposure parameter set in
	 * configurations.c and exposureTimeControl.c
	 */
	state = startAquisition(&sParameters_A, &sParameters_B, &config);
	log_message("Aquisition stopped");
	if (state != 0) {
		log_error("Aquisition failed");
		stop_program(1);
		return 1;
	}

	/* we're done! */
	stop_program(0);

	return 0;
}