/*!
 * \brief Update the age of all ARP entries of all Ethernet devices.
 *
 * Increments the age of all ARP entries. Any entry with an age above
 * \ref MAX_ARPAGE will be removed.
 *
 * If less less than one minute elapsed since the last update, the
 * routine will return without updating any entry.
 */
static void ArpCacheAging(void)
{
    static u_long last_update;
    NUTDEVICE *dev;

    if (NutGetSeconds() - last_update >= 60) {
        last_update = NutGetSeconds();

        /*
         * Loop through the list of all registered devices.
         */
        for (dev = nutDeviceList; dev; dev = dev->dev_next) {

            /* Process network devices only. */
            if (dev->dev_type == IFTYP_NET) {
                IFNET *ifn = dev->dev_icb;

                /* Process Ethernet interfaces only. */
                if (ifn && ifn->if_type == IFT_ETHER) {
                    ARPENTRY *ae;
                    u_char rmf = 0;

                    /* Loop through all ARP entries of this interface. */
                    for (ae = ifn->arpTable; ae; ae = ae->ae_next) {
                        if ((ae->ae_flags & ATF_PERM) == 0 &&   /* Not permanent. */
                            ae->ae_outdated++ >= MAX_ARPAGE) {  /* Outdated. */
                            ae->ae_flags |= ATF_REM;
                        }
                        rmf |= ae->ae_flags;
#ifdef NUTDEBUG
                        if (__tcp_trf) {
                            fprintf(__tcp_trs, "[ARP-AGE %s %u]",       /* */
                                    inet_ntoa(ae->ae_ip), ae->ae_outdated);
                        }
#endif
                    }
                    if (rmf & ATF_REM) {
                        ArpCacheFlush(ifn);
                    }
                }
            }
        }
    }
}
Esempio n. 2
0
/*
 * Display system up time.
 *
 * The value is constantly updated until the user presses a key.
 */
static void DisplayUpTime(void)
{
    uint32_t hours;
    uint32_t minutes;
    uint32_t seconds;
    uint_fast8_t i = 0;

    while (!kbhit()) {
        seconds = NutGetSeconds();
        minutes = seconds / 60UL;
        hours = minutes / 60UL;
        minutes %= 60UL;
        seconds %= 60UL;
        printf(" [%c] System is running %lu hours"
               ", %lu minutes and %lu seconds   \r"
               , rotor[++i & 3], hours, minutes, seconds);
        NutSleep(500);
    }
    putchar('\n');
}
Esempio n. 3
0
    /*
 * \brief Play MP3 stream.
 *
 * \param stream Socket stream to read MP3 data from.
 */
    void PlayMp3Stream(FILE *stream, u_long metaint) {
        size_t rbytes;
        u_char *mp3buf;
        u_char ief;
        int got = 0;
        u_long last;
        u_long mp3left = metaint;

        /*
         * Initialize the MP3 buffer. The NutSegBuf routines provide a global
         * system buffer, which works with banked and non-banked systems.
         */
        if (NutSegBufInit(8192) == 0) {
            puts("Error: MP3 buffer init failed");
            return;
        }

        /*
         * Initialize the MP3 decoder hardware.
         */
        if (VsPlayerInit() || VsPlayerReset(0)) {
            puts("Error: MP3 hardware init failed");
            return;
        }
        VsSetVolume(0, 0);

        /*
         * Reset the MP3 buffer.
         */
        ief = VsPlayerInterrupts(0);
        NutSegBufReset();
        VsPlayerInterrupts(ief);
        last = NutGetSeconds();

        for (; ;) {

            if(STOP_THREAD){
                STOP_THREAD = 0;
                return;
            }

            /*
             * Query number of byte available in MP3 buffer.
             */
            ief = VsPlayerInterrupts(0);
            mp3buf = NutSegBufWriteRequest(&rbytes);
            VsPlayerInterrupts(ief);

            /*
             * If the player is not running, kick it.
             */
            if (VsGetStatus() != VS_STATUS_RUNNING) {
                if (rbytes < 1024 || NutGetSeconds() - last > 4UL) {
                    last = NutGetSeconds();
                    puts("Kick player");
                    VsPlayerKick();
                }
            }

            /*
             * Do not read pass metadata.
             */
            if (metaint && rbytes > mp3left) {
                rbytes = mp3left;
            }

            /*
             * Read data directly into the MP3 buffer.
             */
            while (rbytes) {
                if ((got = fread(mp3buf, 1, rbytes, stream)) > 0) {
                    ief = VsPlayerInterrupts(0);
                    mp3buf = NutSegBufWriteCommit(got);
                    VsPlayerInterrupts(ief);

                    if (metaint) {
                        mp3left -= got;
                        if (mp3left == 0) {
                            ProcessMetaData(stream);
                            mp3left = metaint;
                        }
                    }

                    if (got < rbytes && got < 512) {
                        printf("%lu buffered\n", NutSegBufUsed());
                        NutSleep(250);
                    }
                    else {
                        NutThreadYield();
                    }
                } else {
                    break;
                }
                rbytes -= got;
            }

            if (got <= 0) {
                break;
            }

            NutSleep(100);
        }
    }
