Ejemplo n.º 1
0
class WS16Thread(threading.Thread):
    t = False
    ws16 = socket.socket()
    sendlast = time.time()
    mas = []

    def __init__(self):
        threading.Thread.__init__(self)
        self.t = PerpetualTimer(0.03, self.sw16send)

    def run(self):
        self.ws16.connect(('192.168.0.254', 8080))
        self.send(-1, True)
        while True:
            data = self.ws16.recv(1024)
            #print(data)
            if (data[1] == 12):
                sendlast = True
                data = data.split(b"\xcc\x0c").pop()
                print(data)
                i = 1
                for number in data[0:16]:
                    if (number == 2):
                        structure.set_value(i, False)
                    else:
                        structure.set_value(i, True)
                    if (structure.get_button(i) >= 0):
                        GLib.idle_add(
                            builder.get_object(
                                "i" +
                                str(structure.get_button(i))).set_from_file,
                            "button" + str(int(structure.get_value(i))) +
                            ".png")
                    i = i + 1
            time.sleep(0.01)

    def send(self, pin, val):
        if (pin > -1):
            if (val == 9):
                self.mas.append([pin, not structure.get_value(pin)])
            else:
                self.mas.append([pin, val])
        else:
            self.mas.append([pin, val])
        self.t.start()

    def sw16send(self):
        pin, val = self.mas.pop(0)
        if (pin == -1):
            self.ws16.send(
                b"\xaa\x1e\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\xbb"
            )
        else:
            if (structure.get_value(pin) != bool(val)):
                if (bool(val) == True):
                    self.ws16.send(
                        b"\xaa\x0f" + structure.get_ws16(pin) +
                        b"\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\xbb"
                    )
                else:
                    self.ws16.send(
                        b"\xaa\x0f" + structure.get_ws16(pin) +
                        b"\x02\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\xbb"
                    )
        if (len(self.mas) == 0):
            self.t.cancel()
        sql.addlog("INSERT INTO `SW16` (`pin`,`val`) VALUES (" + str(pin) +
                   "," + str(val) + ")")
Ejemplo n.º 2
0
class AbatractNPLCompiler():
    def __init__(self, interval, paraengine_sdk_folder, paraengine_git_folder,
                 app_bits, callback):
        pass
        self.interval = interval
        self.paraengine_sdk_folder = paraengine_sdk_folder
        self.paraengine_git_folder = paraengine_git_folder
        self.app_bits = app_bits
        self.callback = callback
        self.pkg_txt_file_path = self.paraengine_sdk_folder + "/pkg_file.txt"
        self.zip_file_path = self.paraengine_sdk_folder + "/installer/main_full_mobile.zip"
        self.pkg_file_path = "%s/installer/main_full_mobile.pkg" % self.paraengine_sdk_folder
        self.pkg_txt_timer = PerpetualTimer(interval, self.CheckPkgTxtFile)
        self.pkg_timer = PerpetualTimer(interval, self.CheckPkgFile)

    def GetAppFullPath(self):
        pass

    def OpenApp(self, args):
        pass

    def CloseApp(self):
        pass

    def Clean(self):
        pass

    def MakeZip(self):
        pass

    def MakePkg(self):
        pass

    def RenamePkg(self):
        #self.CloseApp()
        filepath = "%s/installer/main_full_%sbits.pkg" % (
            self.paraengine_sdk_folder, self.app_bits)
        print "rename %s to %s" % (self.pkg_file_path, filepath)
        os.rename(self.pkg_file_path, filepath)
        if (self.callback):
            self.callback()

    def CheckPkgFile(self):
        if (os.path.exists(self.pkg_file_path)):
            self.pkg_timer.cancel()
            print "found %s" % self.pkg_file_path
            timer = Timer(5, self.RenamePkg)
            timer.start()
        else:
            print "waiting for %s %sbits" % (self.pkg_file_path, self.app_bits)

    def CheckPkgTxtFile(self):
        if (os.path.exists(self.pkg_txt_file_path)):
            self.pkg_txt_timer.cancel()
            print "found %s" % self.pkg_txt_file_path
            self.MakeZip()
        else:
            print "waiting for %s %sbits" % (self.pkg_txt_file_path,
                                             self.app_bits)

    def Start(self):
        pass