Skip to content

Commit

Permalink
Add -m (models folder) command line option to leshan-client-demo
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Apr 15, 2020
1 parent 23d0901 commit 1783d39
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public static void main(final String[] args) {
aa.desc("Use additional attributes at registration time, syntax is \n -aa attrName1=attrValue1 attrName2=\\\"attrValue2\\\" ...");
aa.hasArgs();
options.addOption(aa.build());
options.addOption("m", true, "A folder which contains object models in OMA DDF(.xml)format.");
options.addOption("pos", true,
"Set the initial location (latitude, longitude) of the device to be reported by the Location object.\n Format: lat_float:long_float");
options.addOption("sf", true, "Scale factor to apply when shifting position.\n Default is 1.0." + PSKChapter);
Expand Down Expand Up @@ -405,11 +406,15 @@ public static void main(final String[] args) {
return;
}
}

// Get models folder
String modelsFolderPath = cl.getOptionValue("m");

try {
createAndStartClient(endpoint, localAddress, localPort, cl.hasOption("b"), additionalAttributes, lifetime,
communicationPeriod, serverURI, pskIdentity, pskKey, clientPrivateKey, clientPublicKey,
serverPublicKey, clientCertificate, serverCertificate, latitude, longitude, scaleFactor,
cl.hasOption("ocf"), cl.hasOption("oc"), cl.hasOption("r"), cl.hasOption("f"));
cl.hasOption("ocf"), cl.hasOption("oc"), cl.hasOption("r"), cl.hasOption("f"), modelsFolderPath);
} catch (Exception e) {
System.err.println("Unable to create and start client ...");
e.printStackTrace();
Expand All @@ -422,14 +427,17 @@ public static void createAndStartClient(String endpoint, String localAddress, in
byte[] pskIdentity, byte[] pskKey, PrivateKey clientPrivateKey, PublicKey clientPublicKey,
PublicKey serverPublicKey, X509Certificate clientCertificate, X509Certificate serverCertificate,
Float latitude, Float longitude, float scaleFactor, boolean supportOldFormat,
boolean supportDeprecatedCiphers, boolean reconnectOnUpdate, boolean forceFullhandshake)
throws CertificateEncodingException {
boolean supportDeprecatedCiphers, boolean reconnectOnUpdate, boolean forceFullhandshake,
String modelsFolderPath) throws CertificateEncodingException {

locationInstance = new MyLocation(latitude, longitude, scaleFactor);

// Initialize model
List<ObjectModel> models = ObjectLoader.loadDefault();
models.addAll(ObjectLoader.loadDdfResources("/models", modelPaths));
if (modelsFolderPath != null) {
models.addAll(ObjectLoader.loadObjectsFromDir(new File(modelsFolderPath)));
}

// Initialize object list
final LwM2mModel model = new StaticModel(models);
Expand Down

0 comments on commit 1783d39

Please sign in to comment.