mcu_hi3321_watch/application/wearable/nativeapp/nativeui/bluetooth/include/BluetoothModel.h
2025-05-26 20:15:20 +08:00

131 lines
4.5 KiB
C++

/*
* Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved.
* Description: BluetoothModel view
* Author:
* Create: 2021-10-13
*/
#ifndef BLUETOOTH_MODEL_H
#define BLUETOOTH_MODEL_H
#include <list>
#include <cstdio>
#include "gfx_utils/list.h"
#include "bts_def.h"
#include "bts_br_gap.h"
namespace OHOS {
typedef enum : uint16_t {
CALLERSETTING,
CALLERPLAYERS,
} CallerFactor;
typedef struct {
unsigned char deviceName[BD_NAME_LEN]; /* Name of the device record, must be in UTF-8 */
unsigned char addr[BD_ADDR_LEN];
int16_t index;
int16_t connIndex;
int16_t temp;
} BluetoothCaseInfo;
class BluetoothItemView;
class BluetoothModel {
public:
~BluetoothModel(){};
static BluetoothModel *GetInstance(void);
void Init();
int GetBluetoothCalleridStatus(void);
void SetBluetoothCalleridStatus(int16_t value);
// ɨÃèÉ豸¶ÓÁгõʼ»¯
std::list<BluetoothCaseInfo>& GetCase();
void AddCase(BluetoothCaseInfo caseInfo);
void SetScansCaseRssi(const bd_addr_t *bdAddr, int rssi);
void SortScansCaseRssi();
void SetCaseListClear();
bool CheckExistScanList(BluetoothCaseInfo caseInfo); // È¥ÖØ²Ù×÷
void ResetScanDevicesCase(const BluetoothCaseInfo& caseInfo);
// ÒÑÅä¶ÔÉ豸¶ÓÁгõʼ»¯
void SetConnedDevicesListClear();
void AddConnedDevicesCase(BluetoothCaseInfo caseInfo);
bool CheckExistConnedList(BluetoothCaseInfo caseInfo);
List<BluetoothCaseInfo>& GetConnedDevicesCase();
void SetTempMacValue(BluetoothCaseInfo *caseInfo);
BluetoothCaseInfo *GetTempMacValue(void);
void SetLastConnedAddr(const bd_addr_t *addr);
bd_addr_t *GetLastConnedAddr(void);
void SetTagReconnectJump(bool tag);
bool GetTagReconnectJump(void);
void SetCurView(int16_t viewNum);
int GetCurView(void);
bool GetAclConnected(void);
void SetTagConnectView(bool tag);
bool IsTagConnectView(void);
void SetTagDisconnectView(bool tag);
bool IsTagDisconnectView(void);
void SetTagConnectNew(bool tag);
bool IsTagConnectNew(void);
void SetTagReturnToDeviceListView(bool tag);
bool IsTagReturnToDeviceListView(void);
void SetTagScanDeviceClicked(bool tag);
bool IsTagScanDeviceClicked(void);
void SetBtStatus(void);
BluetoothItemView *GetConnectionView(void);
void SetConnectionView(BluetoothItemView *item);
bool FindNameFromList(BluetoothCaseInfo *caseInfo);
bool GetBluetoothAclState(void);
void BtGapDiscoveryResultCallbakHandle(const bd_addr_t &bdAddr);
void BtGapAclStateChangedHandle(gap_acl_state_t state, unsigned int reason, const bd_addr_t &bdAddr);
bool GetAdvStartState(void);
void SetAdvStartState(bool state);
int ConnectRemoteDevice(const bd_addr_t *addr);
bool ConnectRemoteCheck(const bd_addr_t *addr);
char* getWatchName(void);
private:
BluetoothModel();
int16_t callerid{0};
void SetUpListCase();
void SetUpConnedDevicesList();
bool FindNameByAddr(BluetoothCaseInfo &listInfo, BluetoothCaseInfo *caseInfo);
void InitBluetoothInfo(void);
bool aclConnected{false};
BluetoothCaseInfo tempMacValue{};
bd_addr_t lastConnedAddr{0};
bd_addr_t remoteConnectAddr{0};
BluetoothItemView *selectItemView{nullptr};
std::list<BluetoothCaseInfo> btScansDevicesList_{};
List<BluetoothCaseInfo> *btConnedDevicesList_{nullptr};
bool tagReconnectJump{0};
int16_t curView{0};
bool tagConnectView{true};
bool tagDisconnectView{true};
bool tagConnectNew{false};
bool tagReturnToDeviceListView{false};
bool tagScanDeviceClicked{false};
bool advStartState{false};
char watchName[BD_NAME_LEN] = { 0 };
};
#ifdef __cplusplus
extern "C" {
#endif
void BtGapReadRemoteRssiEventCallback(const bd_addr_t *bdAddr, int rssi, int status);
void BtGapDiscoveryResultCallbak(const bd_addr_t *bdAddr);
void BtGapDiscoveryStateChangedCallback(int status);
void GapAclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, unsigned int reason);
void SetSortCaseRssi(const bd_addr_t *bdAddr, int rssi);
void BtRemoteNameChangedCallback(const bd_addr_t *bdAddr, const unsigned char *deviceName, unsigned char length);
void BtIsAcceptConnOnSafeModeCallback(const bd_addr_t *bd_addr, bool *res);
void BtInitCallBacks(void);
void BtInitCallBacksEx(void);
void BtInitGatts(void);
void BtInitSpp(void);
void BleAdvStart(void);
#ifdef __cplusplus
}
#endif
}
#endif