From 514795c44cbad68fe213c5f00c902d370464c022 Mon Sep 17 00:00:00 2001
From: houxiao <houxiao@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期一, 24 七月 2017 20:18:21 +0800
Subject: [PATCH] add panshen TeleWrapper

---
 VisitFace/RtspNativeCodec/app/src/main/cpp/TeleWrapper.cpp |  169 ++++++++++++++++++++++++++-----------------------------
 1 files changed, 80 insertions(+), 89 deletions(-)

diff --git a/VisitFace/RtspNativeCodec/app/src/main/cpp/TeleWrapper.cpp b/VisitFace/RtspNativeCodec/app/src/main/cpp/TeleWrapper.cpp
index c0efaf0..99bff45 100644
--- a/VisitFace/RtspNativeCodec/app/src/main/cpp/TeleWrapper.cpp
+++ b/VisitFace/RtspNativeCodec/app/src/main/cpp/TeleWrapper.cpp
@@ -1,107 +1,96 @@
+#include <logger.h>
 #include "TeleWrapper.h"
+
+extern "C" {
+#include "serial.h"
+}
 
 bool TeleWrapper::start()
 {
-LOG_INFO << "TeleWrapper::start" << LOG_ENDL;
-running = true;
- pthread_mutex_init(&mutex, NULL); // // 初始化互斥对象
-	int ret = pthread_create(&tel_thid, NULL, TeleWrapper::tel_thd, this);
-	if(ret != 0)
-	{
-		LOGP(ERROR, "pthread_create: %s/n", strerror(ret));
-		running = false;
-		return false;
-	}
+    LOG_INFO << "TeleWrapper::start" << LOG_ENDL;
 
-	return true;
- 
+    fd = serialOpen(PORT, BAUD);
+
+    running = true;
+    pthread_mutex_init(&mutex, NULL); // 鍒濆鍖栦簰鏂ュ璞�,鍔ㄦ�佸姞閿�
+    cond = PTHREAD_COND_INITIALIZER;
+    int ret = pthread_create(&tel_thid, NULL, TeleWrapper::tel_thd, this);
+
+    if(ret != 0)
+    {
+        LOGP(ERROR, "pthread_create: %s/n", strerror(ret));
+        running = false;
+        return false;
+    }
+
+    return true;
+
 }
 
 void TeleWrapper::stop()
 {
-LOG_INFO << "TeleWrapper::stop" << LOG_ENDL;
-	
-	if (!running)
-		return;
+    LOG_INFO << "TeleWrapper::stop" << LOG_ENDL;
 
-	running = false;
-	pthread_join(tel_thid, NULL);
-	pthread_mutex_destroy(&mutex);  
-}
+    if (!running)
+        return;
 
-void TeleWrapper::pushTask(TeleTask task)
-{                                      
-      if(telQueue.empty()|| telQueue.back().command!=task.command) //队列为空 或者 放入任务和前一个任务不一致 时
-           {
-              telQueue.push(task); //放进队列 
-              thread_resume(); //唤醒线程
-           }
-  }
-      
-     void TeleWrapper::popTask()
-{
-           TeleTask curTask = telQueue.front();
-            telQueue.pop();
-            switch(curTask.command)
-            {
-                case TeleTask::CALL: //打电话
-                 callNum(curTask.param);
-                 break:
-                 case TeleTask::HANGUP:
-                 //  挂机
-                 hang();
-                 break;
-            }
-}
- 
-     
-void TeleWrapper:: *tel_thd(void *arg)  //线程函数
-{
-	LOG_INFO << "TeleWrapper::tel_thd start" << LOG_ENDL;
-	
-		TeleWrapper& teleWrapper = *(TeleWrapper*)arg;
-     while(teleWrapper.running)
-     {
-         if(telQueue.empty())
-       {
-        thread_pause();
-        return ;
-       }
-          if(!pthread_pause)
-          {
-           popTask();
-        }
-     }
-   LOG_INFO << "TeleWrapper::tel_thd stop" << LOG_ENDL;
-}
+    running = false;
+    pthread_join(tel_thid, NULL);//闃诲绾跨▼锛岀瓑寰呯嚎绋�
+    pthread_mutex_destroy(&mutex);
 
-void TeleWrapper::thread_pause()
-{
-   if(!pthread_pause)
-    {   
-        pthread_mutex_lock(&mutex);
-        pthread_pause = true;
-        LOG_INFO << "thread pause " << LOG_ENDL;
-        pthread_mutex_unlock(&mutex)
-       }
+    serialClose(fd);
 }
 
 
-void TeleWrapper::thread_resume()
+
+
+
+void TeleWrapper::popTask()
 {
-    if(pthread_pause)
+
+    TeleTask curTask = telQueue.front();
+    telQueue.pop();
+    switch(curTask.command)
     {
-      pthread_mutex_lock(&mutex);
-        pthread_pause = false;
-         pthread_cond_broadcast(&cond_pause);  
-        LOG_INFO << "thread wake " << LOG_ENDL;
-        pthread_mutex_unlock(&mutex)
+        case TeleTask::CALL: //鎵撶數璇�
+            callNum(curTask.param);
+            break;
+        case TeleTask::HANGUP:
+            //  鎸傛満
+            hang();
+            break;
     }
 }
+void TeleWrapper::pushTask(TeleTask task)
+{
+    telQueue.push(task);
+    pthread_mutex_unlock(&mutex);
+    //pthread_cond_signal(&cond);
+    //pthread_mutex_lock(&mutex);
+    //thread_resume(); //鍞ら啋绾跨▼
+}
 
+void * TeleWrapper::tel_thd(void *arg)  //绾跨▼鍑芥暟
+{
+    LOG_INFO << "TeleWrapper::tel_thd start" << LOG_ENDL;
 
+    TeleWrapper& teleWrapper = *(TeleWrapper*)arg;
+    while(teleWrapper.running)
+    {
+        if(teleWrapper.telQueue.empty())
+            pthread_mutex_lock(&teleWrapper.mutex);
 
-void TeleWrapper::callNum(  char phone)
+        if(teleWrapper.telQueue.empty())
+            continue;
+
+        teleWrapper.popTask();
+    }
+
+    pthread_mutex_unlock(&teleWrapper.mutex);
+    LOG_INFO << "TeleWrapper::tel_thd stop" << LOG_ENDL;
+}
+
+void TeleWrapper::callNum(char phone)
 {
     switch (phone)
     {
@@ -138,22 +127,24 @@
     }
 }
 
-void TeleWrapper::callNum( std::string phone)
+void TeleWrapper::callNum(const std::string phone)
 {
-   fd = serialOpen(PORT, BAUD);
-    serialWriteString(fd, "AA");//摘机
+
+    //serialWriteString(fd, "BA");
+    serialWriteString(fd, "AA");//鎽樻満
     sleep(1);
-     while (*phone)
+    const char* _phone = phone.c_str();
+    while (*_phone)
     {
         sleep(1);
-        callNum(*(phone++));
+        callNum(*(_phone++));
     }
 }
 
 void TeleWrapper::hang()
 {
-      serialWriteString(fd, "BA");
-      serialClose(fd);
+    sleep(40);
+    serialWriteString(fd, "BA");
 }
 
 

--
Gitblit v1.8.0