// BeaconsDlg.h : header file
//

#pragma once
#include "afxcmn.h"
#include "afxwin.h"

#include "..\..\..\..\Source\Bluetooth\wclBluetooth.h"

using namespace wclCommon;
using namespace wclBluetooth;


// CBeaconsDlg dialog
class CBeaconsDlg : public CDialog
{
// Construction
public:
	CBeaconsDlg(CWnd* pParent = NULL);	// standard constructor

// Dialog Data
	enum { IDD = IDD_BEACONS_DIALOG };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV support


// Implementation
protected:
	HICON m_hIcon;

	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()

private:
	CListBox lbFrames;
	CListBox ListBox;
	
	CwclBluetoothManager wclBluetoothManager;
	CwclBluetoothLeBeaconWatcher wclBluetoothLeBeaconWatcher;
	CwclBluetoothLeAdvertiser wclBluetoothLeAdvertiser;
	
	CString FloatToStr(const double f) const;
	CString IntToStr(const char i) const;
	CString IntToStr(const size_t i) const;
	CString IntToStr(const unsigned char i) const;
	CString IntToStr(const unsigned long i) const;
	CString IntToHex(const unsigned short i) const;
	CString IntToHex(const int i) const;
	CString IntToHex(const __int64 i) const;
	CString IntToHex(const unsigned char i) const;

	void wclBluetoothManagerAfterOpen(void* Sender);
	void wclBluetoothManagerBeforeClose(void* Sender);
	void wclBluetoothManagerStatusChanged(void* Sender, CwclBluetoothRadio* const Radio);

	void wclBluetoothLeBeaconWatcherStarted(void* Sender);
	void wclBluetoothLeBeaconWatcherStopped(void* Sender);
	void wclBluetoothLeBeaconWatcherProximityBeaconFrame(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi, 
		const unsigned short CompanyId, const unsigned short Major, const unsigned short Minor,
		const GUID& Uuid, const char TxRssi, const wclBluetoothLeAdvertisementFrameRawData& Data);
	void wclBluetoothLeBeaconWatcherAltBeaconFrame(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi, const unsigned short CompanyId,
		const unsigned short Major, const unsigned short Minor, const GUID& Uuid, const char TxRssi,
		const unsigned char Reserved, const wclBluetoothLeAdvertisementFrameRawData& Data);
	void wclBluetoothLeBeaconWatcherManufacturerRawFrame(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi, const unsigned short CompanyId,
		const wclBluetoothLeAdvertisementFrameRawData& Data);
	void wclBluetoothLeBeaconWatcherAdvertisementRawFrame(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi, const unsigned char DataType,
		const wclBluetoothLeAdvertisementFrameRawData& Data);
	void wclBluetoothLeBeaconWatcherEddystoneUidFrame(void* Sender, 
		const __int64 Address, const __int64 Timestamp, const char Rssi, const char TxRssi, 
		const GUID& Uuid, const wclBluetoothLeAdvertisementFrameRawData& Data);
	void wclBluetoothLeBeaconWatcherEddystoneUrlFrame(void* Sender, 
		const __int64 Address, const __int64 Timestamp, const char Rssi, const char TxRssi,
		const tstring& Url);
	void wclBluetoothLeBeaconWatcherEddystoneTlmFrame(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi, const unsigned long AdvCnt,
		const unsigned short Batt, const unsigned long SecCnt, const double Temp,
		const wclBluetoothLeAdvertisementFrameRawData& Data);
	void wclBluetoothLeBeaconWatcherAdvertisementFrameInformation(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi,
		const tstring& Name, const wclBluetoothLeAdvertisementType PacketType,
		const wclBluetoothLeAdvertisementFlags& Flags);
	void wclBluetoothLeBeaconWatcherAdvertisementUuidFrame(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi, const GUID& Uuid);
	void wclBluetoothLeBeaconWatcherAdvertisementExtFrameInformation(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi,
		const wclBluetoothAddressType AddressType, const char TxPower,
		const wclBluetoothLeExtendedFrameFlags& Flags);
	void wclBluetoothLeBeaconWatcherAdvertisementService128DataFrame(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi, const GUID& Uuid,
		const wclBluetoothLeAdvertisementFrameRawData& Data);
	void wclBluetoothLeBeaconWatcherAdvertisementService32DataFrame(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi, const unsigned long Uuid,
		const wclBluetoothLeAdvertisementFrameRawData& Data);
	void wclBluetoothLeBeaconWatcherAdvertisementService16DataFrame(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi, const unsigned short Uuid,
		const wclBluetoothLeAdvertisementFrameRawData& Data);
	void wclBluetoothLeBeaconWatcherAdvertisementServiceSol128Frame(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi, const GUID& Uuid);
	void wclBluetoothLeBeaconWatcherAdvertisementServiceSol32Frame(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi, const unsigned long Uuid);
	void wclBluetoothLeBeaconWatcherAdvertisementServiceSol16Frame(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi, const unsigned short Uuid);
	void wclBluetoothLeBeaconWatcherAdvertisementReceived(void* Sender,
		const __int64 Address, const __int64 Timestamp, const char Rssi,
		const wclBluetoothLeAdvertisementFrameRawData& Data);
	void wclBluetoothLeBeaconWatcherAdvertisementTxPowerLevelFrame(void* Sender, const __int64 Address,
		const __int64 Timestamp, const char Rssi, const char TxPower);
	void wclBluetoothLeBeaconWatcherAdvertisementAppearanceFrame(void* Sender, const __int64 Address,
		const __int64 Timestamp, const char Rssi, const unsigned short Appearance);

	void wclBluetoothLeAdvertiserStarted(void* Sender);
	void wclBluetoothLeAdvertiserStopped(void* Sender);
	
	CString ConvertTime(const __int64 Timestamp) const;
	
	void AddAdvertisement(CwclBluetoothLeAdvertisement* const Adv);

	CwclBluetoothRadio* GetRadio() const;

	void EnableAdvertisements(const BOOL Enable);

	void DumpData(const wclBluetoothLeAdvertisementFrameRawData& Data);

	void DefaultScanParams();

public:
	afx_msg void OnDestroy();
	afx_msg void OnBnClickedButtonOpen();
	afx_msg void OnBnClickedButtonClose();
	afx_msg void OnBnClickedButtonStart();
	afx_msg void OnBnClickedButtonStop();
	afx_msg void OnBnClickedButtonClear();
	afx_msg void OnBnClickedButtonClearLog();
	afx_msg void OnBnClickedButtonStopAdvertising();
	afx_msg void OnBnClickedButtonStartAdvertising();
	afx_msg void OnBnClickedButton1();
	afx_msg void OnBnClickedButton3();

private:
	CEdit edScanInterval;
	CEdit edScanWindow;
	CEdit edAdvInterval;
	CButton cbIBeacon;
	CButton cbProximityBeacon;
	CButton cbAltBeacon;
	CButton cbEddystoneUid;
	CButton cbEddystoneUrl;
	CButton cb128SolUuid;
	CButton cbManufacturer;
	CButton cb16UuidService;
	CButton cb32UuidService;
	CButton cb128UuidService;
	CButton cb16UuidData;
	CButton cb32UuidData;
	CButton cb128UuidData;
	CButton cbCustomRaw;
	CButton cbUseExtended;
	CButton cbAnonymous;
	CButton cbIncludeTxRssi;
	CButton cbScanMode;
};
