Skip to content

Commit

Permalink
store cell network information (Freematics protocol)
Browse files Browse the repository at this point in the history
  • Loading branch information
soshial committed Sep 29, 2021
1 parent 60cf59c commit ea9238c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/traccar/model/CellTower.java
Expand Up @@ -57,6 +57,11 @@ public void setRadioType(String radioType) {
this.radioType = radioType;
}

/**
* A valid CID ranges:<br/>
* - from 0 to 65535 (2^16−1) on GSM and CDMA networks<br/>
* - from 0 to 268,435,455 (2^28−1) on UMTS and LTE networks.
*/
private Long cellId;

public Long getCellId() {
Expand All @@ -67,6 +72,9 @@ public void setCellId(Long cellId) {
this.cellId = cellId;
}

/**
* Unsigned 16-bit number
*/
private Integer locationAreaCode;

public Integer getLocationAreaCode() {
Expand Down Expand Up @@ -97,6 +105,9 @@ public void setMobileNetworkCode(Integer mobileNetworkCode) {
this.mobileNetworkCode = mobileNetworkCode;
}

/**
* Signal strength in dBm
*/
private Integer signalStrength;

public Integer getSignalStrength() {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/traccar/model/Network.java
Expand Up @@ -20,6 +20,10 @@
import java.util.ArrayList;
import java.util.Collection;

/**
* This class contains cell tower and Wi-Fi network information. Traccar can use this information to determine
* approximate location (when GPS is not available) via location-based service (LBS) providers.
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Network {

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/traccar/model/Position.java
Expand Up @@ -296,6 +296,9 @@ public void setAccuracy(double accuracy) {
this.accuracy = accuracy;
}

/**
* Cell towers and Wi-Fi networks, that were in the vicinity, when Position was saved.
*/
private Network network;

public Network getNetwork() {
Expand Down
33 changes: 31 additions & 2 deletions src/main/java/org/traccar/protocol/FreematicsProtocolDecoder.java
Expand Up @@ -23,6 +23,8 @@
import org.traccar.helper.Checksum;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.CellTower;
import org.traccar.model.Network;
import org.traccar.model.Position;

import java.net.SocketAddress;
Expand Down Expand Up @@ -119,9 +121,15 @@ private Object decodePosition(long deviceId, String sentence) {
boolean receivedFixTime = false, receivedFixDate = false, receivedDeviceTicker = false;
long deviceLocalTimeMs = 0;

// cell tower
CellTower cellTower = new CellTower();
boolean receivedCellInfo = false;

Double memsTemperature = null;
Double cpuTemperature = null;

position.setNetwork(new Network(cellTower));

for (String pair : sentence.split(",")) {
String[] data = pair.split("[=:]");
int key;
Expand Down Expand Up @@ -191,8 +199,25 @@ private Object decodePosition(long deviceId, String sentence) {
case 0x24:
position.set(Position.KEY_BATTERY, Integer.parseInt(value) * 0.01);
break;
case 0x81:
position.set(Position.KEY_RSSI, Integer.parseInt(value));
case 0x40:
cellTower.setSignalStrength(Integer.parseInt(value));
receivedCellInfo = true;
break;
case 0x41:
cellTower.setMobileCountryCode(Integer.parseInt(value));
receivedCellInfo = true;
break;
case 0x42:
cellTower.setMobileNetworkCode(Integer.parseInt(value));
receivedCellInfo = true;
break;
case 0x43:
cellTower.setLocationAreaCode(Integer.parseInt(value));
receivedCellInfo = true;
break;
case 0x44:
cellTower.setCellId(Long.parseLong(value));
receivedCellInfo = true;
break;
case 0x82:
cpuTemperature = Integer.parseInt(value) * 0.1;
Expand Down Expand Up @@ -229,6 +254,10 @@ private Object decodePosition(long deviceId, String sentence) {
position.setDeviceTime(new Date(deviceLocalTimeMs));
}

if (receivedCellInfo) {
position.setNetwork(new Network(cellTower));
}

// MEMS temperature sensor is more accurate, but MEMS might be turned off
Double deviceTemperature = memsTemperature == null ? cpuTemperature : memsTemperature;
if (deviceTemperature != null) {
Expand Down

0 comments on commit ea9238c

Please sign in to comment.