示例#1
0
文件: fapp_http.c 项目: ErikZalm/fnet
/************************************************************************
* NAME: fapp_http_cgi_stdata_handle
*
* DESCRIPTION:
*************************************************************************/
static int fapp_http_cgi_stdata_handle(char * query, long *cookie)
{
    unsigned long time, t_hour, t_min, t_sec;
	struct fnet_netif_statistics statistics;

    FNET_COMP_UNUSED_ARG(query);
    
	/* Get Time. */    
	time = fnet_timer_ticks();
	t_hour = time/FNET_TIMER_TICK_IN_HOUR;
	t_min  = (time%FNET_TIMER_TICK_IN_HOUR)/FNET_TIMER_TICK_IN_MIN;
	t_sec  = (time%FNET_TIMER_TICK_IN_MIN)/FNET_TIMER_TICK_IN_SEC;
	
	/* Get statistics. */
    fnet_memset_zero( &statistics, sizeof(struct fnet_netif_statistics) );
    fnet_netif_get_statistics(fapp_default_netif, &statistics);

	/* Write to the temprorary buffer. */
    fnet_snprintf(fapp_http_cgi_buffer, sizeof(fapp_http_cgi_buffer), "({\"time\":\"%02d:%02d:%02d\",\"tx\":%d,\"rx\":%d})", 
                             t_hour, t_min, t_sec, statistics.tx_packet, statistics.rx_packet);

    *cookie = (long)fapp_http_cgi_buffer; /* Save fapp_http_cgi_buffer as cookie.*/
                                 
    return FNET_OK;
}
示例#2
0
文件: fapp_fs.c 项目: rschuck/K64f
/************************************************************************
* NAME: fapp_fs_init
*
* DESCRIPTION: File Explorer initialization function.
************************************************************************/
static void fapp_fs_init( fnet_shell_desc_t desc )
{
    /* Format exp shell prompt */
    fnet_snprintf( FAPP_FS_PROMPT_STR, sizeof(FAPP_FS_PROMPT_STR), "%s%s%s",
                  &FAPP_FS_PROMPT_STR_HEADER[0],
                  &fapp_fs_current_path[0],
                  &FAPP_FS_PROMPT_STR_TRAILER[0]);
        
    fnet_shell_println(desc, "\n%s", FAPP_DELIMITER_STR);
    fnet_shell_println(desc, "  File Explorer started.");
    fnet_shell_println(desc, "  Enter 'help' for command list.");
    fnet_shell_println(desc, "%s\n", FAPP_DELIMITER_STR);
}
示例#3
0
/************************************************************************
* NAME: fnet_inet_ntop_ip4
*
* DESCRIPTION:The function converts IPv4 address 
*               to presentation format (string).
*************************************************************************/  
static char *fnet_inet_ntop_ip4 ( const fnet_ip4_addr_t *addr, char *str, unsigned long str_len)
{
	char                    tmp[FNET_IP4_ADDR_STR_SIZE];
	int                     length;
	const unsigned char     *ptr = (const unsigned char *) addr;

    length=fnet_snprintf(tmp, sizeof(tmp), "%d.%d.%d.%d", ptr[0], ptr[1], ptr[2], ptr[3]);
    
	if ((length <= 0) || (length >= str_len))
	{
		return (FNET_NULL);
	}
	else
	{
	    fnet_strncpy(str, tmp, (unsigned long)str_len);

	    return (str);
	}
}
示例#4
0
文件: fapp_http.c 项目: ErikZalm/fnet
/************************************************************************
* NAME: fapp_http_cgi_graph_handle
*
* DESCRIPTION:
*************************************************************************/
static int fapp_http_cgi_graph_handle(char * query, long *cookie)
{
    int q1= (int)fapp_http_cgi_rand();
    int q2= (int)fapp_http_cgi_rand();
    int q3= (int)fapp_http_cgi_rand();
    int q4= (int)fapp_http_cgi_rand();
    int q5= (int)fapp_http_cgi_rand();

    FNET_COMP_UNUSED_ARG(query);

	/* Wrie to the temprorary buffer. */
    fnet_snprintf(fapp_http_cgi_buffer, sizeof(fapp_http_cgi_buffer), 
                        "({\"q1\":%d,\"q2\":%d,\"q3\":%d,\"q4\":%d,\"q5\":%d})", 
                        q1, q2, q3, q4, q5);

    *cookie = (long)fapp_http_cgi_buffer; /* Save fapp_http_cgi_buffer as cookie.*/                        
    
    return FNET_OK;
}
示例#5
0
文件: fapp_http.c 项目: ErikZalm/fnet
static int fapp_http_ssi_echo_handle(char * query, long *cookie)
{
    int result = FNET_OK;
    const struct fapp_http_echo_variable *  echo_var_ptr;
    fnet_netif_desc_t netif = fapp_default_netif;
    
    const char *ssi_buffer_ptr = 0;
    
    /* Find static echo value. */
	for(echo_var_ptr = fapp_http_echo_variables; echo_var_ptr->variable && echo_var_ptr->value; echo_var_ptr++)
	{
        if (!fnet_strcmp( query, echo_var_ptr->variable))                    
        {				 
            ssi_buffer_ptr = echo_var_ptr->value;
            break;
        }
    }
   
    /* Find run-time echo values. */
    if(ssi_buffer_ptr == 0)
    {
    #if FNET_CFG_IP4
        char ip_str[FNET_IP4_ADDR_STR_SIZE];
    #endif

        ssi_buffer_ptr = fapp_http_ssi_buffer; 
        if (!fnet_strcmp( query, "IP_ADDRESS"))
        {
        #if FNET_CFG_IP4
            fnet_ip4_addr_t ip_adr = fnet_netif_get_ip4_addr(netif);
            fnet_inet_ntoa(*(struct in_addr *)( &ip_adr), ip_str);
            fnet_snprintf(fapp_http_ssi_buffer, sizeof(fapp_http_ssi_buffer), "%s", ip_str);
        #else
            fnet_snprintf(fapp_http_ssi_buffer, sizeof(fapp_http_ssi_buffer), "...");            
        #endif /* FNET_CFG_IP4 */
        }
        else if (!fnet_strcmp( query, "SUBNET_MASK"))
        {
        #if FNET_CFG_IP4
            fnet_ip4_addr_t ip_adr = fnet_netif_get_ip4_subnet_mask(netif);
            fnet_inet_ntoa(*(struct in_addr *)( &ip_adr), ip_str);
            fnet_snprintf(fapp_http_ssi_buffer, sizeof(fapp_http_ssi_buffer), "%s", ip_str);
        #else
            fnet_snprintf(fapp_http_ssi_buffer, sizeof(fapp_http_ssi_buffer), "...");            
        #endif /* FNET_CFG_IP4 */            
        }
        else if (!fnet_strcmp( query, "GATEWAY"))
        {
        #if FNET_CFG_IP4
            fnet_ip4_addr_t ip_adr = fnet_netif_get_ip4_gateway(netif);
            fnet_inet_ntoa(*(struct in_addr *)( &ip_adr), ip_str);
            fnet_snprintf(fapp_http_ssi_buffer, sizeof(fapp_http_ssi_buffer), "%s", ip_str);
        #else
            fnet_snprintf(fapp_http_ssi_buffer, sizeof(fapp_http_ssi_buffer), "...");            
        #endif /* FNET_CFG_IP4 */            
        }
        else if (!fnet_strcmp( query, "MAC"))
        {
            fnet_mac_addr_t macaddr;
            char mac_str[FNET_MAC_ADDR_STR_SIZE];
            fnet_netif_get_hw_addr(netif, macaddr, sizeof(fnet_mac_addr_t));
            fnet_mac_to_str(macaddr, mac_str);
            fnet_snprintf(fapp_http_ssi_buffer, sizeof(fapp_http_ssi_buffer), "%s", mac_str);
        }
        else
        {
            result = FNET_ERR;
        }
    }
    
    *cookie = (long)ssi_buffer_ptr; /* Save ssi_buffer_ptr as cookie.*/
    
    return result;
}