Browse Source

故障滤波源码

master
lxd 7 hours ago
commit
6e66e98156
43 changed files with 6233 additions and 0 deletions
  1. 176
    0
      fault-recorder/.cproject
  2. 2
    0
      fault-recorder/.gitignore
  3. 28
    0
      fault-recorder/.project
  4. 25
    0
      fault-recorder/.settings/language.settings.xml
  5. 71
    0
      fault-recorder/.settings/org.eclipse.cdt.codan.core.prefs
  6. 17
    0
      fault-recorder/.settings/org.eclipse.cdt.core.prefs
  7. 2
    0
      fault-recorder/.settings/org.eclipse.core.resources.prefs
  8. 12
    0
      fault-recorder/.tracecompass/.project
  9. 35
    0
      fault-recorder/action/FaultRecorder.h
  10. 339
    0
      fault-recorder/action/impl/fault_filter.cpp
  11. 85
    0
      fault-recorder/action/impl/fault_filter.h
  12. 41
    0
      fault-recorder/common/GUID.cpp
  13. 37
    0
      fault-recorder/common/IFace.h
  14. 24
    0
      fault-recorder/common/IUnknown.h
  15. 445
    0
      fault-recorder/common/Type.h
  16. 67
    0
      fault-recorder/externservice/DAControlerI.h
  17. 123
    0
      fault-recorder/externservice/HardwareI.h
  18. 51
    0
      fault-recorder/externservice/ParaAnalysisI.h
  19. 73
    0
      fault-recorder/externservice/ProtocolI.h
  20. 33
    0
      fault-recorder/externservice/SoCreateI.h
  21. 86
    0
      fault-recorder/externservice/Sqlite3I.h
  22. 34
    0
      fault-recorder/externservice/SubContractI.h
  23. 247
    0
      fault-recorder/servicemodel/Base.h
  24. 279
    0
      fault-recorder/servicemodel/Channel.h
  25. 395
    0
      fault-recorder/servicemodel/Device.h
  26. 638
    0
      fault-recorder/servicemodel/Item.h
  27. 162
    0
      fault-recorder/servicemodel/Packet.h
  28. 120
    0
      fault-recorder/test/main.cpp
  29. 24
    0
      fault-recorder/util/ClassLoaderI.h
  30. 43
    0
      fault-recorder/util/CodeConverter.h
  31. 273
    0
      fault-recorder/util/easylogger/inc/elog.h
  32. 67
    0
      fault-recorder/util/easylogger/inc/elog_cfg.h
  33. 165
    0
      fault-recorder/util/easylogger/plugins/file/elog_file.c
  34. 72
    0
      fault-recorder/util/easylogger/plugins/file/elog_file.h
  35. 41
    0
      fault-recorder/util/easylogger/plugins/file/elog_file_cfg.h
  36. 160
    0
      fault-recorder/util/easylogger/plugins/file/elog_file_port.c
  37. 146
    0
      fault-recorder/util/easylogger/port/elog_port.c
  38. 872
    0
      fault-recorder/util/easylogger/src/elog.c
  39. 352
    0
      fault-recorder/util/easylogger/src/elog_async.c
  40. 104
    0
      fault-recorder/util/easylogger/src/elog_buf.c
  41. 103
    0
      fault-recorder/util/easylogger/src/elog_utils.c
  42. 141
    0
      fault-recorder/util/impl/ClassLoaderImpl.cpp
  43. 23
    0
      fault-recorder/util/impl/ClassLoaderImpl.h

+ 176
- 0
fault-recorder/.cproject View File

@@ -0,0 +1,176 @@
1
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
3
+	<storageModule moduleId="org.eclipse.cdt.core.settings">
4
+		<cconfiguration id="cdt.managedbuild.config.gnu.cross.exe.debug.2138360939">
5
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.cross.exe.debug.2138360939" moduleId="org.eclipse.cdt.core.settings" name="Debug">
6
+				<externalSettings/>
7
+				<extensions>
8
+					<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
9
+					<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
10
+					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
11
+					<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
12
+					<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
13
+					<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
14
+				</extensions>
15
+			</storageModule>
16
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
17
+				<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="rm -rf" description="" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.config.gnu.cross.exe.debug.2138360939" name="Debug" parent="cdt.managedbuild.config.gnu.cross.exe.debug" postannouncebuildStep="" postbuildStep="" preannouncebuildStep="" prebuildStep="">
18
+					<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.debug.2138360939." name="/" resourcePath="">
19
+						<toolChain errorParsers="" id="cdt.managedbuild.toolchain.gnu.cross.base.1936848423" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.base">
20
+							<option id="cdt.managedbuild.option.gnu.cross.prefix.1887783547" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix" useByScannerDiscovery="false" value="arm-linux-gnueabihf-" valueType="string"/>
21
+							<option id="cdt.managedbuild.option.gnu.cross.path.202879637" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path" useByScannerDiscovery="false" value="D:\work\environment\Linaro\Linaro\Linaro\gcc-linaro-arm-linux-gnueabihf-4.7-2013.04\bin" valueType="string"/>
22
+							<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.1373559" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
23
+							<builder buildPath="${workspace_loc:/DataRecorder}/Debug" errorParsers="org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.CWDLocator" id="cdt.managedbuild.builder.gnu.cross.1893100842" keepEnvironmentInBuildfile="false" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
24
+							<tool command="gcc" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.tool.gnu.cross.c.compiler.1272021828" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
25
+								<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.option.optimization.level.617705162" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
26
+								<option id="gnu.c.compiler.option.debugging.level.959485317" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.max" valueType="enumerated"/>
27
+								<option id="gnu.c.compiler.option.include.paths.525395456" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
28
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/util/easylogger/plugins/file}&quot;"/>
29
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/util/easylogger/inc}&quot;"/>
30
+								</option>
31
+								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1910377172" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
32
+							</tool>
33
+							<tool command="g++" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GCCErrorParser" id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.1004400997" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
34
+								<option id="gnu.cpp.compiler.option.optimization.level.1057532236" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
35
+								<option id="gnu.cpp.compiler.option.debugging.level.1392533079" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.default" valueType="enumerated"/>
36
+								<option id="gnu.cpp.compiler.option.dialect.std.1331987922" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.c++11" valueType="enumerated"/>
37
+								<option id="gnu.cpp.compiler.option.include.paths.345885659" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
38
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/util/easylogger/inc}&quot;"/>
39
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/util/easylogger/plugins/file}&quot;"/>
40
+								</option>
41
+								<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1901217181" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
42
+							</tool>
43
+							<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.2097579122" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker"/>
44
+							<tool command="g++" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GLDErrorParser" id="cdt.managedbuild.tool.gnu.cross.cpp.linker.1052998212" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker">
45
+								<option id="gnu.cpp.link.option.flags.2001063983" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="-pthread" valueType="string"/>
46
+								<option id="gnu.cpp.link.option.libs.372818395" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs">
47
+									<listOptionValue builtIn="false" value="dl"/>
48
+								</option>
49
+								<option id="gnu.cpp.link.option.paths.233768696" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" useByScannerDiscovery="false"/>
50
+								<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1135444603" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
51
+									<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
52
+									<additionalInput kind="additionalinput" paths="$(LIBS)"/>
53
+								</inputType>
54
+							</tool>
55
+							<tool id="cdt.managedbuild.tool.gnu.cross.archiver.728802781" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/>
56
+							<tool command="as" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" errorParsers="org.eclipse.cdt.core.GASErrorParser" id="cdt.managedbuild.tool.gnu.cross.assembler.1755437130" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler">
57
+								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.618253824" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
58
+							</tool>
59
+						</toolChain>
60
+					</folderInfo>
61
+					<sourceEntries>
62
+						<entry excluding="util/iLOG" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
63
+					</sourceEntries>
64
+				</configuration>
65
+			</storageModule>
66
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
67
+		</cconfiguration>
68
+		<cconfiguration id="cdt.managedbuild.config.gnu.cross.exe.release.122047322">
69
+			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.cross.exe.release.122047322" moduleId="org.eclipse.cdt.core.settings" name="Release">
70
+				<externalSettings>
71
+					<externalSetting>
72
+						<entry flags="VALUE_WORKSPACE_PATH" kind="includePath" name="/DataRecorder"/>
73
+						<entry flags="VALUE_WORKSPACE_PATH" kind="includePath" name="/data-publish"/>
74
+						<entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/DataRecorder/Release"/>
75
+						<entry flags="VALUE_WORKSPACE_PATH" kind="libraryPath" name="/data-publish/Release"/>
76
+						<entry flags="RESOLVED" kind="libraryFile" name="DataRecorder" srcPrefixMapping="" srcRootPath=""/>
77
+						<entry flags="RESOLVED" kind="libraryFile" name="data-publish" srcPrefixMapping="" srcRootPath=""/>
78
+					</externalSetting>
79
+				</externalSettings>
80
+				<extensions>
81
+					<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
82
+					<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
83
+					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
84
+					<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
85
+					<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
86
+					<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
87
+				</extensions>
88
+			</storageModule>
89
+			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
90
+				<configuration artifactExtension="so" artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.sharedLib" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.sharedLib,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.cross.exe.release.122047322" name="Release" parent="cdt.managedbuild.config.gnu.cross.exe.release">
91
+					<folderInfo id="cdt.managedbuild.config.gnu.cross.exe.release.122047322." name="/" resourcePath="">
92
+						<toolChain id="cdt.managedbuild.toolchain.gnu.cross.exe.release.1706380992" name="Cross GCC" superClass="cdt.managedbuild.toolchain.gnu.cross.exe.release">
93
+							<option id="cdt.managedbuild.option.gnu.cross.prefix.1548789870" name="Prefix" superClass="cdt.managedbuild.option.gnu.cross.prefix" useByScannerDiscovery="false" value="arm-linux-gnueabihf-" valueType="string"/>
94
+							<option id="cdt.managedbuild.option.gnu.cross.path.986643423" name="Path" superClass="cdt.managedbuild.option.gnu.cross.path" useByScannerDiscovery="false" value="C:\Program Files (x86)\Linaro\gcc-linaro-arm-linux-gnueabihf-4.9-2014.07\bin" valueType="string"/>
95
+							<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.targetPlatform.gnu.cross.1702889585" isAbstract="false" osList="all" superClass="cdt.managedbuild.targetPlatform.gnu.cross"/>
96
+							<builder buildPath="${workspace_loc:/DataRecorder}/Release" id="cdt.managedbuild.builder.gnu.cross.1393333861" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" superClass="cdt.managedbuild.builder.gnu.cross"/>
97
+							<tool id="cdt.managedbuild.tool.gnu.cross.c.compiler.132683770" name="Cross GCC Compiler" superClass="cdt.managedbuild.tool.gnu.cross.c.compiler">
98
+								<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.option.optimization.level.1525544860" name="Optimization Level" superClass="gnu.c.compiler.option.optimization.level" useByScannerDiscovery="false" valueType="enumerated"/>
99
+								<option id="gnu.c.compiler.option.debugging.level.1484332544" name="Debug Level" superClass="gnu.c.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.c.debugging.level.none" valueType="enumerated"/>
100
+								<option id="gnu.c.compiler.option.misc.pic.1517126873" name="Position Independent Code (-fPIC)" superClass="gnu.c.compiler.option.misc.pic" useByScannerDiscovery="false" value="true" valueType="boolean"/>
101
+								<option id="gnu.c.compiler.option.include.paths.706624843" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
102
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/util/easylogger/plugins/file}&quot;"/>
103
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/util/easylogger/inc}&quot;"/>
104
+								</option>
105
+								<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.3627946" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
106
+							</tool>
107
+							<tool id="cdt.managedbuild.tool.gnu.cross.cpp.compiler.1056154732" name="Cross G++ Compiler" superClass="cdt.managedbuild.tool.gnu.cross.cpp.compiler">
108
+								<option id="gnu.cpp.compiler.option.optimization.level.1391650391" name="Optimization Level" superClass="gnu.cpp.compiler.option.optimization.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
109
+								<option id="gnu.cpp.compiler.option.debugging.level.1773002192" name="Debug Level" superClass="gnu.cpp.compiler.option.debugging.level" useByScannerDiscovery="false" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
110
+								<option id="gnu.cpp.compiler.option.dialect.std.1602220224" name="Language standard" superClass="gnu.cpp.compiler.option.dialect.std" useByScannerDiscovery="true" value="gnu.cpp.compiler.dialect.c++11" valueType="enumerated"/>
111
+								<option id="gnu.cpp.compiler.option.other.pic.626655716" name="Position Independent Code (-fPIC)" superClass="gnu.cpp.compiler.option.other.pic" useByScannerDiscovery="false" value="true" valueType="boolean"/>
112
+								<option id="gnu.cpp.compiler.option.debugging.codecov.288291752" name="Generate gcov information (-ftest-coverage -fprofile-arcs)" superClass="gnu.cpp.compiler.option.debugging.codecov" useByScannerDiscovery="false" value="false" valueType="boolean"/>
113
+								<option id="gnu.cpp.compiler.option.include.paths.1501630149" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" useByScannerDiscovery="false" valueType="includePath">
114
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/util/easylogger/inc}&quot;"/>
115
+									<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/util/easylogger/plugins/file}&quot;"/>
116
+								</option>
117
+								<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1380180965" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
118
+							</tool>
119
+							<tool id="cdt.managedbuild.tool.gnu.cross.c.linker.736173333" name="Cross GCC Linker" superClass="cdt.managedbuild.tool.gnu.cross.c.linker">
120
+								<option defaultValue="true" id="gnu.c.link.option.shared.1414022703" name="Shared (-shared)" superClass="gnu.c.link.option.shared" valueType="boolean"/>
121
+							</tool>
122
+							<tool id="cdt.managedbuild.tool.gnu.cross.cpp.linker.477312996" name="Cross G++ Linker" superClass="cdt.managedbuild.tool.gnu.cross.cpp.linker">
123
+								<option id="gnu.cpp.link.option.libs.386922318" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs">
124
+									<listOptionValue builtIn="false" value="dl"/>
125
+								</option>
126
+								<option id="gnu.cpp.link.option.flags.2045113115" name="Linker flags" superClass="gnu.cpp.link.option.flags" useByScannerDiscovery="false" value="-pthread" valueType="string"/>
127
+								<option defaultValue="true" id="gnu.cpp.link.option.shared.1816003077" name="Shared (-shared)" superClass="gnu.cpp.link.option.shared" useByScannerDiscovery="false" value="true" valueType="boolean"/>
128
+								<option id="gnu.cpp.link.option.paths.1081825874" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" useByScannerDiscovery="false"/>
129
+								<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1672914678" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
130
+									<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
131
+									<additionalInput kind="additionalinput" paths="$(LIBS)"/>
132
+								</inputType>
133
+								<outputType id="cdt.managedbuild.tool.gnu.cpp.linker.output.870029683" outputPrefix="lib" superClass="cdt.managedbuild.tool.gnu.cpp.linker.output"/>
134
+							</tool>
135
+							<tool id="cdt.managedbuild.tool.gnu.cross.archiver.1071505409" name="Cross GCC Archiver" superClass="cdt.managedbuild.tool.gnu.cross.archiver"/>
136
+							<tool id="cdt.managedbuild.tool.gnu.cross.assembler.265435169" name="Cross GCC Assembler" superClass="cdt.managedbuild.tool.gnu.cross.assembler">
137
+								<inputType id="cdt.managedbuild.tool.gnu.assembler.input.810158662" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
138
+							</tool>
139
+						</toolChain>
140
+					</folderInfo>
141
+					<sourceEntries>
142
+						<entry excluding="util/iLOG|test" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
143
+					</sourceEntries>
144
+				</configuration>
145
+			</storageModule>
146
+			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
147
+		</cconfiguration>
148
+	</storageModule>
149
+	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
150
+		<project id="DataRecorder.cdt.managedbuild.target.gnu.cross.exe.1906770588" name="Executable" projectType="cdt.managedbuild.target.gnu.cross.exe"/>
151
+	</storageModule>
152
+	<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
153
+	<storageModule moduleId="refreshScope"/>
154
+	<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
155
+	<storageModule moduleId="scannerConfiguration">
156
+		<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
157
+		<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.debug.2138360939;cdt.managedbuild.config.gnu.cross.exe.debug.2138360939.;cdt.managedbuild.tool.gnu.cross.cpp.compiler.973926341;cdt.managedbuild.tool.gnu.cpp.compiler.input.432585081">
158
+			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
159
+		</scannerConfigBuildInfo>
160
+		<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.debug.2138360939;cdt.managedbuild.config.gnu.cross.exe.debug.2138360939.;cdt.managedbuild.tool.gnu.cross.c.compiler.1549910781;cdt.managedbuild.tool.gnu.c.compiler.input.113289778">
161
+			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
162
+		</scannerConfigBuildInfo>
163
+		<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.release.122047322;cdt.managedbuild.config.gnu.cross.exe.release.122047322.;cdt.managedbuild.tool.gnu.cross.c.compiler.132683770;cdt.managedbuild.tool.gnu.c.compiler.input.3627946">
164
+			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
165
+		</scannerConfigBuildInfo>
166
+		<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.debug.2138360939;cdt.managedbuild.config.gnu.cross.exe.debug.2138360939.;cdt.managedbuild.tool.gnu.cross.c.compiler.1272021828;cdt.managedbuild.tool.gnu.c.compiler.input.1910377172">
167
+			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
168
+		</scannerConfigBuildInfo>
169
+		<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.release.122047322;cdt.managedbuild.config.gnu.cross.exe.release.122047322.;cdt.managedbuild.tool.gnu.cross.cpp.compiler.1056154732;cdt.managedbuild.tool.gnu.cpp.compiler.input.1380180965">
170
+			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
171
+		</scannerConfigBuildInfo>
172
+		<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.cross.exe.debug.2138360939;cdt.managedbuild.config.gnu.cross.exe.debug.2138360939.;cdt.managedbuild.tool.gnu.cross.cpp.compiler.1004400997;cdt.managedbuild.tool.gnu.cpp.compiler.input.1901217181">
173
+			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
174
+		</scannerConfigBuildInfo>
175
+	</storageModule>
176
+</cproject>

+ 2
- 0
fault-recorder/.gitignore View File

@@ -0,0 +1,2 @@
1
+/Release/
2
+/Debug/

+ 28
- 0
fault-recorder/.project View File

@@ -0,0 +1,28 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>fault-recorder</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+		<buildCommand>
9
+			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
10
+			<triggers>clean,full,incremental,</triggers>
11
+			<arguments>
12
+			</arguments>
13
+		</buildCommand>
14
+		<buildCommand>
15
+			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
16
+			<triggers>full,incremental,</triggers>
17
+			<arguments>
18
+			</arguments>
19
+		</buildCommand>
20
+	</buildSpec>
21
+	<natures>
22
+		<nature>org.eclipse.cdt.core.cnature</nature>
23
+		<nature>org.eclipse.cdt.core.ccnature</nature>
24
+		<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
25
+		<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
26
+		<nature>org.eclipse.linuxtools.tmf.project.nature</nature>
27
+	</natures>
28
+</projectDescription>

+ 25
- 0
fault-recorder/.settings/language.settings.xml View File

@@ -0,0 +1,25 @@
1
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+<project>
3
+	<configuration id="cdt.managedbuild.config.gnu.cross.exe.debug.2138360939" name="Debug">
4
+		<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
5
+			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
6
+			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
7
+			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
8
+			<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-1498762397657668654" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
9
+				<language-scope id="org.eclipse.cdt.core.gcc"/>
10
+				<language-scope id="org.eclipse.cdt.core.g++"/>
11
+			</provider>
12
+		</extension>
13
+	</configuration>
14
+	<configuration id="cdt.managedbuild.config.gnu.cross.exe.release.122047322" name="Release">
15
+		<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
16
+			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
17
+			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
18
+			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
19
+			<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="446225753165184601" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
20
+				<language-scope id="org.eclipse.cdt.core.gcc"/>
21
+				<language-scope id="org.eclipse.cdt.core.g++"/>
22
+			</provider>
23
+		</extension>
24
+	</configuration>
25
+</project>

+ 71
- 0
fault-recorder/.settings/org.eclipse.cdt.codan.core.prefs View File

@@ -0,0 +1,71 @@
1
+eclipse.preferences.version=1
2
+org.eclipse.cdt.codan.checkers.errnoreturn=Warning
3
+org.eclipse.cdt.codan.checkers.errnoreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No return\\")",implicit\=>false}
4
+org.eclipse.cdt.codan.checkers.errreturnvalue=Error
5
+org.eclipse.cdt.codan.checkers.errreturnvalue.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused return value\\")"}
6
+org.eclipse.cdt.codan.checkers.nocommentinside=-Error
7
+org.eclipse.cdt.codan.checkers.nocommentinside.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Nesting comments\\")"}
8
+org.eclipse.cdt.codan.checkers.nolinecomment=-Error
9
+org.eclipse.cdt.codan.checkers.nolinecomment.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Line comments\\")"}
10
+org.eclipse.cdt.codan.checkers.noreturn=Error
11
+org.eclipse.cdt.codan.checkers.noreturn.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No return value\\")",implicit\=>false}
12
+org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation=Error
13
+org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Abstract class cannot be instantiated\\")"}
14
+org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem=Error
15
+org.eclipse.cdt.codan.internal.checkers.AmbiguousProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Ambiguous problem\\")"}
16
+org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem=Warning
17
+org.eclipse.cdt.codan.internal.checkers.AssignmentInConditionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Assignment in condition\\")"}
18
+org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem=Error
19
+org.eclipse.cdt.codan.internal.checkers.AssignmentToItselfProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Assignment to itself\\")"}
20
+org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem=Warning
21
+org.eclipse.cdt.codan.internal.checkers.CaseBreakProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"No break at end of case\\")",no_break_comment\=>"no break",last_case_param\=>false,empty_case_param\=>false,enable_fallthrough_quickfix_param\=>false}
22
+org.eclipse.cdt.codan.internal.checkers.CatchByReference=Warning
23
+org.eclipse.cdt.codan.internal.checkers.CatchByReference.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Catching by reference is recommended\\")",unknown\=>false,exceptions\=>()}
24
+org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem=Error
25
+org.eclipse.cdt.codan.internal.checkers.CircularReferenceProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Circular inheritance\\")"}
26
+org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization=Warning
27
+org.eclipse.cdt.codan.internal.checkers.ClassMembersInitialization.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Class members should be properly initialized\\")",skip\=>true}
28
+org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem=Error
29
+org.eclipse.cdt.codan.internal.checkers.FieldResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Field cannot be resolved\\")"}
30
+org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem=Error
31
+org.eclipse.cdt.codan.internal.checkers.FunctionResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Function cannot be resolved\\")"}
32
+org.eclipse.cdt.codan.internal.checkers.InvalidArguments=Error
33
+org.eclipse.cdt.codan.internal.checkers.InvalidArguments.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid arguments\\")"}
34
+org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem=Error
35
+org.eclipse.cdt.codan.internal.checkers.InvalidTemplateArgumentsProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid template argument\\")"}
36
+org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem=Error
37
+org.eclipse.cdt.codan.internal.checkers.LabelStatementNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Label statement not found\\")"}
38
+org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem=Error
39
+org.eclipse.cdt.codan.internal.checkers.MemberDeclarationNotFoundProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Member declaration not found\\")"}
40
+org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem=Error
41
+org.eclipse.cdt.codan.internal.checkers.MethodResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Method cannot be resolved\\")"}
42
+org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker=-Info
43
+org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Name convention for function\\")",pattern\=>"^[a-z]",macro\=>true,exceptions\=>()}
44
+org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem=Warning
45
+org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructorProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Class has a virtual method and non-virtual destructor\\")"}
46
+org.eclipse.cdt.codan.internal.checkers.OverloadProblem=Error
47
+org.eclipse.cdt.codan.internal.checkers.OverloadProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid overload\\")"}
48
+org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem=Error
49
+org.eclipse.cdt.codan.internal.checkers.RedeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid redeclaration\\")"}
50
+org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem=Error
51
+org.eclipse.cdt.codan.internal.checkers.RedefinitionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Invalid redefinition\\")"}
52
+org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem=-Warning
53
+org.eclipse.cdt.codan.internal.checkers.ReturnStyleProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Return with parenthesis\\")"}
54
+org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem=-Warning
55
+org.eclipse.cdt.codan.internal.checkers.ScanfFormatStringSecurityProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Format String Vulnerability\\")"}
56
+org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem=Warning
57
+org.eclipse.cdt.codan.internal.checkers.StatementHasNoEffectProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Statement has no effect\\")",macro\=>true,exceptions\=>()}
58
+org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem=Warning
59
+org.eclipse.cdt.codan.internal.checkers.SuggestedParenthesisProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Suggested parenthesis around expression\\")",paramNot\=>false}
60
+org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem=Warning
61
+org.eclipse.cdt.codan.internal.checkers.SuspiciousSemicolonProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Suspicious semicolon\\")",else\=>false,afterelse\=>false}
62
+org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem=Error
63
+org.eclipse.cdt.codan.internal.checkers.TypeResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Type cannot be resolved\\")"}
64
+org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem=Warning
65
+org.eclipse.cdt.codan.internal.checkers.UnusedFunctionDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused function declaration\\")",macro\=>true}
66
+org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem=Warning
67
+org.eclipse.cdt.codan.internal.checkers.UnusedStaticFunctionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused static function\\")",macro\=>true}
68
+org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem=Warning
69
+org.eclipse.cdt.codan.internal.checkers.UnusedVariableDeclarationProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Unused variable declaration in file scope\\")",macro\=>true,exceptions\=>("@(\#)","$Id")}
70
+org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem=Error
71
+org.eclipse.cdt.codan.internal.checkers.VariableResolutionProblem.params={launchModes\=>{RUN_ON_FULL_BUILD\=>true,RUN_ON_INC_BUILD\=>true,RUN_ON_FILE_OPEN\=>false,RUN_ON_FILE_SAVE\=>false,RUN_AS_YOU_TYPE\=>true,RUN_ON_DEMAND\=>true},suppression_comment\=>"@suppress(\\"Symbol is not resolved\\")"}

+ 17
- 0
fault-recorder/.settings/org.eclipse.cdt.core.prefs View File

@@ -0,0 +1,17 @@
1
+eclipse.preferences.version=1
2
+environment/project/cdt.managedbuild.config.gnu.cross.exe.debug.2138360939/CWD/delimiter=\:
3
+environment/project/cdt.managedbuild.config.gnu.cross.exe.debug.2138360939/CWD/operation=replace
4
+environment/project/cdt.managedbuild.config.gnu.cross.exe.debug.2138360939/CWD/value=/home/vsbest/nc_eaas_dts/nc_eaas/COM/DataRecorder/Debug
5
+environment/project/cdt.managedbuild.config.gnu.cross.exe.debug.2138360939/PATH/delimiter=;
6
+environment/project/cdt.managedbuild.config.gnu.cross.exe.debug.2138360939/PATH/operation=replace
7
+environment/project/cdt.managedbuild.config.gnu.cross.exe.debug.2138360939/PATH/value=D\:\\work\\environment\\Linaro\\Linaro\\Linaro\\gcc-linaro-arm-linux-gnueabihf-4.7-2013.04\\bin\\;C\:\\Program Files (x86)\\Java\\jre1.8.0_45;C\:\\Program Files (x86)\\ForceControl V7.0;C\:\\Program Files\\nodejs\\;C\:\\Program Files (x86)\\MySQL\\MySQL Fabric 1.5.4 & MySQL Utilities 1.5.4 1.5\\;C\:\\Program Files (x86)\\MySQL\\MySQL Fabric 1.5.4 & MySQL Utilities 1.5.4 1.5\\Doctrine extensions for PHP\\;C\:\\Program Files\\VisualSVN Server\\bin;C\:\\Program Files\\TortoiseSVN\\bin;C\:\\Program Files\\Java\\jdk1.8.0_60\\bin;C\:\\Program Files\\Java\\jdk1.8.0_60\\jre\\bin;C\:\\Program Files (x86)\\IDM Computer Solutions\\UltraCompare;D\:\\apache-maven-3.3.9\\bin;C\:\\Users\\nego\\bin\\Sencha\\Cmd\\6.0.2.14/..;C\:\\Ruby22-x64\\bin;C\:\\Users\\nego\\AppData\\Roaming\\npm;C\:\\Users\\nego\\AppData\\Local\\Microsoft\\WindowsApps;;D\:\\\u8FC5\u96F7\u4E0B\u8F7D\\eclipse
8
+environment/project/cdt.managedbuild.config.gnu.cross.exe.debug.2138360939/PWD/delimiter=;
9
+environment/project/cdt.managedbuild.config.gnu.cross.exe.debug.2138360939/PWD/operation=replace
10
+environment/project/cdt.managedbuild.config.gnu.cross.exe.debug.2138360939/PWD/value=/home/vsbest/nc_eaas_dts/nc_eaas/COM/DataRecorder/Debug
11
+environment/project/cdt.managedbuild.config.gnu.cross.exe.debug.2138360939/append=true
12
+environment/project/cdt.managedbuild.config.gnu.cross.exe.debug.2138360939/appendContributed=true
13
+environment/project/cdt.managedbuild.config.gnu.cross.exe.release.122047322/PATH/delimiter=;
14
+environment/project/cdt.managedbuild.config.gnu.cross.exe.release.122047322/PATH/operation=replace
15
+environment/project/cdt.managedbuild.config.gnu.cross.exe.release.122047322/PATH/value=D\:\\work\\environment\\Linaro\\Linaro\\Linaro\\gcc-linaro-arm-linux-gnueabihf-4.7-2013.04\\bin;C\:/Program Files/Java/jre1.8.0_131/bin/server;C\:/Program Files/Java/jre1.8.0_131/bin;C\:/Program Files/Java/jre1.8.0_131/lib/amd64;C\:\\ProgramData\\Oracle\\Java\\javapath;C\:\\Windows\\system32;C\:\\Windows;C\:\\Windows\\System32\\Wbem;C\:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C\:\\Program Files (x86)\\Common Files\\lenovo\\easyplussdk\\bin;C\:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C\:\\Program Files\\Intel\\WiFi\\bin\\;C\:\\Program Files\\Common Files\\Intel\\WirelessCommon\\;C\:\\WINDOWS\\system32;C\:\\WINDOWS;C\:\\WINDOWS\\System32\\Wbem;C\:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C\:\\Program Files\\TortoiseSVN\\bin;C\:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\;C\:\\Program Files\\Microsoft SQL Server\\100\\Tools\\Binn\\;C\:\\Program Files\\Microsoft SQL Server\\100\\DTS\\Binn\\;C\:\\Program Files\\MySQL\\MySQL Utilities 1.6\\;C\:\\Program Files\\nodejs\\;C\:\\Users\\vsbes\\AppData\\Local\\Microsoft\\WindowsApps;C\:\\Users\\vsbes\\AppData\\Roaming\\npm;C\:\\Users\\vsbes\\AppData\\Local\\atom\\bin;E\:\\soft\\eclipse
16
+environment/project/cdt.managedbuild.config.gnu.cross.exe.release.122047322/append=true
17
+environment/project/cdt.managedbuild.config.gnu.cross.exe.release.122047322/appendContributed=true

