All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

flash-user-led.cc 1.4 KB
Newer Older
Timothy Stack's avatar
Timothy Stack committed
1 2 3 4 5
/*
 * EMULAB-COPYRIGHT
 * Copyright (c) 2005 University of Utah and the Flux Group.
 * All rights reserved.
 */
Timothy Stack's avatar
 
Timothy Stack committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

#include "garciaUtil.hh"
#include "ledManager.hh"

static volatile int looping = 1;

static void sigquit(int signal)
{
    looping = 0;
}

static void usage(void)
{
    fprintf(stderr,
	    "usage: flash-user-led "
	    "<dot|fast-dot|dash|dash-dot|dash-dot-dot|line>\n");
}

int main(int argc, char *argv[])
{
    ledClient::lm_pattern_t lmp;
    int retval = EXIT_SUCCESS;

    if (argc != 2) {
	usage();
	
	retval = EXIT_FAILURE;
    }
    else if ((lmp = ledClient::findPattern(argv[1])) == ledClient::LMP_MAX) {
	fprintf(stderr, "error: invalid pattern - %s\n", argv[1]);
	usage();
	
	retval = EXIT_FAILURE;
    }
    else {
	acpGarcia garcia;
	aIOLib ioRef;
    
	signal(SIGQUIT, sigquit);
	signal(SIGTERM, sigquit);
	signal(SIGINT, sigquit);
	
	aIO_GetLibRef(&ioRef, NULL);
	
	if (!wait_for_brainstem_link(ioRef, garcia)) {
	    fprintf(stderr, "error: cannot establish link to robot\n");
	    
	    retval = EXIT_FAILURE;
	}
	else {
	    ledManager lm(garcia, "user-led");
	    ledClient lc(0, lmp);
	    unsigned long now;

	    lm.addClient(&lc);
	    while (looping) {
		garcia.handleCallbacks(50);
		aIO_GetMSTicks(ioRef, &now, NULL);
		lm.update(now);
	    }
	}
	
	aIO_ReleaseLibRef(ioRef, NULL);
    }
    
    return retval;
}