Example #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})
Example #2
0
    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
Example #3
0
    def serveConfig(self, qs):
        global isListening

        self.send_response(200)
        self.sendDefaultHeaders()
        self.end_headers()
        
        if "platform_set" in qs:
            for m in motes.getMotes():
                motename = "sel_mote" + utils.urlEscape(m.getFullBasename())
                if motename in qs:
                    m.platform = qs[motename][0]
            motes.storeSelected()
            text = '<strong>Mote platforms updated!</strong>\n'
            self.writeChunk(self.serveAnyPage("config", qs, content = text, generatedContentOnly = True))
            return
        else:
            sensor_data.moteData.reset()
            ht.openAllSerial()
            isListening = True
            
            motePortName = None
            filesRequired = False
            for s in qs:
                if s[:4] == "mote":
                    pair = s[4:].split('_')
                    try:
                        motePortName = pair[0]
                        filesRequired = pair[1] == "files"
                    except:
                        pass
                    break
    
            if motePortName is None: # or moteIndex >= len(motes.getMotes()):
                self.writeChunk("<h4 class='err'>Config page requested, but mote not specified!</h4>")
                return

            motePortNameEsc = utils.urlEscape(motePortName)
    
            platform = None
            dropdownName = "sel_mote" + motePortNameEsc
            if dropdownName in qs:
                platform = qs[dropdownName][0]
    
            if platform not in moteconfig.supportedPlatforms:
                self.writeChunk("<h4 class='err'>Config page requested, but platform not specified or unknown!</h4>")
                return

            moteconfig.instance.setMote(motes.getMote(motePortName), platform)
    
            (errmsg, ok) = moteconfig.instance.updateConfigValues(qs)
            if not ok:
                self.writeChunk(errmsg)
                return

            # fill config values from the mote / send new values to the mote
            if "get" in qs:
                reply = moteconfig.instance.getConfigValues()
            elif "set" in qs:
                reply = moteconfig.instance.setConfigValues()

            if filesRequired:
                if "filename" in qs:
                    (text, ok) = moteconfig.instance.getFileContentsHTML(qs)
                else:
                    (text, ok) = moteconfig.instance.getFileListHTML(motePortNameEsc)
            else:
                (text, ok) = moteconfig.instance.getConfigHTML()
            if not ok:
                self.writeChunk("\n<h4 class='err'>Error: " + text + "</h4>\n")
                return
                
            moteidQS = "?sel_mote" + motePortNameEsc + "=" + platform + "&" + "mote" + motePortNameEsc
            replaceValues = {
                "MOTEID_CONFIG" : moteidQS + "_cfg=1",
                "MOTEID_FILES" : moteidQS + "_files=1"
            }
            
            if "update_sensors" in qs:
                configuration.c.selectSection("graph")
                graphConfig = []
                storeConfig = []
                try:
                    graphSensors = json.loads(configuration.c.getCfgValue("graphsensors"))
                except:
                    graphSensors = {}
                for s in moteconfig.instance.activePlatform.sensors:
                    storeFlag = "store_" + s.varname
                    graphFlag = "graph_" + s.varname
                    if storeFlag in qs and qs[storeFlag][0] == 'on':
                        storeConfig.append(s.varname)
                    if graphFlag in qs and qs[graphFlag][0] == 'on':
                        graphConfig.append(s.varname)
                configuration.c.selectSection("graph")
                graphSensors[motePortNameEsc] = graphConfig
                configuration.c.setCfgValue("graphsensors", json.dumps(graphSensors))
                configuration.c.save()
            else:
                try:
                    configuration.c.selectSection("graph")
                    graphSensors = json.loads(configuration.c.getCfgValue("graphsensors"))
                    graphConfig = graphSensors[motePortNameEsc]
                except:
                    graphConfig = []
                for s in moteconfig.instance.activePlatform.sensors:
                    if s.varname in graphConfig:
                        replaceValues["graph_" + s.varname] = "checked"
                    else:
                        replaceValues["graph_" + s.varname] = ""
                
            self.writeChunk(self.serveAnyPage("config", qs, isGeneric = False, content = text, replaceValues = replaceValues, generatedContentOnly = True))
