import_remotecontrol 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/get_code_list.rb +69 -1
- data/lib/import_code.rb +101 -14
- metadata +1 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjhiZWM3ZGEyYjE5ZjA2N2Y3ZmUzZWFkZGMxYzdiNThjMGUzYmExZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YjBkZjc0ZWM1MDEwYWU1YzJkYTRhMTM2ZWE1Y2M3NzBlMzJkN2FiMw==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDk4MWNmOWVjYjIzYTNhMDNhZGZjYWRlZjdjYjY4Mjc4NmQxNDQ1MTJhNWJk
|
10
|
+
ZjU3Y2UzZGVmMTI1NzZmZmYwMjM1MGRiMzI0YWIwYmQwOTQ4NGZiNzI2OGEz
|
11
|
+
M2M2NzIxMzkxMmQyZmNhMmEyN2ZjZGM0MTJmYzcyYmZlNTg4ZWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjhkNjVhMGEyMzVmNDUyNzg0YjQwNDBhODg4MWY4MzlkOGUwMDA3MjQzODll
|
14
|
+
MjVhNWMxNzUwNTk2Y2Q5NGY3ZDkyYTNiYTQ0ZjJlODAxMGRjN2EyNWY0ZDJk
|
15
|
+
ODhkMDI1ZGVjM2M1NzVmZTJlYjIwNDFiZTJmYzcwZjhkYmMxZDg=
|
data/lib/get_code_list.rb
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
#encoding:utf-8
|
2
|
+
|
3
|
+
|
4
|
+
#####SHARP有问题需要查看############
|
5
|
+
#####关于sharp协议的处理###########
|
6
|
+
|
7
|
+
|
2
8
|
module GetCodeList
|
3
9
|
# To change this template use File | Settings | File Templates.
|
4
10
|
|
@@ -6,7 +12,8 @@ module GetCodeList
|
|
6
12
|
PROTOCOLNAME="protocol_name"
|
7
13
|
CODE = "code"
|
8
14
|
METHOD_NAME = "method_name"
|
9
|
-
DEFAULT_PROTOCOL = {"EXT_NEC"=>"1","CUT_NEC"=>"41"}
|
15
|
+
DEFAULT_PROTOCOL = {"EXT_NEC"=>"1","CUT_NEC"=>"41","RCA"=>"6","PANASONIC"=>"9","SHARP"=>"7","RC6"=>"A"}
|
16
|
+
|
10
17
|
|
11
18
|
#获取错误信息用于抛出错误
|
12
19
|
def self.get_error_msg(error,options={})
|
@@ -72,6 +79,14 @@ module GetCodeList
|
|
72
79
|
ret = chuangWeiCutNec(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE])
|
73
80
|
when "EXT_NEC"
|
74
81
|
ret = changHongExtNec(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE])
|
82
|
+
when "RCA"
|
83
|
+
ret = rca(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE])
|
84
|
+
when "RC6"
|
85
|
+
ret = rc6(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE])
|
86
|
+
when "PANASONIC"
|
87
|
+
ret = panasonic(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE])
|
88
|
+
#when "SHARP"
|
89
|
+
# ret = sharp(DEFAULT_PROTOCOL[code[PROTOCOLNAME]],code[CODE])
|
75
90
|
end
|
76
91
|
rescue => err
|
77
92
|
ret = {}
|
@@ -97,6 +112,7 @@ module GetCodeList
|
|
97
112
|
ret
|
98
113
|
end
|
99
114
|
|
115
|
+
#获取反码 (2个16进制数)
|
100
116
|
def self.radix_minus_one_complement(code)
|
101
117
|
begin
|
102
118
|
code = "0" + code if code.size==1
|
@@ -110,6 +126,18 @@ module GetCodeList
|
|
110
126
|
ret
|
111
127
|
end
|
112
128
|
|
129
|
+
#获取反码只转换2位16进制数的后1个
|
130
|
+
def self.radix_minus_one_complement_only_last_4(code)
|
131
|
+
begin
|
132
|
+
code = "0" + code if code.size==1
|
133
|
+
ret = ""
|
134
|
+
ret = code[0] + ((~((code[1]).to_i(16)))&Integer(0b1111)).to_s(16)
|
135
|
+
rescue
|
136
|
+
raise RuntimeError, get_error_msg("get radix-minus-one complement Error, Error msg : #{err.to_s}",{METHOD_NAME => "radix_minus_one_complement"})
|
137
|
+
end
|
138
|
+
ret
|
139
|
+
end
|
140
|
+
|
113
141
|
|
114
142
|
|
115
143
|
#对长虹的扩展NEC编码类型的编码数组进行处理
|
@@ -134,6 +162,46 @@ module GetCodeList
|
|
134
162
|
end
|
135
163
|
end
|
136
164
|
|
165
|
+
#rca的协议处理
|
166
|
+
def self.rca(prtotoname,code)
|
167
|
+
begin
|
168
|
+
codes = code.split(":")
|
169
|
+
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)}"
|
170
|
+
rescue => err
|
171
|
+
raise RuntimeError, get_error_msg("Protocol Error, Error msg : #{err.to_s}",{METHOD_NAME => "Rac"})
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
#rc6的协议处理
|
176
|
+
def self.rc6(prtotoname,code)
|
177
|
+
begin
|
178
|
+
codes = code.split(":")
|
179
|
+
ret = "#{prtotoname}:#{codes[0]}:#{codes[1]}:#{codes[2]}:#{codes[3]}"
|
180
|
+
rescue => err
|
181
|
+
raise RuntimeError, get_error_msg("Protocol Error, Error msg : #{err.to_s}",{METHOD_NAME => "Rac"})
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
#harp的协议处理
|
186
|
+
#def self.sharp(prtotoname,code)
|
187
|
+
# begin
|
188
|
+
# codes = code.split(":")
|
189
|
+
# ret = "#{prtotoname}:#{codes[0]}:#{codes[1]}:#{codes[2]}:#{codes[3]}:#{codes[4]}:#{codes[5]}"
|
190
|
+
# rescue => err
|
191
|
+
# raise RuntimeError, get_error_msg("Protocol Error, Error msg : #{err.to_s}",{METHOD_NAME => "Rac"})
|
192
|
+
# end
|
193
|
+
#end
|
194
|
+
|
195
|
+
#panasonic的协议处理
|
196
|
+
def self.panasonic(prtotoname,code)
|
197
|
+
begin
|
198
|
+
codes = code.split(":")
|
199
|
+
ret = "#{prtotoname}:#{codes[0]}:#{codes[1]}:#{codes[2]}:#{codes[3]}:#{codes[4]}:#{codes[5]}"
|
200
|
+
rescue => err
|
201
|
+
raise RuntimeError, get_error_msg("Protocol Error, Error msg : #{err.to_s}",{METHOD_NAME => "Rac"})
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
137
205
|
end
|
138
206
|
|
139
207
|
|
data/lib/import_code.rb
CHANGED
@@ -5,6 +5,15 @@ module ImportCode
|
|
5
5
|
attr_accessor :file_path_array
|
6
6
|
attr_accessor :remote_code_array
|
7
7
|
attr_accessor :protocol_hash
|
8
|
+
attr_accessor :statistics
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.file_path_array=[]
|
12
|
+
self.remote_code_array=[]
|
13
|
+
self.protocol_hash={}
|
14
|
+
self.statistics = {}
|
15
|
+
end
|
16
|
+
|
8
17
|
|
9
18
|
#不是按键编码的KEY
|
10
19
|
DEFAULT_UNCLUDE = ["FileFormat","Remotecontroldescripe","Device","Brand","Model","Button'scounts"]
|
@@ -79,9 +88,9 @@ module ImportCode
|
|
79
88
|
|
80
89
|
#从文件中读入编码并转换为hash的格式来处理
|
81
90
|
def self.getHashRemoteCode(file_path)
|
91
|
+
begin
|
82
92
|
ret = {}
|
83
93
|
brand = ""
|
84
|
-
p "Open File #{file_path}"
|
85
94
|
remote_code_line = File.read(file_path)
|
86
95
|
remote_code_line.split("\r\n").each do |code|
|
87
96
|
i = code.split("=")
|
@@ -112,48 +121,124 @@ module ImportCode
|
|
112
121
|
end
|
113
122
|
end
|
114
123
|
end
|
124
|
+
_key =""
|
125
|
+
_value = -1
|
126
|
+
@statistics.each do |key,value|
|
127
|
+
if(_value < value)
|
128
|
+
_key = key
|
129
|
+
_value = value
|
130
|
+
end
|
131
|
+
end
|
132
|
+
ret.merge!({"statistics"=>_key})
|
115
133
|
end
|
116
134
|
end
|
135
|
+
rescue => err
|
136
|
+
raise ArgumentError, get_error_msg(err,{METHOD_NAME => "getHashRemoteCode"})
|
137
|
+
end
|
117
138
|
ret
|
118
139
|
end
|
119
140
|
|
120
|
-
|
141
|
+
#将协议名从不同的协议编码转为了数据库对应的字符串(按品牌进行的处理)
|
142
|
+
#def self.getProtocolList(file_path)
|
143
|
+
# @protocol_hash = {}
|
144
|
+
# protocol_lines = File.read(file_path)
|
145
|
+
# protocol_lines.split("\n").each do |protocol_line|
|
146
|
+
# protocol = protocol_line.split(":")
|
147
|
+
# if(@protocol_hash.has_key?(protocol[0]))
|
148
|
+
# @protocol_hash["#{protocol[0]}"].merge!({protocol[1]=>protocol[2]}) if protocol[2]!=nil&&protocol[2]!=""
|
149
|
+
# else
|
150
|
+
# @protocol_hash["#{protocol[0]}"] = {protocol[1]=>protocol[2]} if protocol[2]!=nil&&protocol[2]!=""
|
151
|
+
# end
|
152
|
+
# end
|
153
|
+
# @protocol_hash
|
154
|
+
#end
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
#获取协议码对应协议(忽视品牌直接按协议码进行的处理)
|
121
161
|
def self.getProtocolList(file_path)
|
122
162
|
@protocol_hash = {}
|
163
|
+
begin
|
123
164
|
protocol_lines = File.read(file_path)
|
124
165
|
protocol_lines.split("\n").each do |protocol_line|
|
125
166
|
protocol = protocol_line.split(":")
|
126
|
-
if
|
127
|
-
|
167
|
+
if protocol.count ==2
|
168
|
+
protocol<<" "
|
169
|
+
end
|
170
|
+
unless @protocol_hash.has_key?(protocol[1])
|
171
|
+
@protocol_hash.merge!({protocol[1]=>protocol[2]}) if protocol[2]!=nil&&protocol[2]!=""
|
128
172
|
else
|
129
|
-
@protocol_hash[
|
173
|
+
unless @protocol_hash[protocol[1]]==nil||@protocol_hash[protocol[1]]==""
|
174
|
+
@protocol_hash[protocol[1]]=protocol[2] if protocol[2]!=""&&protocol[2]!=nil
|
175
|
+
end
|
130
176
|
end
|
131
177
|
end
|
178
|
+
rescue => err
|
179
|
+
raise ArgumentError, get_error_msg(err,{METHOD_NAME => "getProtocolList"})
|
180
|
+
end
|
181
|
+
p @protocol_hash
|
132
182
|
@protocol_hash
|
133
183
|
end
|
134
184
|
|
135
185
|
|
136
|
-
|
186
|
+
|
187
|
+
|
188
|
+
#对按键的编码进行了处理(按品牌进行的处理)
|
189
|
+
#def self.disposeProtocolCode(codes,brand)
|
190
|
+
# protocol = ""
|
191
|
+
# codelist = codes.split(" ")
|
192
|
+
# protocol_name = codelist[0]
|
193
|
+
# if @protocol_hash[brand]
|
194
|
+
# protocol = @protocol_hash[brand][protocol_name] if @protocol_hash[brand][protocol_name]
|
195
|
+
# else
|
196
|
+
# end
|
197
|
+
# #protocol_user_code = codelist[1]
|
198
|
+
# #other_code = ""
|
199
|
+
# code = ""
|
200
|
+
# p codelist
|
201
|
+
# 1.upto(codelist.size-1).each do |index|
|
202
|
+
# code =code + codelist[index]
|
203
|
+
# code =code + ":" unless index == codelist.size-1
|
204
|
+
# end
|
205
|
+
# p code
|
206
|
+
# {protocol_name:protocol,code:code}
|
207
|
+
#end
|
208
|
+
|
209
|
+
#对按键的编码进行了处理(按协议码进行的处理)
|
137
210
|
def self.disposeProtocolCode(codes,brand)
|
138
211
|
protocol = ""
|
212
|
+
begin
|
139
213
|
codelist = codes.split(" ")
|
140
214
|
protocol_name = codelist[0]
|
141
|
-
|
142
|
-
|
143
|
-
else
|
144
|
-
end
|
145
|
-
#protocol_user_code = codelist[1]
|
146
|
-
#other_code = ""
|
215
|
+
statisticsProtocol(@protocol_hash[protocol_name])
|
216
|
+
protocol = @protocol_hash[protocol_name] if @protocol_hash[protocol_name]
|
147
217
|
code = ""
|
148
|
-
p codelist
|
149
218
|
1.upto(codelist.size-1).each do |index|
|
150
219
|
code =code + codelist[index]
|
151
220
|
code =code + ":" unless index == codelist.size-1
|
152
221
|
end
|
153
|
-
|
222
|
+
rescue => err
|
223
|
+
raise ArgumentError, get_error_msg(err,{METHOD_NAME => "disposeProtocolCode"})
|
224
|
+
end
|
154
225
|
{protocol_name:protocol,code:code}
|
155
226
|
end
|
156
227
|
|
228
|
+
|
229
|
+
def self.statisticsProtocol(protocol_name)
|
230
|
+
begin
|
231
|
+
unless @statistics.has_key?(protocol_name)
|
232
|
+
@statistics.merge!({protocol_name=>1})
|
233
|
+
else
|
234
|
+
@statistics[protocol_name]=@statistics[protocol_name]+1
|
235
|
+
end
|
236
|
+
rescue => err
|
237
|
+
raise ArgumentError, get_error_msg(err,{METHOD_NAME => "statisticsProtocol"})
|
238
|
+
end
|
239
|
+
@statistics
|
240
|
+
end
|
241
|
+
|
157
242
|
#导入遥控编码
|
158
243
|
def self.importRemoteCode(file_msg)
|
159
244
|
remote_code_hash = {}
|
@@ -181,9 +266,11 @@ module ImportCode
|
|
181
266
|
#获取遥控编码数组
|
182
267
|
def self.getRemoteCodeArray(dir_path)
|
183
268
|
@remote_code_array = []
|
269
|
+
@statistics = {}
|
184
270
|
if FileTest.directory?(dir_path)
|
185
271
|
filenames = getFileNames(dir_path)
|
186
272
|
filenames.each do |file_msg|
|
273
|
+
@statistics={}
|
187
274
|
@remote_code_array<<importRemoteCode(file_msg)
|
188
275
|
end
|
189
276
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: import_remotecontrol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zql
|
@@ -43,4 +43,3 @@ signing_key:
|
|
43
43
|
specification_version: 4
|
44
44
|
summary: only use import remote control code
|
45
45
|
test_files: []
|
46
|
-
has_rdoc:
|