<commit_before>// dumper.h - A helper entity for dumping system info
//
// This is the declaration of a class performing
// information dumps emitted through the serial
// interface.
// The class can be configured to dump information
// at regular intervals or only on request.
// The class works only if #define DEBUG

// dependencies
#include "../core/entity.h"

// dependencies
#include "../core/entity.h"

namespace meisterwerk {
    namespace util {

        class dumper : public meisterwerk::core::entity {
            public:
#ifdef DEBUG
            String debugButton;
            int    iMinDumpSecs;
            int    iCount = 0;

            dumper( String name = "dmp", int _iMinDumpSecs = 0, String _debugButton = "dbg" )
                : meisterwerk::core::entity( name ) {
                debugButton  = _debugButton;
                iMinDumpSecs = _iMinDumpSecs;
            }
#else
            dumper( String name = "", int _iMinDumpSecs = 0, String _debugButton = "" )
                : meisterwerk::core::entity( "" ) {
            }

            bool registerEntity() {
                return true;
            }
#endif

#ifdef DEBUG
            bool registerEntity() {
                return meisterwerk::core::entity::registerEntity( 1000000 );
            }

            void onSetup() override {
                dumpSystemInfo();
                // explicit dump messages
                subscribe( "*/dump" );
                subscribe( "*/sysinfo" );
                subscribe( "*/taskinfo" );
                // Debug Button
                subscribe( debugButton + "/short" );
                subscribe( debugButton + "/long" );
                subscribe( debugButton + "/extralong" );
            }

            virtual void onLoop( unsigned long ticker ) override {
                if ( iMinDumpSecs ) {
                    if ( iCount < 1 ) {
                        dumpRuntimeInfo();
                        iCount = iMinDumpSecs;
                    } else {
                        --iCount;
                    }
                }
            }

            virtual void onReceiveMessage( String topic, const char *pBuf, unsigned int len ) {
                if ( topic == debugButton + "/short" ) {
                    dumpRuntimeInfo();
                } else if ( topic == debugButton + "/long" ) {
                    dumpSystemInfo();
                } else if ( topic == debugButton + "/extralong" ) {
                    dumpTaskInfo();
                }
            }

            void dumpSystemInfo() {
                String pre = "dumper(" + entName + ") ";
                DBG( "System Information:" );
                DBG( "-------------------" );
                DBG( pre + "Chip ID: " + ESP.getChipId() );
                DBG( pre + "Core Verion: " + ESP.getCoreVersion() );
                DBG( pre + "SDK Verion: " + ESP.getSdkVersion() );
                DBG( pre + "CPU Frequency: " + ESP.getCpuFreqMHz() + " MHz" );
                DBG( pre + "Program Size: " + ESP.getSketchSize() + " bytes" );
                DBG( pre + "Program Free: " + ESP.getFreeSketchSpace() + " bytes" );
                DBG( pre + "Flash Chip ID: " + ESP.getFlashChipId() );
                DBG( pre + "Flash Chip Size: " + ESP.getFlashChipSize() + " bytes" );
                DBG( pre + "Flash Chip Real Size: " + ESP.getFlashChipRealSize() + " bytes" );
                DBG( pre + "Flash Chip Speed: " + ESP.getFlashChipSpeed() + " hz" );
                DBG( pre + "Last Reset Reason: " + ESP.getResetReason() );
            }

            void dumpRuntimeInfo() {
                unsigned int qps = meisterwerk::core::message::que.peak();
                unsigned int qln = meisterwerk::core::message::que.length();
                String       pre = "dumper(" + entName + ") ";
                DBG( pre + "Free Heap: " + ESP.getFreeHeap() + " bytes, Queue(cur/max): " + qln +
                     "/" + qps );
            }

            void dumpTaskInfo() {
                String pre = "dumper(" + entName + ") ";
                DBG( "Task Information" );
                DBG( "----------------" );
                // XXX dump task statistics
            }
#endif
        };
    }
}<commit_msg>titel of crypt object fixed.<commit_after>// crypt.h - A helper for symmetric encrytpion
// based on XXTEA algorithm.

namespace meisterwerk {
    namespace util {

