Exemplo n.º 1
0
void client(void)
{
    int s_source;
    struct sockaddr_in local;
    int len;

    diag_printf("client:started\n");
    
    ChangeMacAddr();
    
    init_all_network_interfaces();
    
    show_threads();
    
    s_source = socket(AF_INET, SOCK_DGRAM, 0);
    if (s_source < 0) {
        pexit("stream socket");
    }
    memset(&local, 0, sizeof(local));
    local.sin_family = AF_INET;
    local.sin_len = sizeof(local);
    local.sin_port = htons(SOURCE_PORT);
    local.sin_addr.s_addr = inet_addr("10.130.249.103");//htonl(INADDR_LOOPBACK);
    while(1)
    {
	    if ( (len= sendto(s_source,data_buf_write,sizeof(data_buf_write),
    	                  0,(struct sockaddr *)&local,sizeof(local))) < 0 ) {
        	//CYG_TEST_FAIL_FINISH("Error writing buffer");
        	cyg_thread_yield();
    	}
    	//else
    	//	diag_printf("sendto success\n");
    }
    close(s_source); 
}
Exemplo n.º 2
0
int main( int argc, char **argv )
{
    void *retval;
    pthread_attr_t attr;
    struct sched_param schedparam;

    CYG_TEST_INIT();

#ifdef TEST_NET
    sa.sin_family = AF_INET;
    sa.sin_len = sizeof(sa);
    inet_aton("127.0.0.1", &sa.sin_addr);
    sa.sin_port = htons(1234);
    init_all_network_interfaces();
#endif
    
    // Create test threads

    {
        pthread_attr_init( &attr );

        schedparam.sched_priority = 10;
        pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
        pthread_attr_setschedpolicy( &attr, SCHED_RR );
        pthread_attr_setschedparam( &attr, &schedparam );
        pthread_attr_setstackaddr( &attr, (void *)&thread1_stack[sizeof(thread1_stack)] );
        pthread_attr_setstacksize( &attr, sizeof(thread1_stack) );

        pthread_create( &thread1,
                        &attr,
                        pthread_entry1,
                        (void *)0x12345671);
    }

    {
        pthread_attr_init( &attr );

        schedparam.sched_priority = 5;
        pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
        pthread_attr_setschedpolicy( &attr, SCHED_RR );
        pthread_attr_setschedparam( &attr, &schedparam );
        pthread_attr_setstackaddr( &attr, (void *)&thread2_stack[sizeof(thread2_stack)] );
        pthread_attr_setstacksize( &attr, sizeof(thread2_stack) );

        pthread_create( &thread2,
                        &attr,
                        pthread_entry2,
                        (void *)0x12345672);
    }
    
    // Now join with thread1
    CYG_TEST_INFO( "Main: calling pthread_join(thread1)");
    pthread_join( thread1, &retval );

    // And thread 2
    CYG_TEST_INFO( "Main: calling pthread_join(thread2)");
    pthread_join( thread2, &retval );

    CYG_TEST_PASS_FINISH("select");
}
Exemplo n.º 3
0
void
net_test(test_param_t param)
{
//    int i;
    if (param == 0) {
        test_printf("Start Network Characterization - SLAVE\n");
#ifdef __ECOS
        init_all_network_interfaces();
        calibrate_load(DESIRED_BACKGROUND_LOAD);
#if 0
// I can see what this is trying to do, but I get "bind: Address already in
// use" errors from the 2nd interface - and the parameter is not used
// anyway, so one thread does quite well enough (but only tests one i/f at
// once).

// Comment in the 'int i' above too.
        for (i = 1;  i < CYGHWR_NET_DRIVERS;  i++) {
            cyg_thread_resume(main_thread_handle[i]);   // Start other threads
        }
#endif
#endif
    }
    nc_slave(param);
#ifdef CYGDBG_NET_TIMING_STATS
    show_net_times();
#endif
    cyg_test_exit();
}
Exemplo n.º 4
0
// ------------------------------------------------------------------------
void
net_test(cyg_addrword_t param)
{
    int results = 0;
    diag_printf("Start set_mac_address\n");
#ifdef CYGHWR_NET_DRIVER_ETH0
#ifdef DO_SET_ETH0
    diag_printf("Setting MAC of eth0 to %02x:%02x:%02x:%02x:%02x:%02x\n",
                new_eth0_addr[0],new_eth0_addr[1],
                new_eth0_addr[2],new_eth0_addr[3],
                new_eth0_addr[4],new_eth0_addr[5] );
    results += set_mac_address( "eth0", new_eth0_addr );
#endif
#endif
#ifdef CYGHWR_NET_DRIVER_ETH1
#ifdef DO_SET_ETH1
    diag_printf("Setting MAC of eth1 to %02x:%02x:%02x:%02x:%02x:%02x\n",
                new_eth1_addr[0],new_eth1_addr[1],
                new_eth1_addr[2],new_eth1_addr[3],
                new_eth1_addr[4],new_eth1_addr[5] );
    results += set_mac_address( "eth1", new_eth1_addr );
#endif
#endif

    if ( 0 == results )
        diag_printf( "**** Did not set any MAC addresses ****\n" );

    diag_printf("Init Network Interfaces\n");
    init_all_network_interfaces();
    diag_printf("After init.\n");

    cyg_test_exit();
}
Exemplo n.º 5
0
static void cyg_httpd_init(cyg_addrword_t arg)
{
    int i;
    int err = 0;

    /* Delay for a configurable length of time to give the application
     * a chance to get going, or even complete, without interference
     * from the HTTPD.
     */
    if( CYGNUM_HTTPD_SERVER_DELAY > 0 )
    {
        cyg_thread_delay( CYGNUM_HTTPD_SERVER_DELAY );
    }
    
    server_address.sin_family = AF_INET;
    server_address.sin_len = sizeof(server_address);
    server_address.sin_addr.s_addr = INADDR_ANY;
    server_address.sin_port = htons(CYGNUM_HTTPD_SERVER_PORT);

    /* Get the network going. This is benign if the application has
     * already done this.
     */
    init_all_network_interfaces();

    /* Create and bind the server socket.
     */
    server_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
    CYG_ASSERT( server_socket > 0, "Socket create failed");

    err = bind( server_socket, (struct sockaddr *)&server_address,
                sizeof(server_address) );
    CYG_ASSERT( err == 0, "bind() returned error");

    err = listen( server_socket, SOMAXCONN );
    CYG_ASSERT( err == 0, "listen() returned error" );

    /* If we are configured to have more than one server thread,
     * create them now.
     */
    for( i = 1; i < CYGNUM_HTTPD_THREAD_COUNT; i++ )
    {
        cyg_thread_create( CYGNUM_HTTPD_THREAD_PRIORITY,
                           cyg_httpd_server,
                           0,
                           "HTTPD",
                           &httpd_stacks[i][0],
                           sizeof(httpd_stacks[i]),
                           &httpd_thread[i],
                           &httpd_thread_object[i]
            );
    
        cyg_thread_resume( httpd_thread[i] );
    }

    /* Now go be a server ourself.
     */
    cyg_httpd_server(arg);
}
Exemplo n.º 6
0
void
net_test(test_param_t p)
{
    test_printf("Start Network Characterization - MASTER\n");
#ifdef __ECOS
    init_all_network_interfaces();
#endif
    nc_master((struct test_params *)p);
    cyg_test_exit();
}
Exemplo n.º 7
0
void
tcp_server(cyg_addrword_t param)
{
    init_all_network_interfaces();
    diag_printf("Start TCP server - test\n");
    cyg_thread_resume(client_thread_handle);    // Start it
#if NLOOP > 0
    server();
    CYG_TEST_PASS_FINISH( "server returned OK" );
#endif
    CYG_TEST_NA( "No loopback devs" );
}
Exemplo n.º 8
0
void
httpd_test(cyg_addrword_t p)
{
  
  CYG_TEST_INIT();

  init_all_network_interfaces();

  cyg_thread_delay(1 * 60 * 100);

  CYG_TEST_PASS_FINISH( "httpd test finished" );
}
Exemplo n.º 9
0
void
net_test(cyg_addrword_t param)
{
    cyg_serial_baud_rate_t old;    
    cyg_ppp_options_t options;
    cyg_ppp_handle_t ppp_handle;

    CYG_TEST_INIT();
    
    diag_printf("Start TCP test - ECHO mode\n");
    init_all_network_interfaces();
    calibrate_load(DESIRED_BACKGROUND_LOAD);
#ifdef CYGPKG_SNMPAGENT
    {
        extern void cyg_net_snmp_init(void);
        cyg_net_snmp_init();
    }
#endif

    old = ppp_test_set_baud( CYGNUM_SERIAL_BAUD_115200 );

    ppp_test_announce( "TCP_ECHO" );
    
    cyg_ppp_options_init( &options );

//    options.debug = 1;
//    options.kdebugflag = 1;
//    options.flowctl = CYG_PPP_FLOWCTL_SOFTWARE;

    ppp_handle = cyg_ppp_up( CYGPKG_PPP_TEST_DEVICE, &options );

    CYG_TEST_INFO( "Waiting for PPP to come up");
    
    cyg_ppp_wait_up( ppp_handle );

    echo_test(param);

    CYG_TEST_INFO( "Bringing PPP down");

    cyg_ppp_down( ppp_handle );
    
    CYG_TEST_INFO( "Waiting for PPP to go down");

    cyg_ppp_wait_down( ppp_handle );

    cyg_thread_delay( 200 );
    
    ppp_test_set_baud( old );

    ppp_test_finish();
    
    CYG_TEST_PASS_FINISH("TCP ECHO test OK");
}
Exemplo n.º 10
0
void
net_test(cyg_addrword_t param)
{
    diag_printf("Start SERVER test\n");
    init_all_network_interfaces();
#ifdef CYGHWR_NET_DRIVER_ETH0
    if (eth0_up) {
        server_test(&eth0_bootp_data);
    }
#endif
    cyg_test_exit();
}
Exemplo n.º 11
0
void
net_test(cyg_addrword_t param)
{
    extern void cyg_net_snmp_init(void);

    CYG_TEST_INIT();
    CYG_TEST_INFO("Start multiple SNMP server test");
    init_all_network_interfaces();

    autohost_init();

    cyg_net_snmp_init();

    TNR_INIT();
    
    // Now command the host to do ping to us...
#ifdef CYGHWR_NET_DRIVER_ETH0
    if (eth0_up) {
        do_snmp_tests(&eth0_bootp_data, 3, TESTTIME);
    }
#endif
#ifdef CYGHWR_NET_DRIVER_ETH1
    if (eth1_up) {
        do_snmp_tests(&eth1_bootp_data, 3, TESTTIME);
    }
#endif
    // Let the server run for 5 minutes
    cyg_thread_delay(2*100); // let the stuff start up first
    TNR_ON();
    cyg_thread_delay(TESTTIME*100); // FIXME - assume cS clock.
    // Additional delay 'cos host may be slower than us - and it has to
    // complete a transfer anyway:
    cyg_thread_delay(  30    *100); // FIXME - assume cS clock.
    TNR_OFF();

    autohost_end( 3 * (0
#ifdef CYGHWR_NET_DRIVER_ETH0
                  + eth0_up
#endif
#ifdef CYGHWR_NET_DRIVER_ETH1
                  + eth1_up
#endif
        ) ); // check for N pass messages from hosts

    TNR_PRINT_ACTIVITY();
    CYG_TEST_EXIT("Done");
}
Exemplo n.º 12
0
void
dns_test(cyg_addrword_t p)
{
    struct in_addr addr;
    struct hostent *hent;
    char dn[256];

    CYG_TEST_INIT();

    init_all_network_interfaces();

    CYG_TEST_INFO("Starting dns2 test");

    getdomainname(dn,sizeof(dn));
    diag_printf("INFO:<DHCP said domain name is %s>\n",dn);
#ifndef USE_HARDCODED_DOMAIN
    // If not hard-coded we can't tell what it's _meant_ to be
    CYG_TEST_CHECK(!strncmp(dn,_LOOKUP_DOMAINNAME,sizeof(_LOOKUP_DOMAINNAME)),
                   "DHCP got the wrong domainname");
#endif //ifdef _LOOKUP_DOMAINNAME
    
    /* Expect _LOOKUP_IP as the answer. This is a CNAME lookup */
    inet_aton(_LOOKUP_IP, &addr);
    hent = gethostbyname(_LOOKUP_FQDN);
    if (hent != NULL) {
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
        if (0 != memcmp((void*)&addr, (void*)(hent->h_addr), sizeof(struct in_addr))) {
          diag_printf("FAIL:<expected " _LOOKUP_FQDN " to be " _LOOKUP_IP ">\n");
        }
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_FQDN ". No answer: %s>\n", hstrerror(h_errno));
    }

    /* Now just the hostname */
