module YalgaarConnect

Namespace module for YalgaarConnect default variables…

Public Instance Methods

yalgaarConnect(*args,lamda) click to toggle source

yalgaarConnect(*args,lamda); @brief - <To yalgaarConnect as given length>

@param <Length> : <length for how long uuid generating> DESCRIPTION:<To yalgaarConnect as given length> @bug Known Issues: 1.<max 50 bytes yalgaarConnect using this method.

# File lib/mqttbridge/YalgaarConnect.rb, line 38
def yalgaarConnect(*args,lamda)
        #~ puts "yalgaarConnect"
        #~ puts lamda
        @@lErrorConnectionCallback=lamda
        if args[0]==nil
                errmesg=showErrCode(YALGAAR_103)
                @@lErrorConnectionCallback.call(errmesg)
                return
        end
        if args[1] != 1 && args[1] != 0
                errmesg=showErrCode(YALGAAR_150)
                @@lErrorConnectionCallback.call(errmesg)
                return
        end   
        #~ puts args.size
        case args.size
                when TWOARGV
                        isEncrpt=0
                        @@clientKey=args[0]
                        @@isSecure=args[1]
                        @@uuid=generateUUID(3)
                        #~ puts @@uuid
                        
                        if @@isSecure==0
                                @@client = MQTT::Client.new
                                @@client.keep_alive=@@keepalive
                                @@client.ack_timeout=@@connectTimeout
                                @@client.host = @@host
                                @@client.port = DEFAULT_PORT
                                @@client.client_id = @@clientKey+'/'+@@uuid
                                begin
                                        @@client.connect()
                                        rescue Exception => e
                                        #~ pubACK(e.message)
                                        #~ lamda.call(e.message)  
                                        #~ exit(0)
                                end        
                        else
                                @@client = MQTT::Client.new
                                @@client.keep_alive=@@keepalive
                                @@client.ack_timeout=@@connectTimeout
                                @@client.host = @@host
                                @@client.port = DEFAULT_SSL_PORT
                                @@client.client_id = @@clientKey+'/'+@@uuid
                                @@client.ssl = true
                                @@client.cert_file   = "#{Dir.pwd}""/SSLcomDVCA_2.crt"
                                begin
                                        @@client.connect()
                                        rescue Exception => e
                                        #~ lamda.call(e.message)
                                        #~ pubACK(e.message)      
                                        #~ exit(0)
                                end        
                        end         
                
                        th = Thread.new do |client|
                        @@client.get do |topic,message|
                                messageParsing(topic,message,isEncrpt)
                                end
                        end
                when THREEARGV
                        isEncrpt=0
                        @@clientKey=args[0]
                        @@isSecure=args[1]
                        @@uuid=args[2]
                        if @@uuid == 0
                                @@uuid=generateUUID(3)
                        end
                        
                        if @@isSecure==0
                                @@client = MQTT::Client.new
                                @@client.keep_alive=@@keepalive
                                @@client.ack_timeout=@@connectTimeout
                                @@client.host = @@host
                                @@client.port = DEFAULT_PORT
                                @@client.client_id = @@clientKey+'/'+@@uuid
                                begin
                                        ret =@@client.connect()
                                        puts ret
                                        rescue Exception => e
                                        #~ lamda.call(e.message)  
                                        #~ pubACK(e.message)
                                        #~ exit(0)
                                end        
                        else
                                @@client = MQTT::Client.new
                                @@client.keep_alive=@@keepalive
                                @@client.ack_timeout=@@connectTimeout
                                @@client.host = @@host
                                @@client.port = DEFAULT_SSL_PORT
                                @@client.client_id = @@clientKey+'/'+@@uuid
                                @@client.ssl = true
                                @@client.cert_file   = "#{Dir.pwd}""/SSLcomDVCA_2.crt"
                                begin
                                        ret =@@client.connect()
                                        puts ret
                                        rescue Exception => e
                                        #~ lamda.call(e.message)  
                                        #~ pubACK(e.message)
                                        #~ exit(0)
                                end        
                        end
                                
                        th = Thread.new do |client|
                                @@client.get do |topic,message|
                                        #~ puts "#{topic}: #{message}"
                                        messageParsing(topic,message,isEncrpt)
                                        end
                                end
                when FOURARGV
                        isEncrpt=1
                        @@clientKey=args[0]
                        @@isSecure=args[1]
                        @@uuid=generateUUID(3)
                        @@aesSecretKey=args[2]
                        if args[3]==YALGAR_AES_128
                                @@aesType='AES-128-ECB'
                        elsif args[3]==YALGAR_AES_192
                                @@aesType='AES-192-ECB'
                        elsif args[3]==YALGAR_AES_256
                                @@aesType='AES-256-ECB'            
                        else
                                errmesg=showErrCode(YALGAAR_INVALID_AES_TYPE)
                                @@lErrorConnectionCallback.call(errmesg)
                                return
                        end 
                                        
                        if @@isSecure==0
                                @@client = MQTT::Client.new
                                @@client.keep_alive=@@keepalive
                                @@client.ack_timeout=@@connectTimeout
                                @@client.host = @@host
                                @@client.port = DEFAULT_PORT
                                @@client.client_id = @@clientKey+'/'+@@uuid
                                begin
                                        @@client.connect()
                                        rescue Exception => e
                                        #~ lamda.call(e.message)  
                                        #~ pubACK(e.message)
                                        #~ exit(0)
                                end        
                        else
                                @@client = MQTT::Client.new
                                @@client.keep_alive=@@keepalive
                                @@client.ack_timeout=@@connectTimeout
                                @@client.host = @@host
                                @@client.port = DEFAULT_SSL_PORT
                                @@client.client_id = @@clientKey+'/'+@@uuid
                                @@client.ssl = true
                                @@client.cert_file   = "#{Dir.pwd}""/SSLcomDVCA_2.crt"
                                begin
                                        @@client.connect()
                                        rescue Exception => e
                                        #~ lamda.call(e.message)  
                                        #~ pubACK(e.message)
                                        #~ exit(0)
                                end        
                        end 

                        th = Thread.new do |client|
                        @@client.get do |topic,message|
                                messageParsing(topic,message,isEncrpt)
                                end
                        end
                when FIVEARGV
                        isEncrpt=1
                        @@clientKey=args[0]
                        @@isSecure=args[1]
                        @@uuid=args[2]
                        if @@uuid==0 
                                @@uuid=generateUUID(3)
                        end
                        @@aesSecretKey=args[3]
                        if args[4]==YALGAR_AES_128
                                @@aesType='AES-128-ECB'
                        elsif args[4]==YALGAR_AES_192
                                @@aesType='AES-192-ECB'
                        elsif args[4]==YALGAR_AES_256
                                @@aesType='AES-256-ECB'            
                        else
                                errmesg=showErrCode(YALGAAR_INVALID_AES_TYPE)
                                @@lErrorConnectionCallback.call(errmesg)
                                return
                        end 
                        
                        if @@isSecure==0
                                @@client = MQTT::Client.new
                                @@client.keep_alive=@@keepalive
                                @@client.ack_timeout=@@connectTimeout
                                @@client.host = @@host
                                @@client.port = DEFAULT_PORT
                                @@client.client_id = @@clientKey+'/'+@@uuid
                                begin
                                        @@client.connect()
                                        rescue Exception => e
                                        #~ lamda.call(e.message)  
                                        #~ pubACK(e.message)
                                        #~ exit(0)
                                end        
                        else
                                @@client = MQTT::Client.new
                                @@client.keep_alive=@@keepalive
                                @@client.ack_timeout=@@connectTimeout
                                @@client.host = @@host
                                @@client.port = DEFAULT_SSL_PORT
                                @@client.client_id = @@clientKey+'/'+@@uuid
                                @@client.ssl = true
                                @@client.cert_file   = "#{Dir.pwd}""/SSLcomDVCA_2.crt"
                                begin
                                        @@client.connect()
                                        rescue Exception => e
                                        #~ lamda.call(e.message)  
                                        #~ pubACK(e.message)
                                        #~ exit(0)
                                end        
                        end 
                        th = Thread.new do |client|
                        @@client.get do |topic,message|
                                #puts "#{topic}: #{message}"
                                messageParsing(topic,message,isEncrpt)
                                end
                        end
                else
                  puts 'Invalid Arguments'
        end
end
yalgaarDisconnect(lamda) click to toggle source
# File lib/mqttbridge/YalgaarConnect.rb, line 264
def yalgaarDisconnect(lamda)
        begin
                ret =@@client.disconnect(true)
                rescue Exception => e
                #~ lamda.call(e.message)     
                #~ exit(0)
        end
        errmesg=showErrCode(YALGAAR_DISCONNECT_SUCCESS)
        lamda.call(errmesg)
        #~ lamda.call("Disconnect success")
end