⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calamariplugin.java

📁 传感器网络中的嵌入式操作系统源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        } catch (Exception e) {                            tv.setStatus("ERROR reading from Matlab on ADC channel "+channel);                        }*/                            }                    }                    try {                        if (value == null) return;                        simComm.sendCommand(new SetADCPortValueCommand((short) mote.getID(), 0L,(short)channel, value.intValue())); //                       tv.setStatus("Setting Value for mote " + mote.getID() + " on ADC channel " + channel + " to " + value.toString());                    } catch (Exception e) {                        tv.setStatus("ERROR Setting Value for mote " + mote.getID() + " on ADC channel " + channel);                    }                }            else if (dme.getMessage().indexOf("RSSI MSG:") != -1) {                int rxrID = dme.getMoteID();                int txrID;                try {                    StringTokenizer st = new StringTokenizer(dme.getMessage());                    st.nextToken();st.nextToken();st.nextToken(); //"RSSI MSG: transmitter XX"                    txrID = Integer.parseInt(st.nextToken());                } catch (Exception e) {tv.setStatus("parse error"+ e.getMessage());tv.resume(); return; }                MoteSimObject txr = state.getMoteSimObject(txrID), rxr = state.getMoteSimObject(rxrID);                if (txr == null || rxr == null) {return;}                MoteCoordinateAttribute txrCoord = txr.getCoordinate(), rxrCoord = rxr.getCoordinate();                int txrx = (int) (((txrCoord.getX() * X_SCALE) / cT.getMoteScaleWidth()));                int txry = (int) (((txrCoord.getY() * Y_SCALE) / cT.getMoteScaleHeight()));                int rxrx = (int) (((rxrCoord.getX() * X_SCALE) / cT.getMoteScaleWidth()));                int rxry = (int) (((rxrCoord.getY() * Y_SCALE) / cT.getMoteScaleHeight()));                int distance = (int) Math.sqrt(Math.pow(txrx - rxrx, 2) + Math.pow(txry - rxry, 2));                try {                    /*Object args[] = new Object[3];                    args[0] = new Integer(txrID);                    args[1] = new Integer(rxrID);                    args[2] = new Integer(distance);                    MatlabControl matlab = new MatlabControl(true);                    Integer rssi = (Integer) matlab.blockingFeval("getRssiValue", args);*/                    Integer rssi;                    if(distance>MAX_RANGE)                        rssi= new Integer(0);                    else                        rssi = new Integer(distance + (int)(NOISE_LEVEL*(Math.random()*2-1)));                    simComm.sendCommand(new SetADCPortValueCommand((short) rxr.getID(), 0L, PORT_RSSI, rssi.intValue()));                    simComm.sendCommand(new SetADCPortValueCommand((short) rxr.getID(), 0L, PORT_RSSI_STDV, (int)NOISE_LEVEL));//                    tv.setStatus("Setting RSSI for mote " + rxr.getID() + " to (" + rssi + ")" + "for msg from " + txr.getID());                } catch (Exception e) {                    tv.setStatus("ERROR Setting RSSI for mote " + rxr.getID() + "for msg from " + txr.getID()+": "+e.toString());                }            }        }    }    public void register() {        JTextArea ta = new JTextArea(2, 50);        ta.setFont(tv.defaultFont);        ta.setEditable(false);        ta.setBackground(Color.lightGray);        ta.setLineWrap(true);        ta.setText("Blue arrows are error vectors and circles at the end indicate uncertainty." +                " Nodes with red circles around them are anchor nodes.");        pluginPanel.add(ta);        JPanel parameterPane = new JPanel();        parameterPane.setLayout(new GridLayout(7,2,1,1));        // Create radius constant text field and label        JLabel xscalingFactorLabel = new JLabel("Field width (cm)");        xscalingFactorLabel.setFont(tv.defaultFont);        xscalingFactorTextField = new JTextField(Double.toString(X_SCALE), 5);        xscalingFactorTextField.setFont(tv.smallFont);        xscalingFactorTextField.setEditable(true);        parameterPane.add(xscalingFactorLabel);        parameterPane.add(xscalingFactorTextField);        // Create radius constant text field and label        JLabel yscalingFactorLabel = new JLabel("Field height (cm)");        yscalingFactorLabel.setFont(tv.defaultFont);        yscalingFactorTextField = new JTextField(Double.toString(Y_SCALE), 5);        yscalingFactorTextField.setFont(tv.smallFont);        yscalingFactorTextField.setEditable(true);        parameterPane.add(yscalingFactorLabel);        parameterPane.add(yscalingFactorTextField);        JLabel maxRangeLabel = new JLabel("Maximum Distance (cm)");        maxRangeLabel.setFont(tv.defaultFont);        maxRangeTextField = new JTextField(Double.toString(MAX_RANGE), 5);        maxRangeTextField.setFont(tv.smallFont);        maxRangeTextField.setEditable(true);        parameterPane.add(maxRangeLabel);        parameterPane.add(maxRangeTextField);        JLabel maxErrorLabel = new JLabel("Maximum Error(cm)");        maxErrorLabel.setFont(tv.defaultFont);        maxErrorTextField = new JTextField(Double.toString(NOISE_LEVEL), 5);        maxErrorTextField.setFont(tv.smallFont);        maxErrorTextField.setEditable(true);        parameterPane.add(maxErrorLabel);        parameterPane.add(maxErrorTextField);        // Create button to update radio model        JButton updateButton = new JButton("Update");        updateButton.addActionListener(new CalamariPlugin.UpdateListener());        updateButton.setFont(tv.defaultFont);        //pluginPanel.setLayout(new BorderLayout());        pluginPanel.add(parameterPane);        pluginPanel.add(updateButton);        pluginPanel.revalidate();        update();    }    public void deregister            () {    }    public void update() {        X_SCALE= Double.parseDouble(xscalingFactorTextField.getText());        Y_SCALE= Double.parseDouble(yscalingFactorTextField.getText());        MAX_RANGE= Double.parseDouble(maxRangeTextField.getText());        NOISE_LEVEL= Double.parseDouble(maxErrorTextField.getText());      }    public void draw(Graphics graphics) {        Enumeration enum = locationEstimates.elements();        while (enum.hasMoreElements()) {            LocationEstimate loc = (LocationEstimate) enum.nextElement();            MoteSimObject mote = state.getMoteSimObject(loc.nodeID);            if (mote == null) continue;            MoteCoordinateAttribute coord = mote.getCoordinate();            if (loc.isAnchor) {                graphics.setColor(Color.red);                graphics.setColor(Color.red);                graphics.drawOval((int) cT.simXToGUIX(coord.getX()) - 10, (int) cT.simYToGUIY(coord.getY()) - 10, 20, 20);            }            else{                if( (loc.xStdv * X_SCALE / cT.getMoteScaleWidth()>32000) || (loc.yStdv * Y_SCALE / cT.getMoteScaleHeight()>32000) ) continue;                graphics.setColor(Color.blue);                Arrow.drawArrow(graphics,(int) cT.simXToGUIX(loc.x), (int) cT.simYToGUIY(loc.y), (int) cT.simXToGUIX(coord.getX()), (int) cT.simYToGUIY(coord.getY()),Arrow.SIDE_TRAIL);                graphics.setColor(Color.lightGray);                graphics.drawLine((int) cT.simXToGUIX(loc.x), (int) cT.simYToGUIY(loc.y), (int) cT.simXToGUIX(loc.x+(loc.xStdv/2)), (int) cT.simYToGUIY(loc.y));                graphics.drawLine((int) cT.simXToGUIX(loc.x), (int) cT.simYToGUIY(loc.y), (int) cT.simXToGUIX(loc.x-(loc.xStdv/2)), (int) cT.simYToGUIY(loc.y));                graphics.drawLine((int) cT.simXToGUIX(loc.x), (int) cT.simYToGUIY(loc.y), (int) cT.simXToGUIX(loc.x), (int) cT.simYToGUIY(loc.y+(loc.yStdv/2)));                graphics.drawLine((int) cT.simXToGUIX(loc.x), (int) cT.simYToGUIY(loc.y), (int) cT.simXToGUIX(loc.x), (int) cT.simYToGUIY(loc.y-(loc.yStdv/2)));                graphics.drawOval((int) cT.simXToGUIX(loc.x-(loc.xStdv/2)), (int) cT.simYToGUIY(loc.y-(loc.yStdv/2)), (int) cT.simXToGUIX(loc.xStdv), (int) cT.simYToGUIY(loc.yStdv));            }        }    }    public String toString            () {        return "Calamari";    }    public class LocationEstimate {        public int nodeID,x,y,xStdv,yStdv;        public boolean isAnchor;        LocationEstimate() {            isAnchor = false;        }    }    class UpdateListener implements ActionListener {    public void actionPerformed(ActionEvent e) {        update();      motePanel.refresh();    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -