Преглед на файлове

1、添加IRControl.h及对应的lib文件到工程目录中;
2、完成异常开关机监听,Python脚本接口未处理;
3、未验证异常开关机监听;

Jeff преди 5 години
родител
ревизия
7745789505

+ 1 - 0
SATService/SATService/Global.cpp

@@ -23,6 +23,7 @@
 
 namespace GLOBAL
 {
+	PyNotice g_PyNotify;
 	STSATConfig g_stSATConfig;
 	//////////////////////////////////////////////////////////////////////////
 	// ČŤžÖąäÁż;

+ 14 - 0
SATService/SATService/Global.h

@@ -79,6 +79,20 @@ namespace GLOBAL
 		STLinuxDevice stLinuxDevice;
 	}STSATConfig, *pSTSATConfig;
 
+	typedef struct __PY_NOTICE__{
+		// 是否有通知(实时性,需要时段判断)
+		bool notify;
+		// 监控类型;
+		std::string report_type;
+		// 发生时间(如正常关机的通知时间);
+		std::string report_data;
+		// 接收到脚本通知的时间;
+		__int64 datetime;
+	}PyNotice, *pPyNotice;
+
+	// 只需要一个记录即可,无需记录多个;
+	extern PyNotice g_PyNotify;
+	// 全局配置文件;
 	extern STSATConfig g_stSATConfig;
 	//////////////////////////////////////////////////////////////////////////
 	// 全局变量;

+ 38 - 40
SATService/SATService/SATExecutor.cpp

@@ -3,10 +3,12 @@
 #include "PythonExecutor.h"
 #include "CharEncoding.h"
 #include "SynSerial.h"
