コード例 #1
0
ファイル: main.cpp プロジェクト: vpcola/NucleoCC3K
static void cmd_ping(BaseSequentialStream *chp, int argc, char *argv[])
{
    uint32_t remoteHostIp;
    (void)argv;
    if (argc != 1)
    {
        chprintf(chp, "Usage:\r\n");
        chprintf(chp, "ping <hostname>\r\n");
        return;
    }


    chprintf(chp,"Looking up IP of %s...\r\n", argv[0]);
    gethostbyname(argv[0], strlen(argv[0]), &remoteHostIp);
    chprintf(chp,"Pinging...", NULL); print_ip(chp, (const char *) &remoteHostIp);
    remoteHostIp = htonl(remoteHostIp);

    memset((void *)&cc3000AsyncData.ping, 0, sizeof(cc3000AsyncData.ping));
    netapp_ping_send(&remoteHostIp, 3, 10, 3000);

    while (cc3000AsyncData.ping.present != TRUE)
    {
        chThdSleep(MS2ST(100));
    }
    chprintf(chp,"--Ping Results--:\r\n", NULL);
    chprintf(chp,"Number of Packets Sent: %u\r\n", cc3000AsyncData.ping.report.packets_sent);
    chprintf(chp,"Number of Packet Received: %u\r\n", cc3000AsyncData.ping.report.packets_received);
    chprintf(chp,"Min Round Time: %u\r\n", cc3000AsyncData.ping.report.min_round_time);
    chprintf(chp,"Max Round Time: %u\r\n", cc3000AsyncData.ping.report.max_round_time);
    chprintf(chp,"Avg Round Time: %u\r\n", cc3000AsyncData.ping.report.avg_round_time);
    chprintf(chp,"--End of Ping Results--\r\n", NULL);

}
コード例 #2
0
/**
 * @brief Pings IP address [attempts] times and returns a ping report
 *
 * @param[in] ip_address the IP address to ping
 * @param[out] ping_report returned ping report with statistics
 * @param[in] attempts optional number of times to ping the address
 * @param[in] size optional size of ping buffer (up to 1400 bytes)
 * @param[in] timeout optional time to wait for ping response (milliseconds)
 * @return True if ping command succeeded. False otherwise.
 */
bool SFE_CC3000::ping(  IPAddress ip_address, 
                        PingReport &ping_report,
                        unsigned int attempts, 
                        unsigned int size, 
                        unsigned int timeout)
{
    
    unsigned long ip_addr;
    
    /* If CC3000 is not initialized, return false. */
	if (!getInitStatus()) {
        return false;
    }
    
    /* If not connected, return false. */
    if (!getConnectionStatus()) {
        return false;
    }
    
    /* If DHCP has not been assigned, return false. */
    if (!getDHCPStatus()) {
        return false;
    }
    
    /* Create unsigned long IP address out of char array */
    ip_addr = (unsigned long)ip_address[0] | 
                ((unsigned long)ip_address[1] << 8) |
                ((unsigned long)ip_address[2] << 16) |
                ((unsigned long)ip_address[3] << 24);
                
    /* Send pings and wait for report */
    if (netapp_ping_send(&ip_addr, attempts, size, timeout) != CC3000_SUCCESS) {
        return false;
    }
    delay((timeout * attempts) * 2);
    
    /* Copy output of ping report to return sruct */
    memcpy(&ping_report, &g_ping_report, sizeof(PingReport));
    
    return true;
}