Skip to content

Commit

Permalink
add four new files.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoweihan committed Sep 11, 2017
1 parent deb9e93 commit e772130
Show file tree
Hide file tree
Showing 7 changed files with 474 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Src/Edislab/Edislab Pro/Edislab Pro.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;NEW_VERSION</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -174,7 +174,7 @@
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;NEW_VERSION</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down Expand Up @@ -281,6 +281,8 @@
<ClInclude Include="SensorData.h" />
<ClInclude Include="SensorDataManager.h" />
<ClInclude Include="SensorIDGenerator.h" />
<ClInclude Include="SensorManager.h" />
<ClInclude Include="SensorTypeTable.h" />
<ClInclude Include="SerialPortService.h" />
<ClInclude Include="SplitBar.h" />
<ClInclude Include="stdafx.h" />
Expand Down Expand Up @@ -343,6 +345,8 @@
<ClCompile Include="SensorData.cpp" />
<ClCompile Include="SensorDataManager.cpp" />
<ClCompile Include="SensorIDGenerator.cpp" />
<ClCompile Include="SensorManager.cpp" />
<ClCompile Include="SensorTypeTable.cpp" />
<ClCompile Include="SerialPortService.cpp" />
<ClCompile Include="SplitBar.cpp" />
<ClCompile Include="stdafx.cpp">
Expand Down
12 changes: 12 additions & 0 deletions Src/Edislab/Edislab Pro/Edislab Pro.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@
<ClInclude Include="DlgColumnCommon.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="SensorManager.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="SensorTypeTable.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Edislab Pro.cpp">
Expand Down Expand Up @@ -506,6 +512,12 @@
<ClCompile Include="DlgColumnCommon.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="SensorManager.cpp">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="SensorTypeTable.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Edislab Pro.rc">
Expand Down
105 changes: 105 additions & 0 deletions Src/Edislab/Edislab Pro/SensorManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*********************************************************
Copyright(C):
FileName:SensorManager.cpp
Descripton:全局传感器管理类
Author:xiaowei.han
Data:2017/09/11
Others:
History:
Version:1.0
*********************************************************/
#include "StdAfx.h"
#include "SensorManager.h"
#include <boost/thread/lock_factories.hpp>
#include <algorithm>
#include <string>

CSensorManager::CSensorManager(void)
{
m_SensorInfoArray.clear();
}


CSensorManager::~CSensorManager(void)
{
m_SensorInfoArray.clear();
}

/*********************************************************
FunctionName:RegisterSensor
FunctionDesc:注册传感器
InputParam:
OutputParam:
ResultValue:
Author:xiaowei.han
*********************************************************/
bool CSensorManager::RegisterSensor(const SENSOR_TYPE_INFO_ELEMENT& SensorElement)
{
auto Lock = boost::make_unique_lock(m_Lock);
auto Iter = std::find(m_SensorInfoArray.begin(),m_SensorInfoArray.end(),SensorElement);
//如果找到
if (Iter != m_SensorInfoArray.end())
{
return false;
}
m_SensorInfoArray.push_back(SensorElement);
return true;
}

/*********************************************************
FunctionName:RegisterSensor
FunctionDesc:注册传感器
InputParam:
OutputParam:
ResultValue:
Author:xiaowei.han
*********************************************************/
bool CSensorManager::RegisterSensor(int nSensorTypeID,int nSensorSerialID)
{
using namespace std;
//根据传感器类型的ID查询传感器的名称
string strSensorName;
return RegisterSensor(SENSOR_TYPE_INFO_ELEMENT(strSensorName,nSensorTypeID,nSensorSerialID));
}

/*********************************************************
FunctionName:RegisterSensor
FunctionDesc:注册传感器
InputParam:
OutputParam:
ResultValue:
Author:xiaowei.han
*********************************************************/
bool CSensorManager::UnRegisterSensor(const SENSOR_TYPE_INFO_ELEMENT& SensorElement)
{
auto Lock = boost::make_unique_lock(m_Lock);
auto Iter = std::find(m_SensorInfoArray.begin(),m_SensorInfoArray.end(),SensorElement);

//找到对应的元素
if (Iter != m_SensorInfoArray.end())
{
m_SensorInfoArray.erase(Iter);
}

return true;
}

/*********************************************************
FunctionName:RegisterSensor
FunctionDesc:注册传感器
InputParam:
OutputParam:
ResultValue:
Author:xiaowei.han
*********************************************************/
bool CSensorManager::UnRegisterSensor(int nSensorTypeID,int nSensorSerialID)
{
return UnRegisterSensor(SENSOR_TYPE_INFO_ELEMENT("",nSensorTypeID,nSensorSerialID));
}

CSensorManager& CSensorManager::CreateInstance(void)
{
return s_obj;
}

CSensorManager CSensorManager::s_obj;
41 changes: 41 additions & 0 deletions Src/Edislab/Edislab Pro/SensorManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*********************************************************
Copyright(C):
FileName:SensorManager.h
Descripton:全局传感器管理类
Author:xiaowei.han
Data:2017/09/11
Others:
History:
Version:1.0
*********************************************************/
#pragma once
#include <vector>
#include <boost/thread/mutex.hpp>
#include "Type.h"
class CSensorManager
{

public:
static CSensorManager& CreateInstance(void);
private:
CSensorManager(void);
virtual ~CSensorManager(void);

//开始注册一个传感器
bool RegisterSensor(const SENSOR_TYPE_INFO_ELEMENT& SensorElement);
//重载
bool RegisterSensor(int nSensorTypeID,int nSensorSerialID);
//反注册一个传感器
bool UnRegisterSensor(const SENSOR_TYPE_INFO_ELEMENT& SensorElement);
//重载
bool UnRegisterSensor(int nSensorTypeID,int nSensorSerialID);

private:
//传感器信息列表
std::vector<SENSOR_TYPE_INFO_ELEMENT> m_SensorInfoArray;
//
boost::mutex m_Lock;
//全局唯一实例
static CSensorManager s_obj;
};

Loading

0 comments on commit e772130

Please sign in to comment.