+ 2
- 0
fault-recorder/.settings/org.eclipse.core.resources.prefs View File

@@ -0,0 +1,2 @@
1
+eclipse.preferences.version=1
2
+encoding/<project>=UTF-8

+ 12
- 0
fault-recorder/.tracecompass/.project View File

@@ -0,0 +1,12 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<projectDescription>
3
+	<name>.tracecompass-fault-recorder</name>
4
+	<comment></comment>
5
+	<projects>
6
+	</projects>
7
+	<buildSpec>
8
+	</buildSpec>
9
+	<natures>
10
+		<nature>org.eclipse.linuxtools.tmf.project.nature</nature>
11
+	</natures>
12
+</projectDescription>

+ 35
- 0
fault-recorder/action/FaultRecorder.h View File

@@ -0,0 +1,35 @@
1
+/*
2
+ * FaultRecorder.h
3
+ *
4
+ *  Created on: 2024年11月12日
5
+ *      Author: 13168
6
+ */
7
+
8
+#ifndef ACTION_FAULTRECORDER_H_
9
+#define ACTION_FAULTRECORDER_H_
10
+//#include "../servicemodel/Device.h"
11
+//#include "impl/fault_filter.h"
12
+
13
+#include "../common/IUnknown.h"
14
+#include "../common/Type.h"
15
+
16
+//class data_item;
17
+class Device;
18
+
19
+interface ProtocolI_Fault
20
+{
21
+    /*故障滤波*/
22
+    virtual HRESULT set_fault_list(std::vector<Device*> data_list) = 0;
23
+
24
+    #if 0
25
+    virtual HRESULT fault_filter(
26
+        data_item *fault_type,       //触发故障的源类型
27
+        data_item *source_data,      //源数据
28
+        int save_time_before,   //保存故障发生前的数据时间
29
+        int save_time_after     //保存故障发生后的数据时间
30
+    ) = 0;
31
+    #endif
32
+    virtual ~ProtocolI_Fault(){}
33
+};
34
+
35
+#endif /* ACTION_FAULTRECORDER_H_ */

+ 339
- 0
fault-recorder/action/impl/fault_filter.cpp View File

@@ -0,0 +1,339 @@
1
+/**
2
+ * @content:FaultFilter组件实现文件
3
+ * @time:2024-10-09
4
+ * @author:lxd
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2024-10-09#V1.0#首次生成
8
+ */
9
+
10
+//#include "../../externservice/ProtocolI.h"
11
+
12
+#include <cmath>
13
+#include <cstdlib>
14
+#include <vector>
15
+
16
+#include <fstream>
17
+#include <sstream>
18
+#include <chrono>
19
+#include <iomanip>
20
+#include <cstdlib>
21
+#include "fault_filter.h"
22
+
23
+#include "../../common/GUID.cpp"
24
+#include "../../servicemodel/Base.h"
25
+#include "../../servicemodel/Channel.h"
26
+#include "../../servicemodel/Device.h"
27
+#include "../../servicemodel/Item.h"
28
+#include "../../servicemodel/Packet.h"
29
+//#include "../../service/DAControlerI.h"
30
+
31
+using namespace std;
32
+
33
+static std::string file_save_path = "/home/";
34
+
35
+struct fault_data {
36
+public:
37
+    long long time;
38
+    std::string device_name;
39
+    std::string name;
40
+    std::string id;
41
+    std::string value;
42
+
43
+    // 默认构造函数
44
+    fault_data() : time(0), device_name(""),     name(""), id(""), value("") {}
45
+
46
+    // 带参数的构造函数
47
+    fault_data(long long T, std::string d, std::string n, std::string a, std::string s)
48
+        : time(T),  device_name(d), name(n), id(a), value(s) {}
49
+};
50
+
51
+//获取源文件中最后10分钟的数据
52
+std::vector<fault_data> get_data_for_CSV(const std::string& back_filename, long long current_time, int save_time_before)
53
+{
54
+    std::string line;
55
+    long long base_time = current_time - save_time_before*60;
56
+    std::vector<fault_data> records;
57
+    std::ifstream file(back_filename);
58
+
59
+    // 读取文件并解析数据
60
+    while (std::getline(file, line))
61
+    {
62
+        std::istringstream ss(line);
63
+        long long time;
64
+        std::string device_name;
65
+        std::string name;
66
+        std::string id;
67
+        std::string value;
68
+
69
+        //CSV文件格式为:时间戳,设备名称,采集点名称,ID,值
70
+        if (std::getline(ss, line, ','))
71
+        {
72
+            time = std::stoll(line);
73
+        }
74
+
75
+        //最后10分钟的数据进行保存
76
+        if (time < base_time) {
77
+            continue;
78
+        }
79
+        std::getline(ss, device_name, ',');
80
+        std::getline(ss, name, ',');
81
+        std::getline(ss, id, ',');
82
+        std::getline(ss, value, ',');
83
+        if (std::getline(ss, name, ','))
84
+        {
85
+            std::getline(ss, line, ',');
86
+            id = std::stoi(line);
87
+        }
88
+        if (std::getline(ss, line))
89
+        {
90
+            value = std::stod(line);
91
+        }
92
+        records.emplace_back(time, device_name, name, id, value);
93
+    }
94
+    return records;
95
+}
96
+void save_to_CSV(const std::string& filename, const std::vector<fault_data>& dataList)
97
+{
98
+    std::ofstream file(filename,  std::ios::app);
99
+
100
+    // 检查文件是否成功打开
101
+    if (!file.is_open()) {
102
+        //无法打开,则创建文件
103
+        FILE *total_fp;
104
+        total_fp = fopen("filename", "a+");
105
+        // 写入CSV头部
106
+        printf("写入CSV文件头部\n");
107
+        file << "time,device_name,Name,id,value\n";
108
+        fclose(total_fp);
109
+    }
110
+
111
+    // 写入数据
112
+    for (const auto& data : dataList) {
113
+        file << data.time << "," << data.device_name << "," << data.name << "," << data.id << "," << data.value << "\n";
114
+    }
115
+}
116
+
117
+/*
118
+外部调用接口
119
+Item *fault_type: 触发故障的源类型
120
+Item *source_data: 源数据
121
+int save_time_before: 保存故障发生前的数据时间
122
+int save_time_after: 保存故障发生后的数据时间
123
+*/
124
+HRESULT ProtocolImpl::fault_filter(data_item* fault_type, data_item* source_data, int save_time_before, int save_time_after)
125
+{
126
+    int source_len = 0, i = 0, fault_type_number = 0, temp_count = 0;
127
+    std::string fault_value, fault_id;
128
+    std::string st_id;
129
+    std::string file_name;
130
+    std::string fault_name;
131
+    std::string fault_file_name;
132
+    std::vector<fault_data> source_before_data;
133
+    std::vector<fault_data> fault_before_data;
134
+    //故障文件参数
135
+    fault_type_number = fault_type->number;
136
+    //源文件参数
137
+    source_len = source_data->number;
138
+    std::vector<fault_data> v_data(source_len);
139
+
140
+    printf("fault_type_number is %d, source_len is %d\n", fault_type_number, source_len);
141
+    //获取当前时间;
142
+    auto now = std::chrono::system_clock::now();
143
+    //转换为秒
144
+    long long current_time = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
145
+    // 转换为系统时间
146
+    std::time_t now_time_t = std::chrono::system_clock::to_time_t(now);
147
+
148
+    // 将时间转换为字符串格式
149
+    std::tm *now_tm = std::localtime(&now_time_t);
150
+    char time_buffer[80];
151
+    std::strftime(time_buffer, sizeof(time_buffer), "%Y-%m-%d %H:%M:%S", now_tm);
152
+    //故障检测
153
+    for (i = 0; i < fault_type_number; ++i)
154
+    {
155
+        fault_value = fault_type->fault_pitem.at(i).value.c_str();
156
+        fault_name = fault_type->fault_pitem.at(i).name.c_str();
157
+        int fault_value_I = strtol(fault_value.c_str(), NULL, HEX);
158
+        if (fault_value_I == 1) {
159
+            printf("%s 出现故障\n", fault_name.c_str());
160
+            fault_count++;
161
+            temp_count++;
162
+        }
163
+    }
164
+
165
+    //记录故障数目
166
+    #if 0
167
+    //比较最后一个故障名称
168
+    if (!fault_id.empty() && back_fault_id != fault_id) {
169
+        back_fault_id = fault_id;
170
+    } else {
171
+    }
172
+    #endif
173
+    //解析当前时刻采集到的数据
174
+    for (i = 0; i < source_len; ++i)
175
+    {
176
+        v_data.at(i).time = current_time;
177
+        v_data.at(i).device_name = source_data->source_pitem.at(i).device_name;
178
+        v_data.at(i).name = source_data->source_pitem.at(i).name;
179
+        v_data.at(i).id = source_data->source_pitem.at(i).id;
180
+        v_data.at(i).value = source_data->source_pitem.at(i).value;
181
+    }
182
+
183
+    //第一次保存数据, 更新保存文件名
184
+    if (back_time == 0)
185
+    {
186
+        back_time = current_time;
187
+        file_name = file_save_path + "source_" + time_buffer + ".csv";
188
+        printf("file_name is %s\n", file_name.c_str());
189
+        back_file_name = file_name;
190
+    } else {
191
+        //出现故障, 保存故障数据
192
+        if (fault_count > 0) {
193
+            if (!back_fault_count) {
194
+                //新建故障数据文件
195
+                fault_file_name = file_save_path + "fault_" + time_buffer + ".csv";
196
+                back_fault_file_name = fault_file_name;
197
+                fault_before_data = get_data_for_CSV(back_file_name, current_time, save_time_before);
198
+                fault_save_time_begin = current_time;
199
+                save_to_CSV(back_fault_file_name, fault_before_data);
200
+                back_fault_count = 1;
201
+                fault_number_back = temp_count;
202
+            } else {
203
+                //出现新故障,更新故障保存时间
204
+                if (temp_count > fault_number_back) {
205
+                    fault_save_time_begin = current_time;
206
+                }
207
+                long long differ_fault_time = current_time - fault_save_time_begin;
208
+                if (differ_fault_time > save_time_after * 60) {
209
+                    //达到故障发生后最大记录时间,停止记录数据
210
+                    printf("stop_data_save, 达到故障记录最大时间, 停止记录\n");
211
+                    //故障恢复
212
+                    if (temp_count == 0) {
213
+                        fault_save_time_begin = 0;
214
+                        fault_count = 0;
215
+                        back_fault_count = 0;
216
+                    }
217
+                } else {
218
+                    save_to_CSV(back_fault_file_name, v_data);
219
+                }
220
+            }
221
+        }
222
+
223
+        //保存时间大于1小时, 新建文件保存数据
224
+        // 计算时间差
225
+        long long differ_second = current_time - back_time;
226
+        if (differ_second > 120) {
227
+            file_name = file_save_path + "source_" + time_buffer + ".csv";
228
+            back_time = current_time;
229
+            source_before_data = get_data_for_CSV(back_file_name, current_time, save_time_before);
230
+            save_to_CSV(file_name, source_before_data);
231
+
232
+            std::string rmfile_demand = "rm '" + back_file_name + "'";
233
+            printf("rm rmfile_demand file is %s\n", rmfile_demand.c_str());
234
+            system(rmfile_demand.c_str());
235
+            back_file_name = file_name;
236
+            return S_OK;
237
+        }
238
+    }
239
+
240
+    printf("back_file_name is %s \n", back_file_name.c_str());
241
+    //无故障发生时循环迭代保存一小时数据
242
+    save_to_CSV(back_file_name, v_data);
243
+
244
+    return S_OK;
245
+
246
+}
247
+
248
+HRESULT ProtocolImpl::set_fault_list(vector<Device*> data_list)
249
+{
250
+    ProtocolImpl* pP = new ProtocolImpl();
251
+    data_item *source = new data_item();
252
+    data_item *fault = new data_item();
253
+    std::string dev_name;
254
+    if (data_list.size() <= 0) {
255
+        printf("采集设备列表为空\n");
256
+        return S_FALSE;
257
+    }
258
+
259
+    while(1) {
260
+        source->source_pitem.clear();
261
+        fault->fault_pitem.clear();
262
+        source->number = 0;
263
+        fault->number = 0;
264
+        printf("data_list.size() is %d\n", data_list.size());
265
+        for (int i = 0; i < data_list.size(); ++i)
266
+        {
267
+            //设备名称
268
+            dev_name = data_list.at(i)->getBase().getName().c_str();
269
+            //printf("i is %d, 设备名称为%s, count is %d\n", i, dev_name.c_str(), source->number);
270
+            //printf("i = %d, data_list.at(i)->getVpacket().size()", i, data_list.at(i)->getVpacket().size());
271
+            for(int j = 0; j < data_list.at(i)->getVpacket().size(); ++j)
272
+            {
273
+                Packet *t_ppacket = data_list.at(i)->getVpacket().at(j);
274
+                if (t_ppacket == NULL)
275
+                {
276
+                    printf("查找的包为空\n");
277
+                    continue;
278
+                }
279
+                int pitem_count = t_ppacket->getItemCount();
280
+
281
+                int pitem_i = 0;
282
+                for (pitem_i = 0; pitem_i < pitem_count; ++pitem_i)
283
+                {
284
+                    std::string t_sId, t_sname, t_svalue;
285
+                    int item_enable = 0, item_alarm_enable = 0;
286
+                    Item *forward_pitem = t_ppacket->getVitem().at(pitem_i);
287
+                    if (forward_pitem != NULL)
288
+                    {
289
+                        Base &t_base = forward_pitem->getBase();
290
+                        t_sId = t_base.getObjid().toString().c_str();
291
+                        t_sname = t_base.getName().c_str();
292
+                        t_svalue = forward_pitem->getValue().c_str();
293
+                        if (t_sname.empty() || t_svalue.empty())
294
+                        {
295
+                            continue;
296
+                        }
297
+                        //printf("t_sId is %s, t_sname is %s, t_svalue is %s\n", t_sId.c_str(), t_sname.c_str(), t_svalue.c_str());
298
+                        //printf("i is %d, 设备名称为%s, count is %d\n", i, dev_name.c_str(), source->number);
299
+                        //保存故障滤波源数据
300
+                        source->number += 1;
301
+                        source->add_source_item(dev_name, t_sname, t_sId, t_svalue);
302
+
303
+                        //获取故障类型
304
+                        //获取采集点使能, 采集点报警使能状态
305
+                        item_enable = forward_pitem->getEnable();
306
+                        item_alarm_enable = forward_pitem->getAlarmenable();
307
+                        if (item_enable && item_alarm_enable)
308
+                        {
309
+                            fault->number += 1;
310
+                            fault->add_fault_item(dev_name, t_sname, t_sId, t_svalue);
311
+                        }
312
+                    } else {
313
+                        continue;
314
+                    }
315
+                }
316
+            }
317
+        }
318
+        //临时创建故障检测文件
319
+        //fault->number = 1;
320
+        //std::string test_value = "1";
321
+        //fault->add_fault_item("IO", "干接点", "15a8ef1d-07f9-46ad-8d64-dba326d3adac", test_value);
322
+        printf("before fault.capacity() is %d\n", fault->fault_pitem.capacity());
323
+        if (!source) {
324
+            printf("source is NULL\n");
325
+        }
326
+        if (!fault) {
327
+            printf("fault is NULL\n");
328
+        }
329
+        pP->fault_filter(fault, source, 1, 2);
330
+        secondsSleep(5);
331
+    }
332
+
333
+    delete pP;
334
+    delete source;
335
+    delete fault;
336
+
337
+    return S_OK;
338
+}
339
+

+ 85
- 0
fault-recorder/action/impl/fault_filter.h View File

@@ -0,0 +1,85 @@
1
+/*
2
+ * fault_filter.h
3
+ *
4
+ *  Created on: 2024年11月12日
5
+ *      Author: 13168
6
+ */
7
+
8
+#ifndef ACTION_IMPL_FAULT_FILTER_H_
9
+#define ACTION_IMPL_FAULT_FILTER_H_
10
+
11
+#include <string>
12
+#include "../../common/Type.h"
13
+#include "../../servicemodel/Device.h"
14
+
15
+#include "../../action/FaultRecorder.h"
16
+
17
+class data_attribute
18
+{
19
+public:
20
+    std::string device_name;           // 设备名称
21
+    std::string name;           // 采集点名称
22
+    std::string id;             // ID
23
+    std::string value;          // 值
24
+    // 默认构造函数
25
+    data_attribute() : device_name(""), name(""), id(""), value("") {}
26
+    // 构造函数
27
+    data_attribute(std::string dev_namex, const std::string& namex, std::string idx, std::string val) : device_name(dev_namex), name(namex), id(idx), value(val){}
28
+
29
+    virtual ~data_attribute()
30
+    {
31
+    }
32
+};
33
+
34
+class data_item
35
+{
36
+public:
37
+    int number;
38
+    std::vector<data_attribute> source_pitem;
39
+    std::vector<data_attribute> fault_pitem;
40
+
41
+    void add_source_item(std::string device_name, const std::string& name, std::string id, std::string value) {
42
+        data_attribute newItem(device_name, name, id, value);
43
+        source_pitem.push_back(newItem);  // 使用 push_back 方法新增元素
44
+    }
45
+
46
+    void add_fault_item(std::string device_name, const std::string& name, std::string id, std::string value) {
47
+        data_attribute newfItem(device_name, name, id, value);
48
+        fault_pitem.push_back(newfItem);  // 使用 push_back 方法新增元素
49
+    }
50
+
51
+    virtual ~data_item()
52
+    {
53
+    }
54
+};
55
+
56
+class ProtocolImpl: public ProtocolI_Fault
57
+{
58
+public:
59
+    /*故障滤波*/
60
+     virtual HRESULT set_fault_list(std::vector<Device*> data_list);
61
+
62
+     HRESULT fault_filter(
63
+        data_item* fault_type,            //触发故障的源类型
64
+        data_item* source_data,            //源数据
65
+        int save_time_before,             //保存故障发生前的数据时间
66
+        int save_time_after               //保存故障发生后的数据时间
67
+    );
68
+
69
+    int fault_count;
70
+    int fault_number_back;
71
+    int back_fault_count;
72
+    std::string back_fault_id;
73
+    std::string back_file_name;
74
+    std::string back_fault_file_name;
75
+    double time_difference;
76
+    //std::chrono::steady_clock::time_point back_time;
77
+    long long back_time;
78
+    long long fault_save_time_begin;
79
+
80
+    ~ProtocolImpl()
81
+    {
82
+    }
83
+};
84
+
85
+#endif /* ACTION_IMPL_FAULT_FILTER_H_ */

+ 41
- 0
fault-recorder/common/GUID.cpp View File

@@ -0,0 +1,41 @@
1
+/**
2
+ * @content:GUID�����ļ�
3
+ * @time:2016-8-23
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-8-23#V1.0#�״�����
8
+ */
9
+
10
+#include "Type.h"
11
+
12
+#ifdef __cplusplus
13
+extern "C" {
14
+#endif
15
+const IID IID_IUnknown = { 0x80dd3240, 0x3797, 0x40a2, { 0x82, 0xdd, 0xad, 0xf5,
16
+		0x19, 0x66, 0xf7, 0xa7 } };
17
+const IID IID_IHardWare = { 0x2cdf484c, 0xe100, 0x49f1, { 0xa7, 0x01, 0x84,
18
+		0x4e, 0x7f, 0xf9, 0x5c, 0xb3 } };
19
+const IID IID_ICallBackHandle = { 0xf43b1aa3, 0xa9c4, 0x4b22, { 0x85, 0x67,
20
+		0xb4, 0x17, 0x6d, 0xe7, 0xf7, 0x95 } };
21
+const IID IID_ICreate = { 0x00477f8f, 0xae0c, 0x493b, { 0xb8, 0x8b, 0xba, 0xa0,
22
+		0x6e, 0x1a, 0xae, 0x3f } };
23
+const IID IID_ISqlite3 = { 0x56ffef9d, 0x57f2, 0x4fdf, { 0x8b, 0x8a, 0x26, 0xab,
24
+		0x9d, 0xfc, 0xbe, 0xb7 } };
25
+const IID IID_IDAControler = { 0x82d141e6, 0x29bc, 0x4057, { 0x91, 0x6e, 0xba,
26
+		0x83, 0xc7, 0x82, 0x22, 0x0a } };
27
+const IID IID_IParaAnalysis = { 0x227f6685, 0x3462, 0x4662, { 0xb8, 0x06, 0x9c,
28
+		0xce, 0x32, 0x94, 0x47, 0xed } };
29
+const IID IID_IProtocol = { 0x6e4eb431, 0x8ba5, 0x4142, { 0x84, 0xb1, 0xd1,
30
+		0xbe, 0xf9, 0x79, 0x5b, 0xec } };
31
+const IID IID_ISubContract = { 0x78b41a4a, 0x067a, 0x488d, { 0x9e, 0x8c, 0x31,
32
+		0x6c, 0xfa, 0x95, 0x99, 0x98 } };
33
+const IID IID_IDataRecorder = { 0x1da271da, 0x7322, 0x4d64, { 0xb4, 0x72, 0xa7,
34
+		0x77, 0x2d, 0x14, 0x49, 0xe7 } };
35
+const IID IID_IDataServer = { 0x3480d6c0, 0x73dc, 0x49be, { 0xa4, 0xde, 0xf3,
36
+		0x44, 0x17, 0x2f, 0xdb, 0x20 } };
37
+
38
+const ProgID ProgID_IDataRecorder = "linux.deecs.data-service.micro-service.data-publish.app";
39
+#ifdef __cplusplus
40
+}
41
+#endif

+ 37
- 0
fault-recorder/common/IFace.h View File

@@ -0,0 +1,37 @@
1
+/**
2
+ * @content:�ӿڶ���ͷ�ļ�
3
+ * @time:2016-8-23
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-8-23#V1.0#�״�����
8
+ */
9
+
10
+#ifndef INCLUDE_IFACE_H_
11
+#define INCLUDE_IFACE_H_
12
+
13
+#include "Type.h"
14
+
15
+#ifdef __cplusplus
16
+extern "C" {
17
+#endif
18
+	extern const IID IID_IUnknown;
19
+	extern const IID IID_IHardWare;
20
+	extern const IID IID_ICallBackHandle;
21
+	extern const IID IID_ICreate;
22
+	extern const IID IID_IProtocol;
23
+	extern const IID IID_ISqlite3;
24
+	extern const IID IID_IParaAnalysis;
25
+	extern const IID IID_ISubContract;
26
+	extern const IID IID_IDataRecorder;
27
+
28
+	extern const IID IID_IDAControler;
29
+	extern const IID IID_IDataServer;
30
+	extern const ProgID ProgID_IDAControler;
31
+	extern const ProgID ProgID_IDataRecorder;
32
+
33
+#ifdef __cplusplus
34
+}
35
+#endif
36
+
37
+#endif /* INCLUDE_IFACE_H_ */

+ 24
- 0
fault-recorder/common/IUnknown.h View File

@@ -0,0 +1,24 @@
1
+/**
2
+ * @content:IUnknown接口定义头文件
3
+ * @time:2016-8-23
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-8-23#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_IUNKNOWN_H_
11
+#define INCLUDE_IUNKNOWN_H_
12
+
13
+#include "Type.h"
14
+
15
+interface IUnknown{
16
+	virtual HRESULT queryInterface(const IID& iid, void** ppv) = 0;	//----查询接口
17
+	virtual ULONG addRef() = 0;	//----增加引用计数
18
+	virtual ULONG release() = 0;	//----释放接口
19
+	virtual ULONG getVersion() = 0;	//----获取组件版本
20
+
21
+	virtual ~IUnknown(){};
22
+};
23
+
24
+#endif /* INCLUDE_IUNKNOWN_H_ */

+ 445
- 0
fault-recorder/common/Type.h View File

