Class: ClientTcpCommunication

Inherits:
Object
  • Object
show all
Defined in:
lib/haruzira_sdk/HzClientTcpCommunication.rb

Overview

endregion

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClientTcpCommunication

<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

#EvNotifyCompeteSpeechObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def EvNotifyCompeteSpeech
  @EvNotifyCompeteSpeech
end

#EvNotifyMessageEventObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def EvNotifyMessageEvent
  @EvNotifyMessageEvent
end

#EvNotifyReceivedDisConnectEventObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def EvNotifyReceivedDisConnectEvent
  @EvNotifyReceivedDisConnectEvent
end

#EvNotifySendSpeechRecognitionCommandObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def EvNotifySendSpeechRecognitionCommand
  @EvNotifySendSpeechRecognitionCommand
end

#ReceivedDataDecryptionKeyObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReceivedDataDecryptionKey
  @ReceivedDataDecryptionKey
end

#ReceivePortObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReceivePort
  @ReceivePort
end

#ReceiveStatusObject (readonly)

Returns the value of attribute ReceiveStatus.



117
118
119
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 117

def ReceiveStatus
  @ReceiveStatus
end

#ReqSendDataAccountNameObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReqSendDataAccountName
  @ReqSendDataAccountName
end

#ReqSendDataCompletionNoticeNecessityObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReqSendDataCompletionNoticeNecessity
  @ReqSendDataCompletionNoticeNecessity
end

#ReqSendDataEncryptObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReqSendDataEncrypt
  @ReqSendDataEncrypt
end

#ReqSendDataEncryptKeyObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReqSendDataEncryptKey
  @ReqSendDataEncryptKey
end

#ReqSendDataPasswdObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReqSendDataPasswd
  @ReqSendDataPasswd
end

#ReqSendDataSpeechAgeObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReqSendDataSpeechAge
  @ReqSendDataSpeechAge
end

#ReqSendDataSpeechGenderObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReqSendDataSpeechGender
  @ReqSendDataSpeechGender
end

#ReqSendDataSpeechLevelObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReqSendDataSpeechLevel
  @ReqSendDataSpeechLevel
end

#ReqSendDataSpeechLocaleIdObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReqSendDataSpeechLocaleId
  @ReqSendDataSpeechLocaleId
end

#ReqSendDataSpeechModeObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReqSendDataSpeechMode
  @ReqSendDataSpeechMode
end

#ReqSendDataSpeechRepeatObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReqSendDataSpeechRepeat
  @ReqSendDataSpeechRepeat
end

#ReqSendDataTextObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ReqSendDataText
  @ReqSendDataText
end

#SendDataHexStrObject (readonly)

Returns the value of attribute SendDataHexStr.



117
118
119
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 117

def SendDataHexStr
  @SendDataHexStr
end

#SendDataLengthObject (readonly)

Returns the value of attribute SendDataLength.



117
118
119
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 117

def SendDataLength
  @SendDataLength
end

#ServerIPObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ServerIP
  @ServerIP
end

#ServerPortNoObject

define accessor



113
114
115
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 113

def ServerPortNo
  @ServerPortNo
end

#VersionObject (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

#cancelAsynchronousListenerObject

<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

#ReceiveAckTimeOutObject

<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

#sendSpeechDataExObject

<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

#startAsynchronousListenerObject

<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

#stopSendSpeechDataObject

<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