Remove TODO file
[remote/remote-gui.git] / src / main / util / MoteControlRow.java
blob9a7be01175af0fdc124e79dfcf77bc85276442fd
1 package util;
3 import diku.distlab.motecontrolclientlib.client.SimpleMote;
4 import diku.distlab.motecontrolclientlib.client.SimpleMoteStatus;
5 import diku.distlab.motecontrolclientlib.protocols.motecontrol.MsgCommand;
6 import diku.distlab.motecontrolclientlib.protocols.motecontrol.MsgResult;
7 import diku.distlab.remote.client.motedata.Table;
8 import diku.distlab.remote.client.motedata.TableHeader;
9 import diku.distlab.remote.client.motedata.TableRow;
11 public class MoteControlRow extends MoteControl implements TableRow, Comparable{
13 public static final int COL_MOTE_ID = 0;
15 public static final int COL_SITE = 1;
17 public static final int COL_TOSADDRESS = 2;
19 public static final int COL_MACADDRESS = 3;
21 public static final int COL_STATUS = 4;
23 public static final int COL_LAST_REQUEST = 5;
25 public static final int COL_LEDS = 6;
27 public static final int COL_LOGFILE = 7;
29 MoteControlTable parentTable;
31 TableRow infoRow;
33 MoteControlRow(SimpleMote mote, boolean enableLeds, TableRow infoRow,
34 MoteControlTable parentTable) {
35 super(mote, enableLeds);
36 this.parentTable = parentTable;
37 this.infoRow = infoRow;
40 public Table getTable() {
41 return parentTable;
44 public Object get(int columnIndex) {
45 try {
46 switch (columnIndex) {
47 case COL_MOTE_ID:
48 return this.infoRow.get("mote_id");
49 case COL_SITE:
50 return this.infoRow.get("site");
51 case COL_TOSADDRESS:
52 return this.infoRow.get("tosaddress");
53 case COL_MACADDRESS:
54 return this.infoRow.get("macaddress");
55 case COL_STATUS:
56 return MoteStatusRenderer.getText(this.getMote().getStatus().getStatus());
57 case COL_LAST_REQUEST:
58 return decodeLastCommandResult(this.getMote().getStatus());
59 case COL_LEDS:
60 return this.moteLeds;
61 case COL_LOGFILE:
62 if (this.logging) return this.logFile.getPath();
63 else return "";
65 } catch (Exception e) {}
66 return null;
69 public Object get(String columnName) throws Exception {
70 return this.get(this.parentTable.getHeader().indexOf(columnName));
73 public int compareTo(Object o) {
74 if (o==this) return 0;
75 return 1;
78 public static String decodeLastCommandResult(SimpleMoteStatus s)
80 String prefix,suffix;
81 switch(s.getLastCommand())
83 case -1:
84 prefix = "No messages received yet - ";
85 break;
86 case MsgCommand.CANCELPROGRAMMING:
87 prefix = "Cancel programming ";
88 break;
89 case MsgCommand.PROGRAM:
90 prefix = "Programming ";
91 break;
92 case MsgCommand.RESET:
93 prefix = "Reset ";
94 break;
95 case MsgCommand.START:
96 prefix = "Start ";
97 break;
98 case MsgCommand.STATUS:
99 prefix = "Status request ";
100 break;
101 case MsgCommand.STOP:
102 prefix = "Stop ";
103 break;
104 default:
105 prefix = "Unknown command ";
107 switch(s.getLastResult())
109 case -1:
110 suffix = "no result available";
111 break;
112 case MsgResult.FAILURE:
113 suffix = "failed";
114 break;
115 case MsgResult.NOT_SUPPORTED:
116 suffix = "is not supported";
117 break;
118 case MsgResult.SUCCESS:
119 suffix = "succesful";
120 break;
121 default:
122 suffix = "unknown result";
124 return prefix+suffix;