@@ -0,0 +1,445 @@
1
+/**
2
+ * @content:基本类型定义
3
+ * @time:2016-8-23
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-8-23#V1.0#首次生成
8
+ */
9
+
10
+#ifndef TYPE_H
11
+#define TYPE_H
12
+
13
+#define LOG_TAG    "deecs_datapublish"
14
+
15
+#include <elog.h>
16
+
17
+#include <errno.h>
18
+#include <math.h>
19
+#include <sys/select.h>
20
+#include <sys/time.h>
21
+#include <cstdio>
22
+#include <ctime>
23
+#include <iostream>
24
+#include <iterator>
25
+#include <string>
26
+#include <vector>
27
+
28
+typedef long HRESULT;
29
+typedef unsigned long ULONG;
30
+
31
+typedef char BYTE;
32
+typedef char* PBYTE;
33
+
34
+class IUnknown;
35
+
36
+#ifndef NULL
37
+#define NULL 0
38
+#endif
39
+
40
+typedef struct _GUID
41
+{
42
+	unsigned int Data1;
43
+	unsigned short Data2;
44
+	unsigned short Data3;
45
+	unsigned char Data4[8];
46
+
47
+	std::string toString()
48
+	{
49
+		char t[256];
50
+		snprintf(t, 256, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", Data1, Data2, Data3, Data4[0], Data4[1], Data4[2], Data4[3], Data4[4], Data4[5],
51
+				Data4[6], Data4[7]);
52
+		return t;
53
+	}
54
+
55
+} GUID;
56
+
57
+typedef GUID IID;
58
+
59
+typedef std::string ProgID;
60
+
61
+#define interface struct
62
+#define CLSID IID	//----组件标识符
63
+#define OBJID IID	//----对象标识符
64
+
65
+#define E_NOINTERFACE 0x80004002L
66
+#define S_OK 0
67
+#define S_FALSE 1
68
+
69
+#define SUCCEEDED(x) ((x)==S_OK)
70
+
71
+#define READ_O 0x00000001
72
+#define READ_WAIT 0x00000002
73
+#define READ_TIMEOUT 0x00000004
74
+#define WRITE_O 0x00000008
75
+#define WRITE_WAIT 0x00000010
76
+#define WRITE_TIMEOUT 0x00000020
77
+#define WRITE_FAIL 0x00000040
78
+
79
+#define HEX 16
80
+
81
+typedef IUnknown* (*CreateFuncPTR)();
82
+
83
+inline BYTE HByte(unsigned int x)
84
+{
85
+	return (((x) >> 8) & 0x00ff);
86
+}
87
+inline BYTE LByte(unsigned int x)
88
+{
89
+	return (((x)) & 0x00ff);
90
+}
91
+
92
+inline BYTE HHByte(unsigned int x)
93
+{
94
+	return (((x) >> 24) & 0x000000ff);
95
+}
96
+inline BYTE HLByte(unsigned int x)
97
+{
98
+	return (((x) >> 16) & 0x000000ff);
99
+}
100
+inline BYTE LHByte(unsigned int x)
101
+{
102
+	return (((x) >> 8) & 0x000000ff);
103
+}
104
+inline BYTE LLByte(unsigned int x)
105
+{
106
+	return (((x)) & 0x000000ff);
107
+}
108
+
109
+/**
110
+ * @content:输出调试信息至stdout
111
+ * @time:2016-8-26
112
+ * @author:Mr_zhu
113
+ * @param: const ProgID(组件中文标识符),const char*(待输出信息)
114
+ * @return: void
115
+ * @decribe
116
+ * 1#2016-8-26#V1.0#首次生成
117
+ */
118
+inline void trace(const ProgID pid, const char* msg)
119
+{
120
+	struct timeval tv;
121
+	struct timezone tz;
122
+
123
+	struct tm *p;
124
+
125
+	gettimeofday(&tv, &tz);
126
+//	printf("tv_sec:%ld\n", tv.tv_sec);
127
+//	printf("tv_usec:%ld\n", tv.tv_usec);
128
+//	printf("tz_minuteswest:%d\n", tz.tz_minuteswest);
129
+//	printf("tz_dsttime:%d\n", tz.tz_dsttime);
130
+
131
+	p = localtime(&tv.tv_sec);
132
+	char t[255];
133
+	snprintf(t, 255, "time_now:%04d-%02d-%02d %02d-%02d-%02d,%ld", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec);
134
+//	std::cout << __FILE__ << "," << __LINE__ << "[" << t << "], "<< pid << ":" << msg
135
+//			<< std::endl;
136
+	std::cout << "[" << t << "], " << pid << ":" << msg << std::endl;
137
+}
138
+
139
+/**
140
+ * @content:将String转为Hex
141
+ * @time:2016-10-1
142
+ * @author:Mr_zhu
143
+ * @param: std::string(待转字符串)
144
+ * @return: unsigned int(返回值)
145
+ * @decribe
146
+ * 1#2016-10-1#V1.0#首次生成
147
+ */
148
+inline unsigned int hexstringtoInt(std::string str)
149
+{
150
+	unsigned int result = 0;
151
+	for (unsigned int i = 0; i < str.length(); i++)
152
+	{
153
+		if ((str.at(i) >= '0') && (str.at(i) <= '9'))
154
+		{
155
+			result += ((str.at(i) - 48) * pow(16, str.length() - 1 - i));
156
+		}
157
+		else if ((str.at(i) >= 'a') && (str.at(i) <= 'f'))
158
+		{
159
+			result += ((str.at(i) - 97 + 10) * pow(16, str.length() - 1 - i));
160
+		}
161
+	}
162
+	return result;
163
+}
164
+
165
+/**
166
+ * @content:将String转为Hex
167
+ * @time:2016-10-1
168
+ * @author:Mr_zhu
169
+ * @param: std::string(待转字符串)
170
+ * @return: unsigned short(返回值)
171
+ * @decribe
172
+ * 1#2016-10-1#V1.0#首次生成
173
+ */
174
+inline unsigned short hexstringtoShort(std::string str)
175
+{
176
+	unsigned short result = 0;
177
+	for (unsigned int i = 0; i < str.length(); i++)
178
+	{
179
+		if ((str.at(i) >= '0') && (str.at(i) <= '9'))
180
+		{
181
+			result += (str.at(i) - 48) * pow(16, str.length() - 1 - i);
182
+		}
183
+		if ((str.at(i) >= 'a') && (str.at(i) <= 'f'))
184
+		{
185
+			result += (str.at(i) - 97 + 10) * pow(16, str.length() - 1 - i);
186
+		}
187
+	}
188
+	return result;
189
+}
190
+
191
+/**
192
+ * @content:将String转为Hex
193
+ * @time:2016-10-1
194
+ * @author:Mr_zhu
195
+ * @param: std::string(待转字符串)
196
+ * @return: unsigned char(返回值)
197
+ * @decribe
198
+ * 1#2016-10-1#V1.0#首次生成
199
+ */
200
+inline unsigned char hexstringtoChar(std::string str)
201
+{
202
+	unsigned char result = 0;
203
+	for (unsigned int i = 0; i < str.length(); i++)
204
+	{
205
+		if ((str.at(i) >= '0') && (str.at(i) <= '9'))
206
+		{
207
+			result += (str.at(i) - 48) * pow(16, str.length() - 1 - i);
208
+		}
209
+		if ((str.at(i) >= 'a') && (str.at(i) <= 'f'))
210
+		{
211
+			result += (str.at(i) - 97 + 10) * pow(16, str.length() - 1 - i);
212
+		}
213
+	}
214
+	return result;
215
+}
216
+
217
+/**
218
+ * @content:将String转为GUID
219
+ * @time:2016-10-1
220
+ * @author:Mr_zhu
221
+ * @param: std::string(待转字符串)
222
+ * @return: GUID(返回的GUID)
223
+ * @decribe
224
+ * 1#2016-10-1#V1.0#首次生成
225
+ */
226
+inline GUID stringtoGUID(std::string str)
227
+{
228
+	GUID t_guid =
229
+	{ 0, 0, 0,
230
+	{ 0, 0, 0, 0, 0, 0, 0, 0 } };
231
+
232
+	if (!str.empty())
233
+	{
234
+		std::string t_str = str;
235
+		std::vector<std::string> t_vstr;
236
+//	int index = t_str.find('{');
237
+//	int index1 = t_str.find('}');
238
+		int index = 0;
239
+		int index1 = 0;
240
+		if ((index != -1) && (index1 != -1))
241
+		{
242
+			t_str = t_str.substr(0);
243
+			int index = t_str.find('-');
244
+
245
+			while (index != -1)
246
+			{
247
+				t_vstr.push_back(t_str.substr(0, index));
248
+				t_str = t_str.substr(index + 1);
249
+				index = t_str.find('-');
250
+				if (index == -1)
251
+				{
252
+					break;
253
+				}
254
+			}
255
+			t_vstr.push_back(t_str);
256
+		}
257
+		if (t_vstr.size() == 5)
258
+		{
259
+			t_guid.Data1 = hexstringtoInt(t_vstr.at(0));
260
+			t_guid.Data2 = hexstringtoShort(t_vstr.at(1));
261
+			t_guid.Data3 = hexstringtoShort(t_vstr.at(2));
262
+			t_guid.Data4[0] = hexstringtoChar(t_vstr.at(3).substr(0, 2));
263
+			t_guid.Data4[1] = hexstringtoChar(t_vstr.at(3).substr(2));
264
+			std::string sstr = t_vstr.at(4);
265
+			t_guid.Data4[2] = hexstringtoChar(sstr.substr(0, 2));
266
+			t_guid.Data4[3] = hexstringtoChar(sstr.substr(2, 2));
267
+			t_guid.Data4[4] = hexstringtoChar(sstr.substr(4, 2));
268
+			t_guid.Data4[5] = hexstringtoChar(sstr.substr(6, 2));
269
+			t_guid.Data4[6] = hexstringtoChar(sstr.substr(8, 2));
270
+			t_guid.Data4[7] = hexstringtoChar(sstr.substr(10, 2));
271
+		}
272
+	}
273
+	return t_guid;
274
+}
275
+
276
+/**
277
+ * @content: 比较两个标识符是否相等
278
+ * @time:2016-8-26
279
+ * @author:Mr_zhu
280
+ * @param: const IID&(待比较标识符1),const IID2&(待比较标识符2)
281
+ * @return: void
282
+ * @decribe
283
+ * 1#2016-8-26#V1.0#首次生成
284
+ */
285
+inline bool operator==(const IID& guid1, const IID& guid2)
286
+{
287
+	if (guid1.Data1 != guid2.Data1)
288
+		return false;
289
+	if (guid1.Data2 != guid2.Data2)
290
+		return false;
291
+	if (guid1.Data3 != guid2.Data3)
292
+		return false;
293
+	for (int i = 0; i < 8; i++)
294
+	{
295
+		if (guid1.Data4[i] != guid2.Data4[i])
296
+			return false;
297
+	}
298
+	return true;
299
+}
300
+
301
+/**
302
+ * @content: 比较标识符1是否小于标识符2
303
+ * @time:2016-8-26
304
+ * @author:Mr_zhu
305
+ * @param: const IID&(待比较标识符1),const IID2&(待比较标识符2)
306
+ * @return: void
307
+ * @decribe
308
+ * 1#2016-8-26#V1.0#首次生成
309
+ */
310
+inline bool operator<(const IID& guid1, const IID& guid2)
311
+{
312
+	if (guid1.Data1 >= guid2.Data1)
313
+		return false;
314
+	if (guid1.Data2 >= guid2.Data2)
315
+		return false;
316
+	if (guid1.Data3 >= guid2.Data3)
317
+		return false;
318
+	for (int i = 0; i < 8; i++)
319
+	{
320
+		if (guid1.Data4[i] >= guid2.Data4[i])
321
+			return false;
322
+	}
323
+	return true;
324
+}
325
+
326
+inline bool isGUIDEqual(const IID& guid1, const IID& guid2)
327
+{
328
+	return ((guid1.Data1 == guid2.Data1) && (guid1.Data2 == guid2.Data2) && (guid1.Data3 == guid2.Data3) && (guid1.Data4[0] == guid2.Data4[0])
329
+			&& (guid1.Data4[1] == guid2.Data4[1]) && (guid1.Data4[2] == guid2.Data4[2]) && (guid1.Data4[3] == guid2.Data4[3])
330
+			&& (guid1.Data4[4] == guid2.Data4[4]) && (guid1.Data4[5] == guid2.Data4[5]) && (guid1.Data4[6] == guid2.Data4[6])
331
+			&& (guid1.Data4[7] == guid2.Data4[7]));
332
+}
333
+
334
+/**
335
+ * @content: 以给定的字符分隔输入字符串
336
+ * @time:2016-9-8
337
+ * @author:Mr_zhu
338
+ * @param:
339
+ * @return:
340
+ * @decribe
341
+ * 1#2016-9-8#V1.0#首次生成
342
+ */
343
+inline void getCharsFromString(std::string str, char ch, std::vector<std::string>& iter)
344
+{
345
+	std::string::size_type index = str.find(ch);
346
+	std::string t_str;
347
+
348
+	if (index != std::string::npos)
349
+	{
350
+		while (1)
351
+		{
352
+			if (index <= str.length() && index > 0)
353
+			{
354
+				t_str = str.substr(0, index);
355
+				iter.push_back(t_str);
356
+
357
+				str = str.substr(index + 1);
358
+				index = str.find(ch);
359
+				if (index == std::string::npos)
360
+				{
361
+					iter.push_back(str);
362
+					break;
363
+				}
364
+			}
365
+			else
366
+			{
367
+				break;
368
+			}
369
+
370
+		}
371
+	}
372
+	else
373
+	{
374
+		iter.push_back(str);
375
+	}
376
+}
377
+
378
+inline void secondsSleep(unsigned int seconds)
379
+{
380
+	struct timeval tv;
381
+	tv.tv_sec = seconds;
382
+	tv.tv_usec = 0;
383
+	int err;
384
+	do
385
+	{
386
+		err = select(0, NULL, NULL, NULL, &tv);
387
+	} while (err < 0 && errno == EINTR);
388
+}
389
+
390
+inline void milisecondsSleep(unsigned int mSeconds)
391
+{
392
+	struct timeval tv;
393
+	tv.tv_sec = mSeconds / 1000;
394
+	tv.tv_usec = (mSeconds % 1000) * 1000;
395
+	int err;
396
+	do
397
+	{
398
+		err = select(0, NULL, NULL, NULL, &tv);
399
+	} while (err < 0 && errno == EINTR);
400
+}
401
+
402
+inline void microssecondsSleep(unsigned int uSeconds)
403
+{
404
+	struct timeval tv;
405
+	tv.tv_sec = uSeconds / 1000000;
406
+	tv.tv_usec = uSeconds % 1000000;
407
+	int err;
408
+	do
409
+	{
410
+		err = select(0, NULL, NULL, NULL, &tv);
411
+	} while (err < 0 && errno == EINTR);
412
+}
413
+
414
+inline void initLogger()
415
+{
416
+	/**
417
+	 * LOG系统初始化
418
+	 */
419
+	/* close printf buffer */
420
+	setbuf(stdout, NULL);
421
+	/* initialize EasyLogger */
422
+	elog_init();
423
+	/* set EasyLogger log format */
424
+	elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_ALL);
425
+	elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
426
+	elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
427
+	elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME);
428
+	elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_ALL & ~ELOG_FMT_FUNC);
429
+	elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_ALL & ~ELOG_FMT_FUNC);
430
+#ifdef ELOG_COLOR_ENABLE
431
+	elog_set_text_color_enabled(true);
432
+#endif
433
+	/* start EasyLogger */
434
+	elog_start();
435
+}
436
+
437
+/**
438
+ * DEBUG等级
439
+ */
440
+typedef enum
441
+{
442
+	DEBUG = 0, INFO, WARN, ERROR, FATAL
443
+} LEVEL;
444
+
445
+#endif

+ 67
- 0
fault-recorder/externservice/DAControlerI.h View File

@@ -0,0 +1,67 @@
1
+/*
2
+ * DAControlerI.h DAControler接口定义头文件
3
+ *
4
+ *  Created on: 2016年12月14日
5
+ *      Author: nego
6
+ */
7
+
8
+#ifndef ACTION_DACONTROLERI_H_
9
+#define ACTION_DACONTROLERI_H_
10
+
11
+#include <vector>
12
+
13
+#include "../common/IUnknown.h"
14
+#include "../common/Type.h"
15
+#include "../servicemodel/Base.h"
16
+#include "../servicemodel/Device.h"
17
+
18
+interface DAControlerI: public IUnknown {
19
+public:
20
+	enum TYPE{
21
+		CHANNEL = 0,
22
+		DEVICE,
23
+		PACKET,
24
+		ITEM
25
+	};
26
+
27
+	virtual ~DAControlerI(){}
28
+
29
+	/**
30
+	 * DAControler控制接口
31
+	 */
32
+	virtual HRESULT init() = 0;	//----初始化DA
33
+	virtual HRESULT start() = 0;	//----启动DA
34
+	virtual HRESULT stop() = 0;	//----停止DA
35
+	virtual HRESULT hang() = 0;	//----挂起DA
36
+	virtual HRESULT resume() = 0;	//----恢复DA
37
+
38
+	/**
39
+	 * DAControler_Channel\Device\Packet\Item控制
40
+	 */
41
+	virtual HRESULT restart(CLSID& clsid,TYPE type) = 0;	//----重启
42
+	virtual HRESULT stop(CLSID& clsid,TYPE type) = 0;	//----停止
43
+	virtual HRESULT hang(CLSID& clsid,TYPE type) = 0;	//----挂起
44
+	virtual HRESULT resume(CLSID& clsid,TYPE type) = 0;	//----恢复
45
+
46
+	/**
47
+	 * 动态监视
48
+	 */
49
+	virtual HRESULT dynamicIncreaseDevice(Device& device, bool iseffect) = 0;	//----动态增加设备
50
+	//virtual HRESULT dynamicModifyPara(Device& device, std::string name, int value) = 0;	//----动态修改设备参数
51
+
52
+	/**
53
+	 * 性能监视
54
+	 */
55
+	virtual Base::QUALITY getQuality(CLSID& clsid,TYPE type) = 0;	//----获取采集质量
56
+	virtual ULONG getReadCount(CLSID& clsid,TYPE type) = 0;	//----获取读计数
57
+	virtual ULONG getReadBackCount(CLSID& clsid,TYPE type) = 0;	//----获取读回复计数
58
+	virtual ULONG getWriteCount(CLSID& clsid,TYPE type) = 0;	//----获取写计数
59
+	virtual ULONG getWriteBackCount(CLSID& clsid,TYPE type) = 0;	//----获取写回复计数
60
+
61
+	/**
62
+	 * 获取设备列表
63
+	 */
64
+	virtual std::vector<Device* >& getDeviceList() = 0;	//----获取设备列表
65
+};
66
+
67
+#endif /* ACTION_DACONTROLERI_H_ */

+ 123
- 0
fault-recorder/externservice/HardwareI.h View File

@@ -0,0 +1,123 @@
1
+/**
2
+ * @content:HardwareI接口定义文件
3
+ * @time:2016-9-7
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-9-7#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_IHARDWARE_H_
11
+#define INCLUDE_IHARDWARE_H_
12
+
13
+#include <map>
14
+#include <string>
15
+
16
+#include "../common/IUnknown.h"
17
+#include "../common/Type.h"
18
+
19
+struct CallBackHandleI;
20
+
21
+interface HardwareI:IUnknown{
22
+	/**
23
+	 * 设置硬件参数
24
+	 */
25
+	virtual HRESULT setParam(
26
+		std::map<std::string,std::string>::iterator param,
27
+		const int length
28
+	) = 0;
29
+
30
+	/**
31
+	 * 打开硬件
32
+	 */
33
+	virtual HRESULT openHW() = 0;
34
+
35
+	/**
36
+	 * 初始化硬件
37
+	 */
38
+	virtual HRESULT init() = 0;
39
+
40
+	/**
41
+	 * 启动硬件
42
+	 */
43
+	virtual HRESULT start() = 0;
44
+
45
+	/**
46
+	 * 停止硬件
47
+	 */
48
+	virtual HRESULT stop() = 0;
49
+
50
+	/**
51
+	 * 挂起硬件
52
+	 */
53
+	virtual HRESULT hang() = 0;
54
+
55
+	/**
56
+	 * 恢复硬件
57
+	 */
58
+	virtual HRESULT resume() = 0;
59
+
60
+	/**
61
+	 * 硬件是否处于运行
62
+	 */
63
+	virtual HRESULT isRun() = 0;
64
+
65
+	/**
66
+	 * 硬件是否挂起
67
+	 */
68
+	virtual HRESULT isHang() = 0;
69
+
70
+	/**
71
+	 * 注册硬件回调接口
72
+	 */
73
+	virtual HRESULT registerHandler(
74
+		CallBackHandleI *pfunc
75
+	) = 0;
76
+
77
+	/**
78
+	 * 同步写操作
79
+	 */
80
+	virtual HRESULT syncRead(
81
+		PBYTE preadbuf,
82
+		const unsigned int length,
83
+		int& len,
84
+		const unsigned int timeout
85
+	) = 0;
86
+
87
+	/**
88
+	 * 异步读操作
89
+	 */
90
+	virtual HRESULT asyncRead(
91
+		PBYTE preadbuf,
92
+		const unsigned int length,
93
+		int& len
94
+	) = 0;
95
+
96
+	/**
97
+	 * 同步写操作
98
+	 */
99
+	virtual HRESULT syncWrite(
100
+		PBYTE pwritebuf,
101
+		const unsigned int length,
102
+		int& len,
103
+		const unsigned int timeout
104
+	) = 0;
105
+
106
+	/**
107
+	 * 异步写操作
108
+	 */
109
+	virtual HRESULT asyncWrite(
110
+		PBYTE pwritebuf,
111
+		const unsigned int length,
112
+		int& len
113
+	) = 0;
114
+
115
+	/**
116
+	 * 释放硬件
117
+	 */
118
+	virtual HRESULT realeseHW() = 0;
119
+
120
+	virtual ~HardwareI(){}
121
+};
122
+
123
+#endif /* INCLUDE_IHARDWARE_H_ */

+ 51
- 0
fault-recorder/externservice/ParaAnalysisI.h View File

@@ -0,0 +1,51 @@
1
+/**
2
+ * @content:ParaAnalysisI接口定义头文件
3
+ * @time:2016-8-25
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-8-23#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_IPARAANALYSIS_H_
11
+#define INCLUDE_IPARAANALYSIS_H_
12
+
13
+#include <string>
14
+
15
+#include "../common/IUnknown.h"
16
+#include "../common/Type.h"
17
+
18
+interface ParaAnalysisI: IUnknown
19
+{
20
+
21
+	enum DATATYPE
22
+	{
23
+		STRING = 0,
24
+		INT,
25
+		FLOAT,
26
+		HEXINT,
27
+		HEXFLOAT
28
+	};
29
+
30
+	/**
31
+	 * 获取参数个数
32
+	 */
33
+	virtual ULONG getParaCount() = 0;
34
+
35
+	/**
36
+	 * 根据索引获取参数对
37
+	 */
38
+	virtual HRESULT getParam(const unsigned int index, std::string& key,
39
+			std::string& value, DATATYPE& datatype) = 0;
40
+
41
+	/**
42
+	 * 设置参数字符串
43
+	 */
44
+	virtual HRESULT setParaString(const std::string para) = 0;
45
+
46
+	virtual ~ParaAnalysisI()
47
+	{
48
+	}
49
+};
50
+
51
+#endif /* INCLUDE_IPARAANALYSIS_H_ */

+ 73
- 0
fault-recorder/externservice/ProtocolI.h View File

@@ -0,0 +1,73 @@
1
+/**
2
+ * @content:ProtocolI接口定义文件
3
+ * @time:2016-9-7
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-9-7#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_IPROTOCOL_H_
11
+#define INCLUDE_IPROTOCOL_H_
12
+
13
+#include <string>
14
+
15
+#include "../common/IUnknown.h"
16
+#include "../common/Type.h"
17
+
18
+class Device;
19
+class Item;
20
+class Packet;
21
+
22
+interface ProtocolI:IUnknown{
23
+	/**
24
+	 * 读数据
25
+	 */
26
+	virtual HRESULT onRead(
27
+		Device* pdevice,	//----设备句柄
28
+		Packet* ppacket,	//----包句柄
29
+		Item* pitem,	//----点句柄
30
+		PBYTE pbuf,	//----数据缓冲区
31
+		int& len	//----数据长度
32
+	) = 0;
33
+
34
+	/**
35
+	 * 写数据
36
+	 */
37
+	virtual HRESULT onWrite(
38
+		Device* pdevice,	//----设备句柄
39
+		Packet* ppacket,	//----包句柄
40
+		Item* pitem,	//----点句柄
41
+		PBYTE pbuf,	//----数据缓冲区
42
+		int& len,	//----数据长度
43
+		std::string swritebuf,	//----待写数据字符串
44
+		const unsigned int writelen	//----待写数据长度
45
+	) = 0;
46
+
47
+	/**
48
+	 * 判断回复数据是否完全
49
+	 */
50
+	virtual HRESULT isResponseOK(
51
+		Device* pdevice,	//----设备句柄
52
+		Packet* ppacket,	//----包句柄
53
+		Item* pitem,	//----点句柄
54
+		PBYTE pbuf,	//----数据缓冲区
55
+		const int len	//----数据长度
56
+	) = 0;
57
+
58
+	/**
59
+	 * 解析数据
60
+	 */
61
+	virtual HRESULT onResponse(
62
+		Device* pdevice,	//----设备句柄
63
+		Packet* ppacket,	//----包句柄
64
+		Item* pitem,	//----点句柄
65
+		PBYTE pbuf,	//----数据缓冲区
66
+		const int len,	//----数据长度
67
+		int& deletelen	//----删除数据长度
68
+	) = 0;
69
+
70
+	virtual ~ProtocolI(){}
71
+};
72
+
73
+#endif /* INCLUDE_IMANAGER_H_ */

+ 33
- 0
fault-recorder/externservice/SoCreateI.h View File

@@ -0,0 +1,33 @@
1
+/**
2
+ * @content:CreateI接口定义头文件
3
+ * @time:2016-9-24
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-9-24#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_ICREATE_H_
11
+#define INCLUDE_ICREATE_H_
12
+
13
+#include "../common/IUnknown.h"
14
+#include "../common/Type.h"
15
+
16
+interface CreateI:IUnknown{
17
+	/**
18
+	 * 根据so文件名创建接口
19
+	 */
20
+	virtual IUnknown* coCreateInstance(const char* nameofso) = 0;
21
+
22
+	/**
23
+	 * 根据CLSID创建接口
24
+	 */
25
+	virtual IUnknown* callCreateInstance(CLSID& clsid) = 0;
26
+
27
+	/**
28
+	 * 关闭接口句柄
29
+	 */
30
+	virtual void closeHandle() = 0;
31
+};
32
+
33
+#endif /* INCLUDE_ICREATE_H_ */

+ 86
- 0
fault-recorder/externservice/Sqlite3I.h View File

@@ -0,0 +1,86 @@
1
+/**
2
+ * @content:Sqlite3I接口定义文件
3
+ * @time:2016-8-25
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-8-23#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_SQLITE3I_H_
11
+#define INCLUDE_SQLITE3I_H_
12
+
13
+#include <string>
14
+
15
+#include "../common/IUnknown.h"
16
+#include "../common/Type.h"
17
+
18
+interface Sqlite3I:IUnknown{
19
+	/**
20
+	 * 打开Sqlite3数据库文件
21
+	 */
22
+	virtual bool Open(std::string const& db_file) = 0;
23
+
24
+	virtual bool Close() = 0;
25
+
26
+	/**
27
+	 * 直接执行SQL语句
28
+	 */
29
+	virtual bool DirectStatement(std::string const& stmt) = 0;
30
+
31
+	/**
32
+	 * 执行SQL语句
33
+	 */
34
+	virtual bool Statement(std::string const& stmt) = 0;
35
+
36
+	//virtual bool execBlob(std::string const& sql, std::string para, const char* blob, int length) = 0;
37
+
38
+	/**
39
+	 * SQL事务处理接口
40
+	 */
41
+	virtual bool Begin() = 0;
42
+	virtual bool Commit() = 0;
43
+	virtual bool Rollback() = 0;
44
+
45
+	/**
46
+	 * 获取上次Sqlite3操作错误代码
47
+	 */
48
+	virtual std::string LastError() = 0;
49
+
50
+	/**
51
+	 * 参数绑定
52
+	 */
53
+	virtual bool Bind(int pos_zero_indexed, std::string const& value) = 0;
54
+	virtual bool Bind(int pos_zero_indexed, double value) = 0;
55
+	virtual bool Bind(int pos_zero_indexed, int value) = 0;
56
+	virtual bool BindNull(int pos_zero_indexed) = 0;
57
+
58
+	/**
59
+	 * 执行SQL
60
+	 */
61
+	virtual bool Execute() = 0;
62
+
63
+	/**
64
+	 * 获取查询结果的下一行
65
+	 */
66
+	virtual bool NextRow() = 0;
67
+
68
+	virtual bool Reset() = 0;
69
+	virtual bool RestartSelect() = 0;
70
+
71
+	/**
72
+	 * 获取String结果值
73
+	 */
74
+	virtual std::string ValueString(int pos_zero_indexed) = 0;
75
+
76
+	/**
77
+	 * 获取Int结果值
78
+	 */
79
+	virtual int ValueInt(int pos_zero_indexed) = 0;
80
+
81
+	virtual double ValueFloat(int pos_zero_indexed) = 0;
82
+
83
+	virtual ~Sqlite3I(){}
84
+};
85
+
86
+#endif /* INCLUDE_SQLITE3I_H_ */

+ 34
- 0
fault-recorder/externservice/SubContractI.h View File

@@ -0,0 +1,34 @@
1
+/**
2
+ * @content:分包组件接口头文件
3
+ * @time:2016-10-6
4
+ * @author:Mr_zhu
5
+ * @version: V1.0
6
+ * @describe:
7
+ * 1#2016-10-6#V1.0#首次生成
8
+ */
9
+
10
+#ifndef INCLUDE_SUBCONTRACTI_H_
11
+#define INCLUDE_SUBCONTRACTI_H_
12
+
13
+#include "../common/IUnknown.h"
14
+#include "../common/Type.h"
15
+
16
+class Device;
17
+class Item;
18
+class Packet;
19
+
20
+interface SubContractI:IUnknown{
21
+	/**
22
+	 * 分包算法
23
+	 */
24
+	virtual bool isSubContract(
25
+		Device* device,
26
+		Packet* packet,
27
+		Item* item,
28
+		Packet** rpacket
29
+	) = 0;
30
+
31
+	virtual ~SubContractI(){}
32
+};
33
+
34
+#endif /* INCLUDE_SUBCONTRACTI_H_ */

+ 247
- 0
fault-recorder/servicemodel/Base.h View File

