//
// VAIBO.h
//
// Copyright 2004 Sony Corporation
//

#if !defined(AFX_VAIBO_H__BE593771_F8FA_4F7D_ACB5_349F4A09F6D5__INCLUDED_)
#define AFX_VAIBO_H__BE593771_F8FA_4F7D_ACB5_349F4A09F6D5__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#include    "VAIBODef.h"
#include    "SemID.h"

//
//  Define parameters
//////////////////////////////////////////////////////////////////////
enum {  // SetPosture parameter
    POS_STAND   = 0,
    POS_SIT,
    POS_SLEEP,
    POS_WALK,
    POS_STAND_V,        // Stand with head up straight
    POS_SIT_V,          // Sit with head up straight
    POS_SLEEP_V,        // Sleep with head up straight
    POS_STATION,        // Station posture
    POS_STATION_GOFF,   // Station posture (Neck and front leg gain OFF)
    POS_STATION_GOFF_D  // Station posture (Neck and front leg gain OFF) with the head down
};

enum {  // DoWalking parameters
    DW_FORWARD      = 0,
    DW_BACK,
    DW_FORWARD_FAST,
    DW_FORWARD_SLOW,
    DW_TURN_LEFT,
    DW_TURN_LEFT_FAST,
    DW_TURN_LEFT_SLOW,
    DW_TURN_RIGHT,
    DW_TURN_RIGHT_FAST,
    DW_TURN_RIGHT_SLOW,
    DW_STOP,
    DW_FORWARD_CNORMAL,         // Dogs' walk, normal speed forward
    DW_BACK_CNORMAL,            // Dogs' walk, normal speed backward
    DW_FORWARD_CFAST,           // Dogs' walk, fast
    DW_FORWARD_CSLOW,           // Dogs' walk, slow
    DW_TURN_LEFT_CNORMAL,       // Dogs' walk, turning left, normal speed
    DW_TURN_LEFT_CFAST,
    DW_TURN_LEFT_CSLOW,
    DW_TURN_RIGHT_CNORMAL,
    DW_TURN_RIGHT_CFAST,
    DW_TURN_RIGHT_CSLOW,
    DW_FORWARD_SMALL,           // Walking with narrow stride forward
    DW_BACK_SMALL,              // Walking with narrow stride backward
    DW_TURN_LEFT_SMALL,         // Walking with narrow stride and turning left
    DW_TURN_RIGHT_SMALL,        // Walking with narrow stride and turning right
    DW_FORWARD_CAREFUL,         // Careful walking
    DW_BACK_CAREFUL,            // 
    DW_FORWARD_FASTCAREFUL,     // Fast careful walking
    DW_TURN_LEFT_CAREFUL,       // 
    DW_TURN_LEFT_FASTCAREFUL,   // 
    DW_TURN_RIGHT_CAREFUL,      // 
    DW_TURN_RIGHT_FASTCAREFUL,  // 
    DW_FORWARD_BABY,            // Baby walking
    DW_BACK_BABY,               // Baby walking backword
    DW_TURN_LEFT_BABY,          // 
    DW_TURN_RIGHT_BABY,         // 
    DW_FORWARD_KSLOW,           // Walk slowly with head upward
    DW_TURN_LEFT_KSLOW,         // 
    DW_TURN_RIGHT_KSLOW,        // 
    DW_FORWARD_KNORMAL,         // Walk at normal speed with head upward
    DW_BACK_KNORMAL,            // 
    DW_TURN_LEFT_KNORMAL,       // 
    DW_TURN_RIGHT_KNORMAL,      // 
    DW_CIRCLE_LEFT_NORMAL,      // Circular arc walk, left curve
    DW_CIRCLE_RIGHT_NORMAL,     // Circular arc walk, right curve
    DW_CIRCLE_LEFT_SMALL,       // Circular arc walk with narrow stride, left curve
    DW_CIRCLE_RIGHT_SMALL,      // Circular arc walk with narrow stride, right curve
    DW_CIRCLE_LEFT_CNORMAL,     // Circular arc walk (dogs' walk, normal speed)
    DW_CIRCLE_RIGHT_CNORMAL,    // 
    DW_CIRCLE_LEFT_CFAST,       // Circular arc walk (dogs' walk, fast)
    DW_CIRCLE_RIGHT_CFAST,      // 
    DW_CIRCLE_LEFT_CSLOW,       // Circular arc walk (dogs' walk, slow)
    DW_CIRCLE_RIGHT_CSLOW,      // 
    DW_CIRCLE_LEFT_FAST,        // Circular arc walk (fast)
    DW_CIRCLE_RIGHT_FAST,       // 
    DW_CIRCLE_LEFT_SLOW,        // Circular arc walk (slow)
    DW_CIRCLE_RIGHT_SLOW,       // 
    DW_CIRCLE_LEFT_CAREFUL,     // Circular arc walk (careful)
    DW_CIRCLE_RIGHT_CAREFUL,    // 
    DW_CIRCLE_LEFT_FASTCAREFUL, // Circular arc walk (fast careful)
    DW_CIRCLE_RIGHT_FASTCAREFUL,// 
    DW_CIRCLE_LEFT_BABY,        // Circular arc walk (baby walk)
    DW_CIRCLE_RIGHT_BABY,       // 
    DW_CIRCLE_LEFT_KSLOW,       // Circular arc, slow walk, left curve with head upward
    DW_CIRCLE_RIGHT_KSLOW,      // 
    DW_CIRCLE_LEFT_KNORMAL,     // Circular arc, normal walk, left curve with head upward
    DW_CIRCLE_RIGHT_KNORMAL,    // 
    DW_CIRCLE_LEFT_LNORMAL,     // Circular arc, normal walk, left curve with head downward
    DW_CIRCLE_RIGHT_LNORMAL     // 
};

