コード例 #1
0
    def shutdown(self, secs: int = 10):
        """Tell the node to shutdown."""
        p = admin_pb2.AdminMessage()
        p.shutdown_seconds = secs
        logging.info(f"Telling node to shutdown in {secs} seconds")

        return self._sendAdmin(p)
コード例 #2
0
    def set_canned_message(self, message):
        """Set the canned message. Split into parts of 200 chars each."""

        if len(message) > 800:
            our_exit(
                "Warning: The canned message must be less than 800 characters."
            )

        # split into chunks
        chunks = []
        chunks_size = 200
        for i in range(0, len(message), chunks_size):
            chunks.append(message[i:i + chunks_size])

        # for each chunk, send a message to set the values
        #for i in range(0, len(chunks)):
        for i, chunk in enumerate(chunks):
            p = admin_pb2.AdminMessage()

            # TODO: should be a way to improve this
            if i == 0:
                p.set_canned_message_plugin_part1 = chunk
            elif i == 1:
                p.set_canned_message_plugin_part2 = chunk
            elif i == 2:
                p.set_canned_message_plugin_part3 = chunk
            elif i == 3:
                p.set_canned_message_plugin_part4 = chunk

            logging.debug(f"Setting canned message '{chunk}' part {i+1}")
            self._sendAdmin(p)
コード例 #3
0
    def reboot(self, secs: int = 10):
        """Tell the node to reboot."""
        p = admin_pb2.AdminMessage()
        p.reboot_seconds = secs
        logging.info(f"Telling node to reboot in {secs} seconds")

        return self._sendAdmin(p)
コード例 #4
0
    def _requestSettings(self):
        """Done with initial config messages, now send regular
           MeshPackets to ask for settings."""
        p = admin_pb2.AdminMessage()
        p.get_radio_request = True

        # TODO: should we check that localNode has an 'admin' channel?
        # Show progress message for super slow operations
        if self != self.iface.localNode:
            print("Requesting preferences from remote node.")
            print("Be sure:")
            print(" 1. There is a SECONDARY channel named 'admin'.")
            print(" 2. The '--seturl' was used to configure.")
            print(
                " 3. All devices have the same modem config. (i.e., '--ch-longfast')"
            )
            print(
                " 4. All devices have been rebooted after all of the above. (optional, but recommended)"
            )
            print(
                "Note: This could take a while (it requests remote channel configs, then writes config)"
            )

        return self._sendAdmin(p,
                               wantResponse=True,
                               onResponse=self.onResponseRequestSettings)
コード例 #5
0
    def exitSimulator(self):
        """Tell a simulator node to exit (this message
           is ignored for other nodes)"""
        p = admin_pb2.AdminMessage()
        p.exit_simulator = True
        logging.debug('in exitSimulator()')

        return self._sendAdmin(p)
コード例 #6
0
    def writeChannel(self, channelIndex, adminIndex=0):
        """Write the current (edited) channel to the device"""

        p = admin_pb2.AdminMessage()
        p.set_channel.CopyFrom(self.channels[channelIndex])

        self._sendAdmin(p, adminIndex=adminIndex)
        logging.debug(f"Wrote channel {channelIndex}")
コード例 #7
0
    def writeConfig(self):
        """Write the current (edited) radioConfig to the device"""
        if self.radioConfig is None:
            our_exit("Error: No RadioConfig has been read")

        p = admin_pb2.AdminMessage()
        p.set_radio.CopyFrom(self.radioConfig)

        self._sendAdmin(p)
        logging.debug("Wrote config")
コード例 #8
0
    def setOwner(self,
                 long_name=None,
                 short_name=None,
                 is_licensed=False,
                 team=None):
        """Set device owner name"""
        logging.debug(f"in setOwner nodeNum:{self.nodeNum}")
        nChars = 3
        minChars = 2
        if long_name is not None:
            long_name = long_name.strip()
            if short_name is None:
                words = long_name.split()
                if len(long_name) <= nChars:
                    short_name = long_name
                elif len(words) >= minChars:
                    short_name = ''.join(map(lambda word: word[0], words))
                else:
                    trans = str.maketrans(dict.fromkeys('aeiouAEIOU'))
                    short_name = long_name[0] + long_name[1:].translate(trans)
                    if len(short_name) < nChars:
                        short_name = long_name[:nChars]

        p = admin_pb2.AdminMessage()

        if long_name is not None:
            p.set_owner.long_name = long_name
        if short_name is not None:
            short_name = short_name.strip()
            if len(short_name) > nChars:
                short_name = short_name[:nChars]
            p.set_owner.short_name = short_name
            p.set_owner.is_licensed = is_licensed
        if team is not None:
            p.set_owner.team = team

        # Note: These debug lines are used in unit tests
        logging.debug(f'p.set_owner.long_name:{p.set_owner.long_name}:')
        logging.debug(f'p.set_owner.short_name:{p.set_owner.short_name}:')
        logging.debug(f'p.set_owner.is_licensed:{p.set_owner.is_licensed}')
        logging.debug(f'p.set_owner.team:{p.set_owner.team}')
        return self._sendAdmin(p)