@@ -0,0 +1,247 @@
1
+/*
2
+ * Base.h
3
+ *
4
+ *  Created on: 2016年11月15日
5
+ *      Author: nego
6
+ */
7
+
8
+#ifndef SERVICEMODEL_BASE_H_
9
+#define SERVICEMODEL_BASE_H_
10
+
11
+#include <map>
12
+#include <string>
13
+#include <utility>
14
+
15
+#include "../common/Type.h"
16
+
17
+class Base {
18
+public:
19
+
20
+	enum QUALITY {
21
+		GOOD = 0, BAD
22
+	};
23
+	enum RUNSTATE {
24
+		IDLEE = 0, TIMING, TIMEOUT, FAULT
25
+	};
26
+
27
+	Base() :
28
+		m_rwstate(-1), m_priority(-1), m_readcount(0), m_readbackcount(0), m_writecount(
29
+					0), m_writebackcount(0), m_quality(GOOD), m_runstate(TIMING),
30
+					m_rdatimeoutcount(0),m_rreadretrycount(0),m_rwriteretrycount(0),
31
+					m_rfaultcount(0){
32
+		xLock = PTHREAD_MUTEX_INITIALIZER;
33
+	}
34
+	virtual ~Base() {
35
+	}
36
+
37
+	const std::string& getName() const {
38
+		return m_name;
39
+	}
40
+
41
+	void setName(const std::string& name) {
42
+		if(!name.empty()){
43
+			this->m_name = name;
44
+		}
45
+	}
46
+
47
+	OBJID& getObjid() {
48
+		return m_objid;
49
+	}
50
+
51
+	void setObjid(const OBJID& objid) {
52
+		this->m_objid = objid;
53
+	}
54
+
55
+	std::map<std::string, std::string>& getParams() {
56
+		return m_mparams;
57
+	}
58
+
59
+	void setParams(const std::map<std::string, std::string>& params) {
60
+		this->m_mparams = params;
61
+	}
62
+
63
+	HRESULT setParam(const std::string key, const std::string value) {
64
+		getParams().insert(make_pair(key, value));
65
+		return S_OK;
66
+	}
67
+
68
+	std::string getParam(const std::string key) {
69
+		std::map<std::string, std::string>& m = getParams();
70
+		if (m.count(key) > 0) {
71
+			std::string value = m.find(key)->second;
72
+			return value;
73
+		}
74
+		return "";
75
+	}
76
+
77
+	int getPriority() const {
78
+		return m_priority;
79
+	}
80
+
81
+	void setPriority(int priority) {
82
+		this->m_priority = priority;
83
+	}
84
+
85
+	int getRwstate() const {
86
+		return m_rwstate;
87
+	}
88
+
89
+	void setRwstate(int rwstate) {
90
+		this->m_rwstate = rwstate;
91
+	}
92
+
93
+	QUALITY getQuality() const {
94
+		return m_quality;
95
+	}
96
+
97
+	void setQuality(QUALITY quality) {
98
+		this->m_quality = quality;
99
+	}
100
+
101
+	unsigned int getReadcount() const {
102
+		return m_readcount;
103
+	}
104
+
105
+	void setReadcount(unsigned int readcount) {
106
+		this->m_readcount = readcount;
107
+	}
108
+
109
+	void addReadcount() {
110
+		++this->m_readcount;
111
+	}
112
+
113
+	unsigned int getWritecount() const {
114
+		return m_writecount;
115
+	}
116
+
117
+	void setWritecount(unsigned int writecount) {
118
+		this->m_writecount = writecount;
119
+	}
120
+
121
+	void addWritecount() {
122
+		++this->m_writecount;
123
+	}
124
+
125
+	unsigned int getReadbackcount() const {
126
+		return m_readbackcount;
127
+	}
128
+
129
+	void setReadbackcount(unsigned int readbackcount) {
130
+		this->m_readbackcount = readbackcount;
131
+	}
132
+
133
+	void addReadbackcount() {
134
+		++this->m_readbackcount;
135
+	}
136
+
137
+	unsigned int getWritebackcount() const {
138
+		return m_writebackcount;
139
+	}
140
+
141
+	void setWritebackcount(unsigned int writebackcount) {
142
+		this->m_writebackcount = writebackcount;
143
+	}
144
+
145
+	void addWritebackcount() {
146
+		++this->m_writebackcount;
147
+	}
148
+
149
+	RUNSTATE getRunstate() const {
150
+		return m_runstate;
151
+	}
152
+
153
+	void setRunstate(RUNSTATE runstate) {
154
+		(void) pthread_mutex_lock(&xLock);
155
+		this->m_runstate = runstate;
156
+		(void) pthread_mutex_unlock(&xLock);
157
+	}
158
+
159
+	int getRdatimeoutcount() const {
160
+		return m_rdatimeoutcount;
161
+	}
162
+
163
+	void setRdatimeoutcount(int rdatimeoutcount) {
164
+		m_rdatimeoutcount = rdatimeoutcount;
165
+	}
166
+
167
+	void addRdatimeoutcount(int rdatimeoutcount) {
168
+		m_rdatimeoutcount += rdatimeoutcount;
169
+	}
170
+
171
+	void resetRdatimeoutcount() {
172
+		m_rdatimeoutcount = 0;
173
+	}
174
+
175
+	int getRfaultcount() const {
176
+		return m_rfaultcount;
177
+	}
178
+
179
+	void setRfaultcount(int rfaultcount) {
180
+		m_rfaultcount = rfaultcount;
181
+	}
182
+
183
+	void addRfaultcount(int rfaultcount) {
184
+		m_rfaultcount += rfaultcount;
185
+	}
186
+
187
+	void resetRfaultcount() {
188
+		m_rfaultcount = 0;
189
+	}
190
+
191
+	int getRreadretrycount() const {
192
+		return m_rreadretrycount;
193
+	}
194
+
195
+	void setRreadretrycount(int rreadretrycount) {
196
+		m_rreadretrycount = rreadretrycount;
197
+	}
198
+
199
+	void addRreadretrycount(int rreadretrycount) {
200
+		m_rreadretrycount += rreadretrycount;
201
+	}
202
+
203
+	void resetRreadretrycount() {
204
+		m_rreadretrycount = 0;
205
+	}
206
+
207
+	int getRwriteretrycount() const {
208
+		return m_rwriteretrycount;
209
+	}
210
+
211
+	void setRwriteretrycount(int rwriteretrycount) {
212
+		m_rwriteretrycount = rwriteretrycount;
213
+	}
214
+
215
+	void addRwriteretrycount(int rwriteretrycount) {
216
+		m_rwriteretrycount += rwriteretrycount;
217
+	}
218
+
219
+	void resetRwriteretrycount() {
220
+		m_rwriteretrycount = 0;
221
+	}
222
+
223
+private:
224
+	OBJID m_objid;
225
+	std::string m_name;
226
+	std::map<std::string, std::string> m_mparams;
227
+	int m_rwstate;	//----读写状态
228
+	int m_priority;	//----优先级状态
229
+
230
+	/**
231
+	 * 以下数据用于性能监视
232
+	 */
233
+	unsigned int m_readcount;	//----读计数
234
+	unsigned int m_readbackcount;	//----读回复计数
235
+	unsigned int m_writecount;	//----写计数
236
+	unsigned int m_writebackcount;	//----写回复计数
237
+	QUALITY m_quality;	//----采集质量
238
+	RUNSTATE m_runstate;	//----采集状态,处于空闲、采集、超时、故障等状态
239
+
240
+	int m_rdatimeoutcount;	//----采集超时计数
241
+	int m_rreadretrycount;	//----读重试计数
242
+	int m_rwriteretrycount;	//----写重试计数
243
+	int m_rfaultcount;	//----采集故障计数
244
+
245
+	pthread_mutex_t xLock;
246
+};
247
+#endif /* SERVICEMODEL_BASE_H_ */

+ 279
- 0
fault-recorder/servicemodel/Channel.h View File

@@ -0,0 +1,279 @@
1
+/*
2
+ * Channel.h
3
+ *
4
+ *  Created on: 2016年11月10日
5
+ *      Author: Mr_zhu
6
+ *     Content: 
7
+ */
8
+
9
+#ifndef SERVICEMODEL_CHANNEL_H_
10
+#define SERVICEMODEL_CHANNEL_H_
11
+
12
+#include <stddef.h>
13
+#include <vector>
14
+
15
+#include "../common/Type.h"
16
+#include "../externservice/HardwareI.h"
17
+//#include "../service/CallBackHandleI.h"
18
+//#include "../service/impl/MThreadedJobQImpl.h"
19
+#include "Base.h"
20
+#include "Device.h"
21
+
22
+struct CallBackHandleI;
23
+class MThreadedJobQImpl;
24
+class Device;
25
+
26
+class Channel {
27
+
28
+public:
29
+	enum STATE{
30
+		R = 0,
31
+		S
32
+	};
33
+
34
+public:
35
+	Channel():m_phw(NULL),m_DATimeout(1000),m_BaseDATime(100),m_FaultTime(10000),m_ReadRetryCount(0),
36
+		m_WriteRetryCount(3),m_FaultRetryCount(3),m_pCB(NULL),isHDInitOK(false),m_state(S),m_preadJobThread(NULL){
37
+		xLock = PTHREAD_MUTEX_INITIALIZER;
38
+	}
39
+	virtual ~Channel(){
40
+		if(m_phw!=NULL){
41
+			delete m_phw;
42
+			m_phw = NULL;
43
+		}
44
+		if(m_pCB!=NULL){
45
+			delete m_pCB;
46
+			m_pCB = NULL;
47
+		}
48
+		if(m_preadJobThread!=NULL){
49
+			delete m_preadJobThread;
50
+			m_preadJobThread = NULL;
51
+		}
52
+	}
53
+
54
+	Base& getBase() {
55
+		return m_base;
56
+	}
57
+
58
+	void setBase(const Base& base) {
59
+		this->m_base = base;
60
+	}
61
+
62
+	bool isIsHdInitOk() const {
63
+		return isHDInitOK;
64
+	}
65
+
66
+	void setIsHdInitOk(bool isHdInitOk) {
67
+		isHDInitOK = isHdInitOk;
68
+	}
69
+
70
+	unsigned int getBaseDaTime() const {
71
+		return m_BaseDATime;
72
+	}
73
+
74
+	void setBaseDaTime(unsigned int baseDaTime) {
75
+		m_BaseDATime = baseDaTime;
76
+	}
77
+
78
+	const CLSID& getClsidOfHw() const {
79
+		return m_hwguid;
80
+	}
81
+
82
+	void setClsidOfHw(const CLSID& clsidOfHw) {
83
+		m_hwguid = clsidOfHw;
84
+	}
85
+
86
+	unsigned int getDaTimeout() const {
87
+		return m_DATimeout;
88
+	}
89
+
90
+	void setDaTimeout(unsigned int daTimeout) {
91
+		m_DATimeout = daTimeout;
92
+	}
93
+
94
+	CallBackHandleI* getPCb() {
95
+		return m_pCB;
96
+	}
97
+
98
+	void setPCb(CallBackHandleI* pCb) {
99
+		m_pCB = pCb;
100
+	}
101
+
102
+	HardwareI* getPHd() {
103
+		return m_phw;
104
+	}
105
+
106
+	void setPHd(HardwareI* pHd) {
107
+		m_phw = pHd;
108
+	}
109
+
110
+	const std::vector<BYTE>& getReadBuf() const {
111
+		return m_vReadBuf;
112
+	}
113
+
114
+	void setReadBuf(const std::vector<BYTE>& readBuf) {
115
+		m_vReadBuf = readBuf;
116
+	}
117
+
118
+	unsigned int getReadRetryCount() const {
119
+		return m_ReadRetryCount;
120
+	}
121
+
122
+	void setReadRetryCount(unsigned int readRetryCount) {
123
+		m_ReadRetryCount = readRetryCount;
124
+	}
125
+
126
+	std::vector<Device* >& getVDevice() {
127
+		return m_vDevice;
128
+	}
129
+
130
+	void setVDevice(const std::vector<Device* >& vDevice) {
131
+		m_vDevice = vDevice;
132
+	}
133
+
134
+	const std::vector<BYTE>& getWriteBuf() const {
135
+		return m_vWriteBuf;
136
+	}
137
+
138
+	void setWriteBuf(const std::vector<BYTE>& writeBuf) {
139
+		m_vWriteBuf = writeBuf;
140
+	}
141
+
142
+	unsigned int getWriteRetryCount() const {
143
+		return m_WriteRetryCount;
144
+	}
145
+
146
+	void setWriteRetryCount(unsigned int writeRetryCount) {
147
+		m_WriteRetryCount = writeRetryCount;
148
+	}
149
+
150
+	HRESULT addDevice(Device* device) {
151
+//		bool isexist = false;
152
+//
153
+//		for (Device& d : m_vDevice) {
154
+//			if (d.isEqual(device)) {
155
+//				isexist = true;
156
+//				break;
157
+//			}
158
+//		}
159
+//		if (!isexist) {
160
+//			m_vDevice.push_back(device);
161
+//			return S_OK;
162
+//		}
163
+//		return S_FALSE;
164
+		m_vDevice.push_back(device);
165
+		return S_OK;
166
+	}
167
+
168
+	ULONG getDeviceCount(){
169
+		return m_vDevice.size();
170
+	}
171
+
172
+	unsigned int getFaultRetryCount() const
173
+	{
174
+		return m_FaultRetryCount;
175
+	}
176
+
177
+	void setFaultRetryCount(unsigned int faultRetryCount)
178
+	{
179
+		m_FaultRetryCount = faultRetryCount;
180
+	}
181
+
182
+	unsigned int getFaultTime() const
183
+	{
184
+		return m_FaultTime;
185
+	}
186
+
187
+	void setFaultTime(unsigned int faultTime)
188
+	{
189
+		m_FaultTime = faultTime;
190
+	}
191
+
192
+	CLSID& getHwguid()
193
+	{
194
+		return m_hwguid;
195
+	}
196
+
197
+	void setHwguid(const CLSID& hwguid)
198
+	{
199
+		m_hwguid = hwguid;
200
+	}
201
+
202
+	HardwareI* getPhw()
203
+	{
204
+		return m_phw;
205
+	}
206
+
207
+	void setPhw(HardwareI* phw)
208
+	{
209
+		this->m_phw = phw;
210
+	}
211
+
212
+	STATE getState() const {
213
+		return m_state;
214
+	}
215
+
216
+	void setState(STATE state) {
217
+		(void) pthread_mutex_lock(&xLock);
218
+		this->m_state = state;
219
+		(void) pthread_mutex_unlock(&xLock);
220
+	}
221
+
222
+	MThreadedJobQImpl* getReadJobThread() {
223
+		return m_preadJobThread;
224
+	}
225
+
226
+	void setReadJobThread(MThreadedJobQImpl* readJobThread) {
227
+		m_preadJobThread = readJobThread;
228
+	}
229
+
230
+	void outInfo(){
231
+
232
+
233
+		std::cout << "通道ID: " << m_base.getObjid().toString()  << std::endl;
234
+		std::cout << "通道名称: " << m_base.getName()  << std::endl;
235
+		std::cout << "通道参数: " << std::endl;
236
+		for(std::pair<const std::string,std::string>& s : m_base.getParams()){
237
+			std::cout << s.first <<  " : " << s.second << std::endl;
238
+		}
239
+		std::cout << "通道读写状态: " << m_base.getRwstate() << std::endl;
240
+		std::cout << "通道优先级状态: " << m_base.getPriority() << std::endl;
241
+		std::cout << "硬件组件ID: " << m_hwguid.toString() << std::endl;
242
+		std::cout << "硬件组件句柄: " << m_phw << std::endl;
243
+		std::cout << "采集超时时间: " << m_phw << std::endl;
244
+		std::cout << "基础采集周期: " << m_phw << std::endl;
245
+		std::cout << "采集故障时间: " << m_phw << std::endl;
246
+		std::cout << "读重试次数: " << m_phw << std::endl;
247
+		std::cout << "写重试次数: " << m_phw << std::endl;
248
+		std::cout << "故障重试次数: " << m_phw << std::endl;
249
+		std::cout << "设备数: " << m_vDevice.size() << std::endl;
250
+		for(Device* & d : m_vDevice){
251
+			d->outInfo();
252
+		}
253
+	}
254
+
255
+private:
256
+	CLSID m_hwguid;	//----通道组件标识符
257
+	HardwareI* m_phw;	//----通道组件句柄
258
+	unsigned int m_DATimeout;
259
+	unsigned int m_BaseDATime;
260
+	unsigned int m_FaultTime;
261
+	unsigned int m_ReadRetryCount;
262
+	unsigned int m_WriteRetryCount;
263
+	unsigned int m_FaultRetryCount;
264
+	std::vector<Device* > m_vDevice;
265
+	std::vector<BYTE> m_vReadBuf;
266
+	std::vector<BYTE> m_vWriteBuf;
267
+	CallBackHandleI* m_pCB;
268
+	bool isHDInitOK;
269
+
270
+	STATE m_state;	//---通道处于数据发送或者接受状态
271
+
272
+	MThreadedJobQImpl* m_preadJobThread;	//----读任务线程
273
+
274
+	Base m_base;
275
+
276
+	pthread_mutex_t xLock;
277
+};
278
+
279
+#endif /* SERVICEMODEL_CHANNEL_H_ */

+ 395
- 0
fault-recorder/servicemodel/Device.h View File

@@ -0,0 +1,395 @@
1
+/*
2
+ * Device.h
3
+ *
4
+ *  Created on: 2016年11月10日
5
+ *      Author: Mr_zhu
6
+ *     Content: 
7
+ */
8
+
9
+#ifndef SERVICEMODEL_DEVICE_H_
10
+#define SERVICEMODEL_DEVICE_H_
11
+
12
+#include <string>
13
+#include <vector>
14
+
15
+#include "../common/Type.h"
16
+#include "../externservice/HardwareI.h"
17
+#include "../externservice/ParaAnalysisI.h"
18
+#include "../externservice/ProtocolI.h"
19
+#include "../externservice/SubContractI.h"
20
+#include "Base.h"
21
+#include "Item.h"
22
+#include "Packet.h"
23
+
24
+struct HardwareI;
25
+struct ParaAnalysisI;
26
+struct ProtocolI;
27
+
28
+struct SubContractI;
29
+
30
+struct IHardware;
31
+
32
+struct IParaAnalysis;
33
+struct IProtocol;
34
+
35
+class Channel;
36
+
37
+class Device {
38
+public:
39
+	Device() :
40
+			m_pptcl(NULL), m_hwtype(-1), m_hwnumber(-1), m_phw(NULL), m_ppara(
41
+			NULL), m_psubctact(
42
+			NULL), m_enable(1), m_datimer(100), m_datimeout(1000), m_dafaulttime(
43
+					3000), m_readretrycount(0), m_writeretrycount(3), m_faultcount(
44
+					3), m_parent(NULL) {
45
+
46
+	}
47
+	virtual ~Device() {
48
+//		if (m_pptcl != NULL) {
49
+//			delete m_pptcl;
50
+//			m_pptcl = NULL;
51
+//		}
52
+//		if (m_phw != NULL) {
53
+//			delete m_phw;
54
+//			m_phw = NULL;
55
+//		}
56
+//		if (m_ppara != NULL) {
57
+//			delete m_ppara;
58
+//			m_ppara = NULL;
59
+//		}
60
+//		if (m_psubctact != NULL) {
61
+//			delete m_psubctact;
62
+//			m_psubctact = NULL;
63
+//		}
64
+	}
65
+
66
+	Base& getBase() {
67
+		return m_base;
68
+	}
69
+
70
+	void setBase(const Base& base) {
71
+		this->m_base = base;
72
+	}
73
+
74
+	int getEnable() const {
75
+		return m_enable;
76
+	}
77
+
78
+	void setEnable(int enable) {
79
+		m_enable = enable;
80
+	}
81
+
82
+	CLSID& getHwguid() {
83
+		return m_hwguid;
84
+	}
85
+
86
+	void setHwguid(const CLSID& hwguid) {
87
+		m_hwguid = hwguid;
88
+	}
89
+
90
+	std::string& getHwname() {
91
+		return m_hwname;
92
+	}
93
+
94
+	void setHwname(const std::string& hwname) {
95
+		if (!hwname.empty()) {
96
+			m_hwname = hwname;
97
+		}
98
+	}
99
+
100
+	int getHwnumber() const {
101
+		return m_hwnumber;
102
+	}
103
+
104
+	void setHwnumber(int hwnumber) {
105
+		m_hwnumber = hwnumber;
106
+	}
107
+
108
+	int getHwtype() const {
109
+		return m_hwtype;
110
+	}
111
+
112
+	void setHwtype(int hwtype) {
113
+		m_hwtype = hwtype;
114
+	}
115
+
116
+	std::string& getItemtable() {
117
+		return m_itemtable;
118
+	}
119
+
120
+	void setItemtable(const std::string& itemtable) {
121
+		if (!itemtable.empty()) {
122
+			m_itemtable = itemtable;
123
+		}
124
+	}
125
+
126
+	CLSID& getParaanalysisguid() {
127
+		return m_paraanalysisguid;
128
+	}
129
+
130
+	void setParaanalysisguid(const CLSID& paraanalysisguid) {
131
+		m_paraanalysisguid = paraanalysisguid;
132
+	}
133
+
134
+	CLSID& getProtocolguid() {
135
+		return m_protocolguid;
136
+	}
137
+
138
+	void setProtocolguid(const CLSID& protocolguid) {
139
+		m_protocolguid = protocolguid;
140
+	}
141
+
142
+	const std::string& getProtocolname() const {
143
+		return m_protocolname;
144
+	}
145
+
146
+	void setProtocolname(const std::string& protocolname) {
147
+		if (!protocolname.empty()) {
148
+			m_protocolname = protocolname;
149
+		}
150
+	}
151
+
152
+	CLSID& getSubcontractguid() {
153
+		return m_subcontractguid;
154
+	}
155
+
156
+	void setSubcontractguid(const CLSID& subcontractguid) {
157
+		m_subcontractguid = subcontractguid;
158
+	}
159
+
160
+	const Channel* getParent() const {
161
+		return m_parent;
162
+	}
163
+
164
+	void setParent(Channel* parent) {
165
+		this->m_parent = parent;
166
+	}
167
+
168
+	HardwareI* getPhw() {
169
+		return m_phw;
170
+	}
171
+
172
+	void setPhw(HardwareI* phw) {
173
+		this->m_phw = phw;
174
+	}
175
+
176
+	ParaAnalysisI* getPpara() const {
177
+		return m_ppara;
178
+	}
179
+
180
+	void setPpara(ParaAnalysisI* ppara) {
181
+		this->m_ppara = ppara;
182
+	}
183
+
184
+	ProtocolI* getPptcl() {
185
+		return m_pptcl;
186
+	}
187
+
188
+	void setPptcl(ProtocolI* pptcl) {
189
+		this->m_pptcl = pptcl;
190
+	}
191
+
192
+	SubContractI* getPsubctact() const {
193
+		return m_psubctact;
194
+	}
195
+
196
+	void setPsubctact(SubContractI* psubctact) {
197
+		this->m_psubctact = psubctact;
198
+	}
199
+
200
+	std::vector<Packet* >& getVpacket() {
201
+		return m_vpacket;
202
+	}
203
+
204
+	void setVpacket(const std::vector<Packet* >& vpacket) {
205
+		this->m_vpacket = vpacket;
206
+	}
207
+
208
+	std::vector<Item* >& getVitem() {
209
+		return m_vitem;
210
+	}
211
+
212
+	void setVitem(const std::vector<Item* >& vitem) {
213
+		this->m_vitem = vitem;
214
+	}
215
+
216
+	HRESULT addItem(Item* item) {
217
+		bool isexist = false;
218
+
219
+		for (Item*& i : m_vitem) {
220
+			if (i->isEqual(*item)) {
221
+				isexist = true;
222
+				break;
223
+			}
224
+		}
225
+		if (!isexist) {
226
+			m_vitem.push_back(item);
227
+
228
+			return S_OK;
229
+		}
230
+		return S_FALSE;
231
+	}
232
+
233
+	HRESULT addPacket(Packet* packet) {
234
+		bool isexist = false;
235
+
236
+		for (Packet* & p : m_vpacket) {
237
+			if (p->isEqual(*packet)) {
238
+				isexist = true;
239
+				break;
240
+			}
241
+		}
242
+		if (!isexist) {
243
+			m_vpacket.push_back(packet);
244
+			return S_OK;
245
+		}
246
+		return S_FALSE;
247
+	}
248
+
249
+	ULONG getItemCount() {
250
+		return m_vitem.size();
251
+	}
252
+
253
+	ULONG getPacketCount() {
254
+		return m_vpacket.size();
255
+	}
256
+
257
+public:
258
+	bool isEqual(Device& device) {
259
+
260
+		if ((isGUIDEqual(this->m_hwguid,((device.getHwguid()))))
261
+				&& (this->m_hwname == ((device.getHwname())))
262
+				&& (this->m_hwnumber == device.getHwnumber())
263
+				&& (this->m_hwtype == device.getHwtype())) {
264
+			return true;
265
+		}
266
+
267
+		return false;
268
+	}
269
+
270
+	int getDafaulttime() const {
271
+		return m_dafaulttime;
272
+	}
273
+
274
+	void setDafaulttime(int dafaulttime) {
275
+		m_dafaulttime = dafaulttime;
276
+	}
277
+
278
+	int getDatimeout() const {
279
+		return m_datimeout;
280
+	}
281
+
282
+	void setDatimeout(int datimeout) {
283
+		m_datimeout = datimeout;
284
+	}
285
+
286
+	int getDatimer() const {
287
+		return m_datimer;
288
+	}
289
+
290
+	void setDatimer(int datimer) {
291
+		m_datimer = datimer;
292
+	}
293
+
294
+	int getFaultcount() const {
295
+		return m_faultcount;
296
+	}
297
+
298
+	void setFaultcount(int faultcount) {
299
+		m_faultcount = faultcount;
300
+	}
301
+
302
+	int getReadretrycount() const {
303
+		return m_readretrycount;
304
+	}
305
+
306
+	void setReadretrycount(int readretrycount) {
307
+		m_readretrycount = readretrycount;
308
+	}
309
+
310
+	int getWriteretrycount() const {
311
+		return m_writeretrycount;
312
+	}
313
+
314
+	void setWriteretrycount(int writeretrycount) {
315
+		m_writeretrycount = writeretrycount;
316
+	}
317
+
318
+	void outInfo() {
319
+		log_d( "设备ID: %s", m_base.getObjid().toString().c_str());
320
+		log_d( "设备名称: %s", m_base.getName().c_str());
321
+		log_d( "设备参数: ");
322
+
323
+		for (std::pair<const std::string, std::string>& s : m_base.getParams()) {
324
+			log_d( "参数名称: %s, 参数值: %s", s.first.c_str(), s.second.c_str());
325
+		}
326
+
327
+		log_d( "设备读写状态: %d", m_base.getRwstate());
328
+		log_d( "设备优先级: %d", m_base.getPriority());
329
+		log_d( "设备通信协议组件名称: %s", m_protocolname.c_str());
330
+		log_d( "设备通信协议组件ID: %s", m_protocolguid.toString().c_str());
331
+		log_d( "设备通信协议组件句柄: %d", m_pptcl);
332
+		log_d( "设备硬件通道名称: %s", m_hwname.c_str());
333
+		log_d( "设备硬件通道类型: %d", m_hwtype);
334
+		log_d( "设备硬件通道号: %d", m_hwnumber);
335
+		log_d( "设备硬件通道组件标识符: %s", m_hwguid.toString().c_str());
336
+		log_d( "设备硬件通道组件句柄: %d", m_phw);
337
+		log_d( "设备参数解析组件标识符: %s", m_paraanalysisguid.toString().c_str());
338
+		log_d( "设备参数分析组件句柄: %d", m_ppara);
339
+		log_d( "设备分包参数组件标识符: %s", m_subcontractguid.toString().c_str());
340
+		log_d( "设备分包组件句柄: %d", m_psubctact);
341
+		log_d( "设备使能控制: %d", m_enable);
342
+		log_d( "设备采集周期: %d 毫秒", m_datimer);
343
+		log_d( "设备采集超时时间: %d 毫秒", m_datimeout);
344
+		log_d( "设备采集故障恢复时间: %d 毫秒", m_dafaulttime);
345
+
346
+		log_d( "设备读重试次数: %d 次", m_readretrycount);
347
+		log_d( "设备写重试次数: %d 次", m_writeretrycount);
348
+		log_d( "设备采集故障次数: %d 次", m_faultcount);
349
+		log_d( "设备采集包数量: %d 个", m_vpacket.size());
350
+
351
+		log_d( "设备采集包具体信息: ");
352
+
353
+		for(Packet* & p: m_vpacket){
354
+			p->outInfo();
355
+		}
356
+
357
+		log_d( "设备采集点数量: %d", m_vitem.size());
358
+
359
+		log_d( "设备父句柄: %d", m_parent);
360
+	}
361
+
362
+private:
363
+	std::string m_protocolname;	//----设备通信协议名称
364
+	CLSID m_protocolguid;	//----设备通信协议组件标识符
365
+	ProtocolI* m_pptcl;	//----设备通信协议组件句柄
366
+
367
+	std::string m_hwname;	//----设备硬件通道名称
368
+	int m_hwtype;	//----设备硬件通道类型
369
+	int m_hwnumber;	//----设备硬件通道号
370
+	CLSID m_hwguid;	//----设备硬件通道组件标识符
371
+	HardwareI* m_phw;	//----设备硬件通道组件句柄
372
+
373
+	CLSID m_paraanalysisguid;	//----设备参数解析组件标识符
374
+	ParaAnalysisI* m_ppara;	//----设备参数分析组件句柄
375
+
376
+	CLSID m_subcontractguid;	//----设备分包参数组件标识符
377
+	SubContractI* m_psubctact;	//----设备分包组件句柄
378
+
379
+	std::string m_itemtable;	//----设备点表名称
380
+	int m_enable;	//----设备使能控制
381
+	int m_datimer;	//----采集周期
382
+	int m_datimeout;	//----采集超时时间
383
+	int m_dafaulttime;	//----采集故障恢复时间
384
+	int m_readretrycount;	//----读重试次数
385
+	int m_writeretrycount;	//----写重试次数
386
+	int m_faultcount;	//----采集故障次数
387
+
388
+	Base m_base;	//----公共参数
389
+
390
+	std::vector<Packet* > m_vpacket;	//----设备中的采集包集合
391
+	std::vector<Item* > m_vitem;	//----设备中采集点集合
392
+	Channel* m_parent;	//----父句柄
393
+};
394
+
395
+#endif /* SERVICEMODEL_DEVICE_H_ */

+ 638
- 0
fault-recorder/servicemodel/Item.h View File