enum {  // DoHeader  parameter
    DH_FORWARD      = 0,    // forward
};

enum {  // DoKick parameter
    DK_RIGHT        = 0,
    DK_RIGHT_FORWARD,
    DK_LEFT,
    DK_LEFT_FORWARD
};


// Target ID(SEMLABEL) 
#define     VAIBO_TARGET_NONE       ( 0x0000 )
#define     VAIBO_TARGET_PINK       ( SEMID_PINK )
#define     VAIBO_TARGET_BALL       ( SEMID_BALL )
#define     VAIBO_TARGET_BONE       ( SEMID_BONE )
#define     VAIBO_TARGET_FACE       ( SEMID_FACE )
#define     VAIBO_TARGET_ECARD1     ( SEMID_ECARD1 )
#define     VAIBO_TARGET_ECARD2     ( SEMID_ECARD2 )
#define     VAIBO_TARGET_HAND       ( SEMID_HAND )


// Automony functions 
enum E_ROBOTFUNCTION {
        ROBOTFUNC_SELFCHARGE,
        ROBOTFUNC_AIBONE_APPROACH,
        MAX_ROBOTFUNC
};


// VPR mode
enum EVPRMODE {
    EVPRMODE0,      // normal
    EVPRMODE1,      // Quest beginning mode
    EVPRMODE2,      // Quest middle
    EVPRMODE3,      // Quest finishing mode, SBC  
    EVPRMODE4,      // ESCENE 
    EVPRMODE5,      // ECARD Tracking 
    EVPRMODE6,      // SBC 
    MAX_EVPRMODE
};


