Selaa lähdekoodia

1、脚本通知不返回;
2、py脚本完成通知,但未测试;

Jeff 5 vuotta sitten
vanhempi
commit
0be27b365a
2 muutettua tiedostoa jossa 29 lisäystä ja 0 poistoa
  1. 2 0
      SATService/SATService/SATTCPServer.cpp
  2. 27 0
      SATService/tcp_client.py

+ 2 - 0
SATService/SATService/SATTCPServer.cpp

@@ -1000,6 +1000,7 @@ void CSATTCPServer::_TaskProcess(PER_IO_CONTEXT* pIoContext, SATPROTO::Package*
 						GLOBAL::g_PyNotify.report_type = "reboot";
 					}
 
+#if 0	// 不作任何返回;
 					// 封装返回数据;
 					long len = sizeof(SATPROTO::DataHeader);
 					byte *pbuff = new byte[len];
@@ -1015,6 +1016,7 @@ void CSATTCPServer::_TaskProcess(PER_IO_CONTEXT* pIoContext, SATPROTO::Package*
 					// 释放内存;
 					delete []pbuff;
 					pbuff = NULL;
+#endif
 				}
 				break;
 			default:

+ 27 - 0
SATService/tcp_client.py

@@ -12,6 +12,8 @@ import binascii
 DataHeader = np.dtype({'names': ['protocol', 'len', 'cmd'], 'formats': ['u1', 'u4', 'u1']}, align=False)
 UserInfo = np.dtype({'names': ['userName', 'password', 'actuator'], 'formats': ['|S260', '|S260', '|S260']}, align=False)
 LoginResp = np.dtype({'names': ['bStatus', 'szMessage'], 'formats': ['?', '|S260']}, align=False)
+# 通知SATService正常关机、重启;
+NoticeResp = np.dtype({'names': ['TimeStamp', 'NoticeType'], 'formats': ['u8', 'u4']}, align=False)
 
 class BaseClient(object):
     __metaclass__ = abc.ABCMeta
@@ -194,6 +196,31 @@ class SATClient(object):
         except Exception, e:
             print "BaseClient=> recv Error:", e
             return False
+            
+            
+    # 发送通知,不接收返回;
+    def sendnotice(self, type):
+        '''是否连接'''
+        if self.constate is False:
+            if self.connect() is False:
+                return None
+
+        '''拼装要发送的数据包'''
+        notice = np.array([(time.time(), type)], dtype=NoticeResp)
+
+        '''发送请求数据'''
+        try:
+            self.sock.settimeout(5)
+            phead = np.array([(0xAA, notice.itemsize + np.array([(0xAA, 0, 0x01)], dtype=DataHeader).itemsize, 0x06)], dtype=DataHeader)
+            '''一次性发送完整包'''
+            self.sock.sendall(bytearray(phead.tobytes() + notice.tobytes()))
+            self.sock.settimeout(None)
+        except Exception, e:
+            print "BaseClient=> send Error:", e
+            self.disconnect()
+            self.connect()
+            return False
+       
 
     '''断开连接'''