Module: GetCodeList
- Defined in:
- lib/get_code_list.rb
Constant Summary collapse
- BRAND =
To change this template use File | Settings | File Templates.
"brand"- PROTOCOLNAME =
"protocol_name"- CODE =
"code"- METHOD_NAME =
"method_name"- DEFAULT_PROTOCOL =
{"EXT_NEC"=>"1","CUT_NEC"=>"41","RCA"=>"6","PANASONIC"=>"9","SHARP"=>"7","RC6"=>"A"}
- NEC =
0x01- RC5 =
0x02- SIRC =
0x03- JVC =
0x04- NRC17 =
0x05- RCA =
0x06- SHARP =
0x07- X_SET =
0x08- NEC_MINI =
0x41- SX =
0x09
Class Method Summary collapse
- .changHong(code) ⇒ Object
-
.changHongExtNec(prtotoname, code) ⇒ Object
对长虹的扩展NEC编码类型的编码数组进行处理.
- .chuangWei(code) ⇒ Object
-
.chuangWeiCutNec(prtotoname, code) ⇒ Object
对创维的精简NEC编码类型的编码数组进行处理.
- .default(code) ⇒ Object
-
.get_error_msg(error, options = {}) ⇒ Object
获取错误信息用于抛出错误.
- .getlist(data) ⇒ Object
-
.panasonic(prtotoname, code) ⇒ Object
panasonic的协议处理.
-
.radix_minus_one_complement(code) ⇒ Object
获取反码 (2个16进制数).
-
.radix_minus_one_complement_only_last_4(code) ⇒ Object
获取反码只转换2位16进制数的后1个.
-
.radix_minus_one_complement_only_last_6(code) ⇒ Object
获取反码只转换2位16进制数的后6位.
-
.rc6(prtotoname, code) ⇒ Object
rc6的协议处理.
-
.rca(prtotoname, code) ⇒ Object
rca的协议处理.
-
.sharp(prtotoname, code) ⇒ Object
sharp的协议处理.
- .use_profile ⇒ Object
- .~ ⇒ Object
Class Method Details
.changHong(code) ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/get_code_list.rb', line 109 def self.changHong(code) ret = "" case code[PROTOCOLNAME] when "EXT_NEC" ret = changHongExtNec(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE]) else ret = default(code) end ret end |
.changHongExtNec(prtotoname, code) ⇒ Object
对长虹的扩展NEC编码类型的编码数组进行处理
173 174 175 176 177 178 179 180 181 |
# File 'lib/get_code_list.rb', line 173 def self.changHongExtNec(prtotoname,code) begin codes = code.split(":") ret = "#{prtotoname}:#{codes[0]}:#{codes[1]}:#{codes[2]}:" ret = ret +radix_minus_one_complement(codes[2].to_s) rescue => err raise RuntimeError, get_error_msg("Protocol Error, Error msg : #{err.to_s}",{METHOD_NAME => "changHongExtNec"}) end end |
.chuangWei(code) ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/get_code_list.rb', line 120 def self.chuangWei(code) ret = "" case code[PROTOCOLNAME] when "CUT_NEC" ret = chuangWeiCutNec(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE]) else ret = default(code) end ret end |
.chuangWeiCutNec(prtotoname, code) ⇒ Object
对创维的精简NEC编码类型的编码数组进行处理
184 185 186 187 188 189 190 191 192 |
# File 'lib/get_code_list.rb', line 184 def self.chuangWeiCutNec(prtotoname,code) begin codes = code.split(":") ret = "#{prtotoname}:#{codes[0]}:#{codes[0]}:#{codes[1]}:" ret = ret +radix_minus_one_complement(codes[1].to_s) rescue => err raise RuntimeError, get_error_msg("Protocol Error, Error msg : #{err.to_s}",{METHOD_NAME => "chuangWeiCutNec"}) end end |
.default(code) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/get_code_list.rb', line 86 def self.default(code) ret = {} begin case code[PROTOCOLNAME] when "CUT_NEC" ret = chuangWeiCutNec(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE]) when "EXT_NEC" ret = changHongExtNec(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE]) when "RCA" ret = rca(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE]) when "RC6" ret = rc6(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE]) when "PANASONIC" ret = panasonic(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE]) when "SHARP" ret = sharp(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE]) end rescue => err ret = {} end ret end |
.get_error_msg(error, options = {}) ⇒ Object
获取错误信息用于抛出错误
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/get_code_list.rb', line 19 def self.get_error_msg(error,={}) ret = "" ret = ret + "ClassName: import_remotecontrol gem " if ["method_name"] ret = ret + "MethodName: #{["method_name"]} " end if error ret = ret + "Error Msg: #{error.to_s}" end ret end |
.getlist(data) ⇒ Object
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 |
# File 'lib/get_code_list.rb', line 44 def self.getlist(data) codes = data["codes"] _codes = {} #case data[BRAND] #when "长虹" # codes.each do |key,value| # key = key.upcase # _codes.merge!({key=>changHong(value)}) # end # _codes.merge!({default:false}) #when "创维" # codes.each do |key,value| # key = key.upcase # _codes.merge!({key=>chuangWei(value)}) # end # _codes.merge!({default:false}) #else codes.each do |key,value| get = default(value) if(default(value)!={}&&default(value)) key = key.upcase _codes.merge!({key=>default(value)}) end end _codes.merge!({default:true}) #end data["codes"] = _codes data end |
.panasonic(prtotoname, code) ⇒ Object
panasonic的协议处理
225 226 227 228 229 230 231 232 |
# File 'lib/get_code_list.rb', line 225 def self.panasonic(prtotoname,code) begin codes = code.split(":") ret = "#{prtotoname}:#{codes[0]}:#{codes[1]}:#{codes[2]}:#{codes[3]}:#{codes[4]}:#{codes[5]}" rescue => err raise RuntimeError, get_error_msg("Protocol Error, Error msg : #{err.to_s}",{METHOD_NAME => "Rac"}) end end |
.radix_minus_one_complement(code) ⇒ Object
获取反码 (2个16进制数)
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/get_code_list.rb', line 132 def self.radix_minus_one_complement(code) begin code = "0" + code if code.size==1 ret = "" 2.times.each do |i| ret = ret + ((~((code[i]).to_i(16)))&Integer(0b1111)).to_s(16) end rescue raise RuntimeError, get_error_msg("get radix-minus-one complement Error, Error msg : #{err.to_s}",{METHOD_NAME => "radix_minus_one_complement"}) end ret end |
.radix_minus_one_complement_only_last_4(code) ⇒ Object
获取反码只转换2位16进制数的后1个
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/get_code_list.rb', line 146 def self.radix_minus_one_complement_only_last_4(code) begin code = "0" + code if code.size==1 ret = "" ret = code[0] + ((~((code[1]).to_i(16)))&Integer(0b1111)).to_s(16) rescue raise RuntimeError, get_error_msg("get radix-minus-one complement Error, Error msg : #{err.to_s}",{METHOD_NAME => "radix_minus_one_complement"}) end ret end |
.radix_minus_one_complement_only_last_6(code) ⇒ Object
获取反码只转换2位16进制数的后6位
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/get_code_list.rb', line 159 def self.radix_minus_one_complement_only_last_6(code) begin code = "0" + code if code.size==1 ret = "" ret = ((~((code).to_i(16)))&Integer(0b111111)).to_s(16) rescue raise RuntimeError, get_error_msg("get radix-minus-one complement Error, Error msg : #{err.to_s}",{METHOD_NAME => "radix_minus_one_complement"}) end ret end |
.rc6(prtotoname, code) ⇒ Object
rc6的协议处理
205 206 207 208 209 210 211 212 |
# File 'lib/get_code_list.rb', line 205 def self.rc6(prtotoname,code) begin codes = code.split(":") ret = "#{prtotoname}:#{codes[0]}:#{codes[1]}:#{codes[2]}:#{codes[3]}" rescue => err raise RuntimeError, get_error_msg("Protocol Error, Error msg : #{err.to_s}",{METHOD_NAME => "Rac"}) end end |
.rca(prtotoname, code) ⇒ Object
rca的协议处理
195 196 197 198 199 200 201 202 |
# File 'lib/get_code_list.rb', line 195 def self.rca(prtotoname,code) begin codes = code.split(":") ret = "#{prtotoname}:#{codes[0]}:#{radix_minus_one_complement_only_last_4(codes[0].to_s)}:#{codes[1]}:#{radix_minus_one_complement(codes[1].to_s)}" rescue => err raise RuntimeError, get_error_msg("Protocol Error, Error msg : #{err.to_s}",{METHOD_NAME => "Rac"}) end end |
.sharp(prtotoname, code) ⇒ Object
sharp的协议处理
215 216 217 218 219 220 221 222 |
# File 'lib/get_code_list.rb', line 215 def self.sharp(prtotoname,code) begin codes = code.split(":") ret = "#{prtotoname}:#{codes[0]}:#{codes[1]}:#{codes[2]}:#{codes[0]}:#{radix_minus_one_complement_only_last_6(codes[1])}:#{radix_minus_one_complement_only_last_4(codes[2])}:#{codes[0]}:#{codes[1]}:#{codes[2]}" rescue => err raise RuntimeError, get_error_msg("Protocol Error, Error msg : #{err.to_s}",{METHOD_NAME => "Rac"}) end end |
.use_profile ⇒ Object
76 77 78 |
# File 'lib/get_code_list.rb', line 76 def self.use_profile() end |
.~ ⇒ Object
81 82 83 |
# File 'lib/get_code_list.rb', line 81 def self.~() end |