@@ -0,0 +1,638 @@
1
+/*
2
+ * Item.h
3
+ *
4
+ *  Created on: 2016年11月10日
5
+ *      Author: Mr_zhu
6
+ *     Content:
7
+ */
8
+
9
+#ifndef SERVICEMODEL_ITEM_H_
10
+#define SERVICEMODEL_ITEM_H_
11
+
12
+#include <string>
13
+
14
+#include "../common/Type.h"
15
+#include "Base.h"
16
+
17
+struct ParaAnalysisI;
18
+
19
+class Packet;
20
+
21
+class Item
22
+{
23
+public:
24
+	Item() :
25
+			m_ppara(NULL), m_index(0), m_sourcemin(0.0), m_sourcemax(0.0), m_realmin(0.0), m_realmax(0.0), m_enable(0), m_alarmenable(0), m_hisenable(0), m_histimes(
26
+					0), m_parent(NULL), m_ritem(NULL), lupdatetime(0), updatefreq(0), isFault(false), isReset(false)
27
+	{
28
+		xLock = PTHREAD_MUTEX_INITIALIZER;
29
+		xLock_1 = PTHREAD_MUTEX_INITIALIZER;
30
+	}
31
+	virtual ~Item()
32
+	{
33
+	}
34
+
35
+public:
36
+
37
+	const std::string& getFaultdata() const
38
+	{
39
+		return faultdata;
40
+	}
41
+
42
+	void setFaultdata(const std::string& faultdata)
43
+	{
44
+		this->faultdata = faultdata;
45
+	}
46
+
47
+	const std::string& getFaulttime() const
48
+	{
49
+		return faulttime;
50
+	}
51
+
52
+	void setFaulttime(const std::string& faulttime)
53
+	{
54
+		this->faulttime = faulttime;
55
+	}
56
+
57
+	bool isIsFault()
58
+	{
59
+		return isFault;
60
+	}
61
+
62
+	void setIsFault(bool isFault)
63
+	{
64
+		this->isFault = isFault;
65
+	}
66
+
67
+	bool isIsReset()
68
+	{
69
+		return isReset;
70
+	}
71
+
72
+	void setIsReset(bool isReset)
73
+	{
74
+		this->isReset = isReset;
75
+	}
76
+
77
+	const std::string& getResettime() const
78
+	{
79
+		return resettime;
80
+	}
81
+
82
+	void setResettime(const std::string& resettime)
83
+	{
84
+		this->resettime = resettime;
85
+	}
86
+
87
+	Base& getBase()
88
+	{
89
+		return m_base;
90
+	}
91
+
92
+	void setBase(const Base& base)
93
+	{
94
+		this->m_base = base;
95
+	}
96
+
97
+	const std::string& getAlarmcondition() const
98
+	{
99
+		return m_alarmcondition;
100
+	}
101
+
102
+	void setAlarmcondition(const std::string& alarmcondition)
103
+	{
104
+		if (!alarmcondition.empty())
105
+		{
106
+			m_alarmcondition = alarmcondition;
107
+		}
108
+	}
109
+
110
+	const std::string& getAlarmcontent() const
111
+	{
112
+		return m_alarmcontent;
113
+	}
114
+
115
+	void setAlarmcontent(const std::string& alarmcontent)
116
+	{
117
+		if (!alarmcontent.empty())
118
+		{
119
+			m_alarmcontent = alarmcontent;
120
+		}
121
+	}
122
+
123
+	int getAlarmenable() const
124
+	{
125
+		return m_alarmenable;
126
+	}
127
+
128
+	void setAlarmenable(int alarmenable)
129
+	{
130
+		m_alarmenable = alarmenable;
131
+	}
132
+
133
+	const std::string& getAlarmvalue() const
134
+	{
135
+		return m_alarmvalue;
136
+	}
137
+
138
+	void setAlarmvalue(const std::string& alarmvalue)
139
+	{
140
+		if (!alarmvalue.empty())
141
+		{
142
+			m_alarmvalue = alarmvalue;
143
+		}
144
+	}
145
+
146
+	int getEnable() const
147
+	{
148
+		return m_enable;
149
+	}
150
+
151
+	void setEnable(int enable)
152
+	{
153
+		m_enable = enable;
154
+	}
155
+
156
+	int getHisenable() const
157
+	{
158
+		return m_hisenable;
159
+	}
160
+
161
+	void setHisenable(int hisenable)
162
+	{
163
+		m_hisenable = hisenable;
164
+	}
165
+
166
+	const std::string& getHistimebase() const
167
+	{
168
+		return m_histimebase;
169
+	}
170
+
171
+	void setHistimebase(const std::string& histimebase)
172
+	{
173
+		if (!histimebase.empty())
174
+		{
175
+			m_histimebase = histimebase;
176
+		}
177
+	}
178
+
179
+	int getHistimes() const
180
+	{
181
+		return m_histimes;
182
+	}
183
+
184
+	void setHistimes(int histimes)
185
+	{
186
+		m_histimes = histimes;
187
+	}
188
+
189
+	const std::string& getHistype() const
190
+	{
191
+		return m_histype;
192
+	}
193
+
194
+	void setHistype(const std::string& histype)
195
+	{
196
+		if (!histype.empty())
197
+		{
198
+			m_histype = histype;
199
+		}
200
+	}
201
+
202
+	int getIndex() const
203
+	{
204
+		return m_index;
205
+	}
206
+
207
+	void setIndex(int index)
208
+	{
209
+		m_index = index;
210
+	}
211
+
212
+	const std::string& getInitvalue() const
213
+	{
214
+		return m_initvalue;
215
+	}
216
+
217
+	void setInitvalue(const std::string& initvalue)
218
+	{
219
+		if (!initvalue.empty())
220
+		{
221
+			m_initvalue = initvalue;
222
+		}
223
+	}
224
+
225
+	CLSID& getParaanalysisguid()
226
+	{
227
+		return m_paraanalysisguid;
228
+	}
229
+
230
+	void setParaanalysisguid(const CLSID& paraanalysisguid)
231
+	{
232
+		m_paraanalysisguid = paraanalysisguid;
233
+	}
234
+
235
+	double getRealmax() const
236
+	{
237
+		return m_realmax;
238
+	}
239
+
240
+	void setRealmax(double realmax)
241
+	{
242
+		m_realmax = realmax;
243
+	}
244
+
245
+	double getRealmin() const
246
+	{
247
+		return m_realmin;
248
+	}
249
+
250
+	void setRealmin(double realmin)
251
+	{
252
+		m_realmin = realmin;
253
+	}
254
+
255
+	const std::string& getResetcondition() const
256
+	{
257
+		return m_resetcondition;
258
+	}
259
+
260
+	void setResetcondition(const std::string& resetcondition)
261
+	{
262
+		if (!resetcondition.empty())
263
+		{
264
+			m_resetcondition = resetcondition;
265
+		}
266
+	}
267
+
268
+	const std::string& getResetvalue() const
269
+	{
270
+		return m_resetvalue;
271
+	}
272
+
273
+	void setResetvalue(const std::string& resetvalue)
274
+	{
275
+		if (!resetvalue.empty())
276
+		{
277
+			m_resetvalue = resetvalue;
278
+		}
279
+	}
280
+
281
+	double getSourcemax() const
282
+	{
283
+		return m_sourcemax;
284
+	}
285
+
286
+	void setSourcemax(double sourcemax)
287
+	{
288
+		m_sourcemax = sourcemax;
289
+	}
290
+
291
+	double getSourcemin() const
292
+	{
293
+		return m_sourcemin;
294
+	}
295
+
296
+	void setSourcemin(double sourcemin)
297
+	{
298
+		m_sourcemin = sourcemin;
299
+	}
300
+
301
+	const std::string& getValue() const
302
+	{
303
+		return m_value;
304
+	}
305
+
306
+	void setValue(const std::string& value)
307
+	{
308
+		if (!value.empty())
309
+		{
310
+
311
+			(void) pthread_mutex_lock(&xLock_1);
312
+			setValueO(m_value);
313
+
314
+			char t[256];
315
+			double sfvalue = 0;
316
+			std::string sdatatype = this->getBase().getParam("数据类型");
317
+
318
+			if((m_sourcemax-m_sourcemin)!=0)
319
+			{
320
+				if((sdatatype=="I")||(sdatatype=="B"))
321
+				{
322
+					int ivalue = strtol(value.c_str(),NULL,10);
323
+					sfvalue = (double)(((((double)ivalue-m_sourcemin)*(m_realmax-m_realmin))/(m_sourcemax-m_sourcemin))+m_realmin);
324
+					sprintf(t,"%.4f",sfvalue);
325
+					std::string str;
326
+					str = t;
327
+					m_value = str;
328
+				}
329
+				else
330
+				{
331
+					double ivalue = strtod(value.c_str(),NULL);
332
+					sfvalue = (double)(((((double)ivalue-m_sourcemin)*(m_realmax-m_realmin))/(m_sourcemax-m_sourcemin))+m_realmin);
333
+					sprintf(t,"%.4f",sfvalue);
334
+					std::string str;
335
+					str = t;
336
+					m_value = str;
337
+				}
338
+			}
339
+
340
+			struct timeval tv;
341
+			struct timezone tz;
342
+			struct tm *p;
343
+			gettimeofday(&tv, &tz);
344
+			p = localtime(&tv.tv_sec);
345
+
346
+			char timechar[255];
347
+			snprintf(timechar, 255, "%04d-%02d-%02d %02d:%02d:%02d,%3lf", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec,
348
+					(tv.tv_usec) * 0.001);
349
+
350
+			std::string result = timechar;
351
+
352
+			setSupdatetime(result);
353
+			long diff = (long)(tv.tv_sec * 1000 + tv.tv_usec*0.001) - lupdatetime;
354
+			setUpdatefreq(diff);
355
+
356
+			setLupdatetime((long)(tv.tv_sec * 1000 + tv.tv_usec*0.001));
357
+
358
+//			if(isTrigFaultOrReset(m_value,this->getAlarmvalue(),this->getAlarmcondition())&&!isFault&&!isReset) {
359
+//				this->setIsFault(true);
360
+//				trace("Item","报警触发");
361
+//				std::cout << isReset << "," << isFault << std::endl;
362
+//			}
363
+//
364
+//			if(isTrigFaultOrReset(m_value,this->getResetvalue(),this->getResetcondition())&&isFault&&!isReset) {
365
+//				this->setIsReset(true);
366
+//				trace("Item","报警复位");
367
+//				std::cout << isReset << "," << isFault << std::endl;
368
+//			}
369
+			(void) pthread_mutex_unlock(&xLock_1);
370
+		}
371
+	}
372
+
373
+	const std::string& getValueO() const
374
+	{
375
+		return m_value_o;
376
+	}
377
+
378
+	void setValueO(const std::string& valueO)
379
+	{
380
+		if (!valueO.empty())
381
+		{
382
+			m_value_o = valueO;
383
+		}
384
+	}
385
+
386
+	const std::string& getWvalue() const
387
+	{
388
+		return m_wvalue;
389
+	}
390
+
391
+	void setWvalue(const std::string& wvalue)
392
+	{
393
+		if (!wvalue.empty())
394
+		{
395
+			(void) pthread_mutex_lock(&xLock);
396
+			setWvalueO(m_wvalue);
397
+			m_wvalue = wvalue;
398
+			(void) pthread_mutex_unlock(&xLock);
399
+		}
400
+	}
401
+
402
+	const std::string& getWvalueO() const
403
+	{
404
+		return m_wvalue_o;
405
+	}
406
+
407
+	void setWvalueO(const std::string& wvalueO)
408
+	{
409
+		if (!wvalueO.empty())
410
+		{
411
+			m_wvalue_o = wvalueO;
412
+		}
413
+	}
414
+
415
+	const Packet* getParent() const
416
+	{
417
+		return m_parent;
418
+	}
419
+
420
+	void setParent(Packet* parent)
421
+	{
422
+		this->m_parent = parent;
423
+	}
424
+
425
+	const ParaAnalysisI* getPpara() const
426
+	{
427
+		return m_ppara;
428
+	}
429
+
430
+	void setPpara(ParaAnalysisI* ppara)
431
+	{
432
+		this->m_ppara = ppara;
433
+	}
434
+
435
+public:
436
+	bool isEqual(Item& item)
437
+	{
438
+		if ((this->getBase().getObjid() == item.getBase().getObjid())
439
+				|| (this->getBase().getName() == item.getBase().getName()))
440
+		{
441
+			log_i( "采集点ID或者名称相同: %s,%s", this->getBase().getObjid().toString().c_str(),this->getBase().getName().c_str());
442
+			return true;
443
+		}
444
+		return false;
445
+	}
446
+
447
+	void outInfo()
448
+	{
449
+		log_d( "采集点ID: %s", m_base.getObjid().toString().c_str());
450
+		log_d( "采集点名称: %s", m_base.getName().c_str());
451
+		log_d( "采集点参数: ");
452
+
453
+		for (std::pair<const std::string, std::string>& s : m_base.getParams())
454
+		{
455
+			log_d( "参数名称: %s, 参数值: %s", s.first.c_str(),s.second.c_str());
456
+		}
457
+		log_d( "采集点读写状态: %d", m_base.getRwstate());
458
+		log_d( "采集点优先级: %d", m_base.getPriority());
459
+		log_d( "采集点参数分析组件ID: %s", m_paraanalysisguid.toString().c_str());
460
+		log_d( "采集点参数分析组件句柄: %d", m_ppara);
461
+		log_d( "采集点索引号: %d", m_index);
462
+		log_d( "采集点源数据最小值: %f", m_sourcemin);
463
+		log_d( "采集点元数据最大值: %f", m_sourcemax);
464
+		log_d( "采集点实数据最小值: %f", m_realmin);
465
+		log_d( "采集点实数据最大值: %f", m_realmax);
466
+		log_d( "采集点初始值: %s", m_initvalue.c_str());
467
+		log_d( "采集点实时值: %s", m_value.c_str());
468
+		log_d( "采集点实时值上一拍: %s", m_value_o.c_str());
469
+		log_d( "采集点使能: %d", m_enable);
470
+		log_d( "采集点报警使能: %d", m_alarmenable);
471
+		log_d( "采集点报警条件: %s", m_alarmcondition.c_str());
472
+		log_d( "采集点报警值: %s", m_alarmvalue.c_str());
473
+		log_d( "采集点复位条件: %s", m_resetcondition.c_str());
474
+		log_d( "采集点复位值: %s", m_resetvalue.c_str());
475
+		log_d( "采集点报警内容: %s", m_alarmcontent.c_str());
476
+		log_d( "采集点历史数据使能: %d", m_hisenable);
477
+		log_d( "采集点历史保存类型: %s", m_histype.c_str());
478
+		log_d( "采集点历史保存时基: %s", m_histimebase.c_str());
479
+		log_d( "采集点历史保存周期: %d", m_histimes);
480
+		log_d( "采集点待写值: %s", m_wvalue.c_str());
481
+		log_d( "采集点待写值上一拍: %s", m_wvalue_o.c_str());
482
+		log_d( "采集点父句柄: %d", m_parent);
483
+	}
484
+
485
+	Item*& getRitem()
486
+	{
487
+		return m_ritem;
488
+	}
489
+
490
+	void setRitem(Item*& ritem)
491
+	{
492
+		m_ritem = ritem;
493
+	}
494
+
495
+	long getLupdatetime()
496
+	{
497
+		return lupdatetime;
498
+	}
499
+
500
+	void setLupdatetime(long lupdatetime)
501
+	{
502
+		this->lupdatetime = lupdatetime;
503
+	}
504
+
505
+	const std::string& getSupdatetime()
506
+	{
507
+		return supdatetime;
508
+	}
509
+
510
+	void setSupdatetime(const std::string& supdatetime)
511
+	{
512
+		this->supdatetime = supdatetime;
513
+	}
514
+
515
+	long getUpdatefreq()
516
+	{
517
+		return updatefreq;
518
+	}
519
+
520
+	void setUpdatefreq(long updatefreq)
521
+	{
522
+		this->updatefreq = updatefreq;
523
+	}
524
+
525
+private:
526
+	CLSID m_paraanalysisguid;	//----item's ParaAnalysisGUID
527
+	ParaAnalysisI* m_ppara;//----Item参数分析组件句柄
528
+
529
+	int m_index;//----item's index
530
+	double m_sourcemin;//----item's SourceMin
531
+	double m_sourcemax;//----item's SourceMax
532
+	double m_realmin;//----item's RealMin
533
+	double m_realmax;//----item's RealMax
534
+	std::string m_initvalue;//----item's InitValue
535
+	std::string m_value;//----item's Value
536
+	std::string m_value_o;//----item's Value_o
537
+
538
+	int m_enable;//----item's Enable
539
+	int m_alarmenable;//----item's AlarmEnable
540
+	std::string m_alarmcondition;//----item's AlarmCondition
541
+	std::string m_alarmvalue;//----item's AlarmValue
542
+	std::string m_resetcondition;//----item's ResetCondition
543
+	std::string m_resetvalue;//----item's ResetValue
544
+	std::string m_alarmcontent;//----item's AlarmContent
545
+	int m_hisenable;//----item's HisEnable
546
+	std::string m_histype;//----item's HisType
547
+	std::string m_histimebase;//----item's HisTimeBase
548
+	int m_histimes;//----item's HisTimes
549
+	std::string m_wvalue;//----item's write value
550
+	std::string m_wvalue_o;//----item's write value_o
551
+
552
+	Base m_base;
553
+	Packet* m_parent;
554
+	Item* m_ritem;
555
+
556
+	std::string supdatetime;
557
+	long lupdatetime;
558
+	long updatefreq;
559
+
560
+private:
561
+	pthread_mutex_t xLock;
562
+	pthread_mutex_t xLock_1;
563
+
564
+private:
565
+	bool isFault;//----故障标志位
566
+	bool isReset;//----复位标志位
567
+	std::string faulttime;//----故障发生时间
568
+	std::string resettime;//----故障结束时间
569
+	std::string faultdata;//----故障时刻的值
570
+
571
+//	std::string getLocalTime()
572
+//	{
573
+//		struct timeval tv;
574
+//		struct timezone tz;
575
+//		struct tm *p;
576
+//		gettimeofday(&tv, &tz);
577
+//		p = localtime(&tv.tv_sec);
578
+//
579
+//		char timechar[255];
580
+//		snprintf(timechar, 255, "%04d-%02d-%02d %02d:%02d:%02d,%3lf",
581
+//				1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour,
582
+//				p->tm_min, p->tm_sec, (tv.tv_usec) * 0.001);
583
+//
584
+//		std::string result = timechar;
585
+//		return result;
586
+//	}
587
+
588
+//	bool isTrigFaultOrReset(std::string src, std::string dst, std::string condition) {
589
+//		bool bresult = false;
590
+//
591
+//		if(this->getAlarmenable()==1) {
592
+//			double fsrc = 0.0;
593
+//			double fdst = 0.0;
594
+//
595
+//			fsrc = strtod(src.c_str(),NULL);
596
+//			fdst = strtod(dst.c_str(),NULL);
597
+//
598
+//			if(condition==">") {
599
+//				if(fsrc>fdst) {
600
+//					bresult = true;
601
+//				}
602
+//			}
603
+//			else if(condition==">=") {
604
+//				if(fsrc>=fdst) {
605
+//					bresult = true;
606
+//				}
607
+//			}
608
+//			else if(condition=="=") {
609
+//				if(fsrc==fdst) {
610
+//					bresult = true;
611
+//				}
612
+//			}
613
+//			else if(condition=="<=") {
614
+//				if(fsrc<=fdst) {
615
+//					bresult = true;
616
+//				}
617
+//			}
618
+//			else if(condition=="<") {
619
+//				if(fsrc<fdst) {
620
+//					bresult = true;
621
+//				}
622
+//			}
623
+//			else if(condition=="!=") {
624
+//				if(fsrc!=fdst) {
625
+//					bresult = true;
626
+//				}
627
+//			}
628
+//		}
629
+//		else
630
+//		{
631
+//			bresult = false;
632
+//		}
633
+//
634
+//		return bresult;
635
+//	}
636
+};
637
+
638
+#endif /* SERVICEMODEL_ITEM_H_ */

+ 162
- 0
fault-recorder/servicemodel/Packet.h View File

@@ -0,0 +1,162 @@
1
+/*
2
+ * Packet.h
3
+ *
4
+ *  Created on: 2016年11月10日
5
+ *      Author: Mr_zhu
6
+ *     Content: 
7
+ */
8
+
9
+#ifndef SERVICEMODEL_PACKET_H_
10
+#define SERVICEMODEL_PACKET_H_
11
+
12
+#include <vector>
13
+
14
+#include "../common/Type.h"
15
+#include "Base.h"
16
+#include "Item.h"
17
+
18
+class Device;
19
+
20
+class Packet
21
+{
22
+public:
23
+	Packet() :
24
+			m_parent(NULL)
25
+	{
26
+
27
+	}
28
+	virtual ~Packet()
29
+	{
30
+	}
31
+
32
+	const CLSID& getClsid() const
33
+	{
34
+		return m_clsid;
35
+	}
36
+
37
+	void setClsid(const CLSID& clsid)
38
+	{
39
+		this->m_clsid = clsid;
40
+	}
41
+
42
+	const Device* getParent() const
43
+	{
44
+		return m_parent;
45
+	}
46
+
47
+	void setParent(Device* parent)
48
+	{
49
+		this->m_parent = parent;
50
+	}
51
+
52
+	std::vector<Item*>& getVitem()
53
+	{
54
+		return m_vitem;
55
+	}
56
+
57
+	void setVitem(const std::vector<Item*>& vitem)
58
+	{
59
+		this->m_vitem = vitem;
60
+	}
61
+
62
+	Base& getBase()
63
+	{
64
+		return m_base;
65
+	}
66
+
67
+	void setBase(const Base& base)
68
+	{
69
+		this->m_base = base;
70
+	}
71
+
72
+	HRESULT addItem(Item* item)
73
+	{
74
+		bool isexist = false;
75
+
76
+		for (Item*& i : m_vitem)
77
+		{
78
+			if (i->isEqual(*item))
79
+			{
80
+				isexist = true;
81
+				break;
82
+			}
83
+		}
84
+		if (!isexist)
85
+		{
86
+			m_vitem.push_back(item);
87
+
88
+			return S_OK;
89
+		}
90
+		return S_FALSE;
91
+	}
92
+
93
+	ULONG getItemCount()
94
+	{
95
+		return m_vitem.size();
96
+	}
97
+
98
+public:
99
+	bool isEqual(Packet& packet)
100
+	{
101
+		bool bresult = true;
102
+
103
+		if ((packet.getClsid() == m_clsid) && (packet.getParent() == m_parent))
104
+		{
105
+			return true;
106
+		}
107
+		else
108
+		{
109
+			bresult = false;
110
+		}
111
+		std::vector<Item*>& v = packet.getVitem();
112
+		if (this->getItemCount() == packet.getItemCount())
113
+		{
114
+			for (unsigned int i = 0; i < m_vitem.size(); i++)
115
+			{
116
+				if (!(m_vitem.at(i)->isEqual(*(v.at(i)))))
117
+				{
118
+					bresult = false;
119
+					break;
120
+				}
121
+			}
122
+		}
123
+
124
+		return bresult;
125
+	}
126
+
127
+	void outInfo()
128
+	{
129
+
130
+		log_d( "采集包ID: %s",
131
+				m_base.getObjid().toString().c_str());
132
+		log_d( "采集包名称: %s",
133
+				m_base.getName().c_str());
134
+		log_d( "采集包参数: ");
135
+		for (std::pair<const std::string, std::string>& s : m_base.getParams())
136
+		{
137
+			log_d( "参数名称: %s, 参数值: %s",
138
+					s.first.c_str(),s.second.c_str());
139
+		}
140
+
141
+		log_d( "采集包读写状态: %d", m_base.getRwstate());
142
+		log_d( "采集包优先级: %d", m_base.getPriority());
143
+		log_d( "采集包父句柄: %d", m_parent);
144
+
145
+		log_d( "采集包总采集点数: %d", m_vitem.size());
146
+		log_d( "采集包采集点信息: ");
147
+
148
+		for (Item*& i : m_vitem)
149
+		{
150
+			i->outInfo();
151
+		}
152
+	}
153
+
154
+private:
155
+	CLSID m_clsid;
156
+	Device* m_parent;
157
+	std::vector<Item*> m_vitem;
158
+
159
+	Base m_base;
160
+};
161
+
162
+#endif /* SERVICEMODEL_PACKET_H_ */

+ 120
- 0
fault-recorder/test/main.cpp View File

@@ -0,0 +1,120 @@
1
+/*
2
+ * main.cpp
3
+ *
4
+ *  Created on: 2017年1月4日
5
+ *      Author: nego
6
+ */
7
+
8
+#include <stddef.h>
9
+#include <vector>
10
+
11
+#include "../common/GUID.cpp"
12
+#include "../common/Type.h"
13
+#include "../externservice/DAControlerI.h"
14
+#include "../servicemodel/Device.h"
15
+#include "../util/impl/ClassLoaderImpl.h"
16
+
17
+#include "../action/FaultRecorder.h"
18
+#include "../action/impl/fault_filter.h"
19
+
20
+class DataRecorderI;
21
+
22
+int main()
23
+{
24
+	ClassLoaderI *pClass = new ClassLoaderImpl();
25
+    //ProtocolImpl* pP = new ProtocolImpl();
26
+    ProtocolI_Fault* pP = new ProtocolImpl();
27
+    data_item *source = new data_item();
28
+    data_item *fault = new data_item();
29
+    std::string dev_name;
30
+	DAControlerI *pDA;
31
+	GUID guid = stringtoGUID("4140b836-5fe8-472b-a428-10e103b5016d");
32
+
33
+	pClass->loadClass(IID_IDAControler, guid, (void**) &pDA);
34
+
35
+	std::vector<Device*> ld;
36
+    if (pDA != NULL)
37
+    {
38
+        pDA->init();
39
+        pDA->start();
40
+        ld = pDA->getDeviceList();
41
+
42
+        if (ld.size() <= 0) {
43
+            printf("ld.size is null\n", ld.size());
44
+            delete pP;
45
+            delete source;
46
+            delete fault;
47
+            delete pClass;
48
+            return 0;
49
+        }
50
+    }
51
+
52
+
53
+    pP->set_fault_list(ld);
54
+	while (true)
55
+	{
56
+        #if 0
57
+        if (ld.size() > 0)
58
+        {
59
+            source->source_pitem.clear();
60
+            fault->fault_pitem.clear();
61
+            source->number = 0;
62
+            printf("ld.size() is %d\n", ld.size());
63
+            for (int i = 0; i < ld.size(); ++i)
64
+            {
65
+                source->number += ld.at(i)->getVpacket().size();
66
+                //设备名称
67
+                dev_name = ld.at(i)->getBase().getName().c_str();
68
+                //printf("i is %d, 设备名称为%s, count is %d\n", i, dev_name.c_str(), source->number);
69
+                for(int j = 0; j < ld.at(i)->getVpacket().size(); ++j)
70
+                {
71
+                    Packet *t_ppacket = ld.at(i)->getVpacket().at(j);
72
+                    //Device *ptdevice = (Device*) (t_ppacket->getParent());
73
+                    if (t_ppacket == NULL)
74
+                    {
75
+                        printf("查找的包为空\n");
76
+                        continue;
77
+                    }
78
+
79
+                    std::string t_sId, t_sname, t_svalue;
80
+                    Base &t_base = t_ppacket->getVitem().at(0)->getBase();
81
+                    t_sId = t_base.getObjid().toString().c_str();
82
+                    t_sname = t_base.getName().c_str();
83
+                    t_svalue = t_ppacket->getVitem().at(0)->getValue().c_str();
84
+                    printf("t_sId is %s, t_sname is %s, t_svalue is %s\n", t_sId.c_str(), t_sname.c_str(), t_svalue.c_str());
85
+
86
+                    // t_sId = t_base.getParam("功能码");
87
+                    //int t_iId = 0;
88
+                    //t_iId = strtol(t_sId.c_str(), NULL, HEX);   //----获取帧ID
89
+                    //std::string forward_value = t_ppacket->getVitem()->getValue();
90
+
91
+                    //保存故障滤波文件数据
92
+                    printf("i is %d, 设备名称为%s, count is %d\n", i, dev_name.c_str(), source->number);
93
+                    source->add_source_item(dev_name, t_sname, t_sId, t_svalue);
94
+                }
95
+            }
96
+            //临时创建故障检测文件
97
+            fault->number = 1;
98
+            std::string test_value = "111";
99
+            fault->add_fault_item("fault_test", "fault_test", test_value, test_value);
100
+            if (!source) {
101
+                printf("source is NULL\n");
102
+            }
103
+            if (!fault) {
104
+                printf("fault is NULL\n");
105
+            }
106
+            pP->fault_filter(fault, source, 1, 2);
107
+        }
108
+        #endif
109
+		secondsSleep(5);
110
+	}
111
+
112
+    delete pP;
113
+    delete source;
114
+    delete fault;
115
+    delete pClass;
116
+
117
+    return 0;
118
+
119
+}
120
+

+ 24
- 0
fault-recorder/util/ClassLoaderI.h View File

@@ -0,0 +1,24 @@
1
+/*
2
+ * ClassLoader.h 加载组件实例
3
+ *
4
+ *  Created on: 2016年11月7日
5
+ *      Author: Mr_zhu
6
+ *     Content: 加载组件实例
7
+ */
8
+
9
+#ifndef UTIL_CLASSLOADERI_H_
10
+#define UTIL_CLASSLOADERI_H_
11
+
12
+#include "../common/Type.h"
13
+
14
+interface ClassLoaderI
15
+{
16
+public:
17
+
18
+	virtual HRESULT loadClass(const IID& iid, CLSID& clsid, void** pcmpnt) = 0;
19
+	virtual HRESULT loadSqliteClass(void** pcmpnt) = 0;
20
+
21
+	virtual ~ClassLoaderI(){}
22
+};
23
+
24
+#endif /* UTIL_CLASSLOADERI_H_ */

+ 43
- 0
fault-recorder/util/CodeConverter.h View File

@@ -0,0 +1,43 @@
1
+/*
2
+ * CodeConverter.h
3
+ *
4
+ *  Created on: 2017年4月21日
5
+ *      Author: vsbes
6
+ */
7
+
8
+#ifndef UTIL_CODECONVERTER_H_
9
+#define UTIL_CODECONVERTER_H_
10
+
11
+#include <iconv.h>
12
+#include <cstring>
13
+
14
+// 代码转换操作类
15
+class CodeConverter {
16
+private:
17
+	iconv_t cd;
18
+public:
19
+	// 构造
20
+	CodeConverter(const char *from_charset, const char *to_charset) {
21
+		cd = iconv_open(to_charset, from_charset);
22
+
23
+		if((int )cd==-1){
24
+			perror("cd ");
25
+		}
26
+	}
27
+
28
+	// 析构
29
+	~CodeConverter() {
30
+		iconv_close(cd);
31
+	}
32
+
33
+	// 转换输出
34
+	int convert(char *inbuf, int inlen, char *outbuf, int outlen) {
35
+		char **pin = &inbuf;
36
+		char **pout = &outbuf;
37
+
38
+		memset(outbuf, 0, outlen);
39
+		return iconv(cd, pin, (size_t *) &inlen, pout, (size_t *) &outlen);
40
+	}
41
+};
42
+
43
+#endif /* UTIL_CODECONVERTER_H_ */

+ 273
- 0
fault-recorder/util/easylogger/inc/elog.h View File

