Skip to content

Commit

Permalink
Merge pull request #107 from urbancamo/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
urbancamo authored Aug 13, 2024
2 parents b2fb477 + 56ec095 commit 90fc588
Show file tree
Hide file tree
Showing 666 changed files with 203,293 additions and 124 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<groupId>uk.m0nom</groupId>
<artifactId>adif-processor</artifactId>
<version>1.4.11</version>
<version>1.4.12</version>

<name>ADIF Processor</name>
<url>https://github.com/urbancamo/adif-processor</url>
Expand Down
20 changes: 16 additions & 4 deletions src/doc/VPS-install.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ cd $WORKDIR
mvn -Pprod spring-boot:run >> $LOGDIR/adifproc.log 2>&1 &
```

Create a systemd unit file `adifproc.service` in `/etc/systemd/system` with the following contents:
Create a systemd unit file `adifproc.service` in `/etc/systemd/system` with the following contents
(we have docker.service in the list so that the postgres container is started on boot before the adifproc application):

```
[Unit]
Description=ADIF Processor
After=syslog.target network.target
After=syslog.target network.target docker.service
[Service]
SuccessExitStatus=143
User=adifproc
Expand Down Expand Up @@ -107,7 +108,6 @@ Instructions here: https://www.docker.com/blog/how-to-use-the-postgres-docker-of

