added help method for generating unique mote type identifiers
This commit is contained in:
parent
27d81e5645
commit
1e3ec46ddb
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: ContikiMoteType.java,v 1.25 2008/02/12 15:04:43 fros4943 Exp $
|
* $Id: ContikiMoteType.java,v 1.26 2008/03/19 09:41:03 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.contikimote;
|
package se.sics.cooja.contikimote;
|
||||||
|
@ -1158,6 +1158,56 @@ public class ContikiMoteType implements MoteType {
|
||||||
return messageDigest.digest();
|
return messageDigest.digest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a unique Contiki mote type ID.
|
||||||
|
*
|
||||||
|
* @param existingTypes Already existing mote types, may be null
|
||||||
|
* @param reservedIdentifiers Already reserved identifiers, may be null
|
||||||
|
* @return Unique mote type ID.
|
||||||
|
*/
|
||||||
|
public static String generateUniqueMoteTypeID(Collection<MoteType> existingTypes, Collection reservedIdentifiers) {
|
||||||
|
int counter = 0;
|
||||||
|
String testID = "";
|
||||||
|
boolean okID = false;
|
||||||
|
|
||||||
|
while (!okID) {
|
||||||
|
counter++;
|
||||||
|
testID = ContikiMoteTypeDialog.ID_PREFIX + counter;
|
||||||
|
okID = true;
|
||||||
|
|
||||||
|
// Check if identifier is reserved
|
||||||
|
if (reservedIdentifiers != null && reservedIdentifiers.contains(testID)) {
|
||||||
|
okID = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!okID) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if identifier is used
|
||||||
|
if (existingTypes != null) {
|
||||||
|
for (MoteType existingMoteType : existingTypes) {
|
||||||
|
if (existingMoteType.getIdentifier().equals(testID)) {
|
||||||
|
okID = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!okID) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if identifier library has been loaded
|
||||||
|
File libraryFile = new File(ContikiMoteType.tempOutputDirectory, testID + ContikiMoteType.librarySuffix);
|
||||||
|
if (CoreComm.hasLibraryFileBeenLoaded(libraryFile)) {
|
||||||
|
okID = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return testID;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a panel with interesting data for this mote type.
|
* Returns a panel with interesting data for this mote type.
|
||||||
*
|
*
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: ContikiMoteTypeDialog.java,v 1.41 2008/02/12 15:25:41 fros4943 Exp $
|
* $Id: ContikiMoteTypeDialog.java,v 1.42 2008/03/19 09:41:03 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.contikimote;
|
package se.sics.cooja.contikimote;
|
||||||
|
@ -157,35 +157,8 @@ public class ContikiMoteTypeDialog extends JDialog {
|
||||||
myDialog.setTitle("Recompile Mote Type");
|
myDialog.setTitle("Recompile Mote Type");
|
||||||
} else {
|
} else {
|
||||||
// Suggest new identifier
|
// Suggest new identifier
|
||||||
int counter = 0;
|
String suggestedID = ContikiMoteType.generateUniqueMoteTypeID(myDialog.allOtherTypes, null);
|
||||||
String testIdentifier = "";
|
myDialog.textID.setText(suggestedID);
|
||||||
boolean identifierOK = false;
|
|
||||||
while (!identifierOK) {
|
|
||||||
counter++;
|
|
||||||
testIdentifier = ID_PREFIX + counter;
|
|
||||||
identifierOK = true;
|
|
||||||
|
|
||||||
// Check if identifier is already used by some other type
|
|
||||||
for (MoteType existingMoteType : myDialog.allOtherTypes) {
|
|
||||||
if (existingMoteType != myDialog.myMoteType
|
|
||||||
&& existingMoteType.getIdentifier().equals(testIdentifier)) {
|
|
||||||
identifierOK = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if library file with given identifier has already been loaded
|
|
||||||
if (identifierOK
|
|
||||||
&& CoreComm.hasLibraryFileBeenLoaded(new File(
|
|
||||||
ContikiMoteType.tempOutputDirectory,
|
|
||||||
testIdentifier
|
|
||||||
+ ContikiMoteType.librarySuffix))) {
|
|
||||||
identifierOK = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
myDialog.textID.setText(testIdentifier);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set preset description of mote type
|
// Set preset description of mote type
|
||||||
|
|
Loading…
Reference in a new issue