Class: ClientTcpCommunication
- Inherits:
-
Object
- Object
- ClientTcpCommunication
- Defined in:
- lib/haruzira_sdk/HzClientTcpCommunication.rb
Overview
endregion
Instance Attribute Summary collapse
-
#EvNotifyCompeteSpeech ⇒ Object
define accessor.
-
#EvNotifyMessageEvent ⇒ Object
define accessor.
-
#EvNotifyReceivedDisConnectEvent ⇒ Object
define accessor.
-
#EvNotifySendSpeechRecognitionCommand ⇒ Object
define accessor.
-
#ReceivedDataDecryptionKey ⇒ Object
define accessor.
-
#ReceivePort ⇒ Object
define accessor.
-
#ReceiveStatus ⇒ Object
readonly
Returns the value of attribute ReceiveStatus.
-
#ReqSendDataAccountName ⇒ Object
define accessor.
-
#ReqSendDataEncrypt ⇒ Object
define accessor.
-
#ReqSendDataEncryptKey ⇒ Object
define accessor.
-
#ReqSendDataPasswd ⇒ Object
define accessor.
-
#ReqSendDataSpeechAge ⇒ Object
define accessor.
-
#ReqSendDataSpeechGender ⇒ Object
define accessor.
-
#ReqSendDataSpeechLevel ⇒ Object
define accessor.
-
#ReqSendDataSpeechLocaleId ⇒ Object
define accessor.
-
#ReqSendDataSpeechMode ⇒ Object
define accessor.
-
#ReqSendDataSpeechRepeat ⇒ Object
define accessor.
-
#ReqSendDataText ⇒ Object
define accessor.
-
#SendDataHexStr ⇒ Object
readonly
Returns the value of attribute SendDataHexStr.
-
#SendDataLength ⇒ Object
readonly
Returns the value of attribute SendDataLength.
-
#ServerIP ⇒ Object
define accessor.
-
#ServerPortNo ⇒ Object
define accessor.
-
#Version ⇒ Object
readonly
Returns the value of attribute Version.
Instance Method Summary collapse
-
#cancelAsynchronousListener ⇒ Object
<summary> 非同期メッセージ受信スレッドの終了 </summary>.
-
#initialize ⇒ ClientTcpCommunication
constructor
<summary> Construct </summary>.
-
#ReceiveAckTimeOut ⇒ Object
<summary> 応答受信時タイムアウト取得 </summary> <param name=“value”>タイムアウト値</param>.
-
#ReceiveAckTimeOut=(value) ⇒ Object
<summary> 応答受信時タイムアウト設定 </summary> <param name=“value”>タイムアウト値</param>.
-
#sendSpeechDataEx ⇒ Object
<summary> 読み上げデータ送信(自動) </summary> <returns>OK:タイムスタンプ文字列(00:00:00形式), NG:nil</returns>.
-
#setTraceOutPut(val) ⇒ Object
<summary> トレース出力設定 </summary> <returns></returns>.
-
#startAsynchronousListener ⇒ Object
<summary> 非同期メッセージ受信タスク起動 </summary> <returns></returns>.
-
#stopSendSpeechData ⇒ Object
<summary> 読み上げデータ送信の停止(中断) </summary>.
Constructor Details
#initialize ⇒ ClientTcpCommunication
<summary> Construct </summary>
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 43 def initialize() #region 変数・定数 @DISCONNECT_REASON_END = 0x10 #通信終了通知送信時 @DISCONNECT_REASON_CANCEL = 0x11 #キャンセル発生時 @DISCONNECT_REASON_SERVER_IREGULAR = 0x12 #サーバー側でイレギュラー障害発生 @DISCONNECT_REASON_CLIENT_IREGULAR = 0x13 #クライアント側でイレギュラー障害発生 @QUEUE_RECEIVED = "OK" @encryption = Encryption.new #@encryption = nil @work_rcv = nil #メッセージ受信スレッド @listenTask = nil #非同期メッセージ受信メインスレッド @tcpSvr = nil #TCPServer @ackStartCommAutoResetEvent = Queue.new @ackSendSpeechDataAutoResetEvent = Queue.new @cltSocket = nil @ServerPortNo = 46000 @ServerIP = "127.0.0.1" @ReceivePort = 46100 @ReqSendDataText = "" @ReqSendDataEncrypt = false @ReqSendDataEncryptKey = "" @ReqSendDataAccountName = "" @ReqSendDataPasswd = "" @ReqSendDataSpeechMode = HzSpeechTextMode::Text @ReqSendDataSpeechLevel = HzSpeechLevel::Normal @ReqSendDataSpeechLocaleId = 0x00 @ReqSendDataSpeechGender = HzSpeechGender::Neutral @ReqSendDataSpeechAge = 25 @ReqSendDataSpeechRepeat = 0 @ReceivedDataDecryptionKey = "" @SendDataHexStr = "" @SendDataLength = 0 @ReceiveStatus = 0x00 @ReceiveAckTimeOut = RECEIVE_TIME_OUT @Version = "2.0.0.0" #SDKバージョン #メッセージ受信時イベント定義 @EvNotifyCompeteSpeech = nil #読み上げ完了通知受信時イベント @EvNotifyMessageEvent = nil #Exception発生時イベント(切断以外) @EvNotifyReceivedDisConnectEvent = nil #切断発生時イベント(サーバー側からの切断など) @EvNotifySendSpeechRecognitionCommand = nil #音声認識コマンド送信受信時イベント #endregion end |
Instance Attribute Details
#EvNotifyCompeteSpeech ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def EvNotifyCompeteSpeech @EvNotifyCompeteSpeech end |
#EvNotifyMessageEvent ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def EvNotifyMessageEvent @EvNotifyMessageEvent end |
#EvNotifyReceivedDisConnectEvent ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def EvNotifyReceivedDisConnectEvent @EvNotifyReceivedDisConnectEvent end |
#EvNotifySendSpeechRecognitionCommand ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def EvNotifySendSpeechRecognitionCommand @EvNotifySendSpeechRecognitionCommand end |
#ReceivedDataDecryptionKey ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ReceivedDataDecryptionKey @ReceivedDataDecryptionKey end |
#ReceivePort ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ReceivePort @ReceivePort end |
#ReceiveStatus ⇒ Object (readonly)
Returns the value of attribute ReceiveStatus.
93 94 95 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 93 def ReceiveStatus @ReceiveStatus end |
#ReqSendDataAccountName ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ReqSendDataAccountName @ReqSendDataAccountName end |
#ReqSendDataEncrypt ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ReqSendDataEncrypt @ReqSendDataEncrypt end |
#ReqSendDataEncryptKey ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ReqSendDataEncryptKey @ReqSendDataEncryptKey end |
#ReqSendDataPasswd ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ReqSendDataPasswd @ReqSendDataPasswd end |
#ReqSendDataSpeechAge ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ReqSendDataSpeechAge @ReqSendDataSpeechAge end |
#ReqSendDataSpeechGender ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ReqSendDataSpeechGender @ReqSendDataSpeechGender end |
#ReqSendDataSpeechLevel ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ReqSendDataSpeechLevel @ReqSendDataSpeechLevel end |
#ReqSendDataSpeechLocaleId ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ReqSendDataSpeechLocaleId @ReqSendDataSpeechLocaleId end |
#ReqSendDataSpeechMode ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ReqSendDataSpeechMode @ReqSendDataSpeechMode end |
#ReqSendDataSpeechRepeat ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ReqSendDataSpeechRepeat @ReqSendDataSpeechRepeat end |
#ReqSendDataText ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ReqSendDataText @ReqSendDataText end |
#SendDataHexStr ⇒ Object (readonly)
Returns the value of attribute SendDataHexStr.
93 94 95 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 93 def SendDataHexStr @SendDataHexStr end |
#SendDataLength ⇒ Object (readonly)
Returns the value of attribute SendDataLength.
93 94 95 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 93 def SendDataLength @SendDataLength end |
#ServerIP ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ServerIP @ServerIP end |
#ServerPortNo ⇒ Object
define accessor
90 91 92 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90 def ServerPortNo @ServerPortNo end |
#Version ⇒ Object (readonly)
Returns the value of attribute Version.
93 94 95 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 93 def Version @Version end |
Instance Method Details
#cancelAsynchronousListener ⇒ Object
<summary> 非同期メッセージ受信スレッドの終了</summary>
223 224 225 226 227 228 229 230 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 223 def cancelAsynchronousListener() if (@listenTask != nil) @listenTask.kill @listenTask = nil #HzTrace.traceCommMessage("非同期メッセージ受信スレッドをキャンセルしました。") HzTrace.traceCommMessage("The thread for receiving some asynchronous messsages was canceled.") end end |
#ReceiveAckTimeOut ⇒ Object
<summary> 応答受信時タイムアウト取得</summary> <param name=“value”>タイムアウト値</param>
107 108 109 110 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 107 def ReceiveAckTimeOut #Get return @ReceiveAckTimeOut end |
#ReceiveAckTimeOut=(value) ⇒ Object
<summary> 応答受信時タイムアウト設定</summary> <param name=“value”>タイムアウト値</param>
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 116 def ReceiveAckTimeOut=(value) #Set if(value > RECEIVE_MAX_TIME_OUT) @ReceiveAckTimeOut = RECEIVE_MAX_TIME_OUT elsif(value < RECEIVE_MIN_TIME_OUT) @ReceiveAckTimeOut = RECEIVE_MIN_TIME_OUT else @ReceiveAckTimeOut = value end end |
#sendSpeechDataEx ⇒ Object
<summary> 読み上げデータ送信(自動)</summary> <returns>OK:タイムスタンプ文字列(00:00:00形式), NG:nil</returns>
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 131 def sendSpeechDataEx() timeStamp = "" notifyEndComm = MsgNotifyEndComm.new() begin #電文シーケンス開始 #通信開始要求(0x00) if (@ReqSendDataAccountName != nil && @ReqSendDataPasswd != nil && @ReqSendDataEncryptKey != nil) #暗号化パスワード認証 retStatus = reqStartCommProc(@ReqSendDataAccountName, @ReqSendDataPasswd, @ReqSendDataEncryptKey) elsif (@ReqSendDataAccountName != nil && @ReqSendDataPasswd != nil) #パスワード認証 retStatus = reqStartCommProc(@ReqSendDataAccountName, @ReqSendDataPasswd) else #認証無 retStatus = reqStartCommProc() end if (!retStatus) #puts("【CL】通信開始応答受信(0x%02x):待機結果[%s]" % [reqStartComm.id, "Time Out"]) #raise("通信開始要求メッセージ送信に失敗しました。\r\n通信処理を中断します。") puts("[CL]Received, Responce of Communication Start Request(0x%02x):Waiting Result[%s]" % [reqStartComm.id, "Time Out"]) raise("Sending the message of Communication Strat Request has failed. and then the communication stop.") end #非同期メッセージ受信タスク起動 startAsynchronousListener() #if(@listenTask == nil) # @listenTask = Thread.start do # listenerTask() # end #end #読み上げデータ送信(0x03) if (@ReqSendDataAccountName != nil && @ReqSendDataEncryptKey != nil) #暗号化(アカウント名および暗号化キー有) @ReqSendDataEncrypt = true elsif (@ReqSendDataAccountName == nil && @ReqSendDataEncryptKey != nil) #暗号化(暗号化キーのみ)エラーケース @ReqSendDataAccountName = "" @ReqSendDataEncrypt = true elsif (@ReqSendDataAccountName != nil && @ReqSendDataEncryptKey == nil) #平文(アカウント名のみ) @ReqSendDataEncrypt = false @ReqSendDataEncryptKey = "" else #平文(認証が有効の場合はエラーとなる) @ReqSendDataAccountName = "" @ReqSendDataEncrypt = false @ReqSendDataEncryptKey = "" end timeStamp = sendSpeechData() #通信終了通知(0x01) if(timeStamp == nil || @ReceiveStatus != 0x00) notifyEndCommProc(notifyEndComm.ERR_CODE_OTHER_REASONS) else notifyEndCommProc(notifyEndComm.ERR_CODE_NONE) end rescue => ex HzTrace.traceCommMessage("%s" % [ex]) timeStamp = nil ensure return timeStamp end end |
#setTraceOutPut(val) ⇒ Object
<summary> トレース出力設定</summary> <returns></returns>
99 100 101 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 99 def setTraceOutPut(val) HzTrace.setTraceOutPut(val) end |
#startAsynchronousListener ⇒ Object
<summary> 非同期メッセージ受信タスク起動</summary> <returns></returns>
204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 204 def startAsynchronousListener() begin #非同期メッセージ受信タスク起動 if(@listenTask == nil) @listenTask = Thread.start do listenerTask() end end rescue => ex HzTrace.traceCommMessage("%s" % [ex]) ensure end end |
#stopSendSpeechData ⇒ Object
<summary> 読み上げデータ送信の停止(中断)</summary>
235 236 237 238 239 240 241 242 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 235 def stopSendSpeechData() if (@tcpSvr != nil) @tcpSvr.kill @tcpSvr = nil #HzTrace.traceCommMessage("読み上げデータ送信処理をキャンセルしました。") HzTrace.traceCommMessage("The sending proccess for send of Speech Data was canceled.") end end |