```bash
docker pull postgres
#docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
docker container create --name postgres-container -e POSTGRES_PASSWORD=<password> -p 5432:5432 postgres
docker update --restart=always postgres-container
```
Expand All @@ -122,7 +122,7 @@ psql -h localhost -U postgres -p 5432 -d
select * from log;
```

Open the port 5432 in the firewall:
Open port 5432 in the firewall for remote access to the database:

```bash
sudo ufw allow from any to any port 5432 proto tcp
Expand Down Expand Up @@ -193,3 +193,15 @@ server {
```bash
sudo service nginx restart
```

# Control Options

```bash
sudo service adifproc start
sudo service adifproc stop
sudo service adifproc restart
docker container ls
docker container stop postgres-container
docker container start postgres-container
```

4 changes: 2 additions & 2 deletions src/main/java/uk/m0nom/adifproc/adif3/io/Adif3FileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.marsik.ham.adif.AdiReader;
import org.marsik.ham.adif.Adif3;
import org.marsik.ham.adif.Adif3Record;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Component;
import uk.m0nom.adifproc.qsofile.QsoFileReader;

import java.io.BufferedReader;
Expand All @@ -16,7 +16,7 @@
/**
* Wrapper to the Adif3 library for reading ADIF format files
*/
@Service
@Component
public class Adif3FileReader implements QsoFileReader {

public Adif3 read(String filename, String encoding, boolean sort) throws IOException {
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/uk/m0nom/adifproc/adif3/io/Adif3FileWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

import org.marsik.ham.adif.AdiWriter;
import org.marsik.ham.adif.Adif3;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Component;
import uk.m0nom.adifproc.qsofile.QsoFileWriter;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.logging.Logger;

/**
* Wrapper for the Adif3 library for writing ADIF format files
*/
@Service
@Component
public class Adif3FileWriter implements QsoFileWriter {
private static final Logger logger = Logger.getLogger(Adif3FileWriter.class.getName());

public void write(String filename, String encoding, Adif3 log) throws IOException {
AdiWriter writer = new AdiWriter();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package uk.m0nom.adifproc.file;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

@Profile("!dev")
@Service
@Service("awsInternalFileService")
public class AwsInternalFileService implements InternalFileService {
private final AwsS3FileUtils awsS3FileUtils;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.m0nom.adifproc.file;

public interface InternalFileService {

String readFile(String folder, String filePath);
}
15 changes: 5 additions & 10 deletions src/main/java/uk/m0nom/adifproc/file/LocalInternalFileService.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package uk.m0nom.adifproc.file;

import org.springframework.context.annotation.Profile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@Profile("dev")
@Service
@Service("localInternalFileService")
public class LocalInternalFileService implements InternalFileService {

private final String rootPath;

public LocalInternalFileService() {
Path resourceDirectory = Paths.get("src","main","resources");
rootPath = resourceDirectory.toFile().getAbsolutePath();
}
@Value("${adifproc.files.path}")
private String relativeFilesFolder;

@Override
public String readFile(String folder, String file) {
Path filePath = Paths.get(rootPath, folder, file);
Path filePath = Paths.get(relativeFilesFolder, folder, file);
try {
return Files.readString(filePath);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void drawSatelliteTracks(TransformControl control, Folder folder, Satell
// Calculate position of satellite at the time
GlobalCoords3D currentPosition = satellite.getPosition(groundStation, currentContact);
if (lastPosition == null) {
addSatelliteMarker(control, passFolder, satName, passDate, currentPosition, shadow);
addSatelliteMarker(control, passFolder, satName, currentContact, currentPosition, shadow);
} else {
drawSatelliteTrack(passFolder, currentContact, lastPosition, currentPosition, styleUrl, shadow);
}
Expand Down
16 changes: 4 additions & 12 deletions src/main/java/uk/m0nom/adifproc/satellite/ApSatelliteService.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package uk.m0nom.adifproc.satellite;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import uk.m0nom.adifproc.satellite.norad.NoradSatellite;
import uk.m0nom.adifproc.satellite.norad.NoradSatelliteOrbitReader;
import uk.m0nom.adifproc.satellite.satellites.QO100;
import uk.m0nom.adifproc.satellite.satellites.SatelliteNameAliases;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
Expand All @@ -18,6 +17,7 @@
* Satellites can be identified either by their name or a code
*/
@Service
@RequiredArgsConstructor
public class ApSatelliteService {

private final NoradSatelliteOrbitReader noradSatelliteOrbitReader;
Expand All @@ -29,16 +29,8 @@ public class ApSatelliteService {
@Getter
private final ZonedDateTime earliestDataAvailable = ZonedDateTime.of(LocalDateTime.of(2022, 2, 23, 0, 0), ZoneId.of("UTC"));

public ApSatelliteService(NoradSatelliteOrbitReader noradSatelliteOrbitReader, SatelliteNameAliases satelliteNameAliases) {
satellites = new ApSatellites();
this.satelliteNameAliases = satelliteNameAliases;

this.noradSatelliteOrbitReader = noradSatelliteOrbitReader;
satellites.addOrReplace(new QO100(), null);
}

private void loadCurrentNoradSatelliteTleDataIfRequired() {
if (!satellites.hasDataFor(ZonedDateTime.now())) {
if (satellites.noDataFor(ZonedDateTime.now())) {
noradSatelliteOrbitReader.loadCurrentSatelliteTleDataFromCelestrak(satellites);
}
}
Expand All @@ -48,7 +40,7 @@ public ApSatellite getSatellite(String id, ZonedDateTime date) {
if (satellite == null || satellite instanceof NoradSatellite) {
if (ZonedDateTime.now().isEqual(date)) {
loadCurrentNoradSatelliteTleDataIfRequired();
} else if (!satellites.hasDataFor(date)) {
} else if (satellites.noDataFor(date)) {
noradSatelliteOrbitReader.loadTleDataFromArchive(satellites, date);
}
satellite = getSatellite(id);
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/uk/m0nom/adifproc/satellite/ApSatellites.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package uk.m0nom.adifproc.satellite;

import java.time.LocalDate;
import org.springframework.stereotype.Component;
import uk.m0nom.adifproc.satellite.satellites.QO100;

import java.time.ZonedDateTime;
import java.util.*;

@Component
public class ApSatellites {
private final Map<String, ApSatellite> satelliteMap;
private final Map<String, String> satelliteDesignatorToNameMap;
Expand All @@ -14,6 +17,7 @@ public ApSatellites() {
satelliteMap = new HashMap<>();
satelliteDesignatorToNameMap = new HashMap<>();
datesLoaded = new TreeSet<>();
addOrReplace(new QO100(), null);
}

public void addOrReplace(ApSatellite satellite, ZonedDateTime date) {
Expand All @@ -30,8 +34,8 @@ public void addOrReplace(ApSatellite satellite, ZonedDateTime date) {
}
}

public boolean hasDataFor(ZonedDateTime date) {
return date == null || datesLoaded.contains(date);
public boolean noDataFor(ZonedDateTime date) {
return date != null && !datesLoaded.contains(date);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ public void recordSatelliteActivity(Qso qso) {
private void addOrUpdateSatellitePass(Qso qso) {
Adif3Record rec = qso.getRecord();
SatellitePassId id = new SatellitePassId(rec.getSatName(), rec.getQsoDate());
SatellitePass pass = satellitePasses.get(id);
if (pass == null) {
pass = new SatellitePass(id);
satellitePasses.put(id, pass);
}
SatellitePass pass = satellitePasses.computeIfAbsent(id, SatellitePass::new);
pass.addContact(qso);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
import uk.m0nom.adifproc.satellite.ApSatellite;

import java.sql.Date;
import java.time.*;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -54,7 +55,7 @@ public NoradSatellite(ZonedDateTime date, Satellite satelliteTleData) {
}

public void addTleData(ZonedDateTime date, Satellite satellite) {
satelliteTleDataForDate.put(date, satellite);
satelliteTleDataForDate.put(date.truncatedTo(ChronoUnit.DAYS), satellite);
}

@Override
Expand All @@ -66,7 +67,7 @@ public String getIdentifier() {
}

public Satellite getSatelliteTleDataForDate(ZonedDateTime date) {
Satellite satellite = satelliteTleDataForDate.get(date);
Satellite satellite = satelliteTleDataForDate.get(date.truncatedTo(ChronoUnit.DAYS));
if (satellite == null) {
satellite = satelliteTleDataForDate.get(ZonedDateTime.now());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
import com.github.amsacode.predict4java.Satellite;
import com.github.amsacode.predict4java.SatelliteFactory;
import com.github.amsacode.predict4java.TLE;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import uk.m0nom.adifproc.file.InternalFileService;
import uk.m0nom.adifproc.satellite.ApSatellites;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.logging.Logger;

/**
* Reads a set of TLE definitions of satellite orbits from a NASA format TLE file.
* See http://www.celestrak.com for more info on this format.
*
* See <a href="http://www.celestrak.com">http://www.celestrak.com</a> for more info on this format.
* <p>
* DECODE 2-LINE ELSETS WITH THE FOLLOWING KEY:
* 1 AAAAAU 00 0 0 BBBBB.BBBBBBBB .CCCCCCCC 00000-0 00000-0 0 DDDZ
* 2 AAAAA EEE.EEEE FFF.FFFF GGGGGGG HHH.HHHH III.IIII JJ.JJJJJJJJKKKKKZ
Expand All @@ -29,34 +31,32 @@
@Service
public class NoradSatelliteOrbitReader {
public final static String NORAD_TLE_FILE_LOCATION = "http://www.celestrak.com/NORAD/elements/amateur.txt";
private final static String NORAD_S3_FOLDER = "norad";
private final static String NORAD_FOLDER = "norad";

private static final Logger logger = Logger.getLogger(NoradSatelliteOrbitReader.class.getName());

private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");

private final InternalFileService internalFileService;

public NoradSatelliteOrbitReader(InternalFileService internalFileService) {
public NoradSatelliteOrbitReader(@Qualifier("localInternalFileService") InternalFileService internalFileService) {
this.internalFileService = internalFileService;
}

public boolean loadTleDataFromArchive(ApSatellites satellites, ZonedDateTime date) {
public void loadTleDataFromArchive(ApSatellites satellites, ZonedDateTime date) {
String filename = String.format("%s-amateur.txt", dateFormatter.format(date));
String tleDefinitions = internalFileService.readFile(NORAD_S3_FOLDER, filename);
String tleDefinitions = internalFileService.readFile(NORAD_FOLDER, filename);
if (tleDefinitions != null) {
parseTleData(satellites, tleDefinitions, date);
return true;
}
return false;
}

public void loadCurrentSatelliteTleDataFromCelestrak(ApSatellites satellites) {
logger.info(String.format("Reading NORAD Satellite Definition File: %s", NORAD_TLE_FILE_LOCATION));
try {
String tleDefinitions = readTleDataFromCelestrak();
parseTleData(satellites, tleDefinitions, ZonedDateTime.now());
} catch (IOException e) {
} catch (Exception e) {
logger.severe(String.format("Unable to read TLE definition file: %s", NORAD_TLE_FILE_LOCATION));
}
}
Expand Down Expand Up @@ -88,8 +88,8 @@ private void parseTleData(ApSatellites satellites, String tleDefinitions, ZonedD
logger.info(String.format("Read %d satellite definitions", i));
}

private String readTleDataFromCelestrak() throws IOException {
URL u = new URL(NoradSatelliteOrbitReader.NORAD_TLE_FILE_LOCATION);
private String readTleDataFromCelestrak() throws IOException, URISyntaxException {
URL u = new URI(NoradSatelliteOrbitReader.NORAD_TLE_FILE_LOCATION).toURL();
try (InputStream in = u.openStream()) {
return new String(in.readAllBytes(), StandardCharsets.US_ASCII);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.properties.hibernate.hbm2ddl.auto=update

adifproc.files.path=../var
Loading

0 comments on commit 90fc588

Please sign in to comment.