//
//  Copyright © 2002, RESON Inc. All Rights Reserved.
//
//  No part of this file may be reproduced or transmitted in any form or by
//  any means, electronic or mechanical, including photocopy, recording, or
//  information storage or retrieval system, without permission in writing
//  from RESON Inc.
//
//  Filename:   6046Hasp.h
//
//  Project:    6046
//
//  Author(s):  W. Arcus -- Port and re-work from 6041.
//
//  Purpose:    Defines the 6046 Hasp class and associated dongle layout that is
//              backwards compatible to the 6041 configuration.
//
//  Notes:      
//

#if !defined(AFX_RESONHASP_H__A770B243_141B_4CCA_A64E_55A06F60755F__INCLUDED_)
#define AFX_RESONHASP_H__A770B243_141B_4CCA_A64E_55A06F60755F__INCLUDED_

#include "haspcl.h"

#ifdef RESON_INTERNAL
#include <stdio.h>
#endif

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class C6046Hasp : public CHasp
{
public:

    ///////////////
    // Definitions.

    enum ERESONHASPVERSIONS
    {
        resonHaspVersion1               =   1,
        resonHaspVersion2               =   2,
        resonHaspVersion3               =   3,
        resonHaspVersion4               =   4                                       // 6046 support (6041 backwards compatible).
    };

    enum ERESONHASPWORDLAYOUT
    {
        // Common HASP memory layout words.

        haspLayoutVersion               =   0,                                      // Word 0 (bytes 0 and 1).

        haspLayoutUserTimeUpper         =   52,                                     // Word 52 -- users system time (upper word).
        haspLayoutUserTimeLower         =   53,                                     // Word 53 --   "     "      "  (lower   " ).

        haspLayoutDemoTimeUpper         =   54,                                     // Word 54 -- demo expire time  (upper   " ).
        haspLayoutDemoTimeLower         =   55,                                     // Word 55 -- demo expire time  (lower   " ).

        // Common HASP timer memory layout.

        haspLayoutLastTimeUpper         =   0,                                      // Word 1 and 2 (bytes 0 to 3).
        haspLayoutLastTimeLower         =   1,                                      // Word 1 and 2 (bytes 0 to 3).

        haspLayoutCount                 =   4,                                      // Word 4

        // 6041 HASP memory layout -- these attributes need to match the bytes as documented in the 
        // 6041 Dongle Development text to maintain backwards compatibility.

        haspLayoutOnlineTune            =   1,
        haspLayoutOnlinePipe            =   2,
        haspLayoutOfflineTune           =   3,
        haspLayoutOfflineObj            =   4,
        haspLayoutOfflinePipe           =   5,
        haspLayoutMosaic                =   6,
        haspLayoutDTM                   =   7,
        haspLayoutXYZ                   =   8,
        haspLayoutDespike               =   9,
        haspLayoutExport                =   10,
        haspLayoutFileOpen              =   11,
        haspLayoutBathyPipe             =   12,
        haspLayoutWorldDisp             =   13,
        haspLayoutPipeEdit              =   14,
        haspLayoutOnBathyPipe           =   15,

        // 6046 HASP memory layout -- defined in 6041's reserved area to
        // maintain backwards compatibility.

        haspLayoutPLCOptions            =   31,                                     // PLC modes.
        haspLayoutRESONSonar            =   32,                                     // RESON sonar modes.
        haspLayoutEdgeTechSonar         =   33,                                     // EdgeTech FSDW modes.
        haspLayoutVehicle               =   34,                                     // General vehicle interface properties.
        haspLayout6046Reserved1         =   35,
        haspLayout6046Reserved2         =   36,
        haspLayout6046Reserved3         =   37,
        haspLayout6046Reserved4         =   38,
        haspLayout6046Reserved5         =   39,
        haspLayout6046Reserved6         =   40,
        haspLayout6046Reserved7         =   41,
        haspLayout6046Reserved8         =   42,
        haspLayout6046Reserved9         =   43,
        haspLayout6046Reserved10        =   44,
        haspLayout6046Reserved11        =   45,
        haspLayout6046Reserved12        =   46

    };

    enum EHASPERRORS
    {
        // Errors that don't conflict with those in hasp.h

        haspErrorInvalidVersion         =  -1000,
        haspErrorInvalidKeymaker        =  -1001,
        haspErrorInvalidReson           =  -1002,
        haspErrorBadResonData           =  -1003,
        haspErrorDemoExpired            =  -1004
    };

    enum ERESONHASPTYPE
    { 
        resonHaspTypeUnknown,
        resonHaspType6041KeyMaker,
        resonHaspType,
        resonHaspTypeDemoExpired,
    };

    ///////////////
    // Services.

                            C6046Hasp           (   const unsigned int         &ruiLptNumber    = 0,
                                                    const AutoSearchOptions    &reOptions       = LocalOnly );

    virtual                ~C6046Hasp           (   void );

    WORD                    GetVersion          (   void );

    ERESONHASPTYPE          GetResonHaspType    (   void );

    WORD                    SecureCheck         (   unsigned int                uiAttribute );

#ifdef RESON_INTERNAL

    bool                    Configure           (   const WORD                 &rwVersion           = resonHaspVersion4,
                                                    const bool                 &rbEraseAllMemory    = false,
                                                    const WORD                 *pwMemoryBlock       = NULL,
                                                    const unsigned int         &ruiMemoryWords      = 0U,
                                                    const unsigned int         &ruiMemoryOffset     = haspLayoutPLCOptions,
                                                    const bool                 &rbSetDemo           = false );

    void                    Dump                (   FILE                       *pFile               = stdout );

#endif

private:

    ///////////////
    // Services.

    long                    ReadLong            (   int                         iOffset );

    void                    WriteLong           (   int                         iOffset,
                                                    long                        lVal );

    long                    TimeHASP_ReadLong   (   int                         iOffset );

    void                    TimeHASP_WriteLong  (   unsigned int                uiOffset,
                                                    long                        lVal );

    time_t                  TimeHASP_ReadTime   (   void );

    long                    GetLongTime         (   int                         iIndex );

    time_t                  mktime              (   struct tm                  *tb );
    time_t                  mkgmtime            (   struct tm                  *tb );

    time_t                  _make_time_t        (   struct tm                  *tb,
                                                    int                         ultflag );

                            C6046Hasp           (   const C6046Hasp            &rRhs );         // Not implemented thus private.
    C6046Hasp &             operator =          (   const C6046Hasp            &rRhs );         // Not implemented thus private.

};

#endif // !defined(AFX_RESONHASP_H__A770B243_141B_4CCA_A64E_55A06F60755F__INCLUDED_)
