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

#ifndef mainH
#define mainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <wclBluetooth.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TfmMain : public TForm
{
__published:	// IDE-managed Components
        TButton *btOpen;
        TButton *btClose;
        TButton *btStart;
        TButton *btStop;
        TButton *btClear;
        TListBox *ListBox;
        TButton *btClearLogs;
        TwclBluetoothManager *wclBluetoothManager;
        TListBox *lbFrames;
        TwclBluetoothLeBeaconWatcher *wclBluetoothLeBeaconWatcher;
        TButton *btStartAdvertising;
        TButton *btStopAdvertising;
        TLabel *laScanInterval;
        TEdit *edScanInterval;
        TLabel *laScanWindow;
        TEdit *edScanWindow;
        TLabel *laAdvInterval;
        TEdit *edAdvInterval;
        TwclBluetoothLeAdvertiser *wclBluetoothLeAdvertiser;
        TCheckBox *cbIBeacon;
        TCheckBox *cbProximityBeacon;
        TCheckBox *cbAltBeacon;
        TCheckBox *cb128SolUuid;
        TCheckBox *cbEddystoneUrl;
        TCheckBox *cbEddystoneUid;
        TCheckBox *cbManufacturer;
        TCheckBox *cb16UuidService;
        TCheckBox *cb32UuidService;
        TCheckBox *cb128UuidService;
        TCheckBox *cb16UuidData;
        TCheckBox *cb32UuidData;
        TCheckBox *cb128UuidData;
        TCheckBox *cbCustomRaw;
        TCheckBox *cbUseExtended;
        TCheckBox *cbAnonymous;
        TCheckBox *cbIncludeTxRssi;
        TLabel *laScanMode;
        TCheckBox *cbMode;
        TButton *btDefaultScanParams;
        TButton *btDefInterval;
        void __fastcall FormDestroy(TObject *Sender);
        void __fastcall btOpenClick(TObject *Sender);
        void __fastcall btCloseClick(TObject *Sender);
        void __fastcall btStartClick(TObject *Sender);
        void __fastcall btStopClick(TObject *Sender);
        void __fastcall wclBluetoothManagerAfterOpen(TObject *Sender);
        void __fastcall wclBluetoothManagerBeforeClose(TObject *Sender);
        void __fastcall wclBluetoothManagerStatusChanged(TObject *Sender,
          const TwclBluetoothRadio *Radio);
        void __fastcall btClearClick(TObject *Sender);
        void __fastcall btClearLogsClick(TObject *Sender);
        void __fastcall wclBluetoothLeBeaconWatcherStarted(
          TObject *Sender);
        void __fastcall wclBluetoothLeBeaconWatcherStopped(
          TObject *Sender);
        void __fastcall btStopAdvertisingClick(TObject *Sender);
        void __fastcall btStartAdvertisingClick(TObject *Sender);
        void __fastcall wclBluetoothLeAdvertiserStarted(TObject *Sender);
        void __fastcall wclBluetoothLeAdvertiserStopped(TObject *Sender);
        void __fastcall FormCreate(TObject *Sender);
        void __fastcall btDefaultScanParamsClick(TObject *Sender);
        void __fastcall btDefIntervalClick(TObject *Sender);
        void __fastcall wclBluetoothLeBeaconWatcherAdvertisementExtFrameInformation(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const TwclBluetoothAddressType AddressType,
          const SByte TxPower,
          const TwclBluetoothLeExtendedFrameFlags Flags);
        void __fastcall wclBluetoothLeBeaconWatcherAdvertisementFrameInformation(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const String Name,
          const TwclBluetoothLeAdvertisementType PacketType,
          const TwclBluetoothLeAdvertisementFlags Flags);
        void __fastcall wclBluetoothLeBeaconWatcherAdvertisementRawFrame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const BYTE DataType,
          const TwclBluetoothLeAdvertisementFrameRawData Data);
        void __fastcall wclBluetoothLeBeaconWatcherAdvertisementReceived(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi,
          const TwclBluetoothLeAdvertisementFrameRawData Data);
        void __fastcall wclBluetoothLeBeaconWatcherAdvertisementService128DataFrame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const TGUID &Uuid,
          const TwclBluetoothLeAdvertisementFrameRawData Data);
        void __fastcall wclBluetoothLeBeaconWatcherAdvertisementService16DataFrame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const WORD Uuid,
          const TwclBluetoothLeAdvertisementFrameRawData Data);
        void __fastcall wclBluetoothLeBeaconWatcherAdvertisementService32DataFrame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const DWORD Uuid,
          const TwclBluetoothLeAdvertisementFrameRawData Data);
        void __fastcall wclBluetoothLeBeaconWatcherAdvertisementServiceSol128Frame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const TGUID &Uuid);
        void __fastcall wclBluetoothLeBeaconWatcherAdvertisementServiceSol16Frame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const WORD Uuid);
        void __fastcall wclBluetoothLeBeaconWatcherAdvertisementServiceSol32Frame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const DWORD Uuid);
        void __fastcall wclBluetoothLeBeaconWatcherAdvertisementUuidFrame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const TGUID &Uuid);
        void __fastcall wclBluetoothLeBeaconWatcherAltBeaconFrame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const WORD CompanyId, const WORD Major,
          const WORD Minor, const TGUID &Uuid, const SByte TxRssi,
          const BYTE Reserved,
          const TwclBluetoothLeAdvertisementFrameRawData Data);
        void __fastcall wclBluetoothLeBeaconWatcherEddystoneTlmFrame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const DWORD AdvCnt, const WORD Batt,
          const DWORD SecCnt, const double Temp,
          const TwclBluetoothLeAdvertisementFrameRawData Data);
        void __fastcall wclBluetoothLeBeaconWatcherEddystoneUidFrame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const SByte TxRssi, const TGUID &Uuid,
          const TwclBluetoothLeAdvertisementFrameRawData Data);
        void __fastcall wclBluetoothLeBeaconWatcherEddystoneUrlFrame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const SByte TxRssi, const String Url);
        void __fastcall wclBluetoothLeBeaconWatcherManufacturerRawFrame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const WORD CompanyId,
          const TwclBluetoothLeAdvertisementFrameRawData Data);
        void __fastcall wclBluetoothLeBeaconWatcherProximityBeaconFrame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const WORD CompanyId, const WORD Major,
          const WORD Minor, const TGUID &Uuid, const SByte TxRssi,
          const TwclBluetoothLeAdvertisementFrameRawData Data);
        void __fastcall wclBluetoothLeBeaconWatcherAdvertisementTxPowerLevelFrame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const SByte TxPower);
        void __fastcall wclBluetoothLeBeaconWatcherAdvertisementAppearanceFrame(
          TObject *Sender, const __int64 Address, const __int64 Timestamp,
          const SByte Rssi, const WORD Appearance);
private:	// User declarations
        TDateTime __fastcall ConvertTime(__int64 Timestamp);

        void AddAdvertisement(TwclBluetoothLeAdvertisement* Adv);

        TwclBluetoothRadio* GetRadio();

        void EnableAdvertisements(bool Enable);

        void DumpData(const TwclBluetoothLeAdvertisementFrameRawData Data);

        void DefaultScanParams();
public:		// User declarations
        __fastcall TfmMain(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TfmMain *fmMain;
//---------------------------------------------------------------------------
#endif