Example #4
0
    def serveConfig(self, qs):
        global isListening

        self.send_response(200)
        self.sendDefaultHeaders()
        self.end_headers()

        if "platform_set" in qs:
            for m in motes.getMotes():
                motename = "sel_mote" + utils.urlEscape(m.getFullBasename())
                if motename in qs:
                    m.platform = qs[motename][0]
            motes.storeSelected()
            text = '<strong>Mote platforms updated!</strong>\n'
            self.writeChunk(
                self.serveAnyPage("config",
                                  qs,
                                  content=text,
                                  generatedContentOnly=True))
            return
        else:
            sensor_data.moteData.reset()
            ht.openAllSerial()
            isListening = True

            motePortName = None
            filesRequired = False
            for s in qs:
                if s[:4] == "mote":
                    pair = s[4:].split('_')
                    try:
                        motePortName = pair[0]
                        filesRequired = pair[1] == "files"
                    except:
                        pass
                    break

            if motePortName is None:  # or moteIndex >= len(motes.getMotes()):
                self.writeChunk(
                    "<h4 class='err'>Config page requested, but mote not specified!</h4>"
                )
                return

            motePortNameEsc = utils.urlEscape(motePortName)

            platform = None
            dropdownName = "sel_mote" + motePortNameEsc
            if dropdownName in qs:
                platform = qs[dropdownName][0]

            if platform not in moteconfig.supportedPlatforms:
                self.writeChunk(
                    "<h4 class='err'>Config page requested, but platform not specified or unknown!</h4>"
                )
                return

            moteconfig.instance.setMote(motes.getMote(motePortName), platform)

            (errmsg, ok) = moteconfig.instance.updateConfigValues(qs)
            if not ok:
                self.writeChunk(errmsg)
                return

            # fill config values from the mote / send new values to the mote
            if "get" in qs:
                reply = moteconfig.instance.getConfigValues()
            elif "set" in qs:
                reply = moteconfig.instance.setConfigValues()

            if filesRequired:
                if "filename" in qs:
                    (text, ok) = moteconfig.instance.getFileContentsHTML(qs)
                else:
                    (text,
                     ok) = moteconfig.instance.getFileListHTML(motePortNameEsc)
            else:
                (text, ok) = moteconfig.instance.getConfigHTML()
            if not ok:
                self.writeChunk("\n<h4 class='err'>Error: " + text + "</h4>\n")
                return

            moteidQS = "?sel_mote" + motePortNameEsc + "=" + platform + "&" + "mote" + motePortNameEsc
            replaceValues = {
                "MOTEID_CONFIG": moteidQS + "_cfg=1",
                "MOTEID_FILES": moteidQS + "_files=1"
            }

            if "update_sensors" in qs:
                configuration.c.selectSection("graph")
                graphConfig = []
                storeConfig = []
                try:
                    graphSensors = json.loads(
                        configuration.c.getCfgValue("graphsensors"))
                except:
                    graphSensors = {}
                for s in moteconfig.instance.activePlatform.sensors:
                    storeFlag = "store_" + s.varname
                    graphFlag = "graph_" + s.varname
                    if storeFlag in qs and qs[storeFlag][0] == 'on':
                        storeConfig.append(s.varname)
                    if graphFlag in qs and qs[graphFlag][0] == 'on':
                        graphConfig.append(s.varname)
                configuration.c.selectSection("graph")
                graphSensors[motePortNameEsc] = graphConfig
                configuration.c.setCfgValue("graphsensors",
                                            json.dumps(graphSensors))
                configuration.c.save()
            else:
                try:
                    configuration.c.selectSection("graph")
                    graphSensors = json.loads(
                        configuration.c.getCfgValue("graphsensors"))
                    graphConfig = graphSensors[motePortNameEsc]
                except:
                    graphConfig = []
                for s in moteconfig.instance.activePlatform.sensors:
                    if s.varname in graphConfig:
                        replaceValues["graph_" + s.varname] = "checked"
                    else:
                        replaceValues["graph_" + s.varname] = ""

            self.writeChunk(
                self.serveAnyPage("config",
                                  qs,
                                  isGeneric=False,
                                  content=text,
                                  replaceValues=replaceValues,
                                  generatedContentOnly=True))