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
# 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
    @SendDataHexStr = ""
    @SendDataLength = 0
    @ReceiveStatus = 0x00
    @ReceiveAckTimeOut = RECEIVE_TIME_OUT
    @Version = "1.2.1.0"     #SDKバージョン


    #メッセージ受信時イベント定義

    @EvNotifyCompeteSpeech = nil             #読み上げ完了通知受信時イベント

    @EvNotifyMessageEvent = nil               #Exception発生時イベント(切断以外)

    @EvNotifyReceivedDisConnectEvent = nil    #切断発生時イベント(サーバー側からの切断など)

    #endregion

end

Instance Attribute Details

#EvNotifyCompeteSpeechObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def EvNotifyCompeteSpeech
  @EvNotifyCompeteSpeech
end

#EvNotifyMessageEventObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def EvNotifyMessageEvent
  @EvNotifyMessageEvent
end

#EvNotifyReceivedDisConnectEventObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def EvNotifyReceivedDisConnectEvent
  @EvNotifyReceivedDisConnectEvent
end

#ReceivePortObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ReceivePort
  @ReceivePort
end

#ReceiveStatusObject (readonly)

Returns the value of attribute ReceiveStatus.



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

def ReceiveStatus
  @ReceiveStatus
end

#ReqSendDataAccountNameObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ReqSendDataAccountName
  @ReqSendDataAccountName
end

#ReqSendDataEncryptObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ReqSendDataEncrypt
  @ReqSendDataEncrypt
end

#ReqSendDataEncryptKeyObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ReqSendDataEncryptKey
  @ReqSendDataEncryptKey
end

#ReqSendDataPasswdObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ReqSendDataPasswd
  @ReqSendDataPasswd
end

#ReqSendDataSpeechAgeObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ReqSendDataSpeechAge
  @ReqSendDataSpeechAge
end

#ReqSendDataSpeechGenderObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ReqSendDataSpeechGender
  @ReqSendDataSpeechGender
end

#ReqSendDataSpeechLevelObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ReqSendDataSpeechLevel
  @ReqSendDataSpeechLevel
end

#ReqSendDataSpeechLocaleIdObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ReqSendDataSpeechLocaleId
  @ReqSendDataSpeechLocaleId
end

#ReqSendDataSpeechModeObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ReqSendDataSpeechMode
  @ReqSendDataSpeechMode
end

#ReqSendDataSpeechRepeatObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ReqSendDataSpeechRepeat
  @ReqSendDataSpeechRepeat
end

#ReqSendDataTextObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ReqSendDataText
  @ReqSendDataText
end

#SendDataHexStrObject (readonly)

Returns the value of attribute SendDataHexStr.



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

def SendDataHexStr
  @SendDataHexStr
end

#SendDataLengthObject (readonly)

Returns the value of attribute SendDataLength.



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

def SendDataLength
  @SendDataLength
end

#ServerIPObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ServerIP
  @ServerIP
end

#ServerPortNoObject

define accessor



88
89
90
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 88

def ServerPortNo
  @ServerPortNo
end

#VersionObject (readonly)

Returns the value of attribute Version.



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

def Version
  @Version
end

Instance Method Details

#cancelAsynchronousListenerObject

<summary> 非同期メッセージ受信スレッドの終了</summary>



200
201
202
203
204
205
206
207
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 200

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>



105
106
107
108
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 105

def ReceiveAckTimeOut
    #Get

    return @ReceiveAckTimeOut 
end

#ReceiveAckTimeOut=(value) ⇒ Object

<summary> 応答受信時タイムアウト設定</summary> <param name=“value”>タイムアウト値</param>



114
115
116
117
118
119
120
121
122
123
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 114

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>



129
130
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
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 129

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

        #非同期メッセージ受信タスク起動

        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>



97
98
99
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 97

def setTraceOutPut(val)
    HzTrace.setTraceOutPut(val)
end

#stopSendSpeechDataObject

<summary> 読み上げデータ送信の停止(中断)</summary>



212
213
214
215
216
217
218
219
# File 'lib/haruzira_sdk/HzClientTcpCommunication.rb', line 212

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