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.
-
#ReqSendDataCompletionNoticeNecessity ⇒ 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>
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 62 def initialize() #region 変数・定数 @DISCONNECT_REASON_END = 0x10 #通信終了通知送信時 @DISCONNECT_REASON_CANCEL = 0x11 #キャンセル発生時 @DISCONNECT_REASON_SERVER_IREGULAR = 0x12 #サーバー側でイレギュラー障害発生 @DISCONNECT_REASON_CLIENT_IREGULAR = 0x13 #クライアント側でイレギュラー障害発生 @QUEUE_RECEIVED = "OK" @SDK_LANG_TYPE = HzSdkLangType::Ruby @Version = "2.1.0.0" #SDKバージョン @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 @ReqSendDataCompletionNoticeNecessity = HzSpCompletionNoticeNecessity::Need @ReceivedDataDecryptionKey = "" @SendDataHexStr = "" @SendDataLength = 0 @ReceiveStatus = 0x00 @ReceiveAckTimeOut = RECEIVE_TIME_OUT @SdkVersions = [@Version.split(".")[0].to_i, @Version.split(".")[1].to_i] #SDKバージョン(送信用) #メッセージ受信時イベント定義 @EvNotifyCompeteSpeech = nil #読み上げ完了通知受信時イベント @EvNotifyMessageEvent = nil #Exception発生時イベント(切断以外) @EvNotifyReceivedDisConnectEvent = nil #切断発生時イベント(サーバー側からの切断など) @EvNotifySendSpeechRecognitionCommand = nil #音声認識コマンド送信受信時イベント #endregion end |
Instance Attribute Details
#EvNotifyCompeteSpeech ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def EvNotifyCompeteSpeech @EvNotifyCompeteSpeech end |
#EvNotifyMessageEvent ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def EvNotifyMessageEvent @EvNotifyMessageEvent end |
#EvNotifyReceivedDisConnectEvent ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def EvNotifyReceivedDisConnectEvent @EvNotifyReceivedDisConnectEvent end |
#EvNotifySendSpeechRecognitionCommand ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def EvNotifySendSpeechRecognitionCommand @EvNotifySendSpeechRecognitionCommand end |
#ReceivedDataDecryptionKey ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReceivedDataDecryptionKey @ReceivedDataDecryptionKey end |
#ReceivePort ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReceivePort @ReceivePort end |
#ReceiveStatus ⇒ Object (readonly)
Returns the value of attribute ReceiveStatus.
117 118 119 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 117 def ReceiveStatus @ReceiveStatus end |
#ReqSendDataAccountName ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReqSendDataAccountName @ReqSendDataAccountName end |
#ReqSendDataCompletionNoticeNecessity ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReqSendDataCompletionNoticeNecessity @ReqSendDataCompletionNoticeNecessity end |
#ReqSendDataEncrypt ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReqSendDataEncrypt @ReqSendDataEncrypt end |
#ReqSendDataEncryptKey ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReqSendDataEncryptKey @ReqSendDataEncryptKey end |
#ReqSendDataPasswd ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReqSendDataPasswd @ReqSendDataPasswd end |
#ReqSendDataSpeechAge ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReqSendDataSpeechAge @ReqSendDataSpeechAge end |
#ReqSendDataSpeechGender ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReqSendDataSpeechGender @ReqSendDataSpeechGender end |
#ReqSendDataSpeechLevel ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReqSendDataSpeechLevel @ReqSendDataSpeechLevel end |
#ReqSendDataSpeechLocaleId ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReqSendDataSpeechLocaleId @ReqSendDataSpeechLocaleId end |
#ReqSendDataSpeechMode ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReqSendDataSpeechMode @ReqSendDataSpeechMode end |
#ReqSendDataSpeechRepeat ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReqSendDataSpeechRepeat @ReqSendDataSpeechRepeat end |
#ReqSendDataText ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ReqSendDataText @ReqSendDataText end |
#SendDataHexStr ⇒ Object (readonly)
Returns the value of attribute SendDataHexStr.
117 118 119 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 117 def SendDataHexStr @SendDataHexStr end |
#SendDataLength ⇒ Object (readonly)
Returns the value of attribute SendDataLength.
117 118 119 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 117 def SendDataLength @SendDataLength end |
#ServerIP ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ServerIP @ServerIP end |
#ServerPortNo ⇒ Object
define accessor
113 114 115 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113 def ServerPortNo @ServerPortNo end |
#Version ⇒ Object (readonly)
Returns the value of attribute Version.
117 118 119 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 117 def Version @Version end |
Instance Method Details
#cancelAsynchronousListener ⇒ Object
<summary> 非同期メッセージ受信スレッドの終了</summary>
247 248 249 250 251 252 253 254 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 247 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>
131 132 133 134 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 131 def ReceiveAckTimeOut #Get return @ReceiveAckTimeOut end |
#ReceiveAckTimeOut=(value) ⇒ Object
<summary> 応答受信時タイムアウト設定</summary> <param name=“value”>タイムアウト値</param>
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 140 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>
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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 155 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>
123 124 125 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 123 def setTraceOutPut(val) HzTrace.setTraceOutPut(val) end |
#startAsynchronousListener ⇒ Object
<summary> 非同期メッセージ受信タスク起動</summary> <returns></returns>
228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 228 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>
259 260 261 262 263 264 265 266 |
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 259 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 |