        class crypt {
            public:
            //==CRC-CCITT=================================================================
            //
            // - Source: Dr.Dobb's, <NAME>, June 17, 2007,
            //   http://www.drdobbs.com/implementing-the-ccitt-cyclical-redundan/199904926
            //
            //****************************************************************************
            //
            // crc16.c - generate a ccitt 16 bit cyclic redundancy check (crc)
            //
            //      The code in this module generates the crc for a block of data.
            //
            // crc16() - generate a 16 bit crc
            //
            //
            // PURPOSE
            //      This routine generates the 16 bit remainder of a block of
            //      data using the ccitt polynomial generator.
            //
            // CALLING SEQUENCE
            //      crc = crc16(data, len);
            //
            // PARAMETERS
            //      data    <-- address of start of data block
            //      len     <-- length of data block
            //
            // RETURNED VALUE
            //      crc16 value. data is calcuated using the 16 bit ccitt polynomial.
            //
            // NOTES
            //      The CRC is preset to all 1's to detect errors involving a loss
            //        of leading zero's.
            //      The CRC (a 16 bit value) is generated in LSB MSB order.
            //      Two ways to verify the integrity of a received message
            //        or block of data:
            //        1) Calculate the crc on the data, and compare it to the crc
            //           calculated previously. The location of the saved crc must be
            //           known.
            //         2) Append the calculated crc to the end of the data. Now calculate
            //           the crc of the data and its crc. If the new crc equals the
            //           value in "CRC_OK", the data is valid.
            //
            // PSEUDO CODE:
            //      initialize crc (-1)
            //      DO WHILE count NE zero
            //        DO FOR each bit in the data byte, from LSB to MSB
            //          IF (LSB of crc) EOR (LSB of data)
            //            crc := (crc / 2) EOR polynomial
            //          ELSE
            //            crc := (crc / 2)
            //          FI
            //        OD
            //      OD
            //      1's compliment and swap bytes in crc
            //      RETURN crc
            //
            //*************************************************************************
            uint16_t crc16( uint8_t *data_p, uint16_t length ) {
                uint8_t  i;
                uint16_t data;
                uint16_t crc;

                crc = 0xffff;

                if ( length == 0 )
                    return ( ~crc );

                do {
                    for ( i = 0, data = (unsigned int)0xff & *data_p++; i < 8; i++, data >>= 1 ) {
                        if ( ( crc & 0x0001 ) ^ ( data & 0x0001 ) )
                            crc = ( crc >> 1 ) ^ POLY;
                        else
                            crc >>= 1;
                    }
                } while ( --length );

                crc = ~crc;

                data = crc;
                crc  = ( crc << 8 ) | ( data >> 8 & 0xFF );

                return ( crc );
            }

            //==CRYPT-XXTEA==================================================================
            //
            //  - Source: http://en.wikipedia.org/wiki/XXTEA
            //

            #define DELTA 0x9e3779b9
            #define MX ( ( ( z >> 5 ^ y << 2 ) + ( y >> 3 ^ z << 4 ) ) ^ ( ( sum ^ y ) + ( key[( p & 3 ) ^ e] ^ z ) ) )

            //-------------------------------------------------------------------------------
            // According to Needham and Wheeler:
            //
            // BTEA will encode or decode n words as a single block where n > 1
            //
            // * v is the n word data vector
            // * k is the 4 word key
            // * assumes 32 bit 'long' and same endian coding and decoding
            //

            void xxtea_encrypt( uint32_t *v, int n, uint32_t const key[4] ) {
                uint32_t y, z, sum;
                uint16_t p, rounds, e;

                if ( n < 1 )
                    return;

                rounds = 6 + 52 / n;
                sum    = 0;
                z      = v[n - 1];
                do {
                    sum += DELTA;
                    e = ( sum >> 2 ) & 3;
                    for ( p = 0; p < n - 1; p++ ) {
                        y = v[p + 1];
                        z = v[p] += MX;
                    }
                    y = v[0];
                    z = v[n - 1] += MX;
                } while ( --rounds );
            }

            void xxtea_decrypt( uint32_t *v, int n, uint32_t const key[4] ) {
                uint32_t y, z, sum;
                uint16_t p, rounds, e;

                if ( n < 1 )
                    return;

                rounds = 6 + 52 / n;
                sum    = rounds * DELTA;
                y      = v[0];
                do {
                    e = ( sum >> 2 ) & 3;
                    for ( p = n - 1; p > 0; p-- ) {
                        z = v[p - 1];
                        y = v[p] -= MX;
                    }
                    z = v[n - 1];
                    y = v[0] -= MX;
                    sum -= DELTA;
                } while ( --rounds );
            }
        };
    } // namespace util
} // namespace meisterwerk
{'fraction_non_alphanumeric': 0.14348084937487596, 'fraction_numerical': 0.01418932327842826, 'mean_word_length': 0.9986119373388855, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1298012', 'n_tokens_mistral': 2853, 'n_tokens_neox': 2531, 'n_words': 795}