Ejemplo n.º 1
0
Archivo: Xbee.c Proyecto: SamChenzx/sdp
int main(){
    Board_init();
    Board_configure(USE_TIMER);
    DELAY(10);
    DBPRINT("Starting XBee...\n");
    if (Xbee_init(XBEE_UART_ID) != SUCCESS) {
        DBPRINT("Failed XBee init.\n");
        return FAILURE;
    }
    DBPRINT("XBee initialized.\n");
    DELAY(STARTUP_DELAY);

    Timer_new(TIMER_TEST, PRINT_DELAY);
    unsigned long int sent = 0;
    unsigned long int got = 0;
    while(1){
        Xbee_runSM();
        if (Timer_isExpired(TIMER_TEST)) {
            //dbprint("XBee: Sent=%ld, Got=%ld\n", ++sent, got);
            Mavlink_sendRequestOrigin();
            Timer_new(TIMER_TEST, PRINT_DELAY);
        }
        if (Mavlink_hasNewMessage()) {
            ++got;
        }
    }

    return SUCCESS;
}
Ejemplo n.º 2
0
Archivo: Xbee.c Proyecto: SamChenzx/sdp
int main(){
    Board_init();
    Serial_init();
    Timer_init();
    Xbee_init(XBEE_UART_ID);
    printf("Xbee Test 2\n");
    while(1){
        Xbee_runSM();
        //if(!UART_isTransmitEmpty(UART1_ID));
        //printf("%d\t",Mavlink_returnACKStatus(messageName_start_rescue));
        if(!UART_isReceiveEmpty(UART1_ID)){
            Serial_getChar();
            Mavlink_send_start_rescue(UART2_ID, TRUE, 0xFF, 0x34FD, 0xAB54);
            Timer_new(TIMER_TIMEOUT, DELAY_TIMEOUT);
            printf("\nSENT\n");
        }
        else if(Timer_isActive(TIMER_TIMEOUT) != TRUE && Mavlink_returnACKStatus(messageName_start_rescue) == ACK_STATUS_WAIT){
        //else if(Timer_isActive(TIMER_TIMEOUT) != TRUE){
            Mavlink_editACKStatus(messageName_start_rescue, ACK_STATUS_DEAD);
            printf("ACK DEAD\n");
        }
        else if(Mavlink_returnACKStatus(messageName_start_rescue) == ACK_STATUS_DEAD){
            Mavlink_send_start_rescue(UART2_ID, TRUE, 0xFF, 0x34FD, 0xAB54);
            Timer_new(TIMER_TIMEOUT, DELAY_TIMEOUT);
        }
        else if(Mavlink_returnACKStatus(messageName_start_rescue) == ACK_STATUS_RECIEVED){
            Mavlink_editACKStatus(messageName_start_rescue, ACK_STATUS_NO_ACK);
            printf("GPS SENT AND ACKOWLEGED\n");
        } 
    }
}
Ejemplo n.º 3
0
/**********************************************************************
 * Function: init
 * @return None.
 * @remark Initializes the boat's master state machine and all modules.
 * @author David Goodman
 * @date 2013.04.24
 **********************************************************************/
static void Watchdog_init(void) {
    Board_init();
    Board_configure(USE_SERIAL | USE_TIMER);
    //Board_configure(USE_LCD | USE_TIMER);
    DELAY(10);

    // I2C bus
    //I2C_init(I2C_BUS_ID, I2C_CLOCK_FREQ);

    #ifdef USE_XBEE
    Xbee_init(XBEE_UART_ID);
    #endif

    #ifdef USE_LOGGER
    Logger_init();
    #endif
}
Ejemplo n.º 4
0
Archivo: Compas.c Proyecto: sdajani/sdp
/**
 * Function: initMasterSM
 * @return None.
 * @remark Initializes the master state machine for the command canter.
 * @author David Goodman
 * @date 2013.03.10  */