+#include "IRControl.h"
 
 CSATExecutor::CSATExecutor(void)
 {
 	m_bLogin = FALSE;
+	m_bStopWathTV = FALSE;
 	m_hEventHearbeat = NULL;
 	m_hThreadHearbeat = NULL;
 	m_hEventExcuteScript = NULL;
@@ -15,6 +17,8 @@ CSATExecutor::CSATExecutor(void)
 
 CSATExecutor::~CSATExecutor(void)
 {
+	m_bStopWathTV = FALSE;
+	EndofWork();
 }
 
 bool CSATExecutor::IsTaskExist(SATHTTP::STTask &task)
@@ -1224,6 +1228,11 @@ DWORD CSATExecutor::ExecuteScriptThread(LPVOID lpVoid)
 
 DWORD CSATExecutor::WathTVPortThread(PVOID lpVoid)
 {
+	CSATExecutor *that = (CSATExecutor*)lpVoid;
+	if ( !that )
+		return 0;
+
+	
 	CSynSerial tv;
 	std::string buffer;
 	TCHAR szLastPort[10] = {0};
@@ -1231,41 +1240,36 @@ DWORD CSATExecutor::WathTVPortThread(PVOID lpVoid)
 	std::vector<std::string> vtNotifyReboot;
 	std::vector<std::string> vtNotifyShutdown;
 	DWORD dwTickCount = GetTickCount();
-/*
-	while(!g_bStopThread)
-	{
-		// 读取配置文件;
+
+	while( !that->m_bStopWathTV ) {
+		// 实时读取配置文件;
 		GLOBAL::GetIniInfo();
-		if ( !GLOBAL::g_stSATConfig.bWatchTVPort )
-		{
+		if ( !GLOBAL::g_stSATConfig.bWatchTVPort ) {
 			Sleep(5000);
 			continue;
 		}
 
-		if ( GetTickCount() - dwTickCount > 5000 )
-		{// 5秒更新一次;
-			dwTickCount = GetTickCount();
+		if ( GetTickCount() - dwTickCount > 5000 ) { // 5秒更新一次;
 			vtNotifyReboot.clear();
 			vtNotifyShutdown.clear();
+			dwTickCount = GetTickCount();
 			GLOBAL::Split(GLOBAL::g_stSATConfig.szTVReboot, _T(";"), vtNotifyReboot);
 			GLOBAL::Split(GLOBAL::g_stSATConfig.szTVShutdown, _T(";"), vtNotifyShutdown);
 		}
 
 		// 串口是否变更;
-		if ( _tcsicmp(szLastPort, GLOBAL::g_stSATConfig.szTVPort) )
-		{
+		if ( _tcsicmp(szLastPort, GLOBAL::g_stSATConfig.szTVPort) ) {
 			_tcscpy_s(szLastPort, GLOBAL::g_stSATConfig.szTVPort);
 			// 重启打开串口;
 			tv.CloseSerialPort();
 		}
 
-		if ( !tv.IsOpen() )
-		{
+		// 如果串口打开失败重新打开;
+		if ( !tv.IsOpen() ) {
 			tv.OpenSerialPort(szLastPort, 115200, 8, 0, 1, 0, 1000);
 		}
 
-		if ( tv.IsOpen() )
-		{
+		if ( tv.IsOpen() ) {
 			BYTE szBuffer[1024] = {0};
 			DWORD dwBuffer = tv.ReadComm(szBuffer, 1024, 1000);
 			if ( dwBuffer != 0 )
@@ -1277,20 +1281,17 @@ DWORD CSATExecutor::WathTVPortThread(PVOID lpVoid)
 				// 遍历是否有符合的子串;		
 				for ( std::vector<std::string>::iterator it = vtNotifyReboot.begin(); it != vtNotifyReboot.end(); it++ )
 				{
-					if ( _tcsstr(buffer.c_str(), it->c_str()) )
-					{
+					if ( _tcsstr(buffer.c_str(), it->c_str()) ) {
 						nType = 1;
 						bAbnormal = true;
 						break;
 					}
 				}
 
-				if ( !bAbnormal )
-				{
+				if ( !bAbnormal ) {
 					for ( std::vector<std::string>::iterator it = vtNotifyShutdown.begin(); it != vtNotifyShutdown.end(); it++ )
 					{
-						if ( _tcsstr(buffer.c_str(), it->c_str()) )
-						{
+						if ( _tcsstr(buffer.c_str(), it->c_str()) ) {
 							nType = -1;
 							bAbnormal = true;
 							break;
@@ -1299,38 +1300,36 @@ DWORD CSATExecutor::WathTVPortThread(PVOID lpVoid)
 				}
 
 				// 1分钟前,是否有收到脚本通知;
-				if ( Global::g_notify.notify )
-				{
-					__int64 nd = gmt - Global::g_notify.datetime;
+				if ( GLOBAL::g_PyNotify.notify ) {
+					__int64 nd = gmt - GLOBAL::g_PyNotify.datetime;
 #ifdef _DEBUG
-					TRACE3("判断时间%ld-通知时间%ld=相差时间%ld\n\n", gmt, Global::g_notify.datetime, nd);
+					TRACE3("判断时间%ld-通知时间%ld=相差时间%ld\n\n", gmt, GLOBAL::g_PyNotify.datetime, nd);
 #endif
 					if ( nd < 60)
 					{
 						// 监测的类型与通知类型是否一致;
-						if ( (nType == 1 && Global::g_notify.report_type == _T("reboot")) ||
-							(nType == -1 && Global::g_notify.report_type == _T("shutdown")) ) 
+						if ( (nType == 1 && GLOBAL::g_PyNotify.report_type == _T("reboot")) ||
+							(nType == -1 && GLOBAL::g_PyNotify.report_type == _T("shutdown")) ) 
 						{
 							bAbnormal = false;
 							// 重置;
-							Global::g_notify.notify = false;
-							Global::g_notify.datetime = 0;
-							Global::g_notify.report_type.clear();
+							GLOBAL::g_PyNotify.notify = false;
+							GLOBAL::g_PyNotify.datetime = 0;
+							GLOBAL::g_PyNotify.report_type.clear();
 						}
 					}
 				}
 
-				if (bAbnormal)
-				{
+				if (bAbnormal) {
 					if ( nType == -1 )
 					{
 						// 遥控:重启电视机;
-						if ( Global::g_SendPowerKey )
-							Global::g_SendPowerKey();
+						if ( Connect("127.0.0.1", 40000) )
+							sendSignal("POWER", 1, 1000);
 					}
 
 					// 压入容器中;
-					Global::TLog tlog;
+					GLOBAL::PyNotice tlog;
 					if ( nType == -1 )
 						tlog.report_type = "Abnormal shutdown";
 					else if ( nType == 1 )
@@ -1342,18 +1341,17 @@ DWORD CSATExecutor::WathTVPortThread(PVOID lpVoid)
 					TCHAR szDataTime[64] = {0};
 					_stprintf_s(szDataTime,_T("Time of exception:%04d-%02d-%02d %02d:%02d:%02d"), gmtm.tm_year + 1900, gmtm.tm_mon+1, gmtm.tm_mday, gmtm.tm_hour, gmtm.tm_min, gmtm.tm_sec);
 					tlog.report_data = szDataTime;
-					Global::g_vtAbnormal.push_back(tlog);
 
 					// 最后,重置;
-					Global::g_notify.notify = false;
-					Global::g_notify.datetime = 0;
-					Global::g_notify.report_type.clear();
+					GLOBAL::g_PyNotify.notify = false;
+					GLOBAL::g_PyNotify.datetime = 0;
+					GLOBAL::g_PyNotify.report_type.clear();
 				}
 			}
 		}
 
 		Sleep(200);
 	}
-*/
+
 	return 0;
 }

+ 2 - 0
SATService/SATService/SATExecutor.h

@@ -47,6 +47,8 @@ protected:
 
 	// 是否登录成功;
 	BOOL	m_bLogin;
+	// 是否结束TV串口监听;
+	BOOL	m_bStopWathTV;
 
 	ThreadSection	m_csTask;
 	std::list<SATHTTP::STTask> m_vtTask;

+ 3 - 3
SATService/SATService/SATService.vcproj

@@ -62,7 +62,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="SATHTTP.lib"
+				AdditionalDependencies="SATHTTP.lib IRControl.lib"
 				LinkIncremental="2"
 				AdditionalLibraryDirectories="C:\Python27\libs"
 				UACExecutionLevel="2"
@@ -140,7 +140,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
-				AdditionalDependencies="SATHTTP.lib"
+				AdditionalDependencies="SATHTTP.lib IRControl.lib"
 				LinkIncremental="1"
 				AdditionalLibraryDirectories="C:\Python27\libs"
 				UACExecutionLevel="2"
@@ -287,7 +287,7 @@
 			Name="lib"
 			>
 			<File
-				RelativePath=".\RunPython.h"
+				RelativePath=".\IRControl.h"
 				>
 			</File>
 			<File