//
//  Copyright © 2001 - 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:   7kStatus.h
//
//  Project:    6046.
//
//  Author(s):  W. Arcus
//
//  Purpose:    
//
//  Notes:      

#if !defined(AFX_7KSTATUS_H__6DC6246C_5FF1_41B2_AB50_2BFAE4512A42__INCLUDED_)
#define AFX_7KSTATUS_H__6DC6246C_5FF1_41B2_AB50_2BFAE4512A42__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "7kProtocol.h"
#include "SystemTime.h"

class EXPORT_DLL C7kStatus : public C7kProtocol
{
public:

    ///////////////
    // Defintions.

    typedef enum tagEMESSAGETYPE
    {
        messageTypeStatus,
        messageTypeAlarm
    }
    EMESSAGETYPE;

    typedef enum tagEMODE
    {
        modeUnspecified    = -1,
        modeAlarmClear,
        modeAlarmActive
    }
    EMODE;
    
    typedef enum tagEMESSAGEID
    {
        messageIdVersion,
        messageIdModules,
        messageIdRunList,
        messageIdFileDetails,
        messageIdSensorReply,
        messageIdLoggingSetup,
        messageIdHealth,
        messageIdShutdown
    }
    EMESSAGEID;

    ///////////////
    // Services.

                    C7kStatus       (   void );
                    C7kStatus       (   const C7kStatus                 &rRhs );

    virtual        ~C7kStatus       (   void );

    C7kStatus &     operator =      (   const C7kStatus                 &rRhs );

    bool            Encode          (   const EMESSAGETYPE              &reMessageType,
                                        const EMODE                     &reMode,
                                        const int                       &riMessageId,           // Either from C7kStatus::EMESSAGEID (above) or Include\SurveyEventTypes.h, ::EALARMID.
                                        LPCTSTR                         lpszMessage,
                                        const bool                      &rbUseChecksum );

    bool            Decode          (   BYTE                            *pbyStream,
                                        const unsigned long             &rulTotalBytes,
                                        const bool                      &rbUseChecksum,
                                        EMESSAGETYPE                    &reMessageType,
                                        EMODE                           &reActive,
                                        int                             &riMessageId );

    operator        BYTE *          (   void ) const;
    operator        unsigned long   (   void ) const;

    CString         Message         (   void ) const;

private:

    ///////////////
    // Defintions.

#pragma pack( push, STATUS7K_H_PACK, 1 )

    typedef struct tagRECORDTYPEHEADER
    {
        int             m_iMessageType;
        int             m_iMode;
        int             m_iMessageId;
        unsigned long   m_ulMessageBytesToFollow;

        static unsigned long Size( void )
        {
            return sizeof( struct tagRECORDTYPEHEADER );
        }

        tagRECORDTYPEHEADER(    const int           &riMessageType,
                                const int           &riMode,
                                const int           &riMessageId,
                                const unsigned long &rulMessageBytesToFollow )
        {
            Reset();

            m_iMessageType           = riMessageType;
            m_iMode                  = riMode;
            m_iMessageId             = riMessageId;
            m_ulMessageBytesToFollow = rulMessageBytesToFollow;
        }

        void Reset( void )
        {
            memset( this, 0x00, Size() );
        }
    }
    RECORDTYPEHEADER, *PRECORDTYPEHEADER;

#pragma pack( pop, STATUS7K_H_PACK )

    ///////////////
    // Attributes.

    const unsigned long     m_ulRecordHeaderSize;
    const unsigned long     m_ulRecordType;

    CString                 m_Status;

    ///////////////
    // Services.

    void            SetDefaultHeader(   RECORDHEADER7K      *psRecordHeader );

};

#endif // !defined(AFX_7KSTATUS_H__6DC6246C_5FF1_41B2_AB50_2BFAE4512A42__INCLUDED_)