#ifdef USE_HARDCODED_DOMAIN
    // set the domain by hand if required.
    setdomainname(_LOOKUP_DOMAINNAME, sizeof(_LOOKUP_DOMAINNAME));
#endif //ifdef _LOOKUP_DOMAINNAME
    hent = gethostbyname(_LOOKUP_HOSTNAME);
    if (hent != NULL) {
        diag_printf("PASS:<%s is %s>\n", _LOOKUP_HOSTNAME, inet_ntoa(*(struct in_addr *)hent->h_addr));
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_HOSTNAME ". No answer: %s>\n", hstrerror(h_errno));
    }

    CYG_TEST_FINISH("dns2 test completed");
}
Exemplo n.º 13
0
int main(void) {
    //firewall
    
     char * ipfw_command2[] = {"add","set",  "3",  "allow",  "all",  "from",  "192.168.2.100",  "to",  "192.168.1.100"};
     char * ipfw_command1[] = {"add","set",  "2",  "allow",  "all",  "from",  "192.168.1.100",  "to",  "192.168.2.100"};
     //char * ipfw_nat_config1[] = {"nat-config", "1", "ip", "192.168.1.1", "redirect_addr",  "192.168.2.100",  "192.168.5.1"};
     //char * ipfw_nat_config2[] = {"nat-config", "2", "if", "eth1", "redirect_addr",  "192.168.1.100",  "192.168.2.1"};
     //char * ipfw_nat1[] = {"add", "nat", "1", "ip", "from", "192.168.2.100", "to","192.168.1.100"};
     //char * ipfw_nat2[] = {"add", "nat", "2", "ip", "from", "192.168.2.100", "to","192.168.2.1"};
    
    //vnet_ipfw_init();
    //ipfw_nat_init();
    //struct cfg_nat cfg;

    //(*ipfw_nat_cfg_ptr)(&cfg);
    //ipfw_config_nat(sizeof(ipfw_nat_config2)/sizeof(char*), ipfw_nat_config2);
    //ipfw_config_nat(sizeof(ipfw_nat_config1)/sizeof(char*), ipfw_nat_config1);
     
    //ipfw_add(&ipfw_nat2);
    //ipfw_add(&ipfw_nat1);
    //ipfw_add(&ipfw_command1);
    //ipfw_add(&ipfw_command2);
    init_all_network_interfaces();
    //routing

    cyg_route_init();
    cyg_route_reinit();
    //example - transfers packets from 192.168.5.0/24 to 192.168.2.100 via eth0
    //add_route("eth0", "192.168.5.1", "255.255.255.0", "192.168.2.100");

    
    //mandatory for proper routing, do not remove
    add_route("eth0", "192.168.2.100", "255.255.255.0", "192.168.2.100");
    add_route("eth1", "192.168.1.100", "255.255.255.0", "192.168.1.100");


    show_network_tables(printf);
    printf("Hello, eCos world!\n");


    while (1) {
        printf("Sleeping\n");
        cyg_thread_delay(1000);
    }
    return 0;
}
Exemplo n.º 14
0
void
net_test(cyg_addrword_t param)
{
    diag_printf("Start TCP test - ECHO mode\n");
    init_all_network_interfaces();
    calibrate_load(DESIRED_BACKGROUND_LOAD);
    TNR_INIT();
#ifdef CYGPKG_SNMPAGENT
    {
        extern void cyg_net_snmp_init(void);
        cyg_net_snmp_init();
    }
#endif
    echo_test(param);
    TNR_PRINT_ACTIVITY();
    cyg_test_exit();
}
Exemplo n.º 15
0
// ------------------------------------------------------------------------
// The management thread function
void dhcp_mgt_entry( cyg_addrword_t loop_on_failure )
{
    int j;
    while ( 1 ) {
        while ( 1 ) {
            cyg_semaphore_wait( &dhcp_needs_attention );
            if ( ! dhcp_bind() ) // a lease expired
                break; // If we need to re-bind
        }
        dhcp_halt(); // tear everything down
        if ( !loop_on_failure )
            return; // exit the thread/return
        init_all_network_interfaces(); // re-initialize
        for ( j = 0; j < CYGPKG_NET_NLOOP; j++ )
            init_loopback_interface( j );
#ifdef CYGPKG_SNMPAGENT
        SnmpdShutDown(0); // Cycle the snmpd state
#endif
    }
}
Exemplo n.º 16
0
void
net_test(cyg_addrword_t param)
{
    diag_printf("Start TFTP server test\n");
    init_all_network_interfaces();
    TNR_INIT();
#ifdef CYGHWR_NET_DRIVER_ETH0
    if (eth0_up) {
        tftp_test(&eth0_bootp_data);
    }
#else
    if ( 0 ) ; 
#endif
#ifdef CYGHWR_NET_DRIVER_ETH1
    else if (eth1_up) {
        tftp_test(&eth1_bootp_data);
    }
#endif
    TNR_PRINT_ACTIVITY();
    cyg_test_exit();
}
Exemplo n.º 17
0
///
/// Initializes the framebuffer and the network interfaces
///
void init()
{
    //cyg_interrupt_unmask(CYGNUM_HAL_INTERRUPT_EMAC);

    // initialize profiling timebase
    if (profile_tbwdtInit() != 0) {
        diag_printf("TBWDT initialization failed.\n");
    }
#ifdef DO_STATETRACE
    reconos_clearStateTrace();
#endif

    lcd_init(24);
    lcd_clear();
    lcd_getinfo(&fb_info);
    diag_printf("framebuffer @ %dx%d\n", fb_info.width, fb_info.height);

    init_all_network_interfaces();
    diag_printf("eth0_up = %d\n", eth0_up);

}
Exemplo n.º 18
0
int main(int argc, char **argv)
{
     // Bring up the TCP/IP network
     init_all_network_interfaces();
     
     for (;;)
     {
          cyg_ppp_options_t options;
          cyg_ppp_handle_t ppp_handle;
          
          // Initialize the options
          cyg_ppp_options_init( &options );
          
          options.script=windows_script;
          options.baud = CYGNUM_SERIAL_BAUD_38400;
          options.flowctl = CYG_PPP_FLOWCTL_NONE;
          options.idle_time_limit = 0; // never shut down.      
          
          // Start up PPP
          ppp_handle = cyg_ppp_up( "/dev/ser0", &options );
          
          // Wait for it to get running
          if( cyg_ppp_wait_up( ppp_handle ) == 0 )
          {
               // Make use of PPP
               for (;;)
               {
                    telnet();
               }
               
               // never reached, but  for illustration:
               
               // Bring PPP link down
               cyg_ppp_down( ppp_handle );
               
               // Wait for connection to go down.
               cyg_ppp_wait_down( ppp_handle );
          }
     }
}
Exemplo n.º 19
0
void
ppp_test(cyg_addrword_t p)
{
    cyg_serial_baud_rate_t old;
    
    CYG_TEST_INIT();
    diag_printf("Start PPP test\n");

    init_all_network_interfaces();

//    old = ppp_test_set_baud( CYGNUM_SERIAL_BAUD_115200 );
//    do_test( CYGNUM_SERIAL_BAUD_115200 );

    old = ppp_test_set_baud( CYGNUM_SERIAL_BAUD_19200 );
    do_test( CYGNUM_SERIAL_BAUD_19200 );

#ifdef CYGPKG_PPP_TESTS_AUTOMATE

    {
        static cyg_serial_baud_rate_t test_rates[] =
            { CYGDAT_PPP_TEST_BAUD_RATES, 0 };

        int i;

        for( i = 0; test_rates[i] != 0; i++ )
        {
            ppp_test_set_baud( test_rates[i] );
            do_test( test_rates[i] );
        }

        ppp_test_set_baud( old );
    
        ppp_test_finish();
        
    }
           
#endif
    
    CYG_TEST_PASS_FINISH("PPP test OK");
}
Exemplo n.º 20
0
static void 
startup_thread(CYG_ADDRESS data)
{
    cyg_ucount32 nanox_data_index;
    int i;
    struct nx_thread *nx;

    printf("SYSTEM INITIALIZATION in progress\n");
    printf("NETWORK:\n");
    init_all_network_interfaces();

#ifdef USE_ROMDISK
    {
        char ROM_fs[32];
        int res;

        printf("Mount ROM file system\n");
#ifdef CYGPKG_HAL_ARM_SA11X0_IPAQ
        // Work around hardware anomaly which causes major screen flicker
        {
            char *hold_rom_fs;
            if ((hold_rom_fs = malloc(0x80080)) != 0) {
                // Note: ROM fs requires 32 byte alignment
                hold_rom_fs = (char *)(((unsigned long)hold_rom_fs + 31) & ~31);
                memcpy(hold_rom_fs, 0x50F00000, 0x80000);
                sprintf(ROM_fs, "0x%08x", hold_rom_fs);
            } else {
                printf("Can't allocate memory to hold ROM fs!\n");
            }
        }
#else
        sprintf(ROM_fs, "0x%08x", 0x50F00000);
        sprintf(ROM_fs, "0x%08x", 0x61F00000);
#endif
        printf("ROM fs at %s\n", ROM_fs);
        if ((res = mount(ROM_fs, "/", "romfs")) < 0) {
            printf("... failed\n");
        }
        chdir("/");
    }
#endif

#ifdef USE_JFFS2
    {
        int res;
        printf("... Mounting JFFS2 on \"/\"\n");
        res = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" );
        if (res < 0) {
            printf("Mount \"/\" failed - res: %d\n", res);
        }
        chdir("/");
    }   
#endif

    // Allocate a free thread data slot
    // Note: all MicroWindows/NanoX threads use this slot for NanoX-private
    // data.  That's why there is only one call here.
    nanox_data_index = cyg_thread_new_data_index();
    printf("data index = %d\n", nanox_data_index);

    printf("Creating system threads\n");
    nx = &_threads[1];
    for (i = 1;  i < NUM(_threads);  i++, nx++) {
        cyg_thread_create(nx->prio,
                          nx->entry,
                          (cyg_addrword_t) nanox_data_index,
                          nx->name,
                          (void *)nx->stack, STACKSIZE,
                          &nx->t,
                          &nx->t_obj);
    }

    printf("Starting threads\n");
    nx = &_threads[1];
    for (i = 1;  i < NUM(_threads);  i++, nx++) {
        printf("Starting %s\n", nx->name);
        cyg_thread_resume(nx->t);
        // Special case - run additional code, specific to this environment
        // only after the server has had a chance to startup
        if (i == 2) {
            ecos_nx_init(nanox_data_index);
        }
    }

    printf("SYSTEM THREADS STARTED!\n");
}
Exemplo n.º 21
0
static int initWebs()
{
	char		host[128];
	char		*cp;
	char_t		wbuf[128];

/*
 *	Initialize networking.
 */

	init_all_network_interfaces();

/*
 *	Initialize the socket subsystem
 */
	socketOpen();

/*
 *	Configure the web server options before opening the web server
 */
	websSetDefaultDir("/");
	cp = inet_ntoa(eth0_bootp_data.bp_yiaddr);
	ascToUni(wbuf, cp, min(strlen(cp) + 1, sizeof(wbuf)));
	websSetIpaddr(wbuf);
	ascToUni(wbuf, host, min(strlen(host) + 1, sizeof(wbuf)));
	websSetHost(wbuf);

/*
 *	Configure the web server options before opening the web server
 */
	websSetDefaultPage(T("default.asp"));
	websSetPassword(password);

/* 
 *	Open the web server on the given port. If that port is taken, try
 *	the next sequential port for up to "retries" attempts.
 */
	websOpenServer(port, retries);

/*
 * 	First create the URL handlers. Note: handlers are called in sorted order
 *	with the longest path handler examined first. Here we define the security 
 *	handler, forms handler and the default web page handler.
 */
	websUrlHandlerDefine(T(""), NULL, 0, websSecurityHandler, 
		WEBS_HANDLER_FIRST);
	websUrlHandlerDefine(T("/goform"), NULL, 0, websFormHandler, 0);
	websUrlHandlerDefine(T(""), NULL, 0, websDefaultHandler, 
		WEBS_HANDLER_LAST); 

/*
 *	Now define two test procedures. Replace these with your application
 *	relevant ASP script procedures and form functions.
 */
	websAspDefine(T("aspTest"), aspTest);
	websFormDefine(T("formTest"), formTest);

/*
 *	Create a handler for the default home page
 */
	websUrlHandlerDefine(T("/"), NULL, 0, websHomePageHandler, 0); 
	return 0;
}
Exemplo n.º 22
0
int main( int argc, char **argv )
{
    void *retval;
    pthread_attr_t attr;
    struct sched_param schedparam;

    CYG_TEST_INIT();

    sa.sin_family = AF_INET;
    sa.sin_len = sizeof(sa);
    inet_aton("127.0.0.1", &sa.sin_addr);
    sa.sin_port = htons(1234);
    init_all_network_interfaces();
    
    // Create test threads

    {
        pthread_attr_init( &attr );

        schedparam.sched_priority = 5;
        pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
        pthread_attr_setschedpolicy( &attr, SCHED_RR );
        pthread_attr_setschedparam( &attr, &schedparam );
        pthread_attr_setstackaddr( &attr, (void *)&thread1_stack[sizeof(thread1_stack)] );
        pthread_attr_setstacksize( &attr, sizeof(thread1_stack) );

        pthread_create( &thread1,
                        &attr,
                        pthread_entry1,
                        (void *)0x12345671);
    }

    {
        pthread_attr_init( &attr );

        schedparam.sched_priority = 10;
        pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
        pthread_attr_setschedpolicy( &attr, SCHED_RR );
        pthread_attr_setschedparam( &attr, &schedparam );
        pthread_attr_setstackaddr( &attr, (void *)&thread2_stack[sizeof(thread2_stack)] );
        pthread_attr_setstacksize( &attr, sizeof(thread2_stack) );

        pthread_create( &thread2,
                        &attr,
                        pthread_entry2,
                        (void *)0x12345672);
    }
    
    // Now join with thread1
    CYG_TEST_INFO( "Main: calling pthread_join(thread1)");
    pthread_join( thread1, &retval );

    // And thread 2
    CYG_TEST_INFO( "Main: calling pthread_join(thread2)");
    pthread_join( thread2, &retval );

    diag_printf("INFO: pselect returns: %d\n", pselect_wakeups );
    diag_printf("INFO: pselect EINTR returns: %d\n", pselect_eintr );
    diag_printf("INFO: SIGUSR1 sent: %d\n", sigusr1_sent );
    diag_printf("INFO: SIGUSR1 delivered: %d\n", sigusr1_calls );
    
    CYG_TEST_CHECK( sigusr1_sent == sigusr1_calls, "SIGUSR1 calls != delivered");
    CYG_TEST_CHECK( sigusr1_sent == pselect_eintr, "SIGUSR1 calls != pselect EINTR wakeups");
    
    CYG_TEST_PASS_FINISH("pselect");
}
Exemplo n.º 23
0
BOOL SetIP(enum SET_IP_STATE_E *pIPState)
{
		enum SET_IP_STATE_E ipState;
		BOOL bOK = TRUE;
		int i;
		BOOL bEnable[2];
		
		if (pIPState == NULL)
			pIPState = &ipState;
		
		bEnable[0] = g_ConfigParam.abAsNetEnable[0];
		bEnable[1] = g_ConfigParam.abAsNetEnable[1];
#ifndef WLAN
		if (!bEnable[0] && !bEnable[1]) bEnable[0] = TRUE;
#else
		if (!bEnable[0] && !bEnable[1]) bEnable[1] = TRUE;
#endif
		for (i = sizeof(g_apcNetworkInterface) / sizeof(const char *) - 1; i >= 0; i--)
		{
			const char *pcInterface;
			if (!bEnable[i]) continue;
			pcInterface = g_apcNetworkInterface[i];
			
			if (g_ConfigParam.aucIPAssignedWay[i] == IP_ASSIGNMENT_MANUALLY)
			{	
				struct bootp wlan_bootp_data;
    			int j = 0;
				char ipadd[16];
				char netmask[16];
				char gateway[16];
				char broadcast[16];
				httpIP2String(g_ConfigParam.ulAsIPAddress[i],ipadd);
				httpIP2String(g_ConfigParam.ulAsNetmask[i],netmask);
				httpIP2String(g_ConfigParam.ulAsGateway[i],gateway);
				httpIP2String((~g_ConfigParam.ulAsNetmask[i])|g_ConfigParam.ulAsIPAddress[i],broadcast);
				
				*pIPState = SET_IP__STATIC_IP_TRYING;
				DownInterface(pcInterface);
				
				diag_printf("IP is %s, NetMask is %s, Gateway is %s,Broadcast is %s\n",ipadd,netmask,gateway,broadcast);
       			build_bootp_record(&wlan_bootp_data, pcInterface,
                           ipadd, netmask,broadcast,gateway,gateway);
    			show_bootp(pcInterface, &wlan_bootp_data);

    			if (!init_net(pcInterface, &wlan_bootp_data)) 
    			{
    				*pIPState = SET_IP__STATIC_IP_FAILED;
    				diag_printf("failed for %s\n",pcInterface);
    			}
    			else
	   				*pIPState = SET_IP__STATIC_IP_OK;
				/* Set DNS server */
				if (g_ConfigParam.aulAsDNS[0] != 0)
				{
					struct in_addr dns_server;
					dns_server.s_addr = (g_ConfigParam.aulAsDNS[0]);
					cyg_dns_res_init(&dns_server);
				}

    			for(;j<5;j++)
					init_loopback_interface(0);
				
				
			}
			else         
			{	
#ifndef WLAN
					//WRRunDHCPClient(pcInterface, TRUE);
#else				
					int j = 0;
					
					*pIPState = SET_IP__DHCP_TRYING;
					DownInterface(pcInterface);
					
					diag_printf("Set IP by dhcp\n");
					g_WebCamState.bDHCP_Finished = FALSE;
					init_all_network_interfaces();	
					for(;j<5;j++)
						init_loopback_interface(0);
					
					if (wlan0_dhcpstate != DHCPSTATE_BOOTP_FALLBACK
						&& wlan0_dhcpstate != DHCPSTATE_BOUND)
					{
						bOK = FALSE;
						SetRandomIP("wlan0");
						*pIPState = SET_IP__DHCP_FAILED;
					}
					else
						*pIPState = SET_IP__DHCP_OK;

					g_WebCamState.bDHCP_Finished = TRUE;
						
#endif
			}
		}
		/*display the ip address*/
		{
			unsigned long ulIP;
			
			
			GetPubIPInfo(&ulIP, NULL, NULL, NULL);
			diag_printf("******************ip Address====%x\n", ulIP); 
			if (bOK)
			{
				if (g_ConfigParam.ucWlanOperationMode == 1)	/* Disable suspend in Ad-hoc mode */
					g_netIsSuspendAllowed = FALSE;
				else
					g_netIsSuspendAllowed = TRUE;
			}

			diag_printf("bOK=%d\n", bOK);
			if (!bOK)
				return FALSE;
			else
				OnSetIP();
		}		

	return TRUE;
}
Exemplo n.º 24
0
void
net_test(test_param_t param)
{
#ifdef __ECOS
    cyg_serial_baud_rate_t old;    
    cyg_ppp_options_t options;
    cyg_ppp_handle_t ppp_handle;

    CYG_TEST_INIT();
#endif

//    int i;
    if (param == 0) {
        test_printf("Start Network Characterization - SLAVE\n");
#ifdef __ECOS
        init_all_network_interfaces();
        calibrate_load(DESIRED_BACKGROUND_LOAD);
#if 0
// I can see what this is trying to do, but I get "bind: Address already in
// use" errors from the 2nd interface - and the parameter is not used
// anyway, so one thread does quite well enough (but only tests one i/f at
// once).

// Comment in the 'int i' above too.
        for (i = 1;  i < CYGHWR_NET_DRIVERS;  i++) {
            cyg_thread_resume(main_thread_handle[i]);   // Start other threads
        }
#endif
#endif
    }

#ifdef __ECOS

    old = ppp_test_set_baud( CYGNUM_SERIAL_BAUD_115200 );

    ppp_test_announce( "NC_TEST_SLAVE" );
    
    cyg_ppp_options_init( &options );

//    options.debug = 1;
//    options.kdebugflag = 1;

//    options.script = script;
//    options.flowctl = CYG_PPP_FLOWCTL_SOFTWARE;

    ppp_handle = cyg_ppp_up( CYGPKG_PPP_TEST_DEVICE, &options );

    CYG_TEST_INFO( "Waiting for PPP to come up");
    
    cyg_ppp_wait_up( ppp_handle );
#endif
    
    nc_slave(param);
#ifdef CYGDBG_NET_TIMING_STATS
    show_net_times();
#endif

#ifdef __ECOS
    CYG_TEST_INFO( "Bringing PPP down");

    cyg_ppp_down( ppp_handle );
    
    CYG_TEST_INFO( "Waiting for PPP to go down");

    cyg_ppp_wait_down( ppp_handle );

    cyg_thread_delay( 200 );

    ppp_test_set_baud( old );

    ppp_test_finish();

    CYG_TEST_PASS_FINISH( "Network Characterization - SLAVE" );
    
#endif
    
    cyg_test_exit();
}
Exemplo n.º 25
0
static void 
startup(CYG_ADDRESS data)
{
    cyg_ucount32 nanox_data_index;
    struct _mw_app_entry *nx;

    printf("SYSTEM INITIALIZATION in progress\n");
    printf("NETWORK:\n");
    init_all_network_interfaces();

#ifdef USE_ROMDISK
    {
        char ROM_fs[32];
        int res;

        printf("Mount ROM file system\n");
#if (defined CYGPKG_HAL_ARM_SA11X0_IPAQ) && (!defined CYGBLD_MICROWINDOWS_VNC_DRIVERS)
        // Work around hardware anomaly which causes major screen flicker
        {
            char *hold_rom_fs;
            if ((hold_rom_fs = malloc(0x80080)) != 0) {
                // Note: ROM fs requires 32 byte alignment
                hold_rom_fs = (char *)(((unsigned long)hold_rom_fs + 31) & ~31);
                memcpy(hold_rom_fs, 0x50F00000, 0x80000);
                sprintf(ROM_fs, "0x%08x", hold_rom_fs);
            } else {
                printf("Can't allocate memory to hold ROM fs!\n");
            }
        }
#else
        sprintf(ROM_fs, "0x%08x", 0x50F00000);
        sprintf(ROM_fs, "0x%08x", 0x61F00000);
#endif
        printf("ROM fs at %s\n", ROM_fs);
        if ((res = mount(ROM_fs, "/", "romfs")) < 0) {
            printf("... failed\n");
        }
        chdir("/");
    }
#endif

#ifdef USE_JFFS2
    {
        int res;
        printf("... Mounting JFFS2 on \"/\"\n");
        res = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs2" );
        if (res < 0) {
            printf("Mount \"/\" failed - res: %d\n", res);
        }
        chdir("/");
    }   
#endif

    // Allocate a free thread data slot
    // Note: all MicroWindows/NanoX threads use this slot for NanoX-private
    // data.  That's why there is only one call here.
    nanox_data_index = cyg_thread_new_data_index();
    printf("data index = %d\n", nanox_data_index);

    printf("Creating system threads\n");
    for (nx = __MW_APP_TAB__; nx != &__MW_APP_TAB_END__;  nx++) {
        printf("Creating %s thread\n", nx->name);
        cyg_thread_create(nx->prio,
                          nx->entry,
                          (cyg_addrword_t) nanox_data_index,
                          nx->name,
                          (void *)nx->stack, STACKSIZE,
                          &nx->t,
                          &nx->t_obj);
    }
    printf("Starting threads\n");
    for (nx = __MW_APP_TAB__; nx != &__MW_APP_TAB_END__;  nx++) {
        printf("Starting %s\n", nx->name);
        cyg_thread_resume(nx->t);
        if (nx->init) {
            (nx->init)(nanox_data_index);
        }
    }

    printf("SYSTEM THREADS STARTED!\n");
}
Exemplo n.º 26
0
void
ftp_test(cyg_addrword_t p)
{
  int ret;

  CYG_TEST_INIT();
  
  init_all_network_interfaces();
 
  CYG_TEST_INFO("Getting /etc/passwd from " _FTP_SRV);
  ret = ftp_get(_FTP_SRV,"anonymous","ftpclient1",
                 "/etc/passwd",ftpbuf,FTPBUFSIZE,
                ftpclient_printf);

  if (ret > 0) {
    diag_printf("PASS:< %d bytes received>\n",ret);
  } else {
    diag_printf("FAIL:< ftp_get returned %d>\n",ret);
  }

  CYG_TEST_INFO("Putting passwd file back in /incoming/passwd\n");
  ret = ftp_put(_FTP_SRV,"anonymous","ftpclient1",
                "/incoming/passwd",ftpbuf,ret,
                ftpclient_printf);
  
  if (ret > 0) {
    diag_printf("PASS:\n");
  } else {
    diag_printf("FAIL:< ftp_get returned %d>\n",ret);
  }

  CYG_TEST_INFO("Reading back /incoming/passwd\n");
  ret = ftp_get(_FTP_SRV,"anonymous","ftpclient1",
                 "/incoming/passwd",ftpbuf1,FTPBUFSIZE,
                ftpclient_printf);
  
  if (ret > 0) {
    diag_printf("PASS:< %d bytes received>\n",ret);
  } else {
    diag_printf("FAIL:< ftp_get returned %d>\n",ret);
  }

  CYG_TEST_PASS_FAIL(!memcmp(ftpbuf,ftpbuf1,ret),"Transfer integrity");

#ifdef CYGPKG_NET_INET6
  CYG_TEST_INFO("Getting /etc/passwd from " _FTP_SRV_V6);
  ret = ftp_get(_FTP_SRV_V6,"anonymous","ftpclient1",
                 "/etc/passwd",ftpbuf,FTPBUFSIZE,
                ftpclient_printf);

  if (ret > 0) {
    diag_printf("PASS:< %d bytes received>\n",ret);
  } else {
    diag_printf("FAIL:< ftp_get returned %d>\n",ret);
  }

  CYG_TEST_INFO("Putting passwd file back in /incoming/passwd\n");
  ret = ftp_put(_FTP_SRV_V6,"anonymous","ftpclient1",
                "/incoming/passwd",ftpbuf,ret,
                ftpclient_printf);
  
  if (ret > 0) {
    diag_printf("PASS:\n");
  } else {
    diag_printf("FAIL:< ftp_get returned %d>\n",ret);
  }

  CYG_TEST_INFO("Reading back /incoming/passwd\n");
  ret = ftp_get(_FTP_SRV_V6,"anonymous","ftpclient1",
                 "/incoming/passwd",ftpbuf1,FTPBUFSIZE,
                ftpclient_printf);
  
  if (ret > 0) {
    diag_printf("PASS:< %d bytes received>\n",ret);
  } else {
    diag_printf("FAIL:< ftp_get returned %d>\n",ret);
  }

  CYG_TEST_PASS_FAIL(!memcmp(ftpbuf,ftpbuf1,ret),"Transfer integrity");

#endif

  CYG_TEST_INFO("ftp_Get'ing with a bad username\n");
  ret = ftp_get(_FTP_SRV,"nosuchuser","ftpclient1",
                "/incoming/passwd",ftpbuf1,FTPBUFSIZE,
                ftpclient_printf);
  CYG_TEST_PASS_FAIL(ret==FTP_BADUSER,"Bad Username");

  CYG_TEST_INFO("ftp_get'ting with a bad passwd\n");
  ret = ftp_get(_FTP_SRV,"nobody","ftpclient1",
                "/incoming/passwd",ftpbuf1,FTPBUFSIZE,
                ftpclient_printf);
  CYG_TEST_PASS_FAIL(ret==FTP_BADUSER,"Bad passwd");

  CYG_TEST_INFO("ftp_get'ing from a with a bad passwd\n");
  ret = ftp_get(_FTP_SRV,"nobody","ftpclient1",
                "/incoming/passwd",ftpbuf1,FTPBUFSIZE,
                ftpclient_printf);
  CYG_TEST_PASS_FAIL(ret==FTP_BADUSER,"Bad passwd");

  CYG_TEST_INFO("ftp_get'ing from a bad server\n");
  ret = ftp_get("127.0.0.1","nobody","ftpclient1",
                "/incoming/passwd",ftpbuf1,FTPBUFSIZE,
                ftpclient_printf);
  CYG_TEST_PASS_FAIL(ret==FTP_NOSUCHHOST,"Bad server");

  CYG_TEST_INFO("ftp_get'ing a file which is too big");
  ret = ftp_get(_FTP_SRV,"anonymous","ftpclient1",
                "/incoming/passwd",ftpbuf,2,
                ftpclient_printf);
  CYG_TEST_PASS_FAIL(ret==FTP_TOOBIG,"File too big");
}
Exemplo n.º 27
0
void
dns_test(cyg_addrword_t p)
{
    struct in_addr addr;
    struct hostent *hent;
    char dn[256];

    CYG_TEST_INIT();

    init_all_network_interfaces();

    CYG_TEST_INFO("Connecting to DNS at " _DNS_IP);
    inet_aton(_DNS_IP, &addr);
    CYG_TEST_CHECK(cyg_dns_res_init(&addr) == 0, "Failed to initialize resolver");
    setdomainname(NULL,0);
    
    /* Expect _LOOKUP_IP as the answer. This is a CNAME lookup */
    inet_aton(_LOOKUP_IP, &addr);
    hent = gethostbyname(_LOOKUP_FQDN);
    if (hent != NULL) {
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
        if (0 != memcmp((void*)&addr, (void*)(hent->h_addr), sizeof(struct in_addr))) {
          diag_printf("FAIL:<expected " _LOOKUP_FQDN " to be " _LOOKUP_IP ">\n");
        }
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_FQDN ". No answer: %s>\n", hstrerror(h_errno));
    }

    /* Reverse lookup the _LOOKUP_IP addres, expect _LOOKUP_FQDN
       as the answer. */
    hent = gethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET);
    if (hent != NULL) {
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
        if (0 != strcmp(_LOOKUP_FQDN, hent->h_name)) {
          diag_printf("FAIL:<expected " _LOOKUP_IP " to be " _LOOKUP_FQDN ">\n");
        }
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_IP ". No answer: %s>\n", hstrerror(h_errno));
    }
 
    /* This does not require a DNS lookup. Just turn the value into
       binary */
    hent = gethostbyname(_LOOKUP_IP);
    if (hent != NULL) {
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_IP ". No answer: %s>\n", hstrerror(h_errno));
    }
 
    /* Reverse lookup an address this is not in the server. Expect a
       NULL back */
    inet_aton(_LOOKUP_IP_BAD, &addr);
    hent = gethostbyaddr((char *)&addr, sizeof(struct in_addr), AF_INET);
    if (hent != NULL) {
        diag_printf("FAIL:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
    } else {
        diag_printf("PASS:<Asked for bad IP " _LOOKUP_IP_BAD ". No answer: %s>\n", hstrerror(h_errno));
    }

    /* Setup a domainname. We not don't have to use fully qualified
       domain names */
    setdomainname(_LOOKUP_DOMAINNAME, sizeof(_LOOKUP_DOMAINNAME));
    getdomainname(dn, sizeof(dn));
    diag_printf("INFO:<Domainname is now %s>\n", dn);

    /* Make sure FQDN still work */
    hent = gethostbyname(_LOOKUP_FQDN);
    if (hent != NULL) {
        diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr));
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_FQDN ". No answer: %s>\n", hstrerror(h_errno));
    }

    /* Now just the hostname */
    hent = gethostbyname(_LOOKUP_HOSTNAME);
    if (hent != NULL) {
        diag_printf("PASS:<%s is %s>\n", _LOOKUP_HOSTNAME, inet_ntoa(*(struct in_addr *)hent->h_addr));
    } else {
        diag_printf("FAIL:<Asked for " _LOOKUP_HOSTNAME ". No answer: %s>\n", hstrerror(h_errno));
    }

    CYG_TEST_FINISH("dns1 test completed");
}
Exemplo n.º 28
0
static void
master(cyg_addrword_t param)
{
    int i;
    cyg_handle_t self = cyg_thread_self();

    cyg_semaphore_init( &send_sema, 0 );
    cyg_semaphore_init( &recv_sema, 0 );

    for ( i = 0 ; i < NLISTENERS; i++ )
        cyg_semaphore_init( &listen_sema[i], 0 );

    init_all_network_interfaces();
    CYG_TEST_INFO("Start multiple loopback select test");
#if NLOOP > 0
    // We are currently running at high prio, so we can just go and make
    // loads of threads:

    // Some at higher prio
    for ( i = 0; i < NLISTENERS/2; i++ )
        cyg_thread_create(PRIO_LISTENER_HI,       // Priority
                          listener,               // entry
                          i,                      // entry parameter
                          "listener",             // Name
                          &stack_listener[i][0],  // Stack
                          STACK_SIZE,             // Size
                          &listener_thread_handle[i], // Handle
                          &listener_thread_data[i] // Thread data structure
            );
    // the rest at lower prio
    for (      ; i < NLISTENERS  ; i++ )
        cyg_thread_create(PRIO_LISTENER_LO,       // Priority
                          listener,               // entry
                          i,                      // entry parameter
                          "listener",             // Name
                          &stack_listener[i][0],  // Stack
                          STACK_SIZE,             // Size
                          &listener_thread_handle[i], // Handle
                          &listener_thread_data[i] // Thread data structure
            );

    // make the dummy event-grabber threads
    for ( i = 0; i < NDUMMIES; i++ )
        cyg_thread_create(PRIO_DUMMY,             // Priority
                          dummy,                  // entry
                          i,                      // entry parameter
                          "dummy",                // Name
                          &stack_dummy[i][0],     // Stack
                          STACK_SIZE,             // Size
                          &dummy_thread_handle[i], // Handle
                          &dummy_thread_data[i]   // Thread data structure
            );

    // Start those threads
    for ( i = 0; i < NLISTENERS; i++ )
        cyg_thread_resume(listener_thread_handle[i]);
    for ( i = 0; i < NDUMMIES; i++ )
        cyg_thread_resume(   dummy_thread_handle[i]);

    // and let them start up and start listening...
    cyg_thread_set_priority( self, PRIO_MASTERLOW );
    CYG_TEST_INFO("All listeners should be go now");
    cyg_thread_set_priority( self, PRIO_MASTERHIGH );

    for ( i = 0; i < NSENDERS; i++ ) {
        cyg_thread_create( (0 == i)
                           ?PRIO_SENDER_MID
                           : PRIO_SENDER_LOW,     // Priority
                           sender,                // entry
                           i,                     // entry parameter
                           "sender",              // Name
                           &stack_sender[i][0],   // Stack
                           STACK_SIZE,            // Size
                           &sender_thread_handle[i], // Handle
                           &sender_thread_data[i] // Thread data structure
            );
        cyg_thread_resume(sender_thread_handle[i]);
    }

    // Now we are still higher priority; so go low and let everyone else
    // have their head.  When we next run after this, it should all be
    // over.
    cyg_thread_set_priority( self, PRIO_MASTERLOW );

    cyg_semaphore_peek( &recv_sema, &i );
    CYG_TEST_CHECK( NLISTENERS == i, "Not enough recvs occurred!" );
    
    cyg_semaphore_peek( &send_sema, &i );
    CYG_TEST_CHECK( NLISTENERS == i, "Not enough sends occurred!" );

    CYG_TEST_PASS_FINISH("Master returned OK");
#endif
    CYG_TEST_NA( "No loopback devs" );
}
Exemplo n.º 29
0
//void main_function(cyg_addrword_t data) {
void * main_function(void * data) {

    
    int tmp = 1;

    region_information = (int *) malloc (4 * sizeof(int));

     // create particles
    create_particle_filter(100, 10); 

    /*slots = (int *) malloc (6 * sizeof(int));
    slots[0] = 0;
    slots[1] = 1;
    slots[2] = 2;
    slots[3] = 3;
    slots[4] = 4;
    slots[5] = 5;
    set_importance_hw_static(1, &slots[0]);*/

    /*rthread_attr_init(&hwthread_sorter_attr);
    rthread_attr_setslotnum(&hwthread_sorter_attr, 0);
    rthread_attr_setresources(&hwthread_sorter_attr, hwthread_sorter_resources, 3);
    reconos_hwthread_create( 15,                                               // priority
                             &hwthread_sorter_attr,                             // hardware thread attributes
                             0,                                                // entry data (not needed)
                             "MT_HW_SORT",                                     // thread name
                             hwthread_sorter_stack,                            // stack
                             STACK_SIZE,                                       // stack size
                             &hwthread_sorter_handle,                          // thread handle
                             &hwthread_sorter                                  // thread object
    );
    cyg_thread_resume( hwthread_sorter_handle );*/
    
    //cyg_thread_delay(50);

#ifndef NO_ETHERNET
    init_all_network_interfaces();
    if(!eth0_up){
		printf("failed to initialize eth0\naborting\n");
		return NULL;
    }
    else{
		printf(" eth0 up\n");
    }

    diag_printf( "initializing ECAP interface..." );
    ecap_init();
    diag_printf( "done\n" );

    // establish connection
    while (tmp == 1){
         tmp = establish_connection(6666, region_information);
    }
#endif


    // start read_new_frame 
    cyg_semaphore_post(sem_read_new_frame_start);

    srand(1);

    // set region information for equal time measurements

   #define VIDEO 1
    
   printf("\n#################################################");
   printf("\n#################################################");
      #ifdef VIDEO    
      #if VIDEO==1
       printf("\n##########  S O C C E R   V I D E O  ############");
       region_information[0] = 286;
       region_information[1] = 247;
       region_information[2] = 117;
       region_information[3] = 171;
      #else
      #if VIDEO==2
       printf("\n########  F O O T B A L L   V I D E O  ##########");
       region_information[0] = 255;
       region_information[1] = 252;
       region_information[2] =  23;
       region_information[3] =  41;
      #else
      #if VIDEO==3
       printf("\n##########  H O C K E Y   V I D E O  ############");
       region_information[0] = 152;
       region_information[1] =  95;
       region_information[2] =  19;
       region_information[3] =  39;
      #else
      #if VIDEO==4
       printf("\n##########  H O C K E Y   V I D E O (FULL PICTURE) ############");
       region_information[0] = 159;
       region_information[1] = 119;
       region_information[2] = 320;
       region_information[3] = 240;
      #endif
      #endif
      #endif
      #endif
      #else
       printf("\n######  N O   V I D E O   D E F I N E D  ########");

      #endif
    printf("\n#################################################");
    printf("\n#################################################\n");
    
    // init particles
    init_particles(region_information, 4);


    // Output Object Region
    printf("\n\nx0 = %d\ny0 = %d\nwidth = %d\nheight = %d\n\n", region_information[0], region_information[1], region_information[2], region_information[3]);
    
    particle p;
    p.x = region_information[0]*PF_GRANULARITY;
    p.y = region_information[1]*PF_GRANULARITY;
    p.x0 = p.x;
    p.y0 = p.y;
    p.xp = p.x;
    p.yp = p.y;
    p.s = PF_GRANULARITY;
    p.sp = p.s;
    p.width = region_information[2];
    p.height = region_information[3]; 

    // get reference data
    get_reference_data(&p, &reference_data);

    init_reference_data (&reference_data);

    print_histogram(&reference_data);
    //print_histogram2(&reference_data);

#ifdef STORE_VIDEO
    int i;
    printf("\n\nThe first %d Frames will be stored into Main Memory. Again this will take some time.\n", (int)MAX_FRAMES);

    
    // load first frames
    for(i=0; i<MAX_FRAMES-1; i++){

	  //switch_framebuffer();
	    read_frame();
    }

    printf("\nFinished: The first %d Frames are stored in the Main Memory.\n", (int)MAX_FRAMES);
#endif

       
    parameter_s = (int *) malloc (5 * sizeof(int));
    parameter_s[0] = SIZE_X;
    parameter_s[1] = SIZE_Y;
    parameter_s[2] = 16384; // GRANULARITY / TRANS_STD_X
    parameter_s[3] = 8192;  // GRANULARITY / TRANS_STD_Y
    parameter_s[4] = 16;    // GRANULARITY / TRANS_STD_S

    parameter_o = (int *) malloc (2 * sizeof(int));
    parameter_o[0] = SIZE_X;
    parameter_o[1] = SIZE_Y;

    slots = (int *) malloc (6 * sizeof(int));
    slots[0] = 0;
    slots[1] = 1;
    slots[2] = 2;
    slots[3] = 3;
    slots[4] = 4;
    slots[5] = 5;


    // create sampling, importance, resampling thread

   printf("\n#################################################");
   printf("\n#################################################");
   #ifdef PARTITIONING
    #if PARTITIONING==1
    printf("\n######   P A R T I T I O N I N G    S W   #######");
    set_sample_sw(1);
    set_observe_sw(1);
    set_importance_sw(1);
    set_resample_sw(1);
    #else
    #if PARTITIONING==2
    printf("\n####   P A R T I T I O N I N G    H W  I   #####");
    set_sample_sw(1);
    set_observe_sw(1);
    set_importance_sw(1);
    set_importance_hw_static(1, &slots[2]);
    set_resample_sw(1);   
    #else
    #if PARTITIONING==3
    printf("\n####   P A R T I T I O N I N G    H W   II   #####");
    set_sample_sw(1);
    set_observe_sw(1);
    set_importance_sw(1);
    set_importance_hw_static(2, &slots[2]);
    set_resample_sw(1); 
   #else
   #if PARTITIONING==4
    printf("\n####   P A R T I T I O N I N G    H W   O   #####");
    set_sample_sw(1);
    set_observe_sw(1);
    set_observe_hw_static(1, &slots[0], parameter_o, 2);
    set_importance_sw(1);
    set_resample_sw(1);
   #else
   #if PARTITIONING==5
    printf("\n####   P A R T I T I O N I N G    H W   OO   #####");
    set_sample_sw(1);
    set_observe_sw(1);
    set_observe_hw_static(1, &slots[0], parameter_o, 2);
    set_importance_sw(1);
    set_resample_sw(1);
   #else
   #if PARTITIONING==6
    printf("\n####   P A R T I T I O N I N G    H W   IO   #####");
    set_sample_sw(1);
    set_observe_sw(1);
    set_observe_hw_static(1, &slots[0], parameter_o, 2);
    set_importance_sw(1);
    set_importance_hw_static(1, &slots[2]);
    set_resample_sw(1);
   #else
   #if PARTITIONING==7
    printf("\n####   P A R T I T I O N I N G    H W   IIO   #####");
    set_sample_sw(1);
    set_observe_sw(1);
    set_observe_hw_static(2, &slots[0], parameter_o, 2);
    set_importance_sw(1);
    set_importance_hw_static(1, &slots[2]);
    set_resample_sw(1);
   #else
   #if PARTITIONING==8
    printf("\n####   P A R T I T I O N I N G    H W   IOO   #####");
    set_sample_sw(1);
    set_observe_sw(1);
    set_observe_hw_static(1, &slots[0], parameter_o, 2);
    set_importance_sw(1);
    set_importance_hw_static(2, &slots[2]);
    set_resample_sw(1);
   #else
   #if PARTITIONING==9
    printf("\n####   P A R T I T I O N I N G    H W   IIOO   #####");
    set_sample_sw(1);
    set_observe_sw(1);
    set_observe_hw_static(2, &slots[0], parameter_o, 2);
    set_importance_sw(1);
    set_importance_hw_static(2, &slots[2]);
    set_resample_sw(1);
   #endif
   #endif
   #endif
   #endif
   #endif
   #endif
   #endif
   #endif
   #endif
   #else
    //printf("\n#  N O  P A R T I T I O N I N G   D E F I N E D #");
    printf("\n####   P A R T I T I O N I N G    S W   O   #####");
    reconf_mode_observation_on = TRUE;
    reconf_mode_observation_last_slot_on = FALSE;

    // I. SAMPLING ////////////////////////////////////////
    set_sample_sw(1);
    //set_sample_hw_dynamic(1, &hw_thread_s_circuit, parameter_s, 5);

    // II. OBSERVATION ////////////////////////////////////
    //set_observe_sw(1);
    set_observe_hw_dynamic(2, &hw_thread_o_circuit, parameter_o, 2);
    //set_observe_hw_dynamic(2, &hw_thread_o_circuit, parameter_o, 2);
    //set_observe_hw_static(1, &slots[2], parameter_o, 2);

    // III. IMPORTANCE ////////////////////////////////////
    set_importance_sw(1);
    //set_importance_hw_dynamic(1, &hw_thread_i_circuit);
    //set_importance_hw_dynamic(2, &hw_thread_i_circuit);
    set_importance_hw_static(1, &slots[2]); //[2]

    // IV. RESAMPLING /////////////////////////////////////
    set_resample_sw(1);
   #endif
   printf("\n#################################################");
   printf("\n#################################################\n");
   /*
   // create and start sorting thread
    init_all_network_interfaces();
    if(!eth0_up){
        printf("failed to initialize eth0\naborting\n");
        return NULL;
    }
    else{
        printf(" eth0 up\n");
    }  
   diag_printf( "initializing ECAP interface..." );
   ecap_init();
   diag_printf( "done\n" );*/
   //create_particle_filter(100, 10); 
   //set_observe_hw_dynamic(2, &hw_thread_o_circuit, 0, 0);
   //sw_test_thread = (cyg_thread *) malloc (sizeof(cyg_thread));
   //sw_test_thread_stack = (char *) malloc (sizeof(char) * STACK_SIZE);
   //sw_test_thread_handle = (cyg_handle_t *) malloc(sizeof(cyg_handle_t));
   /*cyg_thread_create(PRIO,                       // scheduling info (eg pri)  
                      test_thread,               // entry point function   
                      0,                         // entry data                
                      "TEST",                    // optional thread name      
                      //sw_test_thread_stack,      // stack base          
                      sw_measurement_thread_4_stack,    // stack base          
                      STACK_SIZE,                // stack size,       
                      //sw_test_thread_handle,     // returned thread handle 
                      &sw_measurement_thread_4_handle,  // returned thread handle  
                      //sw_test_thread             // put thread here 
                      &sw_measurement_thread_4          // put thread here 
          
     );

    // resume thread
    cyg_thread_resume(sw_measurement_thread_4_handle);*/
    //cyg_thread_resume(*sw_test_thread_handle);
   /*cyg_thread_create(PRIO,                             // scheduling info (eg pri)  
                      test_thread,               // entry point function     
                      0,                                // entry data                
                      "READ_MEASUREMENTS_4",            // optional thread name      
                      sw_measurement_thread_4_stack,    // stack base                
                      STACK_SIZE,                       // stack size,       
                      &sw_measurement_thread_4_handle,  // returned thread handle    
                      &sw_measurement_thread_4          // put thread here           
     );

    // resume thread
    cyg_thread_resume(sw_measurement_thread_4_handle);*/

   //cyg_thread_delay(1000);
   //diag_printf( "Reconfigure!\n" );
   /*old_number_of_sortings = 0;
   start_sorting();
   set_sort8k_hw_dynamicB(2);
   set_sort8k_hw_dynamic(2);
   cyg_thread_delay(1000);*/

   start_particle_filter();

   printf("\nstart particle filter");
   return NULL;
  }
