Exemplo n.º 1
0
amString createTCPAddress
(
    const amString &ipAddress,
    int             portNo
)
{
    amString result( "tcp://" );
    result += ipAddress;
    result += ":";
    result += amString( portNo );

    return result;
}
Exemplo n.º 2
0
//-------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------//
//
// SPB7: Speed only Sensor
//
//-------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------//
amDeviceType antSpeedOnlyProcessing::processBikeSpeedSensor
(
    const amString &deviceIDNo,
    const amString &timeStampBuffer,
    BYTE            payLoad[]
)
{
    char         auxBuffer[ C_MEDIUM_BUFFER_SIZE ] = { 0 };
    unsigned int dataPage                          = 0;
    unsigned int bikeSpeedEventTime                = 0;
    unsigned int deltaBikeSpeedEventTime           = 0;
    unsigned int wheelRevolutionCount              = 0;
    unsigned int deltaWheelRevolutionCount         = 0;
    unsigned int additionalData1                   = 0;
    unsigned int additionalData2                   = 0;
    unsigned int additionalData3                   = 0;
    unsigned int rollOver                          = 0;
    bool         rollOverHappened                  = false;
    bool         commonPage                        = false;
    bool         outputPageNo                      = true;
    amDeviceType result                            = OTHER_DEVICE;
    amString     sensorID                          = amString( C_SPEED_DEVICE_HEAD ) + deviceIDNo;

    if ( isRegisteredDevice( sensorID ) )
    {
        if ( ( eventTimeTable.count    ( sensorID ) == 0 ) ||
             ( eventCountTable.count   ( sensorID ) == 0 ) ||
             ( operatingTimeTable.count( sensorID ) == 0 ) )
        {
            eventTimeTable.insert    ( std::pair<amString, unsigned int>( sensorID, 0 ) );
            eventCountTable.insert   ( std::pair<amString, unsigned int>( sensorID, 0 ) );
            operatingTimeTable.insert( std::pair<amString, unsigned int>( sensorID, 0 ) );
            setSpeed( sensorID, 0 );
        }

        dataPage = byte2UInt( payLoad[ 0 ] );
        if ( diagnostics )
        {
            appendDiagnosticsLine( "Data Page", payLoad[ 0 ], dataPage );
        }

        bikeSpeedEventTime      = byte2UInt( payLoad[ 5 ], payLoad[ 4 ] );
        rollOver                = 65536;  // 256^2
        deltaBikeSpeedEventTime = getDeltaInt( rollOverHappened, sensorID, rollOver, eventTimeTable, bikeSpeedEventTime );
        if ( diagnostics )
        {
            appendDiagnosticsLine( "Bike Speed Event Time", payLoad[ 5 ], payLoad[ 4 ], bikeSpeedEventTime );
            *auxBuffer = 0;
            if ( rollOverHappened )
            {
                sprintf( auxBuffer, " (Rollover [%d] occurred)", rollOver );
            }
            appendDiagnosticsLine( "Delta Bike Speed Event Time", deltaBikeSpeedEventTime, auxBuffer );
        }

        wheelRevolutionCount      = byte2UInt( payLoad[ 7 ], payLoad[ 6 ] );
        rollOver                  = 65536;  // 256^2
        deltaWheelRevolutionCount = getDeltaInt( rollOverHappened, sensorID, rollOver, eventCountTable, wheelRevolutionCount );
        if ( diagnostics )
        {
            appendDiagnosticsLine( "Cumulative Wheel Revolution Count", payLoad[ 7 ], payLoad[ 6 ], wheelRevolutionCount );
            *auxBuffer = 0;
            if ( rollOverHappened )
            {
                sprintf( auxBuffer, " (Rollover [%d] occurred)", rollOver );
            }
            appendDiagnosticsLine( "Delta Cumulative Wheel Revolution Count", deltaWheelRevolutionCount, auxBuffer );
        }

        switch ( dataPage & 0x0F )
        {
            case  0: // - - Page 0: No Additional Data - - - - - - - - - - - - - - -
                     result = SPEED_SENSOR;
                     break;

            case  1: // - - Page 1: Operating Time - - - - - - - - - - - - - - - - -
                     result          = SPEED_SENSOR;
                     additionalData2 = byte2UInt( payLoad[ 3 ], payLoad[ 2 ], payLoad[ 1 ] ); // Operating Time
                     rollOver        = 16777216;  // 256^3
                     additionalData1 = getDeltaInt( rollOverHappened, sensorID, rollOver, operatingTimeTable, additionalData2 );
                                   // deltaOperatingTime
                     if ( diagnostics )
                     {
                         double cumOperatingTimeH = ( double ) additionalData2 / 3600.0;
                         sprintf( auxBuffer, " (%2.2lfh)", cumOperatingTimeH );
                         appendDiagnosticsLine( "Cumulative Operating Time", payLoad[ 3 ], payLoad[ 2 ], payLoad[ 1 ], additionalData2, auxBuffer );
                         *auxBuffer = 0;
                         if ( rollOverHappened )
                         {
                             sprintf( auxBuffer, " (Rollover [%d] occurred)", rollOver );
                         }
                         appendDiagnosticsLine( "Delta Cumulative Operating Time", additionalData1, auxBuffer );
                     }
                     break;

            case  2: // - - Page 2: Manufacturer Information - - - - - - - - - - - -
                     result          = SPEED_SENSOR;
                     additionalData1 = byte2UInt( payLoad[ 1 ] );                // Manufacturer ID
                     additionalData2 = byte2UInt( payLoad[ 3 ], payLoad[ 2 ] );  // Serial Number
                     if ( diagnostics )
                     {
                         appendDiagnosticsLine( "Manufacturer ID", payLoad[ 1 ], additionalData1 );
                         appendDiagnosticsLine( "Serial Number", payLoad[ 3 ], payLoad[ 2 ], additionalData2 );
                     }
                     break;

            case  3: // - - Page 3: Product Information  - - - - - - - - - - - - - -
                     result          = SPEED_SENSOR;
                     additionalData1 = byte2UInt( payLoad[ 1 ] );   // H/W Version
                     additionalData2 = byte2UInt( payLoad[ 2 ] );   // S/W Version
                     additionalData3 = byte2UInt( payLoad[ 3 ] );   // Model Number
                     if ( diagnostics )
                     {
                         appendDiagnosticsLine( "Hardware Version", payLoad[ 1 ], additionalData1 );
                         appendDiagnosticsLine( "Software Version", payLoad[ 2 ], additionalData2 );
                         appendDiagnosticsLine( "Model Number", payLoad[ 3 ], additionalData3 );
                     }
                     break;

            default: commonPage = true;
                     result = SPEED_SENSOR;
                     break;
        }
    }

    if ( result == SPEED_SENSOR )
    {
        createOutputHeader( sensorID, timeStampBuffer );
        if ( commonPage )
        {
            commonPage = processCommonPages( sensorID, payLoad, outputPageNo );
            if ( !commonPage )
            {
                result = OTHER_DEVICE;
            }
        }
        else
        {
            unsigned int nbMagnets          = ( unsigned int) round( getNbMagnets( sensorID ) );
            unsigned int zeroTime           = getZeroTimeCount( sensorID );
            double       wheelCircumference = getWheelCircumference( sensorID );
            double       speed              = getSpeed( sensorID );
            createSPB7ResultString
            (
                speed,
                dataPage,
                deltaBikeSpeedEventTime,
                deltaWheelRevolutionCount,
                additionalData1,
                additionalData2,
                additionalData3,
                wheelCircumference,
                nbMagnets,
                zeroTime
            );
            setZeroTimeCount( sensorID, zeroTime );
            setSpeed( sensorID, speed );
        }
        appendOutputFooter( getVersion() );
    }

    if ( result == OTHER_DEVICE )
    {
        resetOutBuffer();
        if ( outputUnknown )
        {
            int deviceIDNoAsInt = deviceIDNo.toInt();
            createUnknownDeviceTypeString( C_SPEED_TYPE, deviceIDNoAsInt, timeStampBuffer, payLoad );
        }
    }

    return result;
}
Exemplo n.º 3
0
//-------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------//
//
// HRM
//
//-------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------//
amDeviceType antHRMProcessing::processHRMSensor
(
    const amString &deviceIDNo,
    const amString &timeStampBuffer,
    BYTE            payLoad[]
)
{
    char         auxBuffer[ C_MEDIUM_BUFFER_SIZE ] = { 0 };
    unsigned int dataPage                          = 0;
    unsigned int heartBeatEventTime                = 0;
    unsigned int heartRate                         = 0;
    unsigned int heartBeatCount                    = 0;
    unsigned int deltaHeartBeatEventTime           = 0;
    unsigned int deltaHeartBeatCount               = 0;
    unsigned int rollOver                          = 0;
    unsigned int additionalData1                   = 0;
    unsigned int additionalData2                   = 0;
    unsigned int additionalData3                   = 0;
    unsigned int totalHeartBeatCount               = 0;
    double       totalHeartBeatEventTime           = 0;
    double       additionalDoubleData1             = 0;
    bool         rollOverHappened                  = false;
    bool         commonPage                        = false;
    bool         outputPageNo                      = true;
    amDeviceType result                            = OTHER_DEVICE;
    amString     sensorID                          = amString( C_HRM_DEVICE_HEAD) + deviceIDNo;


    if ( isRegisteredDevice( sensorID ) )
    {
        if ( ( eventTimeTable.count    ( sensorID ) == 0 ) ||
             ( eventCountTable.count   ( sensorID ) == 0 ) ||
             ( operatingTimeTable.count( sensorID ) == 0 ) )
        {
            eventTimeTable.insert( std::pair<amString, double>( sensorID, 0.0 ) );
            eventCountTable.insert( std::pair<amString, double>( sensorID, 0.0 ) );
            operatingTimeTable.insert( std::pair<amString, unsigned int>( sensorID, 0 ) );
        }

        dataPage = byte2UInt( payLoad[ 0 ] );
        if ( diagnostics )
        {
            appendDiagnosticsLine( "Data Page", payLoad[ 0 ], dataPage );
        }

        heartRate = byte2UInt( payLoad[ 7 ] );
        if ( diagnostics )
        {
            appendDiagnosticsLine( "Heart Rate", payLoad[ 7 ], heartRate );
        }

        heartBeatEventTime         = byte2UInt( payLoad[ 5 ], payLoad[ 4 ] );
        rollOver                   = 65536;  // 256^2
        deltaHeartBeatEventTime    = getDeltaInt( rollOverHappened, sensorID, rollOver, eventTimeTable, heartBeatEventTime );
        totalHeartBeatEventTime    = totalTimeTable[ sensorID ] + ( ( double ) deltaHeartBeatEventTime ) / 1024.0;
        totalTimeTable[ sensorID ] = totalHeartBeatEventTime;
        if ( diagnostics )
        {
            appendDiagnosticsLine( "Heart Beat Even Time", payLoad[ 5 ], payLoad[ 4 ], heartBeatEventTime );

            *auxBuffer = 0;
            if ( rollOverHappened )
            {
                sprintf( auxBuffer, " (Rollover [%d] occurred)", rollOver );
            }
            appendDiagnosticsLine( "Delta Heart Beat Even Time", deltaHeartBeatEventTime, auxBuffer );
        }

        heartBeatCount              = byte2UInt( payLoad[ 6 ] );
        rollOver                    = 256;  // 256 = 1 Byte
        deltaHeartBeatCount         = getDeltaInt( rollOverHappened, sensorID, rollOver, eventCountTable, heartBeatCount );
        totalHeartBeatCount         = totalCountTable[ sensorID ] + deltaHeartBeatCount;
        totalCountTable[ sensorID ] = totalHeartBeatCount;
        if ( diagnostics )
        {
            *auxBuffer = 0;
            if ( rollOverHappened )
            {
                sprintf( auxBuffer, " (Rollover [%d] occurred)", rollOver );
            }
            appendDiagnosticsLine( "Delta Heart Beat Count", deltaHeartBeatCount, auxBuffer );
        }

        int dataPageMod128 = dataPage & 0x0F;
        switch ( dataPageMod128 )
        {
            case  0: // - - Page 0: No Additional Data - - - - - - - - - - - - - - -
                     result = HEART_RATE_METER;
                     break;

            case  1: // - - Page 1: Operating Time - - - - - - - - - - - - - - - - -
                     result          = HEART_RATE_METER;
                     additionalData2 = byte2UInt( payLoad[ 3 ], payLoad[ 2 ], payLoad[ 1 ] ); // Operating Time
                     rollOver        = 16777216;  // 256^3
                     additionalData1 = getDeltaInt( rollOverHappened, sensorID, rollOver, operatingTimeTable, additionalData2 );
                                       // deltaOperatingTime
                     if ( diagnostics )
                     {
                         double cumOperatingTimeH = ( double ) additionalData2 / 3600.0;
                         sprintf( auxBuffer, " (%2.2lfh)", cumOperatingTimeH );
                         appendDiagnosticsLine( "Cumulative Operating Time", payLoad[ 3 ], payLoad[ 2 ], payLoad[ 1 ], additionalData2, auxBuffer );
                         *auxBuffer = 0;
                         if ( rollOverHappened )
                         {
                             sprintf( auxBuffer, " (Rollover [%d] occurred)", rollOver );
                         }
                         appendDiagnosticsLine( "Delta Cumulative Operating Time", additionalData1, auxBuffer );
                     }
                     break;

            case  2: // - - Page 2: Manufacturer Information - - - - - - - - - - - -
                     result          = HEART_RATE_METER;
                     additionalData1 = byte2UInt( payLoad[ 1 ] );                // Manufacturer ID
                     additionalData2 = byte2UInt( payLoad[ 3 ], payLoad[ 2 ] );  // Serial Number
                     if ( diagnostics )
                     {
                         appendDiagnosticsLine( "Manufacturer ID", payLoad[ 1 ], additionalData1 );
                         appendDiagnosticsLine( "Serial Number", payLoad[ 3 ], payLoad[ 2 ], additionalData2 );
                     }
                     break;

            case  3: // - - Page 3: Product Information  - - - - - - - - - - - - - -
                     result          = HEART_RATE_METER;
                     additionalData1 = byte2UInt( payLoad[ 1 ] );   // H/W Version
                     additionalData2 = byte2UInt( payLoad[ 2 ] );   // S/W Version
                     additionalData3 = byte2UInt( payLoad[ 3 ] );   // Model Number
                     if ( diagnostics )
                     {
                         appendDiagnosticsLine( "Hardware Version", payLoad[ 1 ], additionalData1 );
                         appendDiagnosticsLine( "Software Version", payLoad[ 2 ], additionalData2 );
                         appendDiagnosticsLine( "Model Number", payLoad[ 3 ], additionalData3 );
                     }
                     break;

            case  4: // - - Page 4: Previous Heartbeat Time - - - - - - - - - - - - -
                     result                         = HEART_RATE_METER;
                     rollOver                       = 65536;  // 256^2
                     additionalData2                = byte2UInt( payLoad[ 1 ] );                 // Manufacturer Specific Data;
                     additionalData3                = byte2UInt( payLoad[ 3 ], payLoad[ 2 ] );   // Previous Heart Beat Event Time
                     additionalData1                = getDeltaInt( rollOverHappened, sensorID, rollOver, previousHeartRateTable, additionalData3 );
                     additionalDoubleData1          = heartBeatTimeTable[ sensorID ] + ( ( double ) additionalData1 ) / 1024.0;
                     additionalData3                = 0;
                     heartBeatTimeTable[ sensorID ] = additionalDoubleData1;
                     if ( diagnostics )
                     {
                         appendDiagnosticsLine( "Manufacturer Specific Info", payLoad[ 1 ], additionalData1 );
                         appendDiagnosticsLine( "Previous Heart Beat Event Time", payLoad[ 3 ], payLoad[ 2 ], additionalData2 );
                         *auxBuffer = 0;
                         if ( rollOverHappened )
                         {
                             sprintf( auxBuffer, " (Rollover [%d] occurred)", rollOver );
                         }
                         appendDiagnosticsLine( "Delta Previous Heart Beat Event Time", additionalData2, auxBuffer );
                     }
                     break;

            default: commonPage = true;
                     result     = HEART_RATE_METER;
                     break;
        }
    }

    if ( result == HEART_RATE_METER )
    {
        createOutputHeader( sensorID, timeStampBuffer );
        if ( commonPage )
        {
            commonPage = processCommonPages( sensorID, payLoad, outputPageNo );
            if ( !commonPage )
            {
                result = OTHER_DEVICE;
            }
        }
        else
        {
            createHRMResultString
            (
                dataPage,
                heartRate,
                deltaHeartBeatEventTime,
                deltaHeartBeatCount,
                totalHeartBeatEventTime,
                totalHeartBeatCount,
                additionalData1,
                additionalData2,
                additionalData3,
                additionalDoubleData1
            );
        }
        appendOutputFooter( getVersion() );
    }

    return result;
}
Exemplo n.º 4
0
//-------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------//
//
// ENVRIONMENT
//
//-------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------//
//-------------------------------------------------------------------------------------------------//
amDeviceType antEnvironmentProcessing::processEnvironmentSensor
(
    const amString &deviceIDNo,
    const amString &timeStampBuffer,
    BYTE            payLoad[]
)
{
    char         auxBuffer[ C_MEDIUM_BUFFER_SIZE ] = { 0 };
    unsigned int dataPage                          = 0;
    unsigned int auxInt0                           = 0;
    unsigned int auxInt1                           = 0;
    unsigned int auxInt2                           = 0;
    unsigned int additionalData1                   = 0;
    unsigned int additionalData2                   = 0;
    unsigned int additionalData3                   = 0;
    unsigned int additionalData4                   = 0;
    amDeviceType result                            = OTHER_DEVICE;
    amString     sensorID                          = amString( C_ENV_DEVICE_HEAD ) + deviceIDNo;
    bool         commonPage                        = false;
    bool         outputPageNo                      = true;

    if ( isRegisteredDevice( sensorID ) )
    {
        dataPage = byte2UInt( payLoad[ 0 ] );
        if ( diagnostics )
        {
            appendDiagnosticsLine( "Data Page", payLoad[ 0 ], dataPage );
        }

        switch ( dataPage & 0x0F )
        {
            case  0: // - - Page 0: No Additional Data - - - - - - - - - - - - - - -
                     //     Bytes 1, 2, and 3: 0xFF.
                     result          = ENVIRONMENT_SENSOR;
                     auxInt0         = byte2UInt( payLoad[ 3 ] );                                              // Transmission Info
                     additionalData1 = ( auxInt0 << 4 ) & 3;                                             // Local Time
                     additionalData2 = ( auxInt0 << 2 ) & 3;                                             // UTC Time
                     additionalData3 = auxInt0 & 3;                                                      // Transmission Rate
                     additionalData4 = byte2UInt( payLoad[ 7 ], payLoad[ 6 ], payLoad[ 5 ], payLoad[ 4 ] );    // Supported Pages
                     if ( diagnostics )
                     {
                         appendDiagnosticsLine( "Transmission Info", payLoad[ 3 ], auxInt0 );
                         appendDiagnosticsLine( "Local Time",        additionalData1 );
                         appendDiagnosticsLine( "UTC Time",          additionalData2 );
                         appendDiagnosticsLine( "Transmission Rate", additionalData3 );
                         appendDiagnosticsLine( "Supported Pages", payLoad[ 7 ], payLoad[ 6 ], payLoad[ 5 ], payLoad[ 4 ], additionalData4 );
                     }
                     break;
            case  1: // - - Page 1: Temperature - - - - - - - - - - - - - - - - -
                     //     Byte 3 and Bits 4-7 of Byte 4: Low  Temp * 10 (Byte 3 LSB)
                     //     Bits 0-3 of Byte 4 and Byte 5: High Temp * 10 (Byte 5 MSB)
                     //     Bytes 6 & 7                  : Current Temp * 100 (byte 6 LSB, byte 7 MSB)
                     result          = ENVIRONMENT_SENSOR;
                     additionalData4 = byte2UInt( payLoad[ 2 ] );                                              // Event Count
                     auxInt0         = byte2UInt( payLoad[ 4 ] );
                     auxInt1         = auxInt0 >> 4;
                     auxInt2         = auxInt0 & 0x0F;
                     additionalData2 = ( auxInt1 * 256 ) + byte2UInt( payLoad[ 3 ] );                          // Low Temperature 24h
                     additionalData3 = ( byte2UInt( payLoad[ 5 ] ) << 4 ) + auxInt2;                           // High Temperature 24h
                     additionalData1 = byte2UInt( payLoad[ 7 ], payLoad[ 6 ] );                               // Current Temperature
                     if ( diagnostics )
                     {
                         appendDiagnosticsLine( "Current Temperature * 100", payLoad[ 7 ], payLoad[ 6 ], additionalData1 );
                         strcpy( auxBuffer, " (Second Byte: Upper 4 Bits)" );
                         appendDiagnosticsLine( "Low Temperature 24h * 10", payLoad[ 3 ], payLoad[ 4 ], additionalData2, auxBuffer );
                         strcpy( auxBuffer, " (First Byte: Lower 4 Bits)" );
                         appendDiagnosticsLine( "High Temperature 24h * 10", payLoad[ 4 ], payLoad[ 5 ], additionalData3, auxBuffer );
                         appendDiagnosticsLine( "Event Count", payLoad[ 2 ], additionalData4 );
                     }
                     break;

            default: commonPage = true;
                     result     = ENVIRONMENT_SENSOR;
                     break;
        }
    }

    if ( result == ENVIRONMENT_SENSOR )
    {
        createOutputHeader( sensorID, timeStampBuffer );
        if ( commonPage )
        {
            commonPage = processCommonPages( sensorID, payLoad, outputPageNo );
            if ( !commonPage )
            {
                result = OTHER_DEVICE;
            }
        }
        else
        {
            createENVResultString( dataPage, additionalData1, additionalData2, additionalData3, additionalData4 );
        }
        appendOutputFooter( getVersion() );
    }

    if ( result == OTHER_DEVICE )
    {
        resetOutBuffer();
        if ( outputUnknown )
        {
            int deviceIDNoAsInt = deviceIDNo.toInt();
            createUnknownDeviceTypeString( C_ENV_TYPE, deviceIDNoAsInt, timeStampBuffer, payLoad );
        }
    }

    return result;
}