mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-04-15 09:38:16 +00:00
23
sdv_services/hardware_ident/CMakeLists.txt
Normal file
23
sdv_services/hardware_ident/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
# Define project
|
||||
project(hardware_ident VERSION 1.0 LANGUAGES CXX)
|
||||
|
||||
# Define target
|
||||
add_library(hardware_ident SHARED
|
||||
"hardware_ident.h"
|
||||
"hardware_ident.cpp")
|
||||
if (WIN32)
|
||||
target_link_libraries(hardware_ident ${CMAKE_THREAD_LIBS_INIT} Rpcrt4.lib)
|
||||
elseif(UNIX)
|
||||
#target_link_libraries(hardware_ident rt ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries(hardware_ident rt ${CMAKE_DL_LIBS})
|
||||
endif()
|
||||
target_link_options(hardware_ident PRIVATE)
|
||||
target_include_directories(hardware_ident PRIVATE ./include/)
|
||||
set_target_properties(hardware_ident PROPERTIES PREFIX "")
|
||||
set_target_properties(hardware_ident PROPERTIES SUFFIX ".sdv")
|
||||
|
||||
# Build dependencies
|
||||
add_dependencies(hardware_ident CompileCoreIDL)
|
||||
|
||||
# Appending the service in the service list
|
||||
set(SDV_Service_List ${SDV_Service_List} hardware_ident PARENT_SCOPE)
|
||||
101
sdv_services/hardware_ident/hardware_ident.cpp
Normal file
101
sdv_services/hardware_ident/hardware_ident.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#include "hardware_ident.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma push_macro("interface")
|
||||
#undef interface
|
||||
#pragma push_macro("GetObject")
|
||||
#undef GetObject
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <WinSock2.h>
|
||||
#include <Windows.h>
|
||||
#include <array>
|
||||
|
||||
// Resolve conflict
|
||||
#pragma pop_macro("GetObject")
|
||||
#pragma pop_macro("interface")
|
||||
#ifdef GetClassInfo
|
||||
#undef GetClassInfo
|
||||
#endif
|
||||
#ifndef __GNUC__
|
||||
#pragma comment(lib, "Rpcrt4.lib")
|
||||
#endif
|
||||
#elif defined __linux__
|
||||
#include <iostream>
|
||||
//#include <unistd.h>
|
||||
//#include <ifaddrs.h>
|
||||
//#include <netinet/in.h>
|
||||
//#include <arpa/inet.h>
|
||||
//#include <cstdint>
|
||||
//#include <linux/if_packet.h>
|
||||
#else
|
||||
#error OS is not supported!
|
||||
#endif
|
||||
|
||||
uint64_t CHardwareIdent::GetHardwareID()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
uint64_t MACAddr = 0;
|
||||
|
||||
UUID uuid;
|
||||
if (UuidCreateSequential(&uuid) == RPC_S_UUID_NO_ADDRESS)
|
||||
{
|
||||
SDV_LOG_ERROR("Error getting UUID!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Converting MAC address to uint64
|
||||
// INFO: Last 6 bytes of the uuid.Data4 contain MAC address and first two bytes contains variant and version,
|
||||
// that's why only last 6 bytes are taken here
|
||||
for (uint32_t ui_it = 2; ui_it < 8; ui_it++)
|
||||
{
|
||||
MACAddr = (MACAddr << 8) | uuid.Data4[ui_it];
|
||||
}
|
||||
|
||||
if (!MACAddr)
|
||||
{
|
||||
SDV_LOG_ERROR("Error getting MAC Address!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return MACAddr;
|
||||
#elif defined __linux__
|
||||
//struct ifaddrs *ifap, *ifa;
|
||||
//uint64_t MACAddr = 0;
|
||||
//if (getifaddrs(&ifap) == -1)
|
||||
//{
|
||||
// SDV_LOG_ERROR("Error getting 'if address'!");
|
||||
// return 0;
|
||||
//}
|
||||
//for (ifa = ifap; ifa != nullptr; ifa = ifa->ifa_next)
|
||||
//{
|
||||
// if (ifa->ifa_addr != nullptr && ifa->ifa_addr->sa_family == AF_PACKET)
|
||||
// {
|
||||
// struct sockaddr_ll* scktAddr = (struct sockaddr_ll*)ifa->ifa_addr;
|
||||
// if (scktAddr)
|
||||
// {
|
||||
// // Converting MAC address to uint64
|
||||
// for (uint32_t ui_it = 0; ui_it < 6; ui_it++)
|
||||
// {
|
||||
// MACAddr = (MACAddr << 8) | scktAddr->sll_addr[ui_it];
|
||||
// }
|
||||
// if (MACAddr != 0)
|
||||
// {
|
||||
// freeifaddrs(ifap);
|
||||
// return MACAddr;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
//freeifaddrs(ifap);
|
||||
//SDV_LOG_ERROR("Error getting MAC address of the interface!");
|
||||
//return 0;
|
||||
return 0x0102030405060708ll;
|
||||
#else
|
||||
#error OS is not supported!
|
||||
#endif
|
||||
}
|
||||
43
sdv_services/hardware_ident/hardware_ident.h
Normal file
43
sdv_services/hardware_ident/hardware_ident.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @file process_control.h
|
||||
* @author Sudipta Babu Durjoy FRD DISS21 (mailto:sudipta.durjoy@zf.com)
|
||||
* @brief
|
||||
* @version 1.0
|
||||
* @date 2023-10-23
|
||||
*
|
||||
* @copyright Copyright ZF Friedrichshafen AG (c) 2023
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef HARDWARE_IDENT_H
|
||||
#define HARDWARE_IDENT_H
|
||||
|
||||
#include <interfaces/hw_ident.h>
|
||||
#include <support/component_impl.h>
|
||||
|
||||
/**
|
||||
* @brief Hardware ID class
|
||||
*/
|
||||
class CHardwareIdent : public sdv::CSdvObject, public sdv::hardware::IHardwareID
|
||||
{
|
||||
public:
|
||||
|
||||
BEGIN_SDV_INTERFACE_MAP()
|
||||
SDV_INTERFACE_ENTRY(sdv::hardware::IHardwareID)
|
||||
END_SDV_INTERFACE_MAP()
|
||||
|
||||
// Object declarations
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::SystemObject)
|
||||
DECLARE_OBJECT_CLASS_NAME("HardwareIdentificationService")
|
||||
DECLARE_OBJECT_SINGLETON()
|
||||
|
||||
/**
|
||||
* @brief Gets the hardware ID of the current hardware.
|
||||
* It's same for the all processes running in the same hardware and different for the processes of each different hardwares.
|
||||
* @return Return the hardware ID.
|
||||
*/
|
||||
uint64_t GetHardwareID() override;
|
||||
};
|
||||
DEFINE_SDV_OBJECT(CHardwareIdent)
|
||||
|
||||
#endif // !define HARDWARE_IDENT_H
|
||||
Reference in New Issue
Block a user