🐞 fix(软总线): 设置设备类型,并且处理设备类型的转换

This commit is contained in:
huheng@kylinos.cn 2023-05-10 15:41:19 +08:00
parent 973805495d
commit 5f276fd28a
2 changed files with 26 additions and 9 deletions

View File

@ -159,7 +159,6 @@ static int32_t LlGetDeviceName(void *buf, uint32_t len)
return SOFTBUS_OK;
}
static int32_t LlGetBtMac(void *buf, uint32_t len)
{
NodeInfo *info = &g_localNetLedger.localInfo;
@ -328,7 +327,7 @@ static int32_t L1GetMasterNodeWeight(void *buf, uint32_t len)
static int32_t InitLocalDeviceInfo(DeviceBasicInfo *info)
{
char devType[DEVICE_TYPE_BUF_LEN] = TYPE_UNKNOWN;
char devType[DEVICE_TYPE_BUF_LEN] = TYPE_PC;
if (info == NULL) {
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "fail:para error!");
@ -501,8 +500,8 @@ static int32_t UpdateMasterNodeUdid(const void *udid)
} else {
g_localNetLedger.localInfo.role = ROLE_LEAF;
}
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "update local role from %d to %d",
role, g_localNetLedger.localInfo.role);
SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "update local role from %d to %d", role,
g_localNetLedger.localInfo.role);
}
return LnnSetMasterUdid(&g_localNetLedger.localInfo, (const char *)udid);
}

View File

@ -1,12 +1,28 @@
#include <string.h>
#include <algorithm>
#include <arpa/inet.h>
#include "tlv.h"
#include "discdeviceinfo.h"
namespace tlv
{
#define TYPE_UNKNOW_ID 0x00
#define TYPE_PHONE_ID 0x0E
#define TYPE_TV_ID 0x9C
#define TYPE_PC_ID 0x0C
DiscoveryDeviceInfo::DiscoveryDeviceInfo() {}
namespace tlv {
static int g_typeMapLen = 4;
static uint8_t g_typeMap[] = {
TYPE_UNKNOW_ID,
TYPE_PC_ID,
TYPE_PHONE_ID,
TYPE_TV_ID,
};
DiscoveryDeviceInfo::DiscoveryDeviceInfo()
{
}
DiscoveryDeviceInfo::~DiscoveryDeviceInfo()
{
@ -134,7 +150,9 @@ bool DiscoveryDeviceInfo::GetDevTypeValue(int type, int &value) const
{
std::map<int, Tlv *>::const_iterator itor = mTlvMap.find(type);
if (itor != mTlvMap.end()) {
value = ntohl((*(int *)(itor->second->GetValue())));
uint8_t typeId = ntohl((*(int *)(itor->second->GetValue())));
uint8_t *idIndex = std::find(g_typeMap, g_typeMap + g_typeMapLen, typeId);
value = idIndex - g_typeMap;
return true;
}
return false;