//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include "PCANLight.h"
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
/// Message Status structure used to show CAN Messages
/// in a ListView
//
typedef struct ListViewMessageStatus
{
    private:
        TPCANMsg Msg;
        int iIndex;

    public:
        ListViewMessageStatus(TPCANMsg *CanMsg,int Index)
        {
            Msg = *CanMsg;
            iIndex = Index;
        }

        TPCANMsg CANMessage(void)
        {
            return Msg;
        }

        int Position(void)
        {
            return iIndex;
        }
}MessageStatus;

class TForm1 : public TForm
{
__published:	// IDE-managed Components
    TGroupBox *GroupBox1;
    TLabel *Label1;
    TComboBox *cbbHws;
    TButton *btnInfo;
    TButton *btnInit;
    TButton *btnRelease;
    TLabel *Label2;
    TLabel *Label3;
    TLabel *Label4;
    TLabel *Label5;
    TComboBox *cbbBaudrates;
    TComboBox *cbbMsgType;
    TComboBox *cbbIO;
    TComboBox *cbbInterrupt;
    TGroupBox *GroupBox2;
    TLabel *Label6;
    TLabel *Label7;
    TLabel *Label8;
    TEdit *txtID;
    TUpDown *nudLength;
    TEdit *txtLength;
    TEdit *txtData0;
    TEdit *txtData1;
    TEdit *txtData2;
    TEdit *txtData3;
    TEdit *txtData4;
    TEdit *txtData5;
    TEdit *txtData6;
    TEdit *txtData7;
    TCheckBox *chbExtended;
    TCheckBox *chbRemote;
    TButton *btnWrite;
    TGroupBox *GroupBox3;
    TListView *lstMessages;
    TGroupBox *GroupBox4;
    TMemo *txtInfo;
    TButton *btnClose;
    TTimer *tmrRead;
    TGroupBox *GroupBox5;
    TRadioButton *rdbStandard;
    TRadioButton *rdbExtended;
    TEdit *txtIdFrom;
    TEdit *txtIdTo;
    TLabel *Label9;
    TLabel *Label10;
    TButton *btnSetFilter;
    TButton *btnResetFilter;
    TButton *btnGetDeviceNumber;
    TEdit *ediDeviceNumber;
    TUpDown *nudDeviceNumber;
    TButton *btnSetDeviceNumber;
    void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
    void __fastcall cbbHwsChange(TObject *Sender);
    void __fastcall cbbBaudratesChange(TObject *Sender);
    void __fastcall txtIDKeyPress(TObject *Sender, char &Key);
    void __fastcall txtIDExit(TObject *Sender);
    void __fastcall nudLengthClick(TObject *Sender, TUDBtnType Button);
    void __fastcall txtData0Exit(TObject *Sender);
    void __fastcall chbExtendedClick(TObject *Sender);
    void __fastcall chbRemoteClick(TObject *Sender);
    void __fastcall txtInfoDblClick(TObject *Sender);
    void __fastcall lstMessagesDblClick(TObject *Sender);
    void __fastcall tmrReadTimer(TObject *Sender);
    void __fastcall btnInfoClick(TObject *Sender);
    void __fastcall btnInitClick(TObject *Sender);
    void __fastcall btnReleaseClick(TObject *Sender);
    void __fastcall btnWriteClick(TObject *Sender);
    void __fastcall btnCloseClick(TObject *Sender);
    void __fastcall rdbStandardClick(TObject *Sender);
    void __fastcall txtIdFromExit(TObject *Sender);
    void __fastcall btnSetFilterClick(TObject *Sender);
    void __fastcall btnResetFilterClick(TObject *Sender);
    void __fastcall btnGetDeviceNumberClick(TObject *Sender);
    void __fastcall btnSetDeviceNumberClick(TObject *Sender);
private:
    // Save the current initiated hardware type
    //
    HardwareType ActiveHardware;

    // CAN messages Array. Store the Message Status for its display
    //
    TList *LastMsgsList;

    void ModifyMsgEntry(MessageStatus LastMsg,TPCANMsg NewMsg);
    void InsertMsgEntry(TPCANMsg NewMsg);
    void ProcessMessage(TPCANMsg MyMsg);

public:		// User declarations
    __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