// VPR record Policy  
enum EVPRPOLICY {
    EVPRPOLICY0,        // Allow multiple ModelSubID with the same ModelID.
    EVPRPOLICY1,        // Allow only one ModelSubID per ModelID.
    MAX_EVPRPOLICY
};
// * EVPRPOLICY0 and EVPRPOLICY1 : 
// If the ModelID and ModelSubID are already recorded,
// new data will not be trained. VPRRemoveModel() should be called
// before training new data.
// * EVPRPOLICY0 :
// You can train multiple ModelSubID with the same ModelID.
// Example:  Put a can in front of AIBO.
// You can train four angles of the can.
// ModelID=1 ModelSubID=1 front 
// ModelID=1 ModelSubID=2 left side (can turned 90 degrees)
// ModelID=1 ModelSubID=3 right side (can turned -90 degrees)
// ModelID=1 ModelSubID=4 back (can turned 180 degrees)
// then AIBO returns ModelID=1 when AIBO sees the can at any angle.
// * EVPRPOLICY1 :
// You can train only one ModelSubID per ModelID.
// Example:  You train ModelID=2 ModelSubID=1.
// If you train ModelID=2 ModelSubID=2,
// then the ModelID=2 ModelSubID=1 will be deleted.


// VPR model ID 
#define     VPRMODELID_MIN      ( 0 )
#define     VPRMODELID_MAX      ( 0xFF )
#define     VPRMODELSUBID_MIN   ( 0 )
#define     VPRMODELSUBID_MAX   ( 0xFFFF )

//
//  Structure definition
//////////////////////////////////////////////////////////////////////

typedef struct LimitMwcID {
    int nStart[256];
    int nEnd[256];
    int nCount;
} LimitMwcID;

class CVAIBOClient;

