Skip to content

Commit 4b3bded

Browse files
committed
1. Use new allocation data structure. 2. Rename TACP to TUXP.
1 parent 2266e2a commit 4b3bded

File tree

51 files changed

+207
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+207
-149
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@
33
import com.thefirstlineofcode.sand.client.concentrator.IConcentrator;
44
import com.thefirstlineofcode.sand.client.thing.commuication.IAddressConfigurator;
55
import com.thefirstlineofcode.sand.client.thing.commuication.ICommunicator;
6-
import com.thefirstlineofcode.sand.protocols.thing.IAddress;
6+
import com.thefirstlineofcode.sand.protocols.lora.dac.Allocation;
77
import com.thefirstlineofcode.sand.protocols.thing.lora.LoraAddress;
88

9-
public interface ILoraDacService<OA extends IAddress> extends IAddressConfigurator<ICommunicator<OA, LoraAddress, byte[]>,
9+
public interface ILoraDacService extends IAddressConfigurator<ICommunicator<LoraAddress, LoraAddress, byte[]>,
1010
LoraAddress, byte[]> {
1111
public interface Listener {
1212
void addressConfigured(String thingId, String registrationCode, LoraAddress address);
1313
}
1414

15+
public interface Allocator {
16+
Allocation allocate(ILoraDacService dacService);
17+
}
18+
1519
void setUplinkChannelBegin(int uplinkChannelBegin);
20+
int getUplinkChannelBegin();
1621
void setUplinkChannelEnd(int uplinkChannelEnd);
17-
void setUplinkAddress(byte uplinkAddressHighByte, byte uplinkAddressLowByte);
22+
int getUplinkChannelEnd();
23+
void setUplinkAddress(byte[] uplinkAddress);
24+
byte[] getUplinkAddress();
1825
void setConcentrator(IConcentrator concentrator);
26+
IConcentrator getConcentrator();
1927
void start();
2028
boolean isStarted();
2129
void stop();
@@ -27,4 +35,5 @@ public interface Listener {
2735
LoraAddress getDacServiceAddress();
2836
void setThingCommunicationChannel(byte thingCommunicationChannel);
2937
byte getThingCommunicationChannel();
38+
void setAddressAllocator(Allocator addressAllocator);
3039
}

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

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
import com.thefirstlineofcode.sand.protocols.lora.dac.Reconfigure;
3030
import com.thefirstlineofcode.sand.protocols.thing.lora.LoraAddress;
3131

32-
public class LoraDacService implements ILoraDacService<LoraAddress>, ICommunicationListener<LoraAddress, LoraAddress, byte[]> {
32+
public class LoraDacService implements ILoraDacService, ICommunicationListener<LoraAddress, LoraAddress, byte[]> {
3333
private static final byte DEFAULT_DAC_SERVICE_CHANNEL = 0x1f;
3434
private static final LoraAddress DEFAULT_DAC_SERVICE_ADDRESS = new LoraAddress(new byte[] {(byte)0xef, (byte)0xef, DEFAULT_DAC_SERVICE_CHANNEL});
3535

3636
private static final byte DEFAULT_THING_COMMUNICATION_CHANNEL = 0x17;
3737

3838
private static final int MAX_MESSAGES_SIZE = 1024 * 16;
3939

40-
private static final String PROTOCOL_NAMESPACE_LORA_DAC = "urn:leps:tacp:lora-dac";
40+
private static final String PROTOCOL_NAMESPACE_LORA_DAC = "urn:leps:tuxp:lora-dac";
4141

4242
private static final Logger logger = LoggerFactory.getLogger(LoraDacService.class);
4343

@@ -71,13 +71,14 @@ public enum State {
7171
private LoraAddress nodeAllocatedAddress;
7272

7373
private List<Listener> listeners;
74+
private Allocator addressAllocator;
7475

7576
private byte[] messages;
7677
private int messagesLength;
7778

7879
public LoraDacService(ICommunicator<LoraAddress, LoraAddress, byte[]> communicator,
79-
int uplinkChannelBegin, int uplinkChannelEnd, byte uplinkAddressHighByte,
80-
byte uplinkAddressLowByte, IConcentrator concentrator, INotifier notifier) {
80+
int uplinkChannelBegin, int uplinkChannelEnd, byte[] uplinkAddress,
81+
IConcentrator concentrator, INotifier notifier) {
8182
this.concentrator = concentrator;
8283

8384
dacServiceAddress = DEFAULT_DAC_SERVICE_ADDRESS;
@@ -88,7 +89,7 @@ public LoraDacService(ICommunicator<LoraAddress, LoraAddress, byte[]> communicat
8889

8990
setUplinkChannelBegin(uplinkChannelBegin);
9091
setUplinkChannelEnd(uplinkChannelEnd);
91-
setUplinkAddress(uplinkAddressHighByte, uplinkAddressLowByte);
92+
setUplinkAddress(uplinkAddress);
9293
setCommunicator(communicator);
9394

9495
this.notifier = notifier;
@@ -242,15 +243,12 @@ private void doNegotiate(LoraAddress peerAddress, byte[] message) throws Communi
242243
return;
243244
}
244245

245-
Allocation allocation = new Allocation();
246-
allocation.setUplinkChannelBegin(uplinkChannelBegin);
247-
allocation.setUplinkChannelEnd(uplinkChannelEnd);
248-
allocation.setUplinkAddressHighByte(uplinkAddressHighByte);
249-
allocation.setUplinkAddressLowByte(uplinkAddressLowByte);
250-
251-
int nodeLanId = concentrator.getBestSuitedNewLanId();
252-
nodeAllocatedAddress = new LoraAddress(new byte[] {0x0, Byte.parseByte(String.valueOf(nodeLanId)), thingCommunicationChannel});
253-
allocation.setAllocatedAddress(nodeAllocatedAddress.getBytes());
246+
Allocation allocation;
247+
if (addressAllocator != null) {
248+
allocation = addressAllocator.allocate(this);
249+
} else {
250+
allocation = allocate();
251+
}
254252

255253
if (logger.isInfoEnabled()) {
256254
logger.info("Node allocation: {}: {} => {}.", nodeThingId,
@@ -299,6 +297,20 @@ private void doNegotiate(LoraAddress peerAddress, byte[] message) throws Communi
299297
throw new IllegalStateException(String.format("Illegal configuration state: %s.", state));
300298
}
301299
}
300+
301+
protected Allocation allocate() {
302+
Allocation allocation = new Allocation();
303+
allocation.setUplinkChannelBegin(uplinkChannelBegin);
304+
allocation.setUplinkChannelEnd(uplinkChannelEnd);
305+
allocation.setUplinkAddressHighByte(uplinkAddressHighByte);
306+
allocation.setUplinkAddressLowByte(uplinkAddressLowByte);
307+
308+
int nodeLanId = concentrator.getBestSuitedNewLanId();
309+
nodeAllocatedAddress = new LoraAddress(new byte[] {0x0, Byte.parseByte(String.valueOf(nodeLanId)), thingCommunicationChannel});
310+
allocation.setAllocatedAddress(nodeAllocatedAddress.getBytes());
311+
312+
return allocation;
313+
}
302314

303315
@Override
304316
public void reset() {
@@ -508,16 +520,16 @@ public void setConcentrator(IConcentrator concentrator) {
508520
this.concentrator = concentrator;
509521
}
510522

511-
512-
523+
@Override
513524
public int getUplinkChannelBegin() {
514525
return uplinkChannelBegin;
515526
}
516527

517528
public void setUplinkChannelBegin(int uplinkChannelBegin) {
518529
this.uplinkChannelBegin = uplinkChannelBegin;
519530
}
520-
531+
532+
@Override
521533
public int getUplinkChannelEnd() {
522534
return uplinkChannelEnd;
523535
}
@@ -527,8 +539,26 @@ public void setUplinkChannelEnd(int uplinkChannelEnd) {
527539
}
528540

529541
@Override
530-
public void setUplinkAddress(byte uplinkAddressHighByte, byte uplinkAddressLowByte) {
531-
this.uplinkAddressHighByte = uplinkAddressHighByte;
532-
this.uplinkAddressLowByte = uplinkAddressLowByte;
542+
public void setUplinkAddress(byte[] uplinkAddress) {
543+
if (uplinkAddress == null || uplinkAddress.length != 2)
544+
throw new IllegalArgumentException("Null or illegal uplink address.");
545+
546+
this.uplinkAddressHighByte = uplinkAddress[0];
547+
this.uplinkAddressLowByte = uplinkAddress[1];
548+
}
549+
550+
@Override
551+
public byte[] getUplinkAddress() {
552+
return new byte[] {uplinkAddressHighByte, uplinkAddressLowByte};
553+
}
554+
555+
@Override
556+
public void setAddressAllocator(Allocator addressAllocator) {
557+
this.addressAllocator = addressAllocator;
558+
}
559+
560+
@Override
561+
public IConcentrator getConcentrator() {
562+
return concentrator;
533563
}
534564
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import com.thefirstlineofcode.sand.protocols.lora.dac.ResetLoraDacService;
88

99
public class ResetLoraDacServiceExecutor implements IExecutor<ResetLoraDacService> {
10-
private ILoraDacService<?> loraDacService;
10+
private ILoraDacService loraDacService;
1111

12-
public ResetLoraDacServiceExecutor(ILoraDacService<?> loraDacService) {
12+
public ResetLoraDacServiceExecutor(ILoraDacService loraDacService) {
1313
this.loraDacService = loraDacService;
1414
}
1515

client/lora-gateway/src/main/java/com/thefirstlineofcode/sand/client/lora/gateway/ILoraGateway.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public enum Mode {
2323
void setUplinkCommunicators(List<ICommunicator<LoraAddress, LoraAddress, byte[]>> uplinkCommunicators);
2424
void setThingCommunicationChannel(byte thingCommunicationChannel);
2525
IConcentrator getConcentrator();
26-
ILoraDacService<LoraAddress> getDacService();
26+
ILoraDacService getDacService();
2727
void start();
2828
void stop();
2929
boolean isStarted();

client/lora-gateway/src/main/java/com/thefirstlineofcode/sand/client/lora/gateway/LoraGateway.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class LoraGateway implements ILoraGateway, ILoraDacService.Listener {
3030
private ICommunicator<LoraAddress, LoraAddress, byte[]> downlinkCommunicator;
3131
private List<ICommunicator<LoraAddress, LoraAddress, byte[]>> uplinkCommunicators;
3232
private IConcentrator concentrator;
33-
private ILoraDacService<LoraAddress> dacService;
33+
private ILoraDacService dacService;
3434

3535
private byte thingCommunicationChannel;
3636

@@ -104,12 +104,12 @@ public IConcentrator getConcentrator() {
104104
}
105105

106106
@Override
107-
public ILoraDacService<LoraAddress> getDacService() {
107+
public ILoraDacService getDacService() {
108108
if (dacService == null) {
109109
INotificationService notificationService = chatServices.createApi(INotificationService.class);
110110
INotifier notifier = notificationService.getNotifier();
111111
dacService = new LoraDacService(downlinkCommunicator, 0, uplinkCommunicators.size() - 1,
112-
DEFAULT_UPLINK_ADDRESS_HIGH_BYTE, DEFAULT_UPLINK_ADDRESS_LOW_BYTE,
112+
new byte[] {DEFAULT_UPLINK_ADDRESS_HIGH_BYTE, DEFAULT_UPLINK_ADDRESS_LOW_BYTE},
113113
getConcentrator(), notifier);
114114
dacService.setThingCommunicationChannel(thingCommunicationChannel);
115115
}

demo/mud_adaptations/mud_arduino_avr/src/mcu_board_adaptation.cpp

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
#include <ArduinoUniqueID.h>
22
#include <EEPROM.h>
33

4-
#include <tacp.h>
4+
#include <tuxp.h>
55
#include <thing.h>
66
#include <debug.h>
77
#include <radio_module_adaptation.h>
88

99
#include "mcu_board_adaptation.h"
1010

11+
#if defined(ARDUINO_UNO) && defined(USE_SOFTWARE_SERIAL)
12+
SoftwareSerial softwareSerial(SOFTWARE_SERIAL_RX_PIN, SOFTWARE_SERIAL_TX_PIN);
13+
#endif
14+
1115
static char *modelName;
1216

1317
void debugOutputImpl(const char out[]) {
1418
Serial.println(out);
1519
}
1620

1721
void printToSerialPort(char title[], uint8_t message[], int size) {
18-
#ifdef ENABLE_DEBUG
22+
#if defined(ENABLE_DEBUG)
1923

2024
Serial.print(title);
2125

@@ -148,8 +152,10 @@ void loadThingInfoImpl(ThingInfo *thingInfo) {
148152
thingInfo->thingId = NULL;
149153
thingInfo->dacState = NONE;
150154
thingInfo->address = NULL;
151-
thingInfo->gatewayDownlinkAddress = NULL;
152-
thingInfo->gatewayUplinkAddress = NULL;
155+
thingInfo->uplinkChannelBegin = -1;
156+
thingInfo->uplinkChannelEnd = -1;
157+
thingInfo->uplinkAddressHighByte = 0xff;
158+
thingInfo->uplinkAddressLowByte = 0xff;
153159
} else {
154160
int position = 1;
155161
thingInfo->thingId = malloc(sizeof(char) * (thingIdSize + 1));
@@ -165,14 +171,19 @@ void loadThingInfoImpl(ThingInfo *thingInfo) {
165171

166172
if (thingInfo->dacState == ALLOCATED ||
167173
thingInfo->dacState == CONFIGURED) {
174+
EEPROM.get(position, thingInfo->uplinkChannelBegin);
175+
position += 2;
176+
177+
EEPROM.get(position, thingInfo->uplinkChannelEnd);
178+
position += 2;
179+
180+
thingInfo->uplinkAddressHighByte = EEPROM.read(position);
181+
position++;
182+
thingInfo->uplinkAddressLowByte = EEPROM.read(position);
183+
position++;
184+
168185
thingInfo->address = malloc(SIZE_RADIO_ADDRESS);
169-
position = readAddressFromEepRom(thingInfo->address, position);
170-
171-
thingInfo->gatewayDownlinkAddress = malloc(SIZE_RADIO_ADDRESS);
172-
position = readAddressFromEepRom(thingInfo->gatewayDownlinkAddress, position);
173-
174-
thingInfo->gatewayUplinkAddress = malloc(SIZE_RADIO_ADDRESS);
175-
position = readAddressFromEepRom(thingInfo->gatewayUplinkAddress, position);
186+
readAddressFromEepRom(thingInfo->address, position);
176187
}
177188
}
178189

@@ -206,9 +217,17 @@ void saveThingInfoImpl(ThingInfo *thingInfo) {
206217

207218
if (thingInfo->dacState == ALLOCATED ||
208219
thingInfo->dacState == CONFIGURED) {
220+
EEPROM.put(position, thingInfo->uplinkChannelBegin);
221+
position += 2;
222+
EEPROM.put(position, thingInfo->uplinkChannelEnd);
223+
position += 2;
224+
225+
EEPROM.write(position, thingInfo->uplinkAddressHighByte);
226+
position++;
227+
EEPROM.write(position, thingInfo->uplinkAddressLowByte);
228+
position++;
229+
209230
position = writeAddressToEepRom(thingInfo->address, position);
210-
position = writeAddressToEepRom(thingInfo->gatewayDownlinkAddress, position);
211-
writeAddressToEepRom(thingInfo->gatewayUplinkAddress, position);
212231
}
213232

214233
debugOutThingInfo(thingInfo);
@@ -218,13 +237,14 @@ void resetAll() {
218237
EEPROM.write(EEPROM.length() - 1, 0);
219238
}
220239

221-
void configureMcuBoard(char *_modelName) {
240+
void configureMcuBoard(const char *_modelName) {
222241
int modelNameLength = strlen(_modelName);
223242
modelName = malloc(sizeof(char) * (modelNameLength + 1));
224243
strcpy(modelName, _modelName);
225244

226245
#ifdef ENABLE_DEBUG
227246
configureSerial();
247+
Serial.println("Serial has configured.");
228248
setDebugOutputter(debugOutputImpl);
229249
#endif
230250

@@ -242,7 +262,9 @@ void configureMcuBoard(char *_modelName) {
242262
if (lastByteOfEepRom != 0xff ||
243263
nextToLastByteOfEepRom != 0xfe ||
244264
theThirdToLastByteOfEepRom != 0xfd) {
265+
#ifdef ENABLE_DEBUG
245266
Serial.println(F("EEPROM not initialized. Initlize it now."));
267+
#endif
246268
initializeEepRom(eepRomLength);
247269
}
248270
}

demo/server/src/main/java/com/thefirstlineofcode/sand/demo/server/AclPipelinePreprocessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private boolean isConcentratorProtocolGroupObject(Object obj) {
103103
if (pObject == null)
104104
throw new ProtocolException(new InternalServerError("Not project object."));
105105

106-
return pObject.namespace().equals("urn:leps:tacp:concentrator");
106+
return pObject.namespace().equals("urn:leps:tuxp:concentrator");
107107
}
108108

109109
private Object afterParsingPing(JabberId from, Iq iq) {
@@ -157,7 +157,7 @@ private boolean isTacpAction(Object action) {
157157
if (pObject == null)
158158
throw new ProtocolException(new InternalServerError("The action isn't a project object."));
159159

160-
return pObject.namespace().startsWith("urn:leps:tacp:");
160+
return pObject.namespace().startsWith("urn:leps:tuxp:");
161161
}
162162

163163
private Object afterParsingLocateThings(JabberId from, Iq iq, LocateThings locateThings) {

demo/things/lgsc-01/src/main/java/com/thefirstlineofcode/sand/demo/things/lgsc01/LoraGatewayAndCamera.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public IExecutor<ChangeWorkingMode> create() {
418418
};
419419
}
420420

421-
private IExecutorFactory<?> createResetDacServiceExecutatorFactory(ILoraDacService<?> loraDacService) {
421+
private IExecutorFactory<?> createResetDacServiceExecutatorFactory(ILoraDacService loraDacService) {
422422
return new IExecutorFactory<ResetLoraDacService>() {
423423
private IExecutor<ResetLoraDacService> executor = new ResetLoraDacServiceExecutor(loraDacService);
424424

demo/things/sl-02/sl-02.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <Arduino_BuiltIn.h>
22

33
#include <thing.h>
4-
#include <tacp.h>
4+
#include <tuxp.h>
55
#include <debug.h>
66
#include <mcu_board_adaptation.h>
77
#include <radio_module_adaptation.h>

emulators/lora/lora-gateway/src/main/java/com/thefirstlineofcode/sand/emulators/lora/gateway/Gateway.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,7 @@ private void configureLoraGateway(ILoraGateway loraGateway) {
540540
concentrator.registerLanExecutionErrorConverter(getSle01ModelLanExecutionErrorConverter());
541541
concentrator.addListener(this);
542542

543-
ILoraDacService<LoraAddress> dacService = loraGateway.getDacService();
544-
dacService.addListener(this);
543+
loraGateway.getDacService().addListener(this);
545544
}
546545

547546
private void doConnect() throws ConnectionException, AuthFailureException {

0 commit comments

Comments
 (0)