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>



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

#EvNotifyCompeteSpeechObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def EvNotifyCompeteSpeech
  @EvNotifyCompeteSpeech
end

#EvNotifyMessageEventObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def EvNotifyMessageEvent
  @EvNotifyMessageEvent
end

#EvNotifyReceivedDisConnectEventObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def EvNotifyReceivedDisConnectEvent
  @EvNotifyReceivedDisConnectEvent
end

#EvNotifySendSpeechRecognitionCommandObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def EvNotifySendSpeechRecognitionCommand
  @EvNotifySendSpeechRecognitionCommand
end

#ReceivedDataDecryptionKeyObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ReceivedDataDecryptionKey
  @ReceivedDataDecryptionKey
end

#ReceivePortObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ReceivePort
  @ReceivePort
end

#ReceiveStatusObject (readonly)

Returns the value of attribute ReceiveStatus.



93
94
95
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 93

def ReceiveStatus
  @ReceiveStatus
end

#ReqSendDataAccountNameObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ReqSendDataAccountName
  @ReqSendDataAccountName
end

#ReqSendDataEncryptObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ReqSendDataEncrypt
  @ReqSendDataEncrypt
end

#ReqSendDataEncryptKeyObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ReqSendDataEncryptKey
  @ReqSendDataEncryptKey
end

#ReqSendDataPasswdObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ReqSendDataPasswd
  @ReqSendDataPasswd
end

#ReqSendDataSpeechAgeObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ReqSendDataSpeechAge
  @ReqSendDataSpeechAge
end

#ReqSendDataSpeechGenderObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ReqSendDataSpeechGender
  @ReqSendDataSpeechGender
end

#ReqSendDataSpeechLevelObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ReqSendDataSpeechLevel
  @ReqSendDataSpeechLevel
end

#ReqSendDataSpeechLocaleIdObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ReqSendDataSpeechLocaleId
  @ReqSendDataSpeechLocaleId
end

#ReqSendDataSpeechModeObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ReqSendDataSpeechMode
  @ReqSendDataSpeechMode
end

#ReqSendDataSpeechRepeatObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ReqSendDataSpeechRepeat
  @ReqSendDataSpeechRepeat
end

#ReqSendDataTextObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ReqSendDataText
  @ReqSendDataText
end

#SendDataHexStrObject (readonly)

Returns the value of attribute SendDataHexStr.



93
94
95
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 93

def SendDataHexStr
  @SendDataHexStr
end

#SendDataLengthObject (readonly)

Returns the value of attribute SendDataLength.



93
94
95
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 93

def SendDataLength
  @SendDataLength
end

#ServerIPObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ServerIP
  @ServerIP
end

#ServerPortNoObject

define accessor



90
91
92
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 90

def ServerPortNo
  @ServerPortNo
end

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

#cancelAsynchronousListenerObject

<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

#ReceiveAckTimeOutObject

<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

#sendSpeechDataExObject

<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

#startAsynchronousListenerObject

<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

#stopSendSpeechDataObject

<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