#ifdef _VAIBO_DLLEXPORT // 
class  __declspec( dllexport ) CVAIBO  
#else
class  __declspec( dllimport ) CVAIBO  
#endif // _VAIBO_DLLEXPORT 
{
public:
    void    GetUserIdPwd( char* szOwner, char* szPswd );
    void    SetUserIdPwd( char* szOwner, char* szPswd);
    int     ImageOutputCaptureData(LPCTSTR strOutputFileName);
    int     ImageGetFrameRate();
    int     MotionStop();
    int     ImageSetWindowHandle(HWND wnd, HWND wndDlg);
    int     FTPMMSendLEDFile(LPCTSTR szFile);
    int     FTPMMSendAUDIOFile(LPCTSTR szFile);
    int     FTPMMSendMOTIONFile( LPCTSTR szFile );
    int     UpdateContents();
    int     FTPMMSendMWCFile( LPCTSTR szFile );
    int     PlayContents( int nMwcID, BOOL waitF = true );

    CVAIBO( HWND parent );
    virtual ~CVAIBO();

    int     Connect( const char *szIPAddr, const char *szID = NULL, const char *szPWD = NULL);
    int     Disconnect( void );
    int     SendCmd( int cmd, BOOL waitF = true, int nParam1 = 0, int nParam2 = 0, int nParam3 = 0, int nParam4 = 0 );
    int     AudioSendPlay( BOOL isKutipaku = true );
    int     AudioSendStop( void );
    BOOL    RequestNetService( int service );
    int     ChangeHeadAngle( int angleH, int angleV, int nSpeed = 2, BOOL waitF = true );
    int     DoKick( int kick, BOOL waitF = true );
    int     DoHeader( int header, BOOL waitF = true );
    int     DoWalking( int walk, int angle = 0, int distance = 0, BOOL waitF = false );
    int     DoApproach( int walk, unsigned int unTarget = VAIBO_TARGET_NONE, BOOL waitF = false );
    int     DoGetOffStation( BOOL waitF = true );
    int     SetPosture( WORD pos, BOOL waitF = false );
    WORD    GetPosture( void );
    int     PlayMotion( LPARAM lmsCmd, BOOL exF = false, BOOL waitF = true, BOOL infinityF = false, unsigned int unTarget = VAIBO_TARGET_NONE );
    int     PlayMotionWithAngle( LPARAM lmsCmd, int angleH, int angleV, BOOL exF = false, BOOL waitF = true, BOOL infinityF = false, unsigned int unTarget = VAIBO_TARGET_NONE );
    int     GetStatus( void );
    int     GetBatteryLevel( void );
    void    SetBatteryLevelNotify( BOOL onF = true, int interval = 60 );
    int     TurnBody( int angle, BOOL waitF = true );
    int     SetClock( LPARAM date, LPARAM time, BOOL waitF = true );
    BOOL    IsControlReady( void );
    void    GetInputSemantics( int *semID, int *pSubInfoArray, int *pEtcInfoArray = NULL );
    int     GetSemInfo( int *pInfoArray );
    int     SensorTransferStart( void );
    int     SensorTransferStop( void );
    void    SensorGetData( int numOfData, SensorRecP pSensorRec );
    void    SensorSetSkipRate( int skipCount );
    int     SensorGetSkipRate( void );
    void    GetProductID( ProductInfo *pInfo );
    void    GetRemoteMACAddress( MACAddressInfo* pInfo );
    int     SetLock( BOOL bLock );
    BOOL    IsFTPOpen( void );
    int     GetStateSensorTP( void );
    int     GetStateAudioTP( void );
    int     GetStateNetAudio( void );
    int     GetStateImageTP( void );
    BOOL    IsLock( void );
    BOOL    IsConnect( void );
    int     GetRobotDesign( void );
    int     ImageInit( void );
    int     ImageOpen( void );
    int     ImageClose( void );
    int     ImagePause( void );
    int     ImageResume( void );
    int     ImageGetData( unsigned char *buff, int size );
    int     AudioInit( void );
    int     AudioGetOpen( int mode );
    int     AudioClose( void );
    int     AudioSendOpen( int mode = -1 );
    int     AudioGetData( unsigned char *buff, int size );
    int     AudioSendData( char *buff, int size );
    int     AudioSendWAVFile( LPCTSTR szFile );
    int     FTPMMSendWAVFile( LPCTSTR szFile );
    void    SetObserverWnd( HWND hObserver );
    void    GetLocalIPAddress( char *szIPAddr );

    // AIBO Control API 
    BOOL    ExternalControl( BOOL waitF = true );
    BOOL    InternalControl( BOOL waitF = true );
    BOOL    IsRemote();
    BOOL    ChangeDisconnectMode( int nMode );
    BOOL    SetRobotObjectMode( E_ROBOTOBJECT eService, E_ROBOTOBJECTMODE eMode, BOOL waitF = true );
    E_ROBOTOBJECTMODE       GetRobotObjectMode( E_ROBOTOBJECT eService );

    // Camera API 
    BOOL    CameraSetModeDefault();
    BOOL    CameraSetModeManual( int nShutterSpeed, int nExposure );
    BOOL    CameraSetParamExposure( int nExposure );
    BOOL    CameraSetParamShutterSpeed( int nShutterSpeed );
    BOOL    CameraSetModeAEAWB();

    // Audio API 
    int     AudioSendSetMode( int nMode );

    // Get last command ID
    int     GetLastCmdID();

    // Get service protocol version
    BOOL    GetProtocolVersion( int nServiceID, int nVersion[ 4 ] );


    // Automony functions
	int		DoRobotFunction( E_ROBOTFUNCTION eFunction, BOOL waitF = true );
    BOOL    StopRobotFunction();

    // VPR 
    BOOL    VPRSetMode( EVPRMODE eMode );
    BOOL    VPRTrainModel( int nModelID, int nModelSubID, EVPRPOLICY nPolicy = EVPRPOLICY1 );
    BOOL    VPRRemoveModel( int nModelID, int nModelSubID );
    BOOL    VPRQueryModel( int nModelID );
    BOOL    VPRGetImage( int nModelID, int nModelSubID, char* strFileName );

    // Volume 
    BOOL    SetVolume( int nVolume );
    BOOL    RequestVolume();


// Internal use only
private:
    int SetLimitMwcID(int nStart, int nEnd);
    CVAIBOClient    *m_client;
    LimitMwcID  m_LimitMwcID;

};

#endif // !defined(AFX_VAIBO_H__BE593771_F8FA_4F7D_ACB5_349F4A09F6D5__INCLUDED_)
