⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 monitor.c

📁 嵌入式操作系统ECOS的网络开发包
💻 C
📖 第 1 页 / 共 4 页
字号:
    }

    /* Now generate a page showing the current thread state, and
     * including form controls to change it.
     */
    
    html_begin(client);

    html_head(client,"eCos Thread Editor", "");

    html_body_begin(client,"");
    {
        cyg_uint16 id;
        cyg_thread_info info;
        cyg_handle_t thread = 0;
        char idbuf[16];
        
        sscanf( filename, "/monitor/thread-%04hx.html", &id );

        thread = cyg_thread_find( id );
        cyg_thread_get_info(thread, id, &info );
        
        html_heading(client, 2, "Thread State Editor" );

        html_para_begin( client, "" );
        
        fprintf( client, "Editing Thread %04x %s\n",id,
                 info.name?info.name:NULL_THREAD_NAME);

        fputs( thread_edit_blurb, client );
        
        html_form_begin( client, filename, "" );        
        {
            html_table_begin( client, "border" );
            {
                html_table_header( client, "Property", "" );
                html_table_header( client, "Value", "" );

                html_table_row_begin(client, "" );
                {
                    html_table_data_begin( client, "" );
                    fputs( "State", client );

                    html_table_data_begin( client, "" );

                    html_form_input_radio( client, "state", "run", (info.state&0x04)==0 );
                    fputs( "Run", client );
                    html_form_input_radio( client, "state", "suspend", (info.state&0x04)!=0 );
                    fputs( "Suspend", client );
                    html_form_input_radio( client, "state", "release", 0 );
                    fputs( "Release", client );
                }
                html_table_row_end( client );

                html_table_row_begin(client, "" );
                {
                    html_table_data_begin( client, "" );
                    fputs( "Priority", client );

                    html_table_data_begin( client, "" );
                    fprintf(client,"<input type=\"text\" name=\"pri\" size=\"10\" value=\"%d\">\n",
                            info.set_pri);                    
                }
                html_table_row_end( client );

            }
            html_table_end( client );

            /* Add submit and reset buttons */
            html_form_input(client, "submit", "submit", "Submit", "");                
            html_form_input(client, "reset", "reset", "Reset", "");

            /* Pass the thread ID through to our next incarnation */
            sprintf( idbuf, "%04x", id );
            html_form_input_hidden(client, "thread", idbuf );            

        }
        html_form_end( client );
        
        draw_navbar(client);
    }
    html_body_end(client);

    html_end(client);
    
    return 1;
}

CYG_HTTPD_TABLE_ENTRY( cyg_monitor_thread_edit_entry,
                       "/monitor/thread-*",
                       cyg_monitor_thread_edit,
                       NULL );

/* ================================================================= */
/* Interrupt monitor
 *
 * At present this just generates a table showing which interrupts
 * have an ISR attached.
 */

static cyg_bool cyg_monitor_interrupts( FILE * client, char *filename,
                                        char *formdata, void *arg )
{
    html_begin(client);

    html_head(client,"eCos Interrupt Monitor", "");

    html_body_begin(client,"");
    {
        html_heading(client, 2, "Interrupt Monitor" );

        html_table_begin( client, "border" );
        {
            int i;
            int maxint = CYGNUM_HAL_ISR_MAX;

#ifdef CYGPKG_HAL_I386
            maxint = CYGNUM_HAL_ISR_MIN+16;
#endif
            
            html_table_header( client, "ISR", "" );
            html_table_header( client, "State", "" );
            
            for( i = CYGNUM_HAL_ISR_MIN; i <= maxint ; i++ )
            {
                cyg_bool_t inuse;
                HAL_INTERRUPT_IN_USE( i, inuse );

                html_table_row_begin(client, "" );
                {
                    html_table_data_begin( client, "" );
                    fprintf( client, "%d", i);
                    html_table_data_begin( client, "" );
                    fprintf( client, "%s", inuse?"In Use":"Free");
                }
                html_table_row_end( client );
            }
        }
        html_table_end( client );

        draw_navbar(client);
    }
    html_body_end(client);

    html_end(client);
    
    return 1;
    
}

CYG_HTTPD_TABLE_ENTRY( cyg_monitor_interrupts_entry,
                       "/monitor/interrupts.htm*",
                       cyg_monitor_interrupts,
                       NULL );

/* ================================================================= */
/* Memory monitor
 *
 * Generates a table showing a 256 byte page of memory. Form controls
 * allow changes to the base address and display element size.
 */

