Skip to content

Commit b1f1739

Browse files
committed
1. Move mud adaptation libraries to mud project. 2. Fixed a bug.
1 parent 3de586b commit b1f1739

File tree

10 files changed

+20
-581
lines changed

10 files changed

+20
-581
lines changed

client/lora-dac/src/main/java/com/thefirstlineofcode/sand/client/lora/dac/LoraDacService.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.thefirstlineofcode.sand.client.thing.commuication.CommunicationException;
1919
import com.thefirstlineofcode.sand.client.thing.commuication.ICommunicationListener;
2020
import com.thefirstlineofcode.sand.client.thing.commuication.ICommunicator;
21-
import com.thefirstlineofcode.sand.client.thing.obx.IObxFactory;
2221
import com.thefirstlineofcode.sand.client.thing.obx.ObxFactory;
2322
import com.thefirstlineofcode.sand.protocols.lora.dac.Allocated;
2423
import com.thefirstlineofcode.sand.protocols.lora.dac.Allocation;
@@ -324,8 +323,7 @@ public void reset() {
324323
}
325324

326325
private void processIsConfigured(byte[] data) throws CommunicationException, BxmppConversionException {
327-
IObxFactory obxFactory = ObxFactory.getInstance();
328-
IsConfigured isConfigured = (IsConfigured)obxFactory.toObject(data);
326+
IsConfigured isConfigured = ObxFactory.getInstance().toObject(IsConfigured.class, data);
329327

330328
if (logger.isInfoEnabled()) {
331329
logger.info("IsConfigured protocol received. Client thing ID: {}.", isConfigured.getThingId());
@@ -339,13 +337,13 @@ private void processIsConfigured(byte[] data) throws CommunicationException, Bxm
339337
logger.info("Client which's thing ID is {} has been configured. Sending Configured protocol to it.", isConfigured.getThingId() );
340338
}
341339

342-
communicator.send(address, obxFactory.toBinary(new Configured()));
340+
communicator.send(address, ObxFactory.getInstance().toBinary(new Configured()));
343341
} else {
344342
if (logger.isInfoEnabled()) {
345343
logger.info("Client which's thing ID is {} hasn't been configured. Sending NotConfigured protocol to it.", isConfigured.getThingId() );
346344
}
347345

348-
communicator.send(address, obxFactory.toBinary(new NotConfigured()));
346+
communicator.send(address, ObxFactory.getInstance().toBinary(new NotConfigured()));
349347
}
350348
}
351349

client/thing/src/main/java/com/thefirstlineofcode/sand/client/thing/obx/ObxFactory.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
import com.thefirstlineofcode.basalt.oxm.coc.CocParserFactory;
2525
import com.thefirstlineofcode.basalt.oxm.coc.CocTranslatorFactory;
2626
import com.thefirstlineofcode.basalt.oxm.coc.annotations.ProtocolObject;
27+
import com.thefirstlineofcode.basalt.oxm.parsing.FlawedProtocolObject;
2728
import com.thefirstlineofcode.basalt.xmpp.core.MessageProtocolChain;
2829
import com.thefirstlineofcode.basalt.xmpp.core.Protocol;
2930
import com.thefirstlineofcode.basalt.xmpp.core.ProtocolChain;
31+
import com.thefirstlineofcode.basalt.xmpp.core.ProtocolException;
32+
import com.thefirstlineofcode.basalt.xmpp.core.stanza.error.ServiceUnavailable;
3033
import com.thefirstlineofcode.basalt.xmpp.im.stanza.Message;
3134
import com.thefirstlineofcode.sand.protocols.actuator.Execution;
3235
import com.thefirstlineofcode.sand.protocols.actuator.LanExecution;
@@ -303,7 +306,13 @@ private void registerObjectTypeIfNeed(Class<?> type) {
303306
public <T> T toObject(Class<T> type, byte[] data) throws BxmppConversionException {
304307
registerObjectTypeIfNeed(type);
305308

306-
return getMessage(data).getObject();
309+
T obj = getMessage(data).getObject();
310+
if (FlawedProtocolObject.isFlawed(obj)) {
311+
throw new ProtocolException(new ServiceUnavailable(String.format(
312+
"Flawed protocol object: %s.", obj.toString())));
313+
}
314+
315+
return obj;
307316
}
308317

309318
@Override
@@ -389,7 +398,13 @@ public void registerLanData(Class<?> lanDataType) {
389398

390399
@Override
391400
public Object toObject(byte[] data) throws BxmppConversionException {
392-
return getMessage(data).getObject();
401+
Object obj = getMessage(data).getObject();
402+
if (FlawedProtocolObject.isFlawed(obj)) {
403+
throw new ProtocolException(new ServiceUnavailable(String.format(
404+
"Flawed protocol object: %s.", obj.toString())));
405+
}
406+
407+
return obj;
393408
}
394409

395410
private Message getMessage(byte[] data) throws BxmppConversionException {

demo/mud_adaptations/mud_arduino_avr/library.properties

Lines changed: 0 additions & 10 deletions
This file was deleted.

demo/mud_adaptations/mud_arduino_avr/src/mcu_board_adaptation.cpp

Lines changed: 0 additions & 276 deletions
This file was deleted.

demo/mud_adaptations/mud_arduino_avr/src/mcu_board_adaptation.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)