Exemplo n.º 30
0
int main(void)
{
	static struct ImageParams imageParams;
	
	// *** init display ******************************************************
	tft_init();
	tft_test_image();
	
	// *** init network interfaces *******************************************
	init_all_network_interfaces();
	if(!eth0_up){
		diag_printf("failed to initialize eth0\naborting\n");
		return 1;
	}
	else{
		diag_printf(" eth0 up\n");
	}
	
	diag_printf("\n\n");
	diag_printf("########################################\n");
	diag_printf("#        Netimage receiver Demo        #\n");
	diag_printf("########################################\n");
	diag_printf("\n\n");
	
	// *** tcp/ip connect ****************************************************
	diag_printf("waiting for connection...\n");
	int fd = accept_connection();
	if(fd < 0){
		diag_printf("connection failed\naborting\n");
		return 1;
	}
	diag_printf("connection established\n");
	
	if(!recv_header(fd, &imageParams)){
		diag_printf("failed reading image parameters (header)\n");
		return 1;
	}
	
	diag_printf("\n");
	diag_printf("Image stream header:  width = %d\n", imageParams.width);
	diag_printf("                     height = %d\n", imageParams.height);
	diag_printf("                        bpc = %d\n", imageParams.depth);
	diag_printf("                   channels = %d\n", imageParams.nChannels);
	
	while(1){
		// current pixel coordinates
		int x,y;
		// number of bytes between the end of a line in the framebuffer
		// and the beginning of the next line.
		int step = tft_info.rlen/4 - imageParams.width;
		// buffer for incomming pixel data
		uint8_t line[4096];
		// frame buffer pointer
		uint32_t * fb_pos = tft_info.fb;
		
		for(y = 0; y < imageParams.height; y++){
			// read a line into the buffer
			tcp_read(fd, line, imageParams.depth/8*imageParams.nChannels*imageParams.width);
			// current position
			uint8_t * p = line;
			
			for(x = 0; x < imageParams.width; x++){
				// write pixel to framebuffer
				*fb_pos = p[0] | (p[1] << 8) | (p[2] << 16);
				// next pixel
				p += 3;
				fb_pos++;
			}
			// next line
			fb_pos += step;
		}
	}
	
	return 0; // never
}