update 2016-11-02 b1
1. created project 2. initialized ir encode and decode source files
This commit is contained in:
110
src/ir_encoder/s_ac_ii.py
Normal file
110
src/ir_encoder/s_ac_ii.py
Normal file
@@ -0,0 +1,110 @@
|
||||
# !/usr/bin/env python
|
||||
# coding=utf-8
|
||||
# for protocol version V1.0
|
||||
# 29 tags are supported
|
||||
|
||||
import sys,os
|
||||
import xml.dom.minidom
|
||||
import struct
|
||||
|
||||
|
||||
alltags = [300, 301, 302, 303, 305, 306, 307, 1001, 1002, 1003,
|
||||
1004, 1005, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1015,
|
||||
1016, 1501, 1502, 1503, 1504, 1505, 1506, 1508, 1509]
|
||||
tags_max_size = [0 for x in range(0, len(alltags))]
|
||||
|
||||
# Definition of ac tag class
|
||||
# (tag:value)
|
||||
|
||||
|
||||
class ACTag:
|
||||
def __init__(self, tag, value):
|
||||
self.tag = tag
|
||||
self.value = value
|
||||
self.len = len(self.value)
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.tag < other.tag
|
||||
|
||||
def printf(self):
|
||||
print "[%d] %s len:%d" % (self.tag, self.value, len(self.value))
|
||||
|
||||
# Definition of Remote_control class
|
||||
# device id:(tag:value)...(tag:value)
|
||||
|
||||
|
||||
class ACRemoteControl:
|
||||
def __init__(self, device_id):
|
||||
self.device_id = device_id
|
||||
self.tags = []
|
||||
|
||||
def add(self, tag):
|
||||
self.tags.append(tag)
|
||||
|
||||
def sort(self):
|
||||
self.tags.sort()
|
||||
|
||||
def printf(self):
|
||||
print "==========Device id:%d===========" % self.device_id
|
||||
for j in range(len(self.tags)):
|
||||
self.tags[j].printf()
|
||||
|
||||
|
||||
def create_binary(ac_device):
|
||||
find = 0
|
||||
offset = 0
|
||||
|
||||
f_content = open(sys.argv[2] + str(ac_device.device_id) + "_tmp.bin", "wb")
|
||||
f_head = open(sys.argv[2] + "ykir_new_ac_" + str(ac_device.device_id) + ".bin", "wb")
|
||||
f_head.write(struct.pack("B", 29))
|
||||
for i in range(len(alltags)):
|
||||
find = 0
|
||||
for j in range(len(ac_device.tags)):
|
||||
if (alltags[i] == ac_device.tags[j].tag):
|
||||
f_content.write(ac_device.tags[j].value)
|
||||
|
||||
f_head.write(struct.pack("H", offset))
|
||||
offset = offset + ac_device.tags[j].len
|
||||
###############################################################################
|
||||
# Find Max length
|
||||
###############################################################################
|
||||
if (tags_max_size[i] < ac_device.tags[j].len):
|
||||
tags_max_size[i] = ac_device.tags[j].len;
|
||||
find = 1
|
||||
break
|
||||
|
||||
if find == 0:
|
||||
f_head.write(struct.pack("H", 0xffff))
|
||||
#f.write(ac_device)
|
||||
f_content.close()
|
||||
f_tmp = open(sys.argv[2] + str(ac_device.device_id) + "_tmp.bin", "rb")
|
||||
f_head.write(f_tmp.read())
|
||||
f_tmp.close()
|
||||
f_head.close()
|
||||
|
||||
dom = xml.dom.minidom.parse(sys.argv[1])
|
||||
device = dom.documentElement
|
||||
#devices = root.getElementsByTagName('remote_controller')
|
||||
|
||||
print "============================"
|
||||
print "AC data:"
|
||||
print "============================"
|
||||
ac_device_arrary=[]
|
||||
id = device.getElementsByTagName('id')
|
||||
idnum = int(id[0].firstChild.data.encode('ascii'), 10)
|
||||
|
||||
g_ac_device = ACRemoteControl(idnum)
|
||||
print "------------AC Device ID: %d-------------" % idnum
|
||||
exts = device.getElementsByTagName('exts')
|
||||
for n in range(len(exts)):
|
||||
ext = exts[n].getElementsByTagName('ext')
|
||||
for j in range(len(ext)):
|
||||
tag_index=ext[j].getElementsByTagName('tag')
|
||||
tag_index_data = int(tag_index[0].firstChild.data.encode('ascii'), 10)
|
||||
tag_value=ext[j].getElementsByTagName('value')
|
||||
tag_value_data = tag_value[0].firstChild.data.encode('ascii')
|
||||
g_ac_device.add(ACTag(tag_index_data, tag_value_data))
|
||||
g_ac_device.sort()
|
||||
g_ac_device.printf()
|
||||
create_binary(g_ac_device)
|
||||
ac_device_arrary.append(g_ac_device)
|
||||
Reference in New Issue
Block a user