Ejemplo n.º 1
0
    def serveMoteSelect(self, qs):
        self.setSession(qs)
        self.send_response(200)
        self.sendDefaultHeaders()
        self.end_headers()

        if motes.isEmpty():
            text = "No motes connected!"
            self.serveAnyPage("error:critical", qs, errorMsg = text)
            return

        disabled = "" if self.getLevel() > 1 else 'disabled="disabled" '
        tableDesc = "<form action='config'><table class='table'>" \
            + "<thead><tr><th>Mote</th><th>Platform</th><th>Actions</th></tr></thead>" \
            + "${tableContent}</table></form>"
        platformSelect = '\n<select id="sel_${name}" ' + disabled + ' ' \
            + 'title="Select the mote\'s platform: determines the list of sensors the mote has. ' \
            + 'Also has effect on code compilation and uploading">\n' \
            + '${details}</select>&nbsp;<input type="button" name="platform_set" value="Update" ' + disabled \
            +' onclick="updatePlatform(sel_${name})"/>'
        detail = '<option value="${platform}" ${selected}>${platform}</option>\n'
        actions = '<input type="button" name="${name}_cfg" ' \
            + 'title="Get/set mote\'s configuration (e.g. sensor reading periods)" ' \
            + 'value="Configuration" ' + disabled + ' onclick="onConfig(\'${name}\')"/>\n' \
            + '<input type="button" name="${name}_files" ' \
            + 'title="View files on mote\'s filesystem" value="Files" ' + disabled \
            + ' onclick="viewFiles(\'${name}\', sel_${name})"/>'
        tableRow = "<tr><td><a href='javascript:talkToMote(\"${modPortName}\")'>${portName}</a></td><td>${platformSelect}</td>" \
            "<td>${actions}</td></tr>" 
        t1 = string.Template(tableDesc)
        t2 = string.Template(tableRow)
        t3 = string.Template(detail)
        t4 = string.Template(platformSelect)
        t5 = string.Template(actions)
        tableContent = ""

        for m in motes.getMotesSorted():
            name = "mote" + m.getFullBasename()
            escapedName = utils.urlEscape(name)
            details = ""
            for platform in moteconfig.supportedPlatforms:
                selected = 'selected="selected"' if platform == m.platform else ''
                details += t3.substitute(platform = platform, selected = selected)
            tableContent += t2.substitute(portName = m.getFullName(), modPortName = utils.urlEscape(m.getFullBasename()),
                platformSelect = t4.substitute(name = escapedName, details = details),
                actions = t5.substitute(name = escapedName))
        text = t1.substitute(tableContent = tableContent)
        self.serveAnyPage("motes", qs, True, {"MOTE_TABLE" : text})
Ejemplo n.º 2
0
    def serveMoteSelect(self, qs):
        self.setSession(qs)
        self.send_response(200)
        self.sendDefaultHeaders()
        self.end_headers()

        if motes.isEmpty():
            text = "No motes connected!"
            self.serveAnyPage("error:critical", qs, errorMsg = text)
            return

        disabled = "" if self.getLevel() > 1 else 'disabled="disabled" '
        desc = '<div class="mote"><strong>Mote: </strong>${portName}' \
             + '<input type="submit" name="${name}_cfg" ' \
             + 'title="Get/set mote\'s configuration (e.g. sensor reading periods)" ' \
             + 'value="Configuration..." ' + disabled + '/>\n' \
             + '<input type="submit" name="${name}_files" ' \
             + 'title="View files on mote\'s filesystem" value="Files..." ' + disabled + '/>\n' \
             + ' Platform: <select name="sel_${name}"' + disabled + ' ' \
             + 'title="Select the mote\'s platform: determines the list of sensors the mote has. ' \
             + '"Also has effect on code compilation and uploading">\n' \
             + '${details}</select>\n</div>\n'
        detail = '<option value="${platform}" ${selected}>${platform}</option>\n'
            
        text = '<form action="config"><div class="motes2">\n'
        text += 'Directly attached motes:<br/>\n'
        t1 = Template(desc)
        t2 = Template(detail)
        for m in motes.getMotes():
            name = "mote" + m.getPortBasename()
            details = ""
            for platform in moteconfig.supportedPlatforms:
                selected = 'selected="selected"' if platform == m.platform else ''
                details += t2.substitute(platform = platform, selected = selected)
            text += t1.substitute(
                portName = m.getPortName(), name = name, details = details)
        text += '<input type="submit" name="platform_set" value="Update platforms" ' + disabled + '/><br/>\n'
        text += "</div></form>" 
        self.serveAnyPage("motes", qs, content = text)