static cyg_bool cyg_monitor_memory( FILE * client, char *filename,
                                    char *formdata, void *arg )
{
    char *formlist[10];
    cyg_uint32 base = 0;
    unsigned int datasize = 1;
    int size = 256;
    char *p;
    
    cyg_formdata_parse( formdata, formlist, 10 );

    p = cyg_formlist_find( formlist, "base" );

    if( p != NULL )
        sscanf( p, "%x", &base );

    p = cyg_formlist_find( formlist, "datasize" );

    if( p != NULL )
        sscanf( p, "%x", &datasize );

    if( cyg_formlist_find( formlist, "next" ) != NULL )
        base += size;

    if( cyg_formlist_find( formlist, "prev" ) != NULL )
        base -= size;
        
    html_begin(client);

    html_head(client,"eCos Memory Monitor", "");

    html_body_begin(client,"");
    {
        html_heading(client, 2, "Memory Monitor" );

        html_form_begin( client, "/monitor/memory.html", "" );
        {

            /* Text input control for base address
             */
            html_para_begin( client, "" );
            fprintf(client,
                    "Base Address: 0x<input type=\"text\" name=\"base\" size=\"10\" value=\"%x\">\n",
                    base);

            /* A little menu for the element size
             */
            html_para_begin( client, "" );

            fputs( "Element Size: ", client );
            html_form_select_begin( client, "datasize", "" );
            html_form_option( client, "1", "bytes", datasize==1 );
            html_form_option( client, "2", "words", datasize==2 );
            html_form_option( client, "4", "dwords", datasize==4 );
            html_form_select_end( client );
                        
            html_para_begin( client, "" );

            /* Submit and reset buttons
             */
            html_form_input(client, "submit", "submit", "Submit", "");                
            html_form_input(client, "reset", "reset", "Reset", "");

            html_para_begin( client, "" );

            /* Previous page button */
            html_form_input(client, "submit", "prev", "Prev Page", "");

            /* Switch to monospaced font */
            cyg_html_tag_begin( client, "font", "face=\"monospace\"" );
            
            html_table_begin( client, "" );
            {
                cyg_addrword_t loc;
                cyg_addrword_t oloc;
                
                for( oloc = loc = base; loc <= (base+size) ; loc++ )
                {
                    if( ( loc % 16 ) == 0 )
                    {
                        if( loc != base )
                        {
                            html_table_data_begin( client, "" );
                            for( ; oloc < loc; oloc++ )
                            {
                                char c = *(char *)oloc;
                                if( !isprint(c) )
                                    c = '.';
                                putc( c, client );
                            }
                            html_table_row_end( client );
                        }
                        if( loc == (base+size) )
                            break;
                        html_table_row_begin(client, "" );
                        html_table_data_begin( client, "" );
                        fprintf( client, "%08x:",loc);
                    }

                    html_table_data_begin( client, "" );

                    if( (loc % datasize) == 0 )
                    {
                        switch( datasize )
                        {
                        case 1: fprintf( client, "%02x", *(cyg_uint8  *)loc ); break;
                        case 2: fprintf( client, "%04x", *(cyg_uint16 *)loc ); break;
                        case 4: fprintf( client, "%08x", *(cyg_uint32 *)loc ); break;
                        }
                    }
                }
            }
            html_table_end( client );
            cyg_html_tag_end( client, "font" );
            
            html_form_input(client, "submit", "next", "Next Page", "");            
        }
        html_form_end( client );

        draw_navbar(client);
    }
    html_body_end(client);

    html_end(client);
    
    return 1;
    
}

CYG_HTTPD_TABLE_ENTRY( cyg_monitor_memory_entry,
                       "/monitor/memory.htm*",
                       cyg_monitor_memory,
                       NULL );

/* ================================================================= */
/* Network Monitor
 *
 * This function generates a page containing information about the
 * network interfaces and the protocols.
 */

static cyg_bool cyg_monitor_network( FILE * client, char *filename,
                                     char *formdata, void *arg )
{
    struct ifconf ifconf;
    char conf[256];
    int err;
    int sock;

    /* Start by opening a socket and getting a list of all the
     * interfaces present.
     */
    {
        memset( conf, 0, sizeof(conf) );
    
        sock = socket( AF_INET, SOCK_DGRAM, 0 );
    
        ifconf.ifc_len = sizeof(conf);
        ifconf.ifc_buf = (caddr_t)conf;

        err = ioctl( sock, SIOCGIFCONF, &ifconf );
    }
    
    html_begin(client);

    html_head(client,"eCos Network Monitor", "");

    html_body_begin(client,"");
    {
        html_heading(client, 2, "Network Monitor" );

        html_heading(client, 3, "Interfaces" );        

        html_table_begin( client, "border" );
        {
            int i;
            struct ifreq *ifrp;
            struct sockaddr *sa;
            
            html_table_header( client, "Interface", "" );
            html_table_header( client, "Status", "" );

            ifrp = ifconf.ifc_req;
            
            while( ifconf.ifc_len && ifrp->ifr_name[0] )
            {
                struct ifreq ifreq = *ifrp;

                /* For some reason we get two entries for each
                 * interface in the list: one with an AF_INET address
                 * and one with an AF_LINK address. We are currently
                 * only interested in the AF_INET ones.
                 */
                
                if( ifrp->ifr_addr.sa_family == AF_INET )
                {
                
                    html_table_row_begin(client, "" );
                    {
                        html_table_data_begin( client, "" );
                        fprintf( client, "%s", ifrp->ifr_name);

                        html_table_data_begin( client, "" );                        
                        html_table_begin( client, "" );
                        {
                            struct ether_drv_stats ethstats;

                            /* Get the interface's flags and display
                             * the interesting ones.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -