Пример #1
0
static int tunala_world_new_item(tunala_world_t * world, int fd,
                                 const char *ip, unsigned short port,
                                 int flipped)
{
    tunala_item_t *item;
    int newfd;
    SSL *new_ssl = NULL;

    if (!tunala_world_make_room(world))
        return 0;
    if ((new_ssl = SSL_new(world->ssl_ctx)) == NULL) {
        fprintf(stderr, "Error creating new SSL\n");
        ERR_print_errors_fp(stderr);
        return 0;
    }
    item = world->tunnels + (world->tunnels_used++);
    state_machine_init(&item->sm);
    item->clean_read = item->clean_send =
        item->dirty_read = item->dirty_send = -1;
    if ((newfd = ip_create_connection_split(ip, port)) == -1)
        goto err;
    /*
     * Which way round? If we're a server, "fd" is the dirty side and the
     * connection we open is the clean one. For a client, it's the other way
     * around. Unless, of course, we're "flipped" in which case everything
     * gets reversed. :-)
     */
    if ((world->server_mode && !flipped) || (!world->server_mode && flipped)) {
        item->dirty_read = item->dirty_send = fd;
        item->clean_read = item->clean_send = newfd;
    } else {
        item->clean_read = item->clean_send = fd;
        item->dirty_read = item->dirty_send = newfd;
    }
    /*
     * We use the SSL's "app_data" to indicate a call-back induced "kill"
     */
    SSL_set_app_data(new_ssl, NULL);
    if (!state_machine_set_SSL(&item->sm, new_ssl, world->server_mode))
        goto err;
    return 1;
 err:
    tunala_world_del_item(world, world->tunnels_used - 1);
    return 0;

}
Пример #2
0
/**
* 
* @brief Initialize the main state machine.  
*/
void TestMgr::InitStateMachine(void) {
	// Set total number of states
	state_machine_init(&m_StateMachine, RUN_STATE_TOTAL);

	// Add state machine handlers
	state_machine_add_handler(&m_StateMachine, RUN_STATE_IDLE, TestMgr::RunStateIdle);
	state_machine_add_handler(&m_StateMachine, RUN_STATE_START, TestMgr::RunStateStart);
	state_machine_add_handler(&m_StateMachine, RUN_STATE_RAMP_TEMP, TestMgr::RunStateRampTemp);
	state_machine_add_handler(&m_StateMachine, RUN_STATE_WAIT_FOR_TEMP, TestMgr::RunStateWaitForTemp);
	state_machine_add_handler(&m_StateMachine, RUN_STATE_DONE, TestMgr::RunStateDone);

	// Set initial state
	state_machine_set_state(&m_StateMachine, RUN_STATE_START);

	// Call state machine to run the first state (IDLE)
	state_machine_run(&m_StateMachine, (uint32_t *)this, (uint32_t *)NULL);
}
Пример #3
0
void main(void){
    init();
    state_machine_init(&state);
    loopdelay_time_ms = 10;
    
    
    
    while(1){
        loopdelay(state);
        get_events();
        switch(state){
            case :
                
                break;
            
        }
    }
}
Пример #4
0
void state_machine_close(state_machine_t * machine)
{
    if (machine->ssl)
        SSL_free(machine->ssl);
    /*
     * SSL_free seems to decrement the reference counts already so doing this
     * goes kaboom.
     */
# if 0
    if (machine->bio_intossl)
        BIO_free(machine->bio_intossl);
    if (machine->bio_fromssl)
        BIO_free(machine->bio_fromssl);
# endif
    buffer_close(&machine->clean_in);
    buffer_close(&machine->clean_out);
    buffer_close(&machine->dirty_in);
    buffer_close(&machine->dirty_out);
    state_machine_init(machine);
}
Пример #5
0
int main()
{
    struct sTaskTimesStruct *pTtime_pointer = &Ttime;

/*----------------------------------------------------------------------------*/
/*                                SYSTEM INIT                                      */
/*----------------------------------------------------------------------------*/    
    _SWDTEN = 0; // Disable WDT
    
    OSCCONbits.COSC = 0b111;
    OSCCONbits.NOSC = 0b111;
    OSCCONbits.CF = 0;
    while(OSCCONbits.LOCK!=1) {}; // Wait for PLL to lock
    
    SET_CPU_IPL(0b111);            // Force CPU interrupt priority to max.All user masked interrupts with ptiority from 0 to 7 are Disabled.(Safe version)            
     
/*----------------------------------------------------------------------------*/
/*                                MAIN PROGRAM                                  */
/*----------------------------------------------------------------------------*/
    /* INIT */
    delay_ms(10);
    
    if(EE_CheckEEprom() == S_OK)
    {
        /* Parameters Read */
        ee_param_act(1,1);     // INIT and put in PARACT_PARAMS_READ_ALL state
        ee_param_act(0,0);    // RUN read all parameters. NO NEED REINIT!
    }
    
    IF_DigitalIO_Init();
    IF_LCDInit();
    trace_init_first();
    IF_SysTmr1_Init();
    IF_SysTmr2_Init();
    IF_SysTmr3_Init();
    IF_ADC_INIT();
    state_machine_init();
    triac_control_init();
    measure_init();
    temp_ctrl_init();
    
    /* END INIT */
    
    IF_LCDPutc('\f');
    IF_LCDPuts("    SSTU 4.0");
    IF_LCDPutc('\n');
    IF_LCDPuts("     V");
    IF_LCDPutn((FIRMWARE_BASE_VERSION / 100));
    IF_LCDPutc('.');
    IF_LCDPutn(FIRMWARE_SUB_VERSION);
    
    delay_ms(200);
    
    INTCON1bits.NSTDIS = 0;    // Enable Nested Interrupts
    SET_CPU_IPL(0b000);        // Force CPU interrupt priority to low. All user masked interrupts with ptiority from 0 to 7 are Enabled.(Safe version)
    
    IF_Uart_Init(38400);
    
    ClrWdt();         // Clear WDT
    _SWDTEN = 1;    // Enable WDT    
    
    while(1)
    {
    /* BACKGROUND LOOP. */
        
        if(!_is_task1_execute() && !_is_task2_execute()) Sirem_Engine(); // Serial Communication run in background loop    
        
        Idle();
    
        if(!_is_task1_execute() && !_is_task2_execute()) TaskTimesCalc(pTtime_pointer);
        
        Idle();
        
        if(!_is_task1_execute() && !_is_task2_execute()) ee_param_act(0,0); // Online parameters actualization in background
        
        Idle();
        
        if(!_is_task1_execute() && !_is_task2_execute()) Params_check_limit();

        ClrWdt();    //<------ Clear Watchdog timer

        Idle();
    }

    return(0);
}