void initMasterSM() {
    Board_init();
    Serial_init();
    Timer_init();

    // CC buttons
    LOCK_BUTTON_TRIS = 1;
    ZERO_BUTTON_TRIS = 1;

    Encoder_init();

    #ifdef USE_XBEE
    Xbee_init();
    #endif

    #ifdef USE_NAVIGATION
    Navigation_init();
    #endif

    #ifdef USE_ENCODERS
    I2C_init(I2C_BUS_ID, I2C_CLOCK_FREQ);
    #endif


    #ifdef USE_ACCELEROMETER
    //printf("Initializing accelerometer...\n");
    if (Accelerometer_init() != SUCCESS) {
        printf("Failed to initialize the accelerometer.\n");
        //return;
    }
    //printf("Initialized the accelerometer.\n");

    // Configure ports as outputs
    LED_N_TRIS = OUTPUT;
    LED_S_TRIS = OUTPUT;
    LED_E_TRIS = OUTPUT;
    LED_W_TRIS = OUTPUT;


    Timer_new(TIMER_ACCELEROMETER, LED_DELAY );
    #endif
}
Ejemplo n.º 5
0
Archivo: Xbee.c Proyecto: SamChenzx/sdp
int main(){
    Board_init();
    Serial_init();
    printf("Welcome to Xbee Test1\n");
    printf("UART INIT\n");
    Timer_init();

    printf("Timers Init\n");
    if(Xbee_init(XBEE_UART_ID) == FAILURE){
        printf("Xbee Failed to initilize\n");
        return FAILURE;
    }
    printf("XBEE Initialized\n");

// Master sends packets and listens for responses
    #ifdef XBEE_1
    Mavlink_send_Test_data(XBEE_UART_ID, 1);
    Timer_new(TIMER_TIMEOUT, DELAY_TIMEOUT);
    Timer_new(TIMER_STATUS, DELAY_STATUS);
    while(1){
        Xbee_runSM();
        //lost a packet, report it, and restart
        if(Timer_isActive(TIMER_TIMEOUT) != TRUE){
            Mavlink_send_Test_data(XBEE_UART_ID, 1);
            count_lost++;
            Timer_new(TIMER_TIMEOUT, DELAY_TIMEOUT);
            printf("lost_packet: %d\n", get_time());
        }
        //Printout the status
        if(Timer_isActive(TIMER_STATUS) != TRUE){
            Timer_new(TIMER_STATUS, DELAY_STATUS);
            printf("Status: %d,%d [Recieved,Lost] TIME: %d\n", count_recieved, count_lost, get_time());
        }

    }
    #else
    while(1){
        Xbee_runSM();
    }
    #endif
}
Ejemplo n.º 6
0
Archivo: Xbee.c Proyecto: SamChenzx/sdp
int main(){
    Board_init();
    Board_configure(USE_SERIAL | USE_TIMER);
    //Board_configure(USE_LCD | USE_TIMER);
    DELAY(10);
    dbprint("Starting XBee...\n");
    if (Xbee_init(XBEE_UART_ID) != SUCCESS) {
        dbprint("Failed XBee init.\n");
        return FAILURE;
    }
    dbprint("XBee initialized.\n");
    DELAY(STARTUP_DELAY);

    LCD_setPosition(0,0);
    Timer_new(TIMER_TEST, PRINT_DELAY);
    unsigned long int sent = 0;
    unsigned long int got = 0;
    LCD_clearDisplay();
    LCD_setPosition(2,0);
    dbprint("Received: %ld", got);
    while(1){
        Xbee_runSM();
        if (Timer_isExpired(TIMER_TEST)) {
            LCD_setPosition(0,0);
            dbprint("Sent XBee msg.\nSent: %ld\n", ++sent);
            Mavlink_sendSaveStation(WANT_ACK);
            Timer_new(TIMER_TEST, PRINT_DELAY);
        }
        if (Mavlink_hasNewMessage()) {
            LCD_setPosition(2,0);
            dbprint("Received: %ld", ++got);
        }
    }

    return SUCCESS;
}