/** \file
 *
 *  Contains unit tests for the NAL9602 class
 *
 *  Copyright (c) 2007,2008,2009 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 */

#ifndef _DUSBL_HYDROID_TEST_H_
#define _DUSBL_HYDROID_TEST_H_

#include "DUSBL_Hydroid.h"

#include <cxxtest/TestSuite.h>

/**
 *  Unit tests for DUSBL_Hydroid class
 *
 *  \ingroup modules_sensor
 */
class DUSBL_Hydroid_Test : public CxxTest::TestSuite
{
public:

    void testParseRangeAndDirectionMessage( void )
    {
        float xAngle( -1.2345 ), yAngle( -1.2345 ), travelTime( -1.2345 ),
              latency( -1.2345 ), gain( -1.2345 ), inBandSignalToNoise( -1.2345 ), outBandSignalToNoise( -1.2345 );

        bool ok;

        const char* deviceResponse1 = "!U1,R,FC6,000,0028C,184,80,80,D5,FF\r";

        ok = DUSBL_Hydroid::ParseRangeAndDirectionMessage( deviceResponse1,
                xAngle, yAngle, travelTime, latency, gain, inBandSignalToNoise, outBandSignalToNoise );

        TS_ASSERT( ok );
        TS_ASSERT_DELTA( xAngle, -D2R( -58 * 0.05 ), 0.00001 ); // Flipping the sign here to expect positive to port since the DUSBL was originally mounted upside down
        TS_ASSERT_DELTA( yAngle, 0, 0.00001 );
        TS_ASSERT_DELTA( travelTime, 0x28c * 0.00008, 0.00001 );
        TS_ASSERT_EQUALS( latency, 0x184 );
        TS_ASSERT_EQUALS( gain, 0x80 );
        TS_ASSERT_EQUALS( inBandSignalToNoise, 0xD5 );
        TS_ASSERT_EQUALS( outBandSignalToNoise, 0xFF );

        const char* deviceResponse2 = "!U1,R,105,000,002D5,186,80,80,D6,FF\r";

        ok = DUSBL_Hydroid::ParseRangeAndDirectionMessage( deviceResponse2,
                xAngle, yAngle, travelTime, latency, gain, inBandSignalToNoise, outBandSignalToNoise );

        TS_ASSERT( ok );
        TS_ASSERT_DELTA( xAngle, -D2R( 261 * 0.05 ), 0.00001 ); // Flipping the sign here to expect positive to port since the DUSBL was originally mounted upside down
        TS_ASSERT_DELTA( yAngle, 0, 0.00001 );
        TS_ASSERT_DELTA( travelTime, 0x2d5 * 0.00008, 0.00001 );
        TS_ASSERT_EQUALS( latency, 0x186 );
        TS_ASSERT_EQUALS( gain, 0x80 );
        TS_ASSERT_EQUALS( inBandSignalToNoise, 0xD6 );
        TS_ASSERT_EQUALS( outBandSignalToNoise, 0xFF );
    }

    void testGenerateRangeRequest( void )
    {
        /*  #U1,P,nn,ttt,ggg, hh,xx,yy,sss(CR)
            nn = signal number to be received, (0-FF hex).
            ttt = transmit lockout in 0.001 second increments (000-FFF hex).
            ggg = receiver gate time in 0.001 second increments (000-FFF hex).
            hh = detection threshold (00-FF hex)
            xx = x center degrees (2’s complement hex)
            yy = y center degrees (2’s complement hex)
            sss = local sound speed (m/s) (unsigned hex integer)
        */
        char* cmd = DUSBL_Hydroid::GenerateRangeRequest( 0x2, 0x14, 0x800, 0x20, 0x0, 0x0, 0x578 );
        int len = strlen( cmd );
        if( len > 30 ) len = 30;
        TS_ASSERT_SAME_DATA( cmd, "#U1,P,02,014,800,20,00,00,578\r", len );

        cmd = DUSBL_Hydroid::GenerateRangeRequest( 0x2, 0x14, 0x800, 0x20, 0x0, -1, 0x578 );
        len = strlen( cmd );
        if( len > 30 ) len = 30;
        TS_ASSERT_SAME_DATA( cmd, "#U1,P,02,014,800,20,00,FF,578\r", len );
    }

};

#endif // _DUSBL_HYDROID_TEST_H
