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> <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})
def serveMotes(self, action, namedAction, qs, form, extra = False): disabled = "" if self.getLevel() > 1 else 'disabled="disabled" ' c = "" for m in motes.getMotesSorted(): name = "mote" + m.getFullBasename() if qs: if name in qs: m.isSelected = qs[name][0] == 'on' elif "action" in qs: m.isSelected = False elif form: if name in form: m.isSelected = form[name].value == "on" else: m.isSelected = False checked = ' checked="checked"' if m.isSelected else "" c += '<div class="mote"><strong>Mote: </strong>' if extra: c += "<a href='javascript:talkToMote(\"" + utils.urlEscape(m.getFullBasename()) +"\")' " + disabled + ">" arr = m.getFullName().split("@") if (len(arr) == 1): c += m.getFullName() else: c += arr[0] arr = m.getFullName().split("@") if arr[1] != "Local": c += " @ " + m.getFullName().split("@")[1][7:].split(":")[0] c += "</a>" else: c += m.getFullName() c += ' (<strong>Platform: </strong>' + m.platform + ') ' c += ' <input type="checkbox" title="Select the mote" name="' + name + '"' c += checked + ' ' + disabled + '/>' + namedAction c += '</div>\n' # remember which motes were selected and which were not motes.storeSelected() if c: c = '<div class="motes1">\nAttached motes:\n<br/>\n' + c + '</div>\n' return c