コード例 #9
0
    def _requestChannel(self, channelNum: int):
        """Done with initial config messages, now send regular
           MeshPackets to ask for settings"""
        p = admin_pb2.AdminMessage()
        p.get_channel_request = channelNum + 1

        # Show progress message for super slow operations
        if self != self.iface.localNode:
            print(
                f"Requesting channel {channelNum} info from remote node (this could take a while)"
            )
            logging.debug(
                f"Requesting channel {channelNum} info from remote node (this could take a while)"
            )
        else:
            logging.debug(f"Requesting channel {channelNum}")

        return self._sendAdmin(p,
                               wantResponse=True,
                               onResponse=self.onResponseRequestChannel)
コード例 #10
0
    def get_canned_message(self):
        """Get the canned message string. Concatenate all pieces together and return a single string."""
        logging.debug(f'in get_canned_message()')
        if not self.cannedPluginMessage:

            p1 = admin_pb2.AdminMessage()
            p1.get_canned_message_plugin_part1_request = True
            self.gotResponse = False
            self._sendAdmin(p1,
                            wantResponse=True,
                            onResponse=self.
                            onResponseRequestCannedMessagePluginMessagePart1)
            while self.gotResponse is False:
                time.sleep(0.1)

            p2 = admin_pb2.AdminMessage()
            p2.get_canned_message_plugin_part2_request = True
            self.gotResponse = False
            self._sendAdmin(p2,
                            wantResponse=True,
                            onResponse=self.
                            onResponseRequestCannedMessagePluginMessagePart2)
            while self.gotResponse is False:
                time.sleep(0.1)

            p3 = admin_pb2.AdminMessage()
            p3.get_canned_message_plugin_part3_request = True
            self.gotResponse = False
            self._sendAdmin(p3,
                            wantResponse=True,
                            onResponse=self.
                            onResponseRequestCannedMessagePluginMessagePart3)
            while self.gotResponse is False:
                time.sleep(0.1)

            p4 = admin_pb2.AdminMessage()
            p4.get_canned_message_plugin_part4_request = True
            self.gotResponse = False
            self._sendAdmin(p4,
                            wantResponse=True,
                            onResponse=self.
                            onResponseRequestCannedMessagePluginMessagePart4)
            while self.gotResponse is False:
                time.sleep(0.1)

            # TODO: This feels wrong to have a sleep here. Is there a way to ensure that
            # all requests are complete? Perhaps change to a while loop any parts are None... maybe?
            time.sleep(3)

            logging.debug(
                f'self.cannedPluginMessagePart1:{self.cannedPluginMessagePart1}'
            )
            logging.debug(
                f'self.cannedPluginMessagePart2:{self.cannedPluginMessagePart2}'
            )
            logging.debug(
                f'self.cannedPluginMessagePart3:{self.cannedPluginMessagePart3}'
            )
            logging.debug(
                f'self.cannedPluginMessagePart4:{self.cannedPluginMessagePart4}'
            )

            self.cannedPluginMessage = ""
            if self.cannedPluginMessagePart1:
                self.cannedPluginMessage += self.cannedPluginMessagePart1
            if self.cannedPluginMessagePart2:
                self.cannedPluginMessage += self.cannedPluginMessagePart2
            if self.cannedPluginMessagePart3:
                self.cannedPluginMessage += self.cannedPluginMessagePart3
            if self.cannedPluginMessagePart4:
                self.cannedPluginMessage += self.cannedPluginMessagePart4

        print(f'canned_plugin_message:{self.cannedPluginMessage}')
        logging.debug(f'canned_plugin_message:{self.cannedPluginMessage}')
        return self.cannedPluginMessage