static int CgiStatusRow( FILE * stream, int row_no )
{
    time_t secs = time(NULL);

    switch( row_no )
    {

    case -1:
        //HTML("<TR><TH> Type </TH><TH> Value </TH><TH> Comment </TH></TR>\r\n");    break;
        //HTML("<TR><TH align=left> &nbsp; </TH><TH align=left> &nbsp; </TH></TR>\r\n");    break;
        //HTML("<th colspan=\"2\" align=left>Time</th>"); break;
        subhdr( stream, "Time" ); break;

    case 0:
        {
            HTML("<TR><TD>&nbsp;GMT Time </TD><TD>&nbsp;");
            printTime( stream, gmtime(&secs) );
            HTML(" </TD></TR>\r\n");

            //ShowTableRow3( stream, char *c1, char *c2, char *c3 );

        }
        break;

    case 1:
        {
            HTML("<TR><TD>&nbsp;Local Time </TD><TD>&nbsp;");
            printTime( stream, localtime(&secs) );
            HTML(" </TD></TR>\r\n");
        }
        break;

    case 2:
        {
            char minus = _timezone < 0;
            int32_t seconds = labs(_timezone);
            int32_t minutes = seconds / 60UL;
            int32_t hours = minutes / 60UL;
            minutes %= 60UL;
            seconds %= 60UL;
            HTML("<TR><TD>&nbsp;TimeZone </TD><TD>&nbsp;");
            fprintf(stream, "%s%ld:%ld:%ld (%ld)", (minus ? "-" : ""), hours, minutes, seconds, _timezone );
            HTML(" </TD></TR>\r\n");
        }
        break;


    case 3:
        {
            uint32_t seconds = NutGetSeconds();
            uint32_t minutes = seconds / 60UL;
            uint32_t hours = minutes / 60UL;
            uint32_t days = hours / 24UL;
            minutes %= 60UL;
            seconds %= 60UL;
            hours %= 24UL;

            HTML("<TR><TD>&nbsp;UpTime </TD><TD>&nbsp;");
            fprintf(stream, "%lu days  %lu:%lu:%lu", days, hours, minutes, seconds);
            HTML(" </TD></TR>\r\n");
        }
        break;

    //case 4: ShowTableRow2b( stream, "DST", _daylight  );			break;
    case 4: ShowTableRow2b( stream, "Used SNTP", sntp_available );		break;

    //case 6: HTML("<th colspan=\"2\">FirmWare</th>"); break;
    case 5: subhdr( stream, "FirmWare" ); break;

    case 6: ShowTableRow2( stream, "Build", makeDate );                		break;
    case 7: ShowTableRow2( stream, "Name", DEVICE_NAME );                	break;
    case 8: ShowTableRow2( stream, "ModBus Id", modbus_device_id );		break;

    //case 9: HTML("<th colspan=\"2\">ModBus</th>"); break;
    case 9: subhdr( stream, "ModBus" ); break;

    case 10: ShowTableRow2i( stream, "IO count", modbus_event_cnt );		break;
    case 11: ShowTableRow2i( stream, "CRC count", modbus_crc_cnt );		break;
    case 12: ShowTableRow2i( stream, "exceptions count", modbus_exceptions_cnt );break;
    case 13: ShowTableRow2i( stream, "err flags", modbus_error_flags );		break;

    case 14: subhdr( stream, "1-Wire" ); break;

    case 15: ShowTableRow2b( stream, "Devices detected", onewire_available );	break;
    case 16: ShowTableRow2i( stream, "Temp sensors count", nTempSensors );	break;
    case 17:
#if SERVANT_1WMAC
        {
            HTML("<TR><TD>&nbsp;2401 Id </TD><TD>&nbsp;");
            fprintf(stream, "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
                    serialNumber [7], serialNumber [6], serialNumber [5], serialNumber [4],
                    serialNumber [3], serialNumber [2], serialNumber [1], serialNumber [0]
                   );
            HTML(" </TD></TR>\r\n");
        }
#endif
        break;

    case 18: subhdr( stream, "OS" ); break;
    case 19: ShowTableRow2i( stream, "Free mem, K", NutHeapAvailable()/1024 );	break;
    case 20: ShowTableRow2i( stream, "Size of EEPROM cfg", sizeof(struct eeprom_cfg) );	break;
        
    case 21:
        {
            uint32_t tx_total, rx_total;
            uint8_t active;
#if SERVANT_TUN0 || SERVANT_TUN1
            subhdr( stream, "Tunnels" );
#if SERVANT_TUN0
            get_tunnel_stats( 0, &tx_total, &rx_total, &active );
            ShowTableRow2b( stream, "Tun0 active", active );
            ShowTableRow2i( stream, "Tun0 RX, K", rx_total/1024 );
            ShowTableRow2i( stream, "Tun0 TX, K", tx_total/1024 );
#endif
#if SERVANT_TUN1
            get_tunnel_stats( 1, &tx_total, &rx_total, &active );
            ShowTableRow2b( stream, "Tun1 active", active );
            ShowTableRow2i( stream, "Tun1 RX, K", rx_total/1024 );
            ShowTableRow2i( stream, "Tun1 TX, K", tx_total/1024 );
#endif
#endif
            break;
        }

    case 22: subhdr( stream, "DHT11" ); break;
    case 23: ShowTableRow2i( stream, "Errors count", dht11_errorCnt );	break;
        

    default:
        return 0;
    }

    return 1;
}