Skip to content

Commit

Permalink
Merge pull request #18 from openremote/rework/mqtt-handler-rewrite
Browse files Browse the repository at this point in the history
Rework/mqtt handler rewrite
  • Loading branch information
pankalog authored Jan 31, 2024
2 parents a6c2686 + 9b55162 commit de322a4
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.openremote.manager.custom.telematics;

/*
* Interface to be implemented by all handlers for device-specific payload parsing of Telematics equipment.
*
*
* */
public interface TelematicsDeviceProcessor {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openremote.manager.custom.teltonika;
package org.openremote.manager.custom.telematics.processors.teltonika;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -10,7 +10,7 @@
import org.openremote.container.util.UniqueIdentifierGenerator;
import org.openremote.manager.asset.AssetProcessingService;
import org.openremote.manager.asset.AssetStorageService;
import org.openremote.manager.custom.teltonika.helpers.TeltonikaAttributeProcessingHelper;
import org.openremote.manager.custom.telematics.processors.teltonika.helpers.TeltonikaAttributeProcessingHelper;
import org.openremote.manager.datapoint.AssetDatapointService;
import org.openremote.manager.mqtt.MQTTHandler;
import org.openremote.manager.mqtt.Topic;
Expand All @@ -35,7 +35,6 @@
import java.nio.file.Paths;
import java.sql.Timestamp;
import java.text.MessageFormat;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand Down Expand Up @@ -509,6 +508,7 @@ private void createNewAsset(String newDeviceId, String newDeviceImei, String rea

TeltonikaConfiguration config = getConfig();

// This is where you would specify the Asset type that is inherited from the CarAsset class.
CarAsset testAsset = new CarAsset("Teltonika Asset "+newDeviceImei)
.setRealm(realm)
.setModelNumber(getConfig().getDefaultModelNumber())
Expand Down Expand Up @@ -537,8 +537,6 @@ private void createNewAsset(String newDeviceId, String newDeviceImei, String rea
attributes.forEach(attribute -> attribute.setTimestamp(dateVal.getTime()));
});



updateAsset(testAsset, attributes);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openremote.manager.custom.teltonika.helpers;
package org.openremote.manager.custom.telematics.processors.teltonika.helpers;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -172,6 +172,7 @@ public static AttributeMap getAttributes(Map<Map.Entry<String, TeltonikaParamete
try{
long unixTimestampMillis = Long.parseLong(entry.getValue().toString());
Timestamp deviceTimestamp = Timestamp.from(Instant.ofEpochMilli(unixTimestampMillis));
//Maybe this attribute should have the value set as server time and the device time as a timestamp?
attributes.add(new Attribute<>(CarAsset.LAST_CONTACT, deviceTimestamp, deviceTimestamp.getTime()));

//Update all affected attribute timestamps
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.openremote.manager.custom.telematics.processors.teltonika.helpers;

import org.openremote.model.teltonika.TeltonikaParameter;

import java.util.Map;

public class TeltonikaParameterData {
String key;
TeltonikaParameter value;

public TeltonikaParameterData(String key, TeltonikaParameter value) {
this.key = key;
this.value = value;
}

public String getParameterId() {
return key;
}

public TeltonikaParameter getParameter() {
return value;
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.openremote.manager.custom.teltonika.TeltonikaMQTTHandler
org.openremote.manager.custom.telematics.processors.teltonika.TeltonikaMQTTHandler
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"hwSupport",
"parameterGroup"
})
//TODO: Create interface for this class called TelematicsDeviceParameter
public class TeltonikaParameter implements Serializable {

@JsonProperty("propertyIdInAvlPacket")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.openremote.manager.asset.AssetProcessingService
import org.openremote.manager.asset.AssetStorageService
import org.openremote.manager.event.ClientEventService
import org.openremote.manager.mqtt.MQTTBrokerService
import org.openremote.manager.custom.teltonika.TeltonikaMQTTHandler
import org.openremote.manager.custom.telematics.processors.teltonika.TeltonikaMQTTHandler
import org.openremote.manager.setup.SetupService
import org.openremote.manager.setup.custom.CustomKeycloakSetup
import org.openremote.model.Constants
Expand Down

0 comments on commit de322a4

Please sign in to comment.