use of org.openremote.agent.protocol.bluetooth.mesh.transport.MeshModel in project openremote by openremote.
the class BluetoothMeshNetwork method addMeshModel.
public synchronized void addMeshModel(int address, int modelId, int appKeyIndex) {
MeshNetwork network = getMeshNetwork();
MeshModel model = SigModelParser.getSigModel(modelId);
if (model == null) {
LOG.severe("Bluetooth Mesh model with ID='" + String.format("0x%04X", modelId) + "' is not supported.");
return;
}
// TODO: proper handling of unicast and group addresses
if (address < 0xC000) {
ProvisionedMeshNode node = getNode(address);
if (node == null) {
List<NetworkKey> networkKeys = new ArrayList<>(1);
networkKeys.add(networkKey);
List<ApplicationKey> applicationKeys = new ArrayList<>(applicationKeyMap.size());
applicationKeys.addAll(applicationKeyMap.values());
node = new ProvisionedMeshNode(network.getSelectedProvisioner(), networkKeys, applicationKeys);
node.setUnicastAddress(address);
}
Map<Integer, Element> oldElementMap = node.getElements();
Map<Integer, Element> newElementMap = new HashMap<>();
Map<Integer, MeshModel> newModelMap = new HashMap<>();
Element oldElement = oldElementMap.get(address);
if (oldElement != null) {
newModelMap.putAll(oldElement.getMeshModels());
}
int locationDescriptor = 0;
model.setBoundAppKeyIndex(appKeyIndex);
newModelMap.put(modelId, model);
Element newElement = new Element(address, locationDescriptor, newModelMap);
newElementMap.putAll(oldElementMap);
newElementMap.put(address, newElement);
node.setElements(newElementMap);
if (getNode(address) == null) {
network.nodes.add(node);
network.sequenceNumbers.put(node.getUnicastAddress(), node.getSequenceNumber());
network.unicastAddress = network.nextAvailableUnicastAddress(node.getNumberOfElements(), network.getSelectedProvisioner());
node.setMeshUuid(network.getMeshUUID());
network.loadSequenceNumbers();
}
}
addShadowModel(address, modelId, appKeyIndex);
}
Aggregations