コード例 #1
0
ファイル: swapmanager.py プロジェクト: panStamp/python_tools
 def transmit_product_code(self):
     """
     Transmit SWAP status packet containing the product code
     """
     pcode = SwapValue(self.FIRMSERVER_PRODUCT_CODE)
     status = SwapStatusPacket(self.server.devaddress, SwapRegId.ID_PRODUCT_CODE, pcode)
     status.send(self.server)
コード例 #2
0
ファイル: swapmanager.py プロジェクト: mgehre/panstamp
 def transmit_product_code(self):
     """
     Transmit SWAP status packet containing the product code
     """
     pcode = SwapValue(self.FIRMSERVER_PRODUCT_CODE)
     status = SwapStatusPacket(self.server.devaddress, SwapRegId.ID_PRODUCT_CODE, pcode)
     status.send(self.server)
コード例 #3
0
ファイル: swapmanager.py プロジェクト: rsalinas/python_tools
    def swapPacketReceived(self, packet):
        """
        New SWAP packet received
        
        @param packet: SWAP packet received
        """
        if packet.destAddress in [
                SwapAddress.BROADCAST_ADDR, self.server.devaddress
        ]:
            # Packet broadcasted or explicitely addressed to our server
            if packet.function == SwapFunction.QUERY:
                # SWAP query received
                if packet.destAddress == self.server.devaddress:
                    # Local register being queried
                    if packet.regId == SwapRegId.ID_PRODUCT_CODE:
                        # Server's product code
                        self.transmit_product_code()
                    elif packet.regId == SwapRegId.ID_FIRMWARE:
                        # Query comming from our node in programming mode?
                        if self.prog_address == packet.srcAddress:
                            # Firmware image being queried
                            if packet.value.getLength() == 2:
                                # The query contains 2 bytes of data
                                # Take line number
                                nb_line = (packet.value.toList()[0] <<
                                           8) | packet.value.toList()[1]
                                line = self.hexfile.get_line(nb_line)

                                if line is not None:
                                    prefix = packet.value.toList()
                                    payload = prefix + line.data
                                    val = SwapValue(payload)
                                    page_packet = SwapStatusPacket(
                                        self.server.devaddress,
                                        SwapRegId.ID_FIRMWARE, val)
                                    page_packet.send(self.server)

                                if nb_line == 0:
                                    self.hexfile_line = 0
                                    print "Erasing flash memory"
                                    self.progress + 1
                                elif nb_line == 1:
                                    print "Uploading code to node"
                                elif 1 < nb_line < (
                                        self.hexfile.nbof_data_lines - 1):
                                    if (nb_line != self.hexfile_line):
                                        self.hexfile_line = nb_line
                                        self.progress + 1
                                        self.progress.show_progress()
                                elif nb_line == (self.hexfile.nbof_data_lines):
                                    self.progress + 2
                                    self.progress.show_progress()
                                    print "\n\rUpload completed"
                                    self.prog_address = None
                                    self.hexfile_line = 0
コード例 #4
0
ファイル: ModemMote.py プロジェクト: ekoeppen/panstamp-python
 def staRegister(self, regId):
     """
     Send SWAP status packet about the current value of the register passed as argument
     
     @param regId: Register ID
     @param value: New value
     """
     # Get register
     reg = self.getRegister(regId)
     # Status packet to be sent
     infPacket = SwapStatusPacket(self.address, regId, reg.value)
     # Send SWAP status packet to server
     infPacket.send(self.server)
コード例 #5
0
ファイル: swapmanager.py プロジェクト: panStamp/python_tools
    def swapPacketReceived(self, packet):
        """
        New SWAP packet received
        
        @param packet: SWAP packet received
        """
        if packet.destAddress in [SwapAddress.BROADCAST_ADDR, self.server.devaddress]:
            # Packet broadcasted or explicitely addressed to our server
            if packet.function == SwapFunction.QUERY:
                # SWAP query received
                if packet.destAddress == self.server.devaddress:
                    # Local register being queried
                    if packet.regId == SwapRegId.ID_PRODUCT_CODE:
                        # Server's product code
                        self.transmit_product_code()
                    elif packet.regId == SwapRegId.ID_FIRMWARE:
                        # Query comming from our node in programming mode?
                        if self.prog_address == packet.srcAddress:
                            # Firmware image being queried
                            if packet.value.getLength() == 2:
                                # The query contains 2 bytes of data
                                # Take line number
                                nb_line = (packet.value.toList()[0] << 8) | packet.value.toList()[1]
                                line = self.hexfile.get_line(nb_line)

                                if line is not None:
                                    prefix = packet.value.toList()
                                    payload = prefix + line.data
                                    val = SwapValue(payload)
                                    page_packet = SwapStatusPacket(self.server.devaddress, SwapRegId.ID_FIRMWARE, val)
                                    page_packet.send(self.server)

                                if nb_line == 0:
                                    self.hexfile_line = 0
                                    print "Erasing flash memory"
                                    self.progress + 1
                                elif nb_line == 1:
                                    print "Uploading code to node"
                                elif 1 < nb_line < (self.hexfile.nbof_data_lines - 1):
                                    if nb_line != self.hexfile_line:
                                        self.hexfile_line = nb_line
                                        self.progress + 1
                                        self.progress.show_progress()
                                elif nb_line == (self.hexfile.nbof_data_lines):
                                    self.progress + 2
                                    self.progress.show_progress()
                                    print "\n\rUpload completed"
                                    self.prog_address = None
                                    self.hexfile_line = 0