@@ -0,0 +1,273 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2019, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: It is an head file for this library. You can see all be called functions.
26
+ * Created on: 2015-04-28
27
+ */
28
+
29
+#ifndef __ELOG_H__
30
+#define __ELOG_H__
31
+
32
+#include <elog_cfg.h>
33
+#include <stdint.h>
34
+#include <stddef.h>
35
+#include <stdbool.h>
36
+
37
+#ifdef __cplusplus
38
+extern "C" {
39
+#endif
40
+
41
+/* output log's level */
42
+#define ELOG_LVL_ASSERT                      0
43
+#define ELOG_LVL_ERROR                       1
44
+#define ELOG_LVL_WARN                        2
45
+#define ELOG_LVL_INFO                        3
46
+#define ELOG_LVL_DEBUG                       4
47
+#define ELOG_LVL_VERBOSE                     5
48
+
49
+/* the output silent level and all level for filter setting */
50
+#define ELOG_FILTER_LVL_SILENT               ELOG_LVL_ASSERT
51
+#define ELOG_FILTER_LVL_ALL                  ELOG_LVL_VERBOSE
52
+
53
+/* output log's level total number */
54
+#define ELOG_LVL_TOTAL_NUM                   6
55
+
56
+/* EasyLogger software version number */
57
+#define ELOG_SW_VERSION                      "2.2.99"
58
+
59
+/* EasyLogger assert for developer. */
60
+#ifdef ELOG_ASSERT_ENABLE
61
+    #define ELOG_ASSERT(EXPR)                                                 \
62
+    if (!(EXPR))                                                              \
63
+    {                                                                         \
64
+        if (elog_assert_hook == NULL) {                                       \
65
+            elog_a("elog", "(%s) has assert failed at %s:%ld.", #EXPR, __FUNCTION__, __LINE__); \
66
+            while (1);                                                        \
67
+        } else {                                                              \
68
+            elog_assert_hook(#EXPR, __FUNCTION__, __LINE__);                  \
69
+        }                                                                     \
70
+    }
71
+#else
72
+    #define ELOG_ASSERT(EXPR)                    ((void)0);
73
+#endif
74
+
75
+#ifndef ELOG_OUTPUT_ENABLE
76
+    #define elog_assert(tag, ...)
77
+    #define elog_error(tag, ...)
78
+    #define elog_warn(tag, ...)
79
+    #define elog_info(tag, ...)
80
+    #define elog_debug(tag, ...)
81
+    #define elog_verbose(tag, ...)
82
+#else /* ELOG_OUTPUT_ENABLE */
83
+    #if ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT
84
+        #define elog_assert(tag, ...) \
85
+                elog_output(ELOG_LVL_ASSERT, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
86
+    #else
87
+        #define elog_assert(tag, ...)
88
+    #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_ASSERT */
89
+
90
+    #if ELOG_OUTPUT_LVL >= ELOG_LVL_ERROR
91
+        #define elog_error(tag, ...) \
92
+                elog_output(ELOG_LVL_ERROR, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
93
+    #else
94
+        #define elog_error(tag, ...)
95
+    #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_ERROR */
96
+
97
+    #if ELOG_OUTPUT_LVL >= ELOG_LVL_WARN
98
+        #define elog_warn(tag, ...) \
99
+                elog_output(ELOG_LVL_WARN, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
100
+    #else
101
+        #define elog_warn(tag, ...)
102
+    #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_WARN */
103
+
104
+    #if ELOG_OUTPUT_LVL >= ELOG_LVL_INFO
105
+        #define elog_info(tag, ...) \
106
+                elog_output(ELOG_LVL_INFO, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
107
+    #else
108
+        #define elog_info(tag, ...)
109
+    #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_INFO */
110
+
111
+    #if ELOG_OUTPUT_LVL >= ELOG_LVL_DEBUG
112
+        #define elog_debug(tag, ...) \
113
+                elog_output(ELOG_LVL_DEBUG, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
114
+    #else
115
+        #define elog_debug(tag, ...)
116
+    #endif /* ELOG_OUTPUT_LVL >= ELOG_LVL_DEBUG */
117
+
118
+    #if ELOG_OUTPUT_LVL == ELOG_LVL_VERBOSE
119
+        #define elog_verbose(tag, ...) \
120
+                elog_output(ELOG_LVL_VERBOSE, tag, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
121
+    #else
122
+        #define elog_verbose(tag, ...)
123
+    #endif /* ELOG_OUTPUT_LVL == ELOG_LVL_VERBOSE */
124
+#endif /* ELOG_OUTPUT_ENABLE */
125
+
126
+/* all formats index */
127
+typedef enum {
128
+    ELOG_FMT_LVL    = 1 << 0, /**< level */
129
+    ELOG_FMT_TAG    = 1 << 1, /**< tag */
130
+    ELOG_FMT_TIME   = 1 << 2, /**< current time */
131
+    ELOG_FMT_P_INFO = 1 << 3, /**< process info */
132
+    ELOG_FMT_T_INFO = 1 << 4, /**< thread info */
133
+    ELOG_FMT_DIR    = 1 << 5, /**< file directory and name */
134
+    ELOG_FMT_FUNC   = 1 << 6, /**< function name */
135
+    ELOG_FMT_LINE   = 1 << 7, /**< line number */
136
+} ElogFmtIndex;
137
+
138
+/* macro definition for all formats */
139
+#define ELOG_FMT_ALL    (ELOG_FMT_LVL|ELOG_FMT_TAG|ELOG_FMT_TIME|ELOG_FMT_P_INFO|ELOG_FMT_T_INFO| \
140
+    ELOG_FMT_DIR|ELOG_FMT_FUNC|ELOG_FMT_LINE)
141
+
142
+/* output log's tag filter */
143
+typedef struct {
144
+    uint8_t level;
145
+    char tag[ELOG_FILTER_TAG_MAX_LEN + 1];
146
+    bool tag_use_flag; /**< false : tag is no used   true: tag is used */
147
+} ElogTagLvlFilter, *ElogTagLvlFilter_t;
148
+
149
+/* output log's filter */
150
+typedef struct {
151
+    uint8_t level;
152
+    char tag[ELOG_FILTER_TAG_MAX_LEN + 1];
153
+    char keyword[ELOG_FILTER_KW_MAX_LEN + 1];
154
+    ElogTagLvlFilter tag_lvl[ELOG_FILTER_TAG_LVL_MAX_NUM];
155
+} ElogFilter, *ElogFilter_t;
156
+
157
+/* easy logger */
158
+typedef struct {
159
+    ElogFilter filter;
160
+    size_t enabled_fmt_set[ELOG_LVL_TOTAL_NUM];
161
+    bool init_ok;
162
+    bool output_enabled;
163
+    bool output_lock_enabled;
164
+    bool output_is_locked_before_enable;
165
+    bool output_is_locked_before_disable;
166
+
167
+#ifdef ELOG_COLOR_ENABLE
168
+    bool text_color_enabled;
169
+#endif
170
+
171
+}EasyLogger, *EasyLogger_t;
172
+
173
+/* EasyLogger error code */
174
+typedef enum {
175
+    ELOG_NO_ERR,
176
+} ElogErrCode;
177
+
178
+/* elog.c */
179
+ElogErrCode elog_init(void);
180
+void elog_start(void);
181
+void elog_set_output_enabled(bool enabled);
182
+bool elog_get_output_enabled(void);
183
+void elog_set_text_color_enabled(bool enabled);
184
+bool elog_get_text_color_enabled(void);
185
+void elog_set_fmt(uint8_t level, size_t set);
186
+void elog_set_filter(uint8_t level, const char *tag, const char *keyword);
187
+void elog_set_filter_lvl(uint8_t level);
188
+void elog_set_filter_tag(const char *tag);
189
+void elog_set_filter_kw(const char *keyword);
190
+void elog_set_filter_tag_lvl(const char *tag, uint8_t level);
191
+uint8_t elog_get_filter_tag_lvl(const char *tag);
192
+void elog_raw(const char *format, ...);
193
+void elog_output(uint8_t level, const char *tag, const char *file, const char *func,
194
+        const long line, const char *format, ...);
195
+void elog_output_lock_enabled(bool enabled);
196
+extern void (*elog_assert_hook)(const char* expr, const char* func, size_t line);
197
+void elog_assert_set_hook(void (*hook)(const char* expr, const char* func, size_t line));
198
+int8_t elog_find_lvl(const char *log);
199
+const char *elog_find_tag(const char *log, uint8_t lvl, size_t *tag_len);
200
+void elog_hexdump(const char *name, uint8_t width, uint8_t *buf, uint16_t size);
201
+
202
+#define elog_a(tag, ...)     elog_assert(tag, __VA_ARGS__)
203
+#define elog_e(tag, ...)     elog_error(tag, __VA_ARGS__)
204
+#define elog_w(tag, ...)     elog_warn(tag, __VA_ARGS__)
205
+#define elog_i(tag, ...)     elog_info(tag, __VA_ARGS__)
206
+#define elog_d(tag, ...)     elog_debug(tag, __VA_ARGS__)
207
+#define elog_v(tag, ...)     elog_verbose(tag, __VA_ARGS__)
208
+
209
+/**
210
+ * log API short definition
211
+ * NOTE: The `LOG_TAG` and `LOG_LVL` must defined before including the <elog.h> when you want to use log_x API.
212
+ */
213
+#if !defined(LOG_TAG)
214
+    #define LOG_TAG          "NO_TAG"
215
+#endif
216
+#if !defined(LOG_LVL)
217
+    #define LOG_LVL          ELOG_LVL_VERBOSE
218
+#endif
219
+#if LOG_LVL >= ELOG_LVL_ASSERT
220
+    #define log_a(...)       elog_a(LOG_TAG, __VA_ARGS__)
221
+#else
222
+    #define log_a(...)       ((void)0);
223
+#endif
224
+#if LOG_LVL >= ELOG_LVL_ERROR
225
+    #define log_e(...)       elog_e(LOG_TAG, __VA_ARGS__)
226
+#else
227
+    #define log_e(...)       ((void)0);
228
+#endif
229
+#if LOG_LVL >= ELOG_LVL_WARN
230
+    #define log_w(...)       elog_w(LOG_TAG, __VA_ARGS__)
231
+#else
232
+    #define log_w(...)       ((void)0);
233
+#endif
234
+#if LOG_LVL >= ELOG_LVL_INFO
235
+    #define log_i(...)       elog_i(LOG_TAG, __VA_ARGS__)
236
+#else
237
+    #define log_i(...)       ((void)0);
238
+#endif
239
+#if LOG_LVL >= ELOG_LVL_DEBUG
240
+    #define log_d(...)       elog_d(LOG_TAG, __VA_ARGS__)
241
+#else
242
+    #define log_d(...)       ((void)0);
243
+#endif
244
+#if LOG_LVL >= ELOG_LVL_VERBOSE
245
+    #define log_v(...)       elog_v(LOG_TAG, __VA_ARGS__)
246
+#else
247
+    #define log_v(...)       ((void)0);
248
+#endif
249
+
250
+/* assert API short definition */
251
+#if !defined(assert)
252
+    #define assert           ELOG_ASSERT
253
+#endif
254
+
255
+/* elog_buf.c */
256
+void elog_buf_enabled(bool enabled);
257
+void elog_flush(void);
258
+
259
+/* elog_async.c */
260
+void elog_async_enabled(bool enabled);
261
+size_t elog_async_get_log(char *log, size_t size);
262
+size_t elog_async_get_line_log(char *log, size_t size);
263
+
264
+/* elog_utils.c */
265
+size_t elog_strcpy(size_t cur_len, char *dst, const char *src);
266
+size_t elog_cpyln(char *line, const char *log, size_t len);
267
+void *elog_memcpy(void *dst, const void *src, size_t count);
268
+
269
+#ifdef __cplusplus
270
+}
271
+#endif
272
+
273
+#endif /* __ELOG_H__ */

+ 67
- 0
fault-recorder/util/easylogger/inc/elog_cfg.h View File

@@ -0,0 +1,67 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: It is the configure head file for this library.
26
+ * Created on: 2015-07-30
27
+ */
28
+
29
+#ifndef _ELOG_CFG_H_
30
+#define _ELOG_CFG_H_
31
+
32
+/* enable log output. default open this macro */
33
+#define ELOG_OUTPUT_ENABLE
34
+/* enable log write file. default open this macro */
35
+#define ELOG_FILE_ENABLE
36
+/* enable flush file cache. default open this macro */
37
+#define ELOG_FILE_FLUSH_CAHCE_ENABLE
38
+/* setting static output log level */
39
+#define ELOG_OUTPUT_LVL                      ELOG_LVL_INFO
40
+/* enable assert check */
41
+#define ELOG_ASSERT_ENABLE
42
+/* buffer size for every line's log */
43
+#define ELOG_LINE_BUF_SIZE                   512
44
+/* output line number max length */
45
+#define ELOG_LINE_NUM_MAX_LEN                5
46
+/* output filter's tag max length */
47
+#define ELOG_FILTER_TAG_MAX_LEN              16
48
+/* output filter's keyword max length */
49
+#define ELOG_FILTER_KW_MAX_LEN               16
50
+/* output filter's tag level max num */
51
+#define ELOG_FILTER_TAG_LVL_MAX_NUM          5
52
+/* output newline sign */
53
+#define ELOG_NEWLINE_SIGN                    "\n"
54
+/* enable log color */
55
+// #define ELOG_COLOR_ENABLE
56
+/* enable asynchronous output mode */
57
+#define ELOG_ASYNC_OUTPUT_ENABLE
58
+/* the highest output level for async mode, other level will sync output */
59
+#define ELOG_ASYNC_OUTPUT_LVL                ELOG_LVL_INFO
60
+/* buffer size for asynchronous output mode */
61
+#define ELOG_ASYNC_OUTPUT_BUF_SIZE           (ELOG_LINE_BUF_SIZE * 100)
62
+/* each asynchronous output's log which must end with newline sign */
63
+//#define ELOG_ASYNC_LINE_OUTPUT
64
+/* asynchronous output mode using POSIX pthread implementation */
65
+#define ELOG_ASYNC_OUTPUT_USING_PTHREAD
66
+
67
+#endif /* _ELOG_CFG_H_ */

+ 165
- 0
fault-recorder/util/easylogger/plugins/file/elog_file.c View File

@@ -0,0 +1,165 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2019, Qintl, <qintl_linux@163.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: Save log to file.
26
+ * Created on: 2019-01-05
27
+ */
28
+
29
+ #define LOG_TAG    "elog.file"
30
+
31
+#include <stdio.h>
32
+#include <stdbool.h>
33
+#include <stdlib.h>
34
+#include <string.h>
35
+
36
+#include "elog_file.h"
37
+
38
+/* initialize OK flag */
39
+static bool init_ok = false;
40
+static FILE *fp = NULL;
41
+static ElogFileCfg local_cfg;
42
+
43
+ElogErrCode elog_file_init(void)
44
+{
45
+    ElogErrCode result = ELOG_NO_ERR;
46
+    ElogFileCfg cfg;
47
+
48
+    if (init_ok)
49
+        goto __exit;
50
+
51
+    elog_file_port_init();
52
+
53
+    cfg.name = ELOG_FILE_NAME;
54
+    cfg.max_size = ELOG_FILE_MAX_SIZE;
55
+    cfg.max_rotate = ELOG_FILE_MAX_ROTATE;
56
+
57
+    elog_file_config(&cfg);
58
+
59
+    init_ok = true;
60
+__exit:
61
+    return result;
62
+}
63
+
64
+/*
65
+ * rotate the log file xxx.log.n-1 => xxx.log.n, and xxx.log => xxx.log.0
66
+ */
67
+static bool elog_file_rotate(void)
68
+{
69
+#define SUFFIX_LEN                     10
70
+    /* mv xxx.log.n-1 => xxx.log.n, and xxx.log => xxx.log.0 */
71
+    int n, err = 0;
72
+    char oldpath[256], newpath[256];
73
+    size_t base = strlen(local_cfg.name);
74
+    bool result = true;
75
+    FILE *tmp_fp;
76
+
77
+    memcpy(oldpath, local_cfg.name, base);
78
+    memcpy(newpath, local_cfg.name, base);
79
+
80
+    fclose(fp);
81
+
82
+    for (n = local_cfg.max_rotate - 1; n >= 0; --n) {
83
+        snprintf(oldpath + base, SUFFIX_LEN, n ? ".%d" : "", n - 1);
84
+        snprintf(newpath + base, SUFFIX_LEN, ".%d", n);
85
+        /* remove the old file */
86
+        if ((tmp_fp = fopen(newpath , "r")) != NULL) {
87
+            fclose(tmp_fp);
88
+            remove(newpath);
89
+        }
90
+        /* change the new log file to old file name */
91
+        if ((tmp_fp = fopen(oldpath , "r")) != NULL) {
92
+            fclose(tmp_fp);
93
+            err = rename(oldpath, newpath);
94
+        }
95
+
96
+        if (err < 0) {
97
+            result = false;
98
+            goto __exit;
99
+        }
100
+    }
101
+
102
+__exit:
103
+    /* reopen the file */
104
+    fp = fopen(local_cfg.name, "a+");
105
+
106
+    return result;
107
+}
108
+
109
+
110
+void elog_file_write(const char *log, size_t size)
111
+{
112
+    size_t file_size = 0;
113
+
114
+    ELOG_ASSERT(init_ok);
115
+    ELOG_ASSERT(log);
116
+
117
+    elog_file_port_lock();
118
+
119
+    fseek(fp, 0L, SEEK_END);
120
+    file_size = ftell(fp);
121
+
122
+    if (unlikely(file_size > local_cfg.max_size)) {
123
+#if ELOG_FILE_MAX_ROTATE > 0
124
+        if (!elog_file_rotate()) {
125
+            goto __exit;
126
+        }
127
+#else
128
+        goto __exit;
129
+#endif
130
+    }
131
+
132
+    fwrite(log, size, 1, fp);
133
+
134
+#ifdef ELOG_FILE_FLUSH_CAHCE_ENABLE
135
+    fflush(fp);
136
+#endif
137
+
138
+__exit:
139
+    elog_file_port_unlock();
140
+}
141
+
142
+void elog_file_deinit(void)
143
+{
144
+    ELOG_ASSERT(init_ok);
145
+
146
+    elog_file_port_deinit();
147
+    fclose(fp);
148
+}
149
+
150
+void elog_file_config(ElogFileCfg *cfg)
151
+{
152
+    if (fp) {
153
+        fclose(fp);
154
+    }
155
+
156
+    elog_file_port_lock();
157
+
158
+    local_cfg.name = cfg->name;
159
+    local_cfg.max_size = cfg->max_size;
160
+    local_cfg.max_rotate = cfg->max_rotate;
161
+
162
+    fp = fopen(local_cfg.name, "a+");
163
+
164
+    elog_file_port_unlock();
165
+}

+ 72
- 0
fault-recorder/util/easylogger/plugins/file/elog_file.h View File

@@ -0,0 +1,72 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2019, Qintl, <qintl_linux@163.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function:  It is an head file for file log plugin. You can see all be called functions.
26
+ * Created on: 2019-01-05
27
+ */
28
+
29
+#ifndef __ELOG_FILE__H__
30
+#define __ELOG_FILE__H__
31
+
32
+#include <stdio.h>
33
+#include <elog.h>
34
+#include <elog_file_cfg.h>
35
+
36
+#ifdef __cplusplus
37
+extern "C" {
38
+#endif
39
+
40
+/* EasyLogger file log plugin's software version number */
41
+#define ELOG_FILE_SW_VERSION                "V1.0.0"
42
+#ifdef linux
43
+#define likely(x) __builtin_expect(!!(x), 1)
44
+#define unlikely(x) __builtin_expect(!!(x), 0)
45
+#else
46
+#define likely(x)   (x)
47
+#define unlikely(x) (x)
48
+#endif
49
+
50
+typedef struct {
51
+    char *name;              /* file name */
52
+    size_t max_size;         /* file max size */
53
+    int max_rotate;          /* max rotate file count */
54
+} ElogFileCfg;
55
+
56
+/* elog_file.c */
57
+ElogErrCode elog_file_init(void);
58
+void elog_file_write(const char *log, size_t size);
59
+void elog_file_config(ElogFileCfg *cfg);
60
+void elog_file_deinit(void);
61
+
62
+/* elog_file_port.c */
63
+ElogErrCode elog_file_port_init(void);
64
+void elog_file_port_lock(void);
65
+void elog_file_port_unlock(void);
66
+void elog_file_port_deinit(void);
67
+
68
+#ifdef __cplusplus
69
+}
70
+#endif
71
+
72
+#endif

+ 41
- 0
fault-recorder/util/easylogger/plugins/file/elog_file_cfg.h View File

@@ -0,0 +1,41 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2019, Qintl, <qintl_linux@163.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function:  It is the configure head file for this flash log plugin.
26
+ * Created on: 2019-01-05
27
+ */
28
+
29
+#ifndef _ELOG_FILE_CFG_H_
30
+#define _ELOG_FILE_CFG_H_
31
+
32
+/* EasyLogger file log plugin's using file name */
33
+#define ELOG_FILE_NAME      "/mnt/logs/deecs_datapublish.out"
34
+
35
+/* EasyLogger file log plugin's using file max size */
36
+#define ELOG_FILE_MAX_SIZE  (10 * 1024 * 1024)
37
+
38
+/* EasyLogger file log plugin's using max rotate file count */
39
+#define ELOG_FILE_MAX_ROTATE 5
40
+
41
+#endif /* _ELOG_FILE_CFG_H_ */

+ 160
- 0
fault-recorder/util/easylogger/plugins/file/elog_file_port.c View File

@@ -0,0 +1,160 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2019, Qintl, <qintl_linux@163.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function:  Portable interface for EasyLogger's file log pulgin.
26
+ * Created on: 2019-01-05
27
+ */
28
+
29
+#include <stdio.h>
30
+#include <sys/types.h>
31
+#include <sys/stat.h>
32
+#include <fcntl.h>
33
+#include <sys/ipc.h>
34
+#include <sys/sem.h>
35
+
36
+#include <unistd.h>
37
+
38
+#include <elog_file.h>
39
+#include <elog_file_cfg.h>
40
+
41
+#define ELOG_FILE_SEM_KEY   ((key_t)0x19910612)
42
+#ifdef _SEM_SEMUN_UNDEFINED
43
+union semun {
44
+    int              val;    /* Value for SETVAL */
45
+    struct semid_ds *buf;    /* Buffer for IPC_STAT, IPC_SET */
46
+    unsigned short  *array;  /* Array for GETALL, SETALL */
47
+    struct seminfo  *__buf;  /* Buffer for IPC_INFO
48
+                                (Linux-specific) */
49
+};
50
+#endif
51
+
52
+static int semid = -1;
53
+static struct sembuf const up = {0, 1, SEM_UNDO};
54
+static struct sembuf const down = {0, -1, SEM_UNDO};
55
+
56
+static void lock_init(void);
57
+static int lock_open(void);
58
+/**
59
+ * EasyLogger flile log pulgin port initialize
60
+ *
61
+ * @return result
62
+ */
63
+ElogErrCode elog_file_port_init(void) {
64
+    ElogErrCode result = ELOG_NO_ERR;
65
+
66
+    lock_init();
67
+
68
+    return result;
69
+}
70
+
71
+/**
72
+ * file log lock
73
+ */
74
+void inline elog_file_port_lock(void)
75
+{
76
+    semid == -1 ? -1 : semop(semid, (struct sembuf *)&down, 1);
77
+}
78
+
79
+/**
80
+ * file log unlock
81
+ */
82
+void inline elog_file_port_unlock(void)
83
+{
84
+    semid == -1 ? -1 : semop(semid, (struct sembuf *)&up, 1);
85
+}
86
+/**
87
+ * file log deinit
88
+ */
89
+void elog_file_port_deinit(void)
90
+{
91
+
92
+}
93
+
94
+/**
95
+ * initialize the lock 
96
+ */
97
+static void lock_init(void)
98
+{
99
+    int id, rc;
100
+    union semun arg;
101
+    struct sembuf sembuf;
102
+
103
+    id = semget(ELOG_FILE_SEM_KEY, 1, IPC_CREAT | IPC_EXCL | 0666);
104
+    if(likely(id == -1)) {
105
+        id = lock_open();
106
+        if (id == -1)
107
+            goto __exit;
108
+    } else {
109
+        arg.val = 0;
110
+        rc = semctl(id, 0, SETVAL, arg);
111
+        if (rc == -1)
112
+            goto __exit;
113
+
114
+        sembuf.sem_num = 0;
115
+        sembuf.sem_op = 1;
116
+        sembuf.sem_flg = 0;
117
+
118
+        rc = semop(id, &sembuf, 1);
119
+        if (rc == -1)
120
+            goto __exit;
121
+    }
122
+
123
+    semid = id;
124
+__exit:
125
+    return ;
126
+}
127
+
128
+/**
129
+ * gets the lock 
130
+ */
131
+static int lock_open(void)
132
+{
133
+    int id, rc, i;
134
+    union semun arg;
135
+    struct semid_ds ds;
136
+
137
+    id = semget(ELOG_FILE_SEM_KEY, 1, 0666);
138
+    if(unlikely(id == -1))
139
+        goto err;
140
+
141
+    arg.buf = &ds;
142
+
143
+    for (i = 0; i < 10; i++) {
144
+        rc = semctl(id, 0, IPC_STAT, arg);
145
+        if (unlikely(rc == -1))
146
+            goto err;
147
+
148
+        if(ds.sem_otime != 0)
149
+            break;
150
+
151
+        usleep(10 * 1000);
152
+    }
153
+
154
+    if (unlikely(ds.sem_otime == 0))
155
+        goto err;
156
+
157
+    return id;
158
+err:
159
+    return -1;
160
+}

+ 146
- 0
fault-recorder/util/easylogger/port/elog_port.c View File

@@ -0,0 +1,146 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: Portable interface for linux.
26
+ * Created on: 2015-04-28
27
+ */
28
+
29
+#include <elog.h>
30
+#include <pthread.h>
31
+#include <stddef.h>
32
+#include <stdio.h>
33
+#include <sys/time.h>
34
+#include <time.h>
35
+#include <unistd.h>
36
+
37
+#ifdef ELOG_FILE_ENABLE
38
+#include <elog_file.h>
39
+#endif
40
+static pthread_mutex_t output_lock;
41
+
42
+/**
43
+ * EasyLogger port initialize
44
+ *
45
+ * @return result
46
+ */
47
+ElogErrCode elog_port_init(void)
48
+{
49
+	ElogErrCode result = ELOG_NO_ERR;
50
+
51
+	pthread_mutex_init(&output_lock, NULL);
52
+
53
+#ifdef ELOG_FILE_ENABLE
54
+	elog_file_init();
55
+#endif
56
+
57
+	return result;
58
+}
59
+
60
+/**
61
+ * output log port interface
62
+ *
63
+ * @param log output of log
64
+ * @param size log size
65
+ */
66
+void elog_port_output(const char *log, size_t size)
67
+{
68
+	/* output to terminal */
69
+	printf("%.*s", (int) size, log);
70
+#ifdef ELOG_FILE_ENABLE
71
+	/* write the file */
72
+	elog_file_write(log, size);
73
+#endif 
74
+}
75
+
76
+/**
77
+ * output lock
78
+ */
79
+void elog_port_output_lock(void)
80
+{
81
+	pthread_mutex_lock(&output_lock);
82
+}
83
+
84
+/**
85
+ * output unlock
86
+ */
87
+void elog_port_output_unlock(void)
88
+{
89
+	pthread_mutex_unlock(&output_lock);
90
+}
91
+
92
+/**
93
+ * get current time interface
94
+ *
95
+ * @return current time
96
+ */
97
+const char *elog_port_get_time(void)
98
+{
99
+	static char cur_system_time[30] =
100
+	{ 0 };
101
+
102
+	struct timeval tv;
103
+	struct timezone tz;
104
+	struct tm *p;
105
+	gettimeofday(&tv, &tz);
106
+	p = localtime(&tv.tv_sec);
107
+
108
+	if(p == NULL) {
109
+		return "";
110
+	}
111
+
112
+	snprintf(cur_system_time, 26, "%04d-%02d-%02d %02d:%02d:%02d.%06ld", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday,
113
+			p->tm_hour, p->tm_min, p->tm_sec, tv.tv_usec);
114
+
115
+	return cur_system_time;
116
+}
117
+
118
+/**
119
+ * get current process name interface
120
+ *
121
+ * @return current process name
122
+ */
123
+const char *elog_port_get_p_info(void)
124
+{
125
+	static char cur_process_info[10] =
126
+	{ 0 };
127
+
128
+	snprintf(cur_process_info, 10, "pid:%04d", getpid());
129
+
130
+	return cur_process_info;
131
+}
132
+
133
+/**
134
+ * get current thread name interface
135
+ *
136
+ * @return current thread name
137
+ */
138
+const char *elog_port_get_t_info(void)
139
+{
140
+	static char cur_thread_info[10] =
141
+	{ 0 };
142
+
143
+	snprintf(cur_thread_info, 10, "tid:%04ld", pthread_self());
144
+
145
+	return cur_thread_info;
146
+}

+ 872
- 0
fault-recorder/util/easylogger/src/elog.c View File

@@ -0,0 +1,872 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2018, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: Initialize function and other general function.
26
+ * Created on: 2015-04-28
27
+ */
28
+
29
+#define LOG_TAG      "elog"
30
+
31
+#include <elog.h>
32
+#include <string.h>
33
+#include <stdarg.h>
34
+#include <stdio.h>
35
+
36
+#if !defined(ELOG_OUTPUT_LVL)
37
+    #error "Please configure static output log level (in elog_cfg.h)"
38
+#endif
39
+
40
+#if !defined(ELOG_LINE_NUM_MAX_LEN)
41
+    #error "Please configure output line number max length (in elog_cfg.h)"
42
+#endif
43
+
44
+#if !defined(ELOG_LINE_BUF_SIZE)
45
+    #error "Please configure buffer size for every line's log (in elog_cfg.h)"
46
+#endif
47
+
48
+#if !defined(ELOG_FILTER_TAG_MAX_LEN)
49
+    #error "Please configure output filter's tag max length (in elog_cfg.h)"
50
+#endif
51
+
52
+#if !defined(ELOG_FILTER_KW_MAX_LEN)
53
+    #error "Please configure output filter's keyword max length (in elog_cfg.h)"
54
+#endif
55
+
56
+#if !defined(ELOG_NEWLINE_SIGN)
57
+    #error "Please configure output newline sign (in elog_cfg.h)"
58
+#endif
59
+
60
+/* output filter's tag level max num */
61
+#ifndef ELOG_FILTER_TAG_LVL_MAX_NUM
62
+#define ELOG_FILTER_TAG_LVL_MAX_NUM          4
63
+#endif
64
+
65
+#ifdef ELOG_COLOR_ENABLE
66
+/**
67
+ * CSI(Control Sequence Introducer/Initiator) sign
68
+ * more information on https://en.wikipedia.org/wiki/ANSI_escape_code
69
+ */
70
+#define CSI_START                      "\033["
71
+#define CSI_END                        "\033[0m"
72
+/* output log front color */
73
+#define F_BLACK                        "30;"
74
+#define F_RED                          "31;"
75
+#define F_GREEN                        "32;"
76
+#define F_YELLOW                       "33;"
77
+#define F_BLUE                         "34;"
78
+#define F_MAGENTA                      "35;"
79
+#define F_CYAN                         "36;"
80
+#define F_WHITE                        "37;"
81
+/* output log background color */
82
+#define B_NULL
83
+#define B_BLACK                        "40;"
84
+#define B_RED                          "41;"
85
+#define B_GREEN                        "42;"
86
+#define B_YELLOW                       "43;"
87
+#define B_BLUE                         "44;"
88
+#define B_MAGENTA                      "45;"
89
+#define B_CYAN                         "46;"
90
+#define B_WHITE                        "47;"
91
+/* output log fonts style */
92
+#define S_BOLD                         "1m"
93
+#define S_UNDERLINE                    "4m"
94
+#define S_BLINK                        "5m"
95
+#define S_NORMAL                       "22m"
96
+/* output log default color definition: [front color] + [background color] + [show style] */
97
+#ifndef ELOG_COLOR_ASSERT
98
+#define ELOG_COLOR_ASSERT              (F_MAGENTA B_NULL S_NORMAL)
99
+#endif
100
+#ifndef ELOG_COLOR_ERROR
101
+#define ELOG_COLOR_ERROR               (F_RED B_NULL S_NORMAL)
102
+#endif
103
+#ifndef ELOG_COLOR_WARN
104
+#define ELOG_COLOR_WARN                (F_YELLOW B_NULL S_NORMAL)
105
+#endif
106
+#ifndef ELOG_COLOR_INFO
107
+#define ELOG_COLOR_INFO                (F_CYAN B_NULL S_NORMAL)
108
+#endif
109
+#ifndef ELOG_COLOR_DEBUG
110
+#define ELOG_COLOR_DEBUG               (F_GREEN B_NULL S_NORMAL)
111
+#endif
112
+#ifndef ELOG_COLOR_VERBOSE
113
+#define ELOG_COLOR_VERBOSE             (F_BLUE B_NULL S_NORMAL)
114
+#endif
115
+#endif /* ELOG_COLOR_ENABLE */
116
+
117
+/* EasyLogger object */
118
+static EasyLogger elog;
119
+/* every line log's buffer */
120
+static char log_buf[ELOG_LINE_BUF_SIZE] = { 0 };
121
+/* level output info */
122
+static const char *level_output_info[] = {
123
+        [ELOG_LVL_ASSERT]  = "A/",
124
+        [ELOG_LVL_ERROR]   = "E/",
125
+        [ELOG_LVL_WARN]    = "W/",
126
+        [ELOG_LVL_INFO]    = "I/",
127
+        [ELOG_LVL_DEBUG]   = "D/",
128
+        [ELOG_LVL_VERBOSE] = "V/",
129
+};
130
+
131
+#ifdef ELOG_COLOR_ENABLE
132
+/* color output info */
133
+static const char *color_output_info[] = {
134
+        [ELOG_LVL_ASSERT]  = ELOG_COLOR_ASSERT,
135
+        [ELOG_LVL_ERROR]   = ELOG_COLOR_ERROR,
136
+        [ELOG_LVL_WARN]    = ELOG_COLOR_WARN,
137
+        [ELOG_LVL_INFO]    = ELOG_COLOR_INFO,
138
+        [ELOG_LVL_DEBUG]   = ELOG_COLOR_DEBUG,
139
+        [ELOG_LVL_VERBOSE] = ELOG_COLOR_VERBOSE,
140
+};
141
+#endif /* ELOG_COLOR_ENABLE */
142
+
143
+static bool get_fmt_enabled(uint8_t level, size_t set);
144
+static void elog_set_filter_tag_lvl_default();
145
+
146
+/* EasyLogger assert hook */
147
+void (*elog_assert_hook)(const char* expr, const char* func, size_t line);
148
+
149
+extern void elog_port_output(const char *log, size_t size);
150
+extern void elog_port_output_lock(void);
151
+extern void elog_port_output_unlock(void);
152
+
153
+/**
154
+ * EasyLogger initialize.
155
+ *
156
+ * @return result
157
+ */
158
+ElogErrCode elog_init(void) {
159
+    extern ElogErrCode elog_port_init(void);
160
+    extern ElogErrCode elog_async_init(void);
161
+
162
+    ElogErrCode result = ELOG_NO_ERR;
163
+
164
+    if (elog.init_ok == true) {
165
+        return result;
166
+    }
167
+
168
+    /* port initialize */
169
+    result = elog_port_init();
170
+    if (result != ELOG_NO_ERR) {
171
+        return result;
172
+    }
173
+
174
+#ifdef ELOG_ASYNC_OUTPUT_ENABLE
175
+    result = elog_async_init();
176
+    if (result != ELOG_NO_ERR) {
177
+        return result;
178
+    }
179
+#endif
180
+
181
+    /* enable the output lock */
182
+    elog_output_lock_enabled(true);
183
+    /* output locked status initialize */
184
+    elog.output_is_locked_before_enable = false;
185
+    elog.output_is_locked_before_disable = false;
186
+
187
+#ifdef ELOG_COLOR_ENABLE
188
+    /* disable text color by default */
189
+    elog_set_text_color_enabled(false);
190
+#endif
191
+
192
+    /* set level is ELOG_LVL_VERBOSE */
193
+    elog_set_filter_lvl(ELOG_LVL_VERBOSE);
194
+
195
+    /* set tag_level to default val */
196
+    elog_set_filter_tag_lvl_default();
197
+
198
+    elog.init_ok = true;
199
+
200
+    return result;
201
+}
202
+
203
+/**
204
+ * EasyLogger start after initialize.
205
+ */
206
+void elog_start(void) {
207
+    /* enable output */
208
+    elog_set_output_enabled(true);
209
+
210
+#if defined(ELOG_ASYNC_OUTPUT_ENABLE)
211
+    elog_async_enabled(true);
212
+#elif defined(ELOG_BUF_OUTPUT_ENABLE)
213
+    elog_buf_enabled(true);
214
+#endif
215
+
216
+    /* show version */
217
+    log_i("EasyLogger V%s is initialize success.", ELOG_SW_VERSION);
218
+}
219
+
220
+/**
221
+ * set output enable or disable
222
+ *
223
+ * @param enabled TRUE: enable FALSE: disable
224
+ */
225
+void elog_set_output_enabled(bool enabled) {
226
+    ELOG_ASSERT((enabled == false) || (enabled == true));
227
+
228
+    elog.output_enabled = enabled;
229
+}
230
+
231
+#ifdef ELOG_COLOR_ENABLE
232
+/**
233
+ * set log text color enable or disable
234
+ * 
235
+ * @param enabled TRUE: enable FALSE:disable
236
+ */
237
+void elog_set_text_color_enabled(bool enabled) {
238
+    elog.text_color_enabled = enabled;
239
+}
240
+
241
+/**
242
+ * get log text color enable status
243
+ *
244
+ * @return enable or disable
245
+ */
246
+bool elog_get_text_color_enabled(void) {
247
+    return elog.text_color_enabled;
248
+}
249
+#endif /* ELOG_COLOR_ENABLE */
250
+
251
+/**
252
+ * get output is enable or disable
253
+ *
254
+ * @return enable or disable
255
+ */
256
+bool elog_get_output_enabled(void) {
257
+    return elog.output_enabled;
258
+}
259
+
260
+/**
261
+ * set log output format. only enable or disable
262
+ *
263
+ * @param level level
264
+ * @param set format set
265
+ */
266
+void elog_set_fmt(uint8_t level, size_t set) {
267
+    ELOG_ASSERT(level <= ELOG_LVL_VERBOSE);
268
+
269
+    elog.enabled_fmt_set[level] = set;
270
+}
271
+
272
+/**
273
+ * set log filter all parameter
274
+ *
275
+ * @param level level
276
+ * @param tag tag
277
+ * @param keyword keyword
278
+ */
279
+void elog_set_filter(uint8_t level, const char *tag, const char *keyword) {
280
+    ELOG_ASSERT(level <= ELOG_LVL_VERBOSE);
281
+
282
+    elog_set_filter_lvl(level);
283
+    elog_set_filter_tag(tag);
284
+    elog_set_filter_kw(keyword);
285
+}
286
+
287
+/**
288
+ * set log filter's level
289
+ *
290
+ * @param level level
291
+ */
292
+void elog_set_filter_lvl(uint8_t level) {
293
+    ELOG_ASSERT(level <= ELOG_LVL_VERBOSE);
294
+
295
+    elog.filter.level = level;
296
+}
297
+
298
+/**
299
+ * set log filter's tag
300
+ *
301
+ * @param tag tag
302
+ */
303
+void elog_set_filter_tag(const char *tag) {
304
+    strncpy(elog.filter.tag, tag, ELOG_FILTER_TAG_MAX_LEN);
305
+}
306
+
307
+/**
308
+ * set log filter's keyword
309
+ *
310
+ * @param keyword keyword
311
+ */
312
+void elog_set_filter_kw(const char *keyword) {
313
+    strncpy(elog.filter.keyword, keyword, ELOG_FILTER_KW_MAX_LEN);
314
+}
315
+
316
+/**
317
+ * lock output 
318
+ */
319
+void elog_output_lock(void) {
320
+    if (elog.output_lock_enabled) {
321
+        elog_port_output_lock();
322
+        elog.output_is_locked_before_disable = true;
323
+    } else {
324
+        elog.output_is_locked_before_enable = true;
325
+    }
326
+}
327
+
328
+/**
329
+ * unlock output
330
+ */
331
+void elog_output_unlock(void) {
332
+    if (elog.output_lock_enabled) {
333
+        elog_port_output_unlock();
334
+        elog.output_is_locked_before_disable = false;
335
+    } else {
336
+        elog.output_is_locked_before_enable = false;
337
+    }
338
+}
339
+
340
+/**
341
+ * set log filter's tag level val to default
342
+ */
343
+static void elog_set_filter_tag_lvl_default()
344
+{
345
+    uint8_t i = 0;
346
+
347
+    for (i =0; i< ELOG_FILTER_TAG_LVL_MAX_NUM; i++){
348
+        memset(elog.filter.tag_lvl[i].tag, '\0', ELOG_FILTER_TAG_MAX_LEN + 1);
349
+        elog.filter.tag_lvl[i].level = ELOG_FILTER_LVL_SILENT;
350
+        elog.filter.tag_lvl[i].tag_use_flag = false;
351
+    }
352
+}
353
+
354
+/**
355
+ * Set the filter's level by different tag.
356
+ * The log on this tag which level is less than it will stop output.
357
+ *
358
+ * example:
359
+ *     // the example tag log enter silent mode
360
+ *     elog_set_filter_tag_lvl("example", ELOG_FILTER_LVL_SILENT);
361
+ *     // the example tag log which level is less than INFO level will stop output
362
+ *     elog_set_filter_tag_lvl("example", ELOG_LVL_INFO);
363
+ *     // remove example tag's level filter, all level log will resume output
364
+ *     elog_set_filter_tag_lvl("example", ELOG_FILTER_LVL_ALL);
365
+ *
366
+ * @param tag log tag
367
+ * @param level The filter level. When the level is ELOG_FILTER_LVL_SILENT, the log enter silent mode.
368
+ *        When the level is ELOG_FILTER_LVL_ALL, it will remove this tag's level filer.
369
+ *        Then all level log will resume output.
370
+ *
371
+ */
372
+void elog_set_filter_tag_lvl(const char *tag, uint8_t level)
373
+{
374
+    ELOG_ASSERT(level <= ELOG_LVL_VERBOSE);
375
+    ELOG_ASSERT(tag != ((void *)0));
376
+    uint8_t i = 0;
377
+
378
+    if (!elog.init_ok) {
379
+        return;
380
+    }
381
+
382
+    elog_port_output_lock();
383
+    /* find the tag in arr */
384
+    for (i =0; i< ELOG_FILTER_TAG_LVL_MAX_NUM; i++){
385
+        if (elog.filter.tag_lvl[i].tag_use_flag == true &&
386
+            !strncmp(tag, elog.filter.tag_lvl[i].tag,ELOG_FILTER_TAG_MAX_LEN)){
387
+            break;
388
+        }
389
+    }
390
+
391
+    if (i < ELOG_FILTER_TAG_LVL_MAX_NUM){
392
+        /* find OK */
393
+        if (level == ELOG_FILTER_LVL_ALL){
394
+            /* remove current tag's level filter when input level is the lowest level */
395
+             elog.filter.tag_lvl[i].tag_use_flag = false;
396
+             memset(elog.filter.tag_lvl[i].tag, '\0', ELOG_FILTER_TAG_MAX_LEN + 1);
397
+             elog.filter.tag_lvl[i].level = ELOG_FILTER_LVL_SILENT;
398
+        } else{
399
+            elog.filter.tag_lvl[i].level = level;
400
+        }
401
+    } else{
402
+        /* only add the new tag's level filer when level is not ELOG_FILTER_LVL_ALL */
403
+        if (level != ELOG_FILTER_LVL_ALL){
404
+            for (i =0; i< ELOG_FILTER_TAG_LVL_MAX_NUM; i++){
405
+                if (elog.filter.tag_lvl[i].tag_use_flag == false){
406
+                    strncpy(elog.filter.tag_lvl[i].tag, tag, ELOG_FILTER_TAG_MAX_LEN);
407
+                    elog.filter.tag_lvl[i].level = level;
408
+                    elog.filter.tag_lvl[i].tag_use_flag = true;
409
+                    break;
410
+                }
411
+            }
412
+        }
413
+    }
414
+    elog_output_unlock();
415
+}
416
+
417
+/**
418
+ * get the level on tag's level filer
419
+ *
420
+ * @param tag tag
421
+ *
422
+ * @return It will return the lowest level when tag was not found.
423
+ *         Other level will return when tag was found.
424
+ */
425
+uint8_t elog_get_filter_tag_lvl(const char *tag)
426
+{
427
+    ELOG_ASSERT(tag != ((void *)0));
428
+    uint8_t i = 0;
429
+    uint8_t level = ELOG_FILTER_LVL_ALL;
430
+
431
+    if (!elog.init_ok) {
432
+        return level;
433
+    }
434
+
435
+    elog_port_output_lock();
436
+    /* find the tag in arr */
437
+    for (i =0; i< ELOG_FILTER_TAG_LVL_MAX_NUM; i++){
438
+        if (elog.filter.tag_lvl[i].tag_use_flag == true &&
439
+            !strncmp(tag, elog.filter.tag_lvl[i].tag,ELOG_FILTER_TAG_MAX_LEN)){
440
+            level = elog.filter.tag_lvl[i].level;
441
+            break;
442
+        }
443
+    }
444
+    elog_output_unlock();
445
+
446
+    return level;
447
+}
448
+
449
+/**
450
+ * output RAW format log
451
+ *
452
+ * @param format output format
453
+ * @param ... args
454
+ */
455
+void elog_raw(const char *format, ...) {
456
+    va_list args;
457
+    size_t log_len = 0;
458
+    int fmt_result;
459
+
460
+    /* check output enabled */
461
+    if (!elog.output_enabled) {
462
+        return;
463
+    }
464
+
465
+    /* args point to the first variable parameter */
466
+    va_start(args, format);
467
+
468
+    /* lock output */
469
+    elog_output_lock();
470
+
471
+    /* package log data to buffer */
472
+    fmt_result = vsnprintf(log_buf, ELOG_LINE_BUF_SIZE, format, args);
473
+
474
+    /* output converted log */
475
+    if ((fmt_result > -1) && (fmt_result <= ELOG_LINE_BUF_SIZE)) {
476
+        log_len = fmt_result;
477
+    } else {
478
+        log_len = ELOG_LINE_BUF_SIZE;
479
+    }
480
+    /* output log */
481
+#if defined(ELOG_ASYNC_OUTPUT_ENABLE)
482
+    extern void elog_async_output(uint8_t level, const char *log, size_t size);
483
+    /* raw log will using assert level */
484
+    elog_async_output(ELOG_LVL_ASSERT, log_buf, log_len);
485
+#elif defined(ELOG_BUF_OUTPUT_ENABLE)
486
+    extern void elog_buf_output(const char *log, size_t size);
487
+    elog_buf_output(log_buf, log_len);
488
+#else
489
+    elog_port_output(log_buf, log_len);
490
+#endif
491
+    /* unlock output */
492
+    elog_output_unlock();
493
+
494
+    va_end(args);
495
+}
496
+
497
+/**
498
+ * output the log
499
+ *
500
+ * @param level level
501
+ * @param tag tag
502
+ * @param file file name
503
+ * @param func function name
504
+ * @param line line number
505
+ * @param format output format
506
+ * @param ... args
507
+ *
508
+ */
509
+void elog_output(uint8_t level, const char *tag, const char *file, const char *func,
510
+        const long line, const char *format, ...) {
511
+    extern const char *elog_port_get_time(void);
512
+    extern const char *elog_port_get_p_info(void);
513
+    extern const char *elog_port_get_t_info(void);
514
+
515
+    size_t tag_len = strlen(tag), log_len = 0, newline_len = strlen(ELOG_NEWLINE_SIGN);
516
+    char line_num[ELOG_LINE_NUM_MAX_LEN + 1] = { 0 };
517
+    char tag_sapce[ELOG_FILTER_TAG_MAX_LEN / 2 + 1] = { 0 };
518
+    va_list args;
519
+    int fmt_result;
520
+
521
+    ELOG_ASSERT(level <= ELOG_LVL_VERBOSE);
522
+
523
+    /* check output enabled */
524
+    if (!elog.output_enabled) {
525
+        return;
526
+    }
527
+    /* level filter */
528
+    if (level > elog.filter.level || level > elog_get_filter_tag_lvl(tag)) {
529
+        return;
530
+    } else if (!strstr(tag, elog.filter.tag)) { /* tag filter */
531
+        return;
532
+    }
533
+    /* args point to the first variable parameter */
534
+    va_start(args, format);
535
+    /* lock output */
536
+    elog_output_lock();
537
+
538
+#ifdef ELOG_COLOR_ENABLE
539
+    /* add CSI start sign and color info */
540
+    if (elog.text_color_enabled) {
541
+        log_len += elog_strcpy(log_len, log_buf + log_len, CSI_START);
542
+        log_len += elog_strcpy(log_len, log_buf + log_len, color_output_info[level]);
543
+    }
544
+#endif
545
+
546
+    /* package level info */
547
+    if (get_fmt_enabled(level, ELOG_FMT_LVL)) {
548
+        log_len += elog_strcpy(log_len, log_buf + log_len, level_output_info[level]);
549
+    }
550
+    /* package tag info */
551
+    if (get_fmt_enabled(level, ELOG_FMT_TAG)) {
552
+        log_len += elog_strcpy(log_len, log_buf + log_len, tag);
553
+        /* if the tag length is less than 50% ELOG_FILTER_TAG_MAX_LEN, then fill space */
554
+        if (tag_len <= ELOG_FILTER_TAG_MAX_LEN / 2) {
555
+            memset(tag_sapce, ' ', ELOG_FILTER_TAG_MAX_LEN / 2 - tag_len);
556
+            log_len += elog_strcpy(log_len, log_buf + log_len, tag_sapce);
557
+        }
558
+        log_len += elog_strcpy(log_len, log_buf + log_len, " ");
559
+    }
560
+    /* package time, process and thread info */
561
+    if (get_fmt_enabled(level, ELOG_FMT_TIME | ELOG_FMT_P_INFO | ELOG_FMT_T_INFO)) {
562
+        log_len += elog_strcpy(log_len, log_buf + log_len, "[");
563
+        /* package time info */
564
+        if (get_fmt_enabled(level, ELOG_FMT_TIME)) {
565
+            log_len += elog_strcpy(log_len, log_buf + log_len, elog_port_get_time());
566
+            if (get_fmt_enabled(level, ELOG_FMT_P_INFO | ELOG_FMT_T_INFO)) {
567
+                log_len += elog_strcpy(log_len, log_buf + log_len, " ");
568
+            }
569
+        }
570
+        /* package process info */
571
+        if (get_fmt_enabled(level, ELOG_FMT_P_INFO)) {
572
+            log_len += elog_strcpy(log_len, log_buf + log_len, elog_port_get_p_info());
573
+            if (get_fmt_enabled(level, ELOG_FMT_T_INFO)) {
574
+                log_len += elog_strcpy(log_len, log_buf + log_len, " ");
575
+            }
576
+        }
577
+        /* package thread info */
578
+        if (get_fmt_enabled(level, ELOG_FMT_T_INFO)) {
579
+            log_len += elog_strcpy(log_len, log_buf + log_len, elog_port_get_t_info());
580
+        }
581
+        log_len += elog_strcpy(log_len, log_buf + log_len, "] ");
582
+    }
583
+    /* package file directory and name, function name and line number info */
584
+    if (get_fmt_enabled(level, ELOG_FMT_DIR | ELOG_FMT_FUNC | ELOG_FMT_LINE)) {
585
+        log_len += elog_strcpy(log_len, log_buf + log_len, "(");
586
+        /* package time info */
587
+        if (get_fmt_enabled(level, ELOG_FMT_DIR)) {
588
+            log_len += elog_strcpy(log_len, log_buf + log_len, file);
589
+            if (get_fmt_enabled(level, ELOG_FMT_FUNC)) {
590
+                log_len += elog_strcpy(log_len, log_buf + log_len, " ");
591
+            } else if (get_fmt_enabled(level, ELOG_FMT_LINE)) {
592
+                log_len += elog_strcpy(log_len, log_buf + log_len, ":");
593
+            }
594
+        }
595
+        /* package process info */
596
+        if (get_fmt_enabled(level, ELOG_FMT_FUNC)) {
597
+            log_len += elog_strcpy(log_len, log_buf + log_len, func);
598
+            if (get_fmt_enabled(level, ELOG_FMT_LINE)) {
599
+                log_len += elog_strcpy(log_len, log_buf + log_len, ":");
600
+            }
601
+        }
602
+        /* package thread info */
603
+        if (get_fmt_enabled(level, ELOG_FMT_LINE)) {
604
+            snprintf(line_num, ELOG_LINE_NUM_MAX_LEN, "%ld", line);
605
+            log_len += elog_strcpy(log_len, log_buf + log_len, line_num);
606
+        }
607
+        log_len += elog_strcpy(log_len, log_buf + log_len, ")");
608
+    }
609
+    /* package other log data to buffer. '\0' must be added in the end by vsnprintf. */
610
+    fmt_result = vsnprintf(log_buf + log_len, ELOG_LINE_BUF_SIZE - log_len, format, args);
611
+
612
+    va_end(args);
613
+    /* calculate log length */
614
+    if ((log_len + fmt_result <= ELOG_LINE_BUF_SIZE) && (fmt_result > -1)) {
615
+        log_len += fmt_result;
616
+    } else {
617
+        /* using max length */
618
+        log_len = ELOG_LINE_BUF_SIZE;
619
+    }
620
+    /* overflow check and reserve some space for CSI end sign and newline sign */
621
+#ifdef ELOG_COLOR_ENABLE
622
+    if (log_len + (sizeof(CSI_END) - 1) + newline_len > ELOG_LINE_BUF_SIZE) {
623
+        /* using max length */
624
+        log_len = ELOG_LINE_BUF_SIZE;
625
+        /* reserve some space for CSI end sign */
626
+        log_len -= (sizeof(CSI_END) - 1);
627
+#else
628
+    if (log_len + newline_len > ELOG_LINE_BUF_SIZE) {
629
+        /* using max length */
630
+        log_len = ELOG_LINE_BUF_SIZE;
631
+#endif /* ELOG_COLOR_ENABLE */
632
+        /* reserve some space for newline sign */
633
+        log_len -= newline_len;
634
+    }
635
+    /* keyword filter */
636
+    if (elog.filter.keyword[0] != '\0') {
637
+        /* add string end sign */
638
+        log_buf[log_len] = '\0';
639
+        /* find the keyword */
640
+        if (!strstr(log_buf, elog.filter.keyword)) {
641
+            /* unlock output */
642
+            elog_output_unlock();
643
+            return;
644
+        }
645
+    }
646
+
647
+#ifdef ELOG_COLOR_ENABLE
648
+    /* add CSI end sign */
649
+    if (elog.text_color_enabled) {
650
+        log_len += elog_strcpy(log_len, log_buf + log_len, CSI_END);
651
+    }
652
+#endif
653
+
654
+    /* package newline sign */
655
+    log_len += elog_strcpy(log_len, log_buf + log_len, ELOG_NEWLINE_SIGN);
656
+    /* output log */
657
+#if defined(ELOG_ASYNC_OUTPUT_ENABLE)
658
+    extern void elog_async_output(uint8_t level, const char *log, size_t size);
659
+    elog_async_output(level, log_buf, log_len);
660
+#elif defined(ELOG_BUF_OUTPUT_ENABLE)
661
+    extern void elog_buf_output(const char *log, size_t size);
662
+    elog_buf_output(log_buf, log_len);
663
+#else
664
+    elog_port_output(log_buf, log_len);
665
+#endif
666
+    /* unlock output */
667
+    elog_output_unlock();
668
+}
669
+
670
+/**
671
+ * get format enabled
672
+ *
673
+ * @param level level
674
+ * @param set format set
675
+ *
676
+ * @return enable or disable
677
+ */
678
+static bool get_fmt_enabled(uint8_t level, size_t set) {
679
+    ELOG_ASSERT(level <= ELOG_LVL_VERBOSE);
680
+
681
+    if (elog.enabled_fmt_set[level] & set) {
682
+        return true;
683
+    } else {
684
+        return false;
685
+    }
686
+}
687
+
688
+/**
689
+ * enable or disable logger output lock
690
+ * @note disable this lock is not recommended except you want output system exception log
691
+ *
692
+ * @param enabled true: enable  false: disable
693
+ */
694
+void elog_output_lock_enabled(bool enabled) {
695
+    elog.output_lock_enabled = enabled;
696
+    /* it will re-lock or re-unlock before output lock enable */
697
+    if (elog.output_lock_enabled) {
698
+        if (!elog.output_is_locked_before_disable && elog.output_is_locked_before_enable) {
699
+            /* the output lock is unlocked before disable, and the lock will unlocking after enable */
700
+            elog_port_output_lock();
701
+        } else if (elog.output_is_locked_before_disable && !elog.output_is_locked_before_enable) {
702
+            /* the output lock is locked before disable, and the lock will locking after enable */
703
+            elog_port_output_unlock();
704
+        }
705
+    }
706
+}
707
+
708
+/**
709
+ * Set a hook function to EasyLogger assert. It will run when the expression is false.
710
+ *
711
+ * @param hook the hook function
712
+ */
713
+void elog_assert_set_hook(void (*hook)(const char* expr, const char* func, size_t line)) {
714
+    elog_assert_hook = hook;
715
+}
716
+
717
+/**
718
+ * find the log level
719
+ * @note make sure the log level is output on each format
720
+ *
721
+ * @param log log buffer
722
+ *
723
+ * @return log level, found failed will return -1
724
+ */
725
+int8_t elog_find_lvl(const char *log) {
726
+    ELOG_ASSERT(log);
727
+    /* make sure the log level is output on each format */
728
+    ELOG_ASSERT(elog.enabled_fmt_set[ELOG_LVL_ASSERT] & ELOG_FMT_LVL);
729
+    ELOG_ASSERT(elog.enabled_fmt_set[ELOG_LVL_ERROR] & ELOG_FMT_LVL);
730
+    ELOG_ASSERT(elog.enabled_fmt_set[ELOG_LVL_WARN] & ELOG_FMT_LVL);
731
+    ELOG_ASSERT(elog.enabled_fmt_set[ELOG_LVL_INFO] & ELOG_FMT_LVL);
732
+    ELOG_ASSERT(elog.enabled_fmt_set[ELOG_LVL_DEBUG] & ELOG_FMT_LVL);
733
+    ELOG_ASSERT(elog.enabled_fmt_set[ELOG_LVL_VERBOSE] & ELOG_FMT_LVL);
734
+
735
+#ifdef ELOG_COLOR_ENABLE
736
+    uint8_t i;
737
+    size_t csi_start_len = strlen(CSI_START);
738
+    for(i = 0; i < ELOG_LVL_TOTAL_NUM; i ++) {
739
+        if (!strncmp(color_output_info[i], log + csi_start_len, strlen(color_output_info[i]))) {
740
+            return i;
741
+        }
742
+    }
743
+    /* found failed */
744
+    return -1;
745
+#else
746
+    switch (log[0]) {
747
+    case 'A': return ELOG_LVL_ASSERT;
748
+    case 'E': return ELOG_LVL_ERROR;
749
+    case 'W': return ELOG_LVL_WARN;
750
+    case 'I': return ELOG_LVL_INFO;
751
+    case 'D': return ELOG_LVL_DEBUG;
752
+    case 'V': return ELOG_LVL_VERBOSE;
753
+    default: return -1;
754
+    }
755
+#endif
756
+}
757
+
758
+/**
759
+ * find the log tag
760
+ * @note make sure the log tag is output on each format
761
+ * @note the tag don't have space in it
762
+ *
763
+ * @param log log buffer
764
+ * @param lvl log level, you can get it by @see elog_find_lvl
765
+ * @param tag_len found tag length
766
+ *
767
+ * @return log tag, found failed will return NULL
768
+ */
769
+const char *elog_find_tag(const char *log, uint8_t lvl, size_t *tag_len) {
770
+    const char *tag = NULL, *tag_end = NULL;
771
+
772
+    ELOG_ASSERT(log);
773
+    ELOG_ASSERT(tag_len);
774
+    ELOG_ASSERT(lvl < ELOG_LVL_TOTAL_NUM);
775
+    /* make sure the log tag is output on each format */
776
+    ELOG_ASSERT(elog.enabled_fmt_set[lvl] & ELOG_FMT_TAG);
777
+
778
+#ifdef ELOG_COLOR_ENABLE
779
+    tag = log + strlen(CSI_START) + strlen(color_output_info[lvl]) + strlen(level_output_info[lvl]);
780
+#else
781
+    tag = log + strlen(level_output_info[lvl]);
782
+#endif
783
+    /* find the first space after tag */
784
+    if ((tag_end = memchr(tag, ' ', ELOG_FILTER_TAG_MAX_LEN)) != NULL) {
785
+        *tag_len = tag_end - tag;
786
+    } else {
787
+        tag = NULL;
788
+    }
789
+
790
+    return tag;
791
+}
792
+
793
+/**
794
+ * dump the hex format data to log
795
+ *
796
+ * @param name name for hex object, it will show on log header
797
+ * @param width hex number for every line, such as: 16, 32
798
+ * @param buf hex buffer
799
+ * @param size buffer size
800
+ */
801
+void elog_hexdump(const char *name, uint8_t width, uint8_t *buf, uint16_t size)
802
+{
803
+#define __is_print(ch)       ((unsigned int)((ch) - ' ') < 127u - ' ')
804
+
805
+    uint16_t i, j;
806
+    uint16_t log_len = 0;
807
+    char dump_string[8] = {0};
808
+    int fmt_result;
809
+
810
+    if (!elog.output_enabled) {
811
+        return;
812
+    }
813
+
814
+    /* level filter */
815
+    if (ELOG_LVL_DEBUG > elog.filter.level) {
816
+        return;
817
+    } else if (!strstr(name, elog.filter.tag)) { /* tag filter */
818
+        return;
819
+    }
820
+
821
+    /* lock output */
822
+    elog_output_lock();
823
+
824
+    for (i = 0; i < size; i += width) {
825
+        /* package header */
826
+        fmt_result = snprintf(log_buf, ELOG_LINE_BUF_SIZE, "D/HEX %s: %04X-%04X: ", name, i, i + width - 1);
827
+        /* calculate log length */
828
+        if ((fmt_result > -1) && (fmt_result <= ELOG_LINE_BUF_SIZE)) {
829
+            log_len = fmt_result;
830
+        } else {
831
+            log_len = ELOG_LINE_BUF_SIZE;
832
+        }
833
+        /* dump hex */
834
+        for (j = 0; j < width; j++) {
835
+            if (i + j < size) {
836
+                snprintf(dump_string, sizeof(dump_string), "%02X ", buf[i + j]);
837
+            } else {
838
+                strncpy(dump_string, "   ", sizeof(dump_string));
839
+            }
840
+            log_len += elog_strcpy(log_len, log_buf + log_len, dump_string);
841
+            if ((j + 1) % 8 == 0) {
842
+                log_len += elog_strcpy(log_len, log_buf + log_len, " ");
843
+            }
844
+        }
845
+        log_len += elog_strcpy(log_len, log_buf + log_len, "  ");
846
+        /* dump char for hex */
847
+        for (j = 0; j < width; j++) {
848
+            if (i + j < size) {
849
+                snprintf(dump_string, sizeof(dump_string), "%c", __is_print(buf[i + j]) ? buf[i + j] : '.');
850
+                log_len += elog_strcpy(log_len, log_buf + log_len, dump_string);
851
+            }
852
+        }
853
+        /* overflow check and reserve some space for newline sign */
854
+        if (log_len + strlen(ELOG_NEWLINE_SIGN) > ELOG_LINE_BUF_SIZE) {
855
+            log_len = ELOG_LINE_BUF_SIZE - strlen(ELOG_NEWLINE_SIGN);
856
+        }
857
+        /* package newline sign */
858
+        log_len += elog_strcpy(log_len, log_buf + log_len, ELOG_NEWLINE_SIGN);
859
+        /* do log output */
860
+#if defined(ELOG_ASYNC_OUTPUT_ENABLE)
861
+        extern void elog_async_output(uint8_t level, const char *log, size_t size);
862
+        elog_async_output(ELOG_LVL_DEBUG, log_buf, log_len);
863
+#elif defined(ELOG_BUF_OUTPUT_ENABLE)
864
+        extern void elog_buf_output(const char *log, size_t size);
865
+    elog_buf_output(log_buf, log_len);
866
+#else
867
+        elog_port_output(log_buf, log_len);
868
+#endif
869
+    }
870
+    /* unlock output */
871
+    elog_output_unlock();
872
+}

+ 352
- 0
fault-recorder/util/easylogger/src/elog_async.c View File

@@ -0,0 +1,352 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2016-2017, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: Logs asynchronous output.
26
+ * Created on: 2016-11-06
27
+ */
28
+
29
+#include <elog.h>
30
+#include <string.h>
31
+
32
+#ifdef ELOG_ASYNC_OUTPUT_ENABLE
33
+
34
+#ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD
35
+#include <pthread.h>
36
+#include <sched.h>
37
+#include <semaphore.h>
38
+/* thread default stack size */
39
+#ifndef ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE
40
+#if PTHREAD_STACK_MIN > 4*1024
41
+#define ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE     PTHREAD_STACK_MIN
42
+#else
43
+#define ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE     (1*1024)
44
+#endif
45
+/* thread default priority */
46
+#ifndef ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY
47
+#define ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY       (sched_get_priority_max(SCHED_RR) - 1)
48
+#endif
49
+/* output thread poll get log buffer size  */
50
+#ifndef ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE
51
+#define ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE         (ELOG_LINE_BUF_SIZE - 4)
52
+#endif
53
+#endif /* ELOG_ASYNC_OUTPUT_USING_PTHREAD */
54
+
55
+/* asynchronous output log notice */
56
+static sem_t output_notice;
57
+/* asynchronous output pthread thread */
58
+static pthread_t async_output_thread;
59
+#endif /* ELOG_ASYNC_OUTPUT_USING_PTHREAD */
60
+
61
+/* the highest output level for async mode, other level will sync output */
62
+#ifdef ELOG_ASYNC_OUTPUT_LVL
63
+#define OUTPUT_LVL                               ELOG_ASYNC_OUTPUT_LVL
64
+#else
65
+#define OUTPUT_LVL                               ELOG_LVL_ASSERT
66
+#endif /* ELOG_ASYNC_OUTPUT_LVL */
67
+
68
+/* buffer size for asynchronous output mode */
69
+#ifdef ELOG_ASYNC_OUTPUT_BUF_SIZE
70
+#define OUTPUT_BUF_SIZE                          ELOG_ASYNC_OUTPUT_BUF_SIZE
71
+#else
72
+#define OUTPUT_BUF_SIZE                          (ELOG_LINE_BUF_SIZE * 10)
73
+#endif /* ELOG_ASYNC_OUTPUT_BUF_SIZE */
74
+
75
+/* Initialize OK flag */
76
+static bool init_ok = false;
77
+/* asynchronous output mode enabled flag */
78
+static bool is_enabled = false;
79
+/* asynchronous output mode's ring buffer */
80
+static char log_buf[OUTPUT_BUF_SIZE] = { 0 };
81
+/* log ring buffer write index */
82
+static size_t write_index = 0;
83
+/* log ring buffer read index */
84
+static size_t read_index = 0;
85
+/* log ring buffer full flag */
86
+static bool buf_is_full = false;
87
+/* log ring buffer empty flag */
88
+static bool buf_is_empty = true;
89
+
90
+extern void elog_port_output(const char *log, size_t size);
91
+extern void elog_output_lock(void);
92
+extern void elog_output_unlock(void);
93
+
94
+/**
95
+ * asynchronous output ring buffer used size
96
+ *
97
+ * @return used size
98
+ */
99
+static size_t elog_async_get_buf_used(void) {
100
+    if (write_index > read_index) {
101
+        return write_index - read_index;
102
+    } else {
103
+        if (!buf_is_full && !buf_is_empty) {
104
+            return OUTPUT_BUF_SIZE - (read_index - write_index);
105
+        } else if (buf_is_full) {
106
+            return OUTPUT_BUF_SIZE;
107
+        } else {
108
+            return 0;
109
+        }
110
+    }
111
+}
112
+
113
+/**
114
+ * asynchronous output ring buffer remain space
115
+ *
116
+ * @return remain space
117
+ */
118
+static size_t async_get_buf_space(void) {
119
+    return OUTPUT_BUF_SIZE - elog_async_get_buf_used();
120
+}
121
+
122
+/**
123
+ * put log to asynchronous output ring buffer
124
+ *
125
+ * @param log put log buffer
126
+ * @param size log size
127
+ *
128
+ * @return put log size, the log which beyond ring buffer space will be dropped
129
+ */
130
+static size_t async_put_log(const char *log, size_t size) {
131
+    size_t space = 0;
132
+
133
+    space = async_get_buf_space();
134
+    /* no space */
135
+    if (!space) {
136
+        size = 0;
137
+        goto __exit;
138
+    }
139
+    /* drop some log */
140
+    if (space <= size) {
141
+        size = space;
142
+        buf_is_full = true;
143
+    }
144
+
145
+    if (write_index + size < OUTPUT_BUF_SIZE) {
146
+        memcpy(log_buf + write_index, log, size);
147
+        write_index += size;
148
+    } else {
149
+        memcpy(log_buf + write_index, log, OUTPUT_BUF_SIZE - write_index);
150
+        memcpy(log_buf, log + OUTPUT_BUF_SIZE - write_index,
151
+                size - (OUTPUT_BUF_SIZE - write_index));
152
+        write_index += size - OUTPUT_BUF_SIZE;
153
+    }
154
+
155
+    buf_is_empty = false;
156
+
157
+__exit:
158
+
159
+    return size;
160
+}
161
+
162
+#ifdef ELOG_ASYNC_LINE_OUTPUT
163
+/**
164
+ * Get line log from asynchronous output ring buffer.
165
+ * It will copy all log when the newline sign isn't find.
166
+ *
167
+ * @param log get line log buffer
168
+ * @param size line log size
169
+ *
170
+ * @return get line log size, the log size is less than ring buffer used size
171
+ */
172
+size_t elog_async_get_line_log(char *log, size_t size) {
173
+    size_t used = 0, cpy_log_size = 0;
174
+    /* lock output */
175
+    elog_output_lock();
176
+    used = elog_async_get_buf_used();
177
+
178
+    /* no log */
179
+    if (!used || !size) {
180
+        goto __exit;
181
+    }
182
+    /* less log */
183
+    if (used <= size) {
184
+        size = used;
185
+    }
186
+
187
+    if (read_index + size < OUTPUT_BUF_SIZE) {
188
+        cpy_log_size = elog_cpyln(log, log_buf + read_index, size);
189
+        read_index += cpy_log_size;
190
+    } else {
191
+        cpy_log_size = elog_cpyln(log, log_buf + read_index, OUTPUT_BUF_SIZE - read_index);
192
+        if (cpy_log_size == OUTPUT_BUF_SIZE - read_index) {
193
+            cpy_log_size += elog_cpyln(log + cpy_log_size, log_buf, size - cpy_log_size);
194
+            read_index += cpy_log_size - OUTPUT_BUF_SIZE;
195
+        } else {
196
+            read_index += cpy_log_size;
197
+        }
198
+    }
199
+
200
+    if (used == cpy_log_size) {
201
+        buf_is_empty = true;
202
+    }
203
+
204
+    if (cpy_log_size) {
205
+        buf_is_full = false;
206
+    }
207
+
208
+__exit:
209
+    /* lock output */
210
+    elog_output_unlock();
211
+    return cpy_log_size;
212
+}
213
+#else
214
+/**
215
+ * get log from asynchronous output ring buffer
216
+ *
217
+ * @param log get log buffer
218
+ * @param size log size
219
+ *
220
+ * @return get log size, the log size is less than ring buffer used size
221
+ */
222
+size_t elog_async_get_log(char *log, size_t size) {
223
+    size_t used = 0;
224
+    /* lock output */
225
+    elog_output_lock();
226
+    used = elog_async_get_buf_used();
227
+    /* no log */
228
+    if (!used || !size) {
229
+        size = 0;
230
+        goto __exit;
231
+    }
232
+    /* less log */
233
+    if (used <= size) {
234
+        size = used;
235
+        buf_is_empty = true;
236
+    }
237
+
238
+    if (read_index + size < OUTPUT_BUF_SIZE) {
239
+        memcpy(log, log_buf + read_index, size);
240
+        read_index += size;
241
+    } else {
242
+        memcpy(log, log_buf + read_index, OUTPUT_BUF_SIZE - read_index);
243
+        memcpy(log + OUTPUT_BUF_SIZE - read_index, log_buf,
244
+                size - (OUTPUT_BUF_SIZE - read_index));
245
+        read_index += size - OUTPUT_BUF_SIZE;
246
+    }
247
+
248
+    buf_is_full = false;
249
+
250
+__exit:
251
+    /* lock output */
252
+    elog_output_unlock();
253
+    return size;
254
+}
255
+#endif /* ELOG_ASYNC_LINE_OUTPUT */
256
+
257
+void elog_async_output(uint8_t level, const char *log, size_t size) {
258
+    /* this function must be implement by user when ELOG_ASYNC_OUTPUT_USING_PTHREAD is not defined */
259
+    extern void elog_async_output_notice(void);
260
+    size_t put_size;
261
+
262
+    if (is_enabled) {
263
+        if (level >= OUTPUT_LVL) {
264
+            put_size = async_put_log(log, size);
265
+            /* notify output log thread */
266
+            if (put_size > 0) {
267
+                elog_async_output_notice();
268
+            }
269
+        } else {
270
+            elog_port_output(log, size);
271
+        }
272
+    } else {
273
+        elog_port_output(log, size);
274
+    }
275
+}
276
+
277
+#ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD
278
+void elog_async_output_notice(void) {
279
+    sem_post(&output_notice);
280
+}
281
+
282
+static void *async_output(void *arg) {
283
+    size_t get_log_size = 0;
284
+    static char poll_get_buf[ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE];
285
+
286
+    while(true) {
287
+        /* waiting log */
288
+        sem_wait(&output_notice);
289
+        /* polling gets and outputs the log */
290
+        while(true) {
291
+
292
+#ifdef ELOG_ASYNC_LINE_OUTPUT
293
+            get_log_size = elog_async_get_line_log(poll_get_buf, ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE);
294
+#else
295
+            get_log_size = elog_async_get_log(poll_get_buf, ELOG_ASYNC_POLL_GET_LOG_BUF_SIZE);
296
+#endif
297
+
298
+            if (get_log_size) {
299
+                elog_port_output(poll_get_buf, get_log_size);
300
+            } else {
301
+                break;
302
+            }
303
+        }
304
+    }
305
+    return NULL;
306
+}
307
+#endif
308
+
309
+/**
310
+ * enable or disable asynchronous output mode
311
+ * the log will be output directly when mode is disabled
312
+ *
313
+ * @param enabled true: enabled, false: disabled
314
+ */
315
+void elog_async_enabled(bool enabled) {
316
+    is_enabled = enabled;
317
+}
318
+
319
+/**
320
+ * asynchronous output mode initialize
321
+ *
322
+ * @return result
323
+ */
324
+ElogErrCode elog_async_init(void) {
325
+    ElogErrCode result = ELOG_NO_ERR;
326
+
327
+    if (init_ok) {
328
+        return result;
329
+    }
330
+
331
+#ifdef ELOG_ASYNC_OUTPUT_USING_PTHREAD
332
+    pthread_attr_t thread_attr;
333
+    struct sched_param thread_sched_param;
334
+
335
+    sem_init(&output_notice, 0, 0);
336
+
337
+    pthread_attr_init(&thread_attr);
338
+    pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
339
+    pthread_attr_setstacksize(&thread_attr, ELOG_ASYNC_OUTPUT_PTHREAD_STACK_SIZE);
340
+    pthread_attr_setschedpolicy(&thread_attr, SCHED_RR);
341
+    thread_sched_param.sched_priority = ELOG_ASYNC_OUTPUT_PTHREAD_PRIORITY;
342
+    pthread_attr_setschedparam(&thread_attr, &thread_sched_param);
343
+    pthread_create(&async_output_thread, &thread_attr, async_output, NULL);
344
+    pthread_attr_destroy(&thread_attr);
345
+#endif
346
+
347
+    init_ok = true;
348
+
349
+    return result;
350
+}
351
+
352
+#endif /* ELOG_ASYNC_OUTPUT_ENABLE */

+ 104
- 0
fault-recorder/util/easylogger/src/elog_buf.c View File

@@ -0,0 +1,104 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2016, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: Logs buffered output.
26
+ * Created on: 2016-11-09
27
+ */
28
+
29
+#include <elog.h>
30
+#include <string.h>
31
+
32
+#ifdef ELOG_BUF_OUTPUT_ENABLE
33
+#if !defined(ELOG_BUF_OUTPUT_BUF_SIZE)
34
+    #error "Please configure buffer size for buffered output mode (in elog_cfg.h)"
35
+#endif
36
+
37
+/* buffered output mode's buffer */
38
+static char log_buf[ELOG_BUF_OUTPUT_BUF_SIZE] = { 0 };
39
+/* log buffer current write size */
40
+static size_t buf_write_size = 0;
41
+/* buffered output mode enabled flag */
42
+static bool is_enabled = false;
43
+
44
+extern void elog_port_output(const char *log, size_t size);
45
+extern void elog_output_lock(void);
46
+extern void elog_output_unlock(void);
47
+
48
+/**
49
+ * output buffered logs when buffer is full
50
+ *
51
+ * @param log will be buffered line's log
52
+ * @param size log size
53
+ */
54
+void elog_buf_output(const char *log, size_t size) {
55
+    size_t write_size = 0, write_index = 0;
56
+
57
+    if (!is_enabled) {
58
+        elog_port_output(log, size);
59
+        return;
60
+    }
61
+
62
+    while (true) {
63
+        if (buf_write_size + size > ELOG_BUF_OUTPUT_BUF_SIZE) {
64
+            write_size = ELOG_BUF_OUTPUT_BUF_SIZE - buf_write_size;
65
+            memcpy(log_buf + buf_write_size, log + write_index, write_size);
66
+            write_index += write_size;
67
+            size -= write_size;
68
+            buf_write_size += write_size;
69
+            /* output log */
70
+            elog_port_output(log_buf, buf_write_size);
71
+            /* reset write index */
72
+            buf_write_size = 0;
73
+        } else {
74
+            memcpy(log_buf + buf_write_size, log + write_index, size);
75
+            buf_write_size += size;
76
+            break;
77
+        }
78
+    }
79
+}
80
+
81
+/**
82
+ * flush all buffered logs to output device
83
+ */
84
+void elog_flush(void) {
85
+    /* lock output */
86
+    elog_output_lock();
87
+    /* output log */
88
+    elog_port_output(log_buf, buf_write_size);
89
+    /* reset write index */
90
+    buf_write_size = 0;
91
+    /* unlock output */
92
+    elog_output_unlock();
93
+}
94
+
95
+/**
96
+ * enable or disable buffered output mode
97
+ * the log will be output directly when mode is disabled
98
+ *
99
+ * @param enabled true: enabled, false: disabled
100
+ */
101
+void elog_buf_enabled(bool enabled) {
102
+    is_enabled = enabled;
103
+}
104
+#endif /* ELOG_BUF_OUTPUT_ENABLE */

+ 103
- 0
fault-recorder/util/easylogger/src/elog_utils.c View File

@@ -0,0 +1,103 @@
1
+/*
2
+ * This file is part of the EasyLogger Library.
3
+ *
4
+ * Copyright (c) 2015-2018, Armink, <armink.ztl@gmail.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining
7
+ * a copy of this software and associated documentation files (the
8
+ * 'Software'), to deal in the Software without restriction, including
9
+ * without limitation the rights to use, copy, modify, merge, publish,
10
+ * distribute, sublicense, and/or sell copies of the Software, and to
11
+ * permit persons to whom the Software is furnished to do so, subject to
12
+ * the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be
15
+ * included in all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
18
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ *
25
+ * Function: Some utils for this library.
26
+ * Created on: 2015-04-28
27
+ */
28
+
29
+#include <elog.h>
30
+#include <string.h>
31
+
32
+/**
33
+ * another copy string function
34
+ *
35
+ * @param cur_len current copied log length, max size is ELOG_LINE_BUF_SIZE
36
+ * @param dst destination
37
+ * @param src source
38
+ *
39
+ * @return copied length
40
+ */
41
+size_t elog_strcpy(size_t cur_len, char *dst, const char *src) {
42
+    const char *src_old = src;
43
+
44
+    assert(dst);
45
+    assert(src);
46
+
47
+    while (*src != 0) {
48
+        /* make sure destination has enough space */
49
+        if (cur_len++ < ELOG_LINE_BUF_SIZE) {
50
+            *dst++ = *src++;
51
+        } else {
52
+            break;
53
+        }
54
+    }
55
+    return src - src_old;
56
+}
57
+
58
+/**
59
+ * Copy line log split by newline sign. It will copy all log when the newline sign isn't find.
60
+ *
61
+ * @param line line log buffer
62
+ * @param log origin log buffer
63
+ * @param len origin log buffer length
64
+ *
65
+ * @return copy size
66
+ */
67
+size_t elog_cpyln(char *line, const char *log, size_t len) {
68
+    size_t newline_len = strlen(ELOG_NEWLINE_SIGN), copy_size = 0;
69
+
70
+    assert(line);
71
+    assert(log);
72
+
73
+    while (len--) {
74
+        *line++ = *log++;
75
+        copy_size++;
76
+        if (copy_size >= newline_len && !strncmp(log - newline_len, ELOG_NEWLINE_SIGN, newline_len)) {
77
+            break;
78
+        }
79
+    }
80
+    return copy_size;
81
+}
82
+
83
+/**
84
+ * This function will copy memory content from source address to destination
85
+ * address.
86
+ *
87
+ * @param dst the address of destination memory
88
+ * @param src  the address of source memory
89
+ * @param count the copied length
90
+ *
91
+ * @return the address of destination memory
92
+ */
93
+void *elog_memcpy(void *dst, const void *src, size_t count) {
94
+    char *tmp = (char *) dst, *s = (char *) src;
95
+
96
+    assert(dst);
97
+    assert(src);
98
+
99
+    while (count--)
100
+        *tmp++ = *s++;
101
+
102
+    return dst;
103
+}

+ 141
- 0
fault-recorder/util/impl/ClassLoaderImpl.cpp View File

@@ -0,0 +1,141 @@
1
+/*
2
+ * ClassLoader.cpp
3
+ *
4
+ *  Created on: 2016年11月7日
5
+ *      Author: Mr_zhu
6
+ *     Content: 
7
+ */
8
+
9
+#include "ClassLoaderImpl.h"
10
+
11
+#include <dlfcn.h>
12
+#include <stddef.h>
13
+#include <iostream>
14
+
15
+#include "../../common/GUID.cpp"
16
+#include "../../externservice/SoCreateI.h"
17
+
18
+using namespace std;
19
+
20
+HRESULT ClassLoaderImpl::loadClass(const IID& iid, CLSID& clsid, void** pcmpnt)
21
+{
22
+	char* error;
23
+	CreateFuncPTR CreateInstance;
24
+	HRESULT t_result = S_FALSE;
25
+
26
+	/**
27
+	 * 打开创建组件的组件
28
+	 */
29
+	void* handle = dlopen("libsocreater.so", RTLD_LAZY);
30
+
31
+	if (!handle)
32
+	{
33
+		log_e(
34
+				"libsocreater.so打开失败,文件不存在或者存在错误, 错误码: %s", dlerror());
35
+		return S_FALSE;
36
+	}
37
+
38
+	*(void**) (&CreateInstance) = dlsym(handle, "CreateInstance");
39
+	if ((error = dlerror()) != NULL)
40
+	{
41
+		log_e( "创建CoCreate组件失败,错误码: %s", error);
42
+		return S_FALSE;
43
+	}
44
+	IUnknown* pIUnknown = NULL;
45
+	IUnknown* pICreateUnknown = NULL;
46
+
47
+	pIUnknown = CreateInstance();
48
+	if (pIUnknown == NULL)
49
+	{
50
+		log_e( "CoCreate接口调用失败");
51
+		return S_FALSE;
52
+	}
53
+
54
+	CreateI* pICreate = NULL;
55
+	HRESULT hr = pIUnknown->queryInterface(IID_ICreate, (void**) &pICreate);
56
+	if (SUCCEEDED(hr))
57
+	{
58
+		log_d( "成功获取 创建组件的组件(CoCreate)接口");
59
+		if ((pICreateUnknown = pICreate->callCreateInstance(clsid)) != NULL)
60
+		{
61
+			pICreateUnknown->queryInterface(iid, (void**) pcmpnt);
62
+			pICreateUnknown->release();
63
+		}
64
+		else
65
+		{
66
+			log_e( "创建组件失败, 组件ID: %s",
67
+					clsid.toString().c_str());
68
+			return S_FALSE;
69
+		}
70
+
71
+		//pICreate->closeHandle();
72
+		pICreate->release();
73
+	}
74
+	else
75
+	{
76
+		log_e( "获取 创建组件的组件(CoCreate)接口失败");
77
+		return S_FALSE;
78
+	}
79
+	//pICreateUnknown->release();
80
+	pICreateUnknown = NULL;
81
+
82
+	pIUnknown->release();
83
+	pIUnknown = NULL;
84
+
85
+	dlclose(handle);
86
+
87
+	if ((*pcmpnt) != NULL)
88
+	{
89
+		t_result = S_OK;
90
+	}
91
+	return t_result;
92
+}
93
+
94
+HRESULT ClassLoaderImpl::loadSqliteClass(void** pcmpnt)
95
+{
96
+	char* error;
97
+	CreateFuncPTR CreateInstance;
98
+	IUnknown* pIUnknown;
99
+	HRESULT result = S_FALSE;
100
+
101
+	void* handle = dlopen("libsqlitewrapper.so", RTLD_LAZY);
102
+	if (!handle)
103
+	{
104
+		log_e(
105
+				"libsqlitewrapper.so打开失败,文件不存在或者存在错误, 错误码: %s", dlerror());
106
+		return S_FALSE;
107
+	}
108
+
109
+	*(void**) (&CreateInstance) = dlsym(handle, "CreateInstance");
110
+	if ((error = dlerror()) != NULL)
111
+	{
112
+		log_e( "创建Sqlite3组件失败,错误码: %s", error);
113
+		return S_FALSE;
114
+	}
115
+	pIUnknown = CreateInstance();
116
+	if (pIUnknown == NULL)
117
+	{
118
+		log_e( "创建Sqlite3接口的接口调用失败");
119
+		return S_FALSE;
120
+	}
121
+	HRESULT hr = pIUnknown->queryInterface(IID_ISqlite3, (void**) pcmpnt);
122
+
123
+	if (SUCCEEDED(hr))
124
+	{
125
+		log_d( "成功获取 Sqlite3接口");
126
+	}
127
+	else
128
+	{
129
+		log_e( "获取Sqlite3接口失败");
130
+		return S_FALSE;
131
+	}
132
+
133
+	pIUnknown->release();
134
+
135
+	if ((*pcmpnt) != NULL)
136
+	{
137
+		result = S_OK;
138
+	}
139
+
140
+	return result;
141
+}

+ 23
- 0
fault-recorder/util/impl/ClassLoaderImpl.h View File

@@ -0,0 +1,23 @@
1
+/*
2
+ * ClassLoaderImpl.h
3
+ *
4
+ *  Created on: 2016年11月7日
5
+ *      Author: Mr_zhu
6
+ *     Content: 
7
+ */
8
+
9
+#ifndef UTIL_IMPL_CLASSLOADERIMPL_H_
10
+#define UTIL_IMPL_CLASSLOADERIMPL_H_
11
+
12
+#include "../../common/Type.h"
13
+#include "../ClassLoaderI.h"
14
+
15
+class ClassLoaderImpl:public ClassLoaderI{
16
+public:
17
+	virtual HRESULT loadClass(const IID& iid, CLSID& clsid, void** pcmpnt);
18
+	virtual HRESULT loadSqliteClass(void** pcmpnt);
19
+};
20
+
21
+
22
+
23
+#endif /* UTIL_IMPL_CLASSLOADERIMPL_H_ */

Loading…
Cancel
Save