|
1 | | -# README for nmeaSIMULATOR.py |
2 | | -## Sonar simulator NMEA-0183 |
| 1 | +# SonarSimulator |
3 | 2 |
|
| 3 | +NMEA-0183 depth simulator for serial-connected systems. |
4 | 4 |
|
| 5 | +## Features |
| 6 | +- Generates `SDDPT` or `SDDBT` frames once per second by default. |
| 7 | +- Uses a deterministic depth pattern based on current second (`10 + second`). |
| 8 | +- Sends data over a serial port (`/dev/ttyUSB0` and `9600` by default). |
| 9 | +- Can run manually or as a `systemd` service (`nmea.service`). |
5 | 10 |
|
6 | | -### foncitonnalities : |
| 11 | +## Repository Layout |
| 12 | +- `Script/sonar_simulator.py`: simulator entrypoint. |
| 13 | +- `Script/autolaunch.sh`: launcher used by systemd. |
| 14 | +- `Script/sonar_simulator_unittest.py`: unit tests. |
| 15 | +- `Script/unittest.sh`: test runner. |
| 16 | +- `Install/install.sh`: service installation script. |
| 17 | +- `BOM.txt`: hardware bill of materials. |
7 | 18 |
|
8 | | -Generate nmea-0183 string of types : |
9 | | -- Depth of water (SDDPT) |
| 19 | +## Requirements |
| 20 | +- Ubuntu (tested workflow targets Raspberry Pi with Ubuntu Server). |
| 21 | +- Python 3. |
| 22 | +- `pyserial` (`python3-serial` package). |
10 | 23 |
|
11 | | -### HOW TO MAKE IT WORK: |
12 | | - |
13 | | -On a Raspberry pi : |
| 24 | +## Manual Run |
| 25 | +From repository root: |
14 | 26 |
|
15 | | -1. Install ubuntu server on as sdcard with the user ubuntu |
| 27 | +```bash |
| 28 | +python3 Script/sonar_simulator.py /dev/ttyUSB0 9600 |
| 29 | +``` |
16 | 30 |
|
17 | | -2. Connect the usb serial adapter on the Raspberry |
| 31 | +Optional arguments: |
18 | 32 |
|
19 | | -3. apply the power on the raspberry |
| 33 | +```bash |
| 34 | +python3 Script/sonar_simulator.py /dev/ttyUSB0 9600 --sentence-type dbt --interval 0.5 --iterations 10 |
| 35 | +``` |
20 | 36 |
|
21 | | -4. validate if the serial adapter is detected by the OS |
22 | | - ls /dev/ttyU* |
23 | | - you should see ttyUSB0 |
24 | | - |
25 | | -5. clone the repository in /home/ubuntu |
| 37 | +## Install as Service |
| 38 | +From repository root: |
26 | 39 |
|
27 | | -6. Validate and modify the setting for the serial port and baudrate in the autolaunch.sh |
28 | | - nano /home/ubuntu/SonarSimulator/autolaunch.sh |
29 | | - python /home/ubuntu/SonarSimulator/Script/sonar_simulator_DPT.py /dev/ttyUSB0 9600 |
30 | | - the 2 last argument are the serial port and the baudrate |
31 | | - ex: |
32 | | - python /home/ubuntu/SonarSimulator/Script/sonar_simulator_DPT.py /dev/ttyUSB1 9600 |
33 | | - python /home/ubuntu/SonarSimulator/Script/sonar_simulator_DPT.py /dev/ttyAMA0 115200 |
| 40 | +```bash |
| 41 | +bash Install/install.sh |
| 42 | +``` |
34 | 43 |
|
35 | | -7. go in the install directory and run the installation script |
36 | | - cd /home/ubuntu/SonarSimulator/Install |
37 | | - ./install.sh |
| 44 | +This installs and starts `nmea.service` with default environment values: |
| 45 | +- `SONAR_SERIAL_PORT=/dev/ttyUSB0` |
| 46 | +- `SONAR_BAUD_RATE=9600` |
| 47 | +- `SONAR_SENTENCE_TYPE=dpt` |
38 | 48 |
|
39 | | -The script is installed as a service. |
40 | | -If you do some modification in the autolaunch.sh file you have to relaunch the service. |
| 49 | +Service commands: |
| 50 | + |
| 51 | +```bash |
| 52 | +sudo systemctl status nmea |
41 | 53 | sudo systemctl restart nmea |
| 54 | +sudo systemctl stop nmea |
| 55 | +``` |
| 56 | + |
| 57 | +## Change Serial Port, Baud Rate, or Sentence Type |
| 58 | +Option 1 (recommended): override service environment values in the unit file. |
| 59 | + |
| 60 | +```bash |
| 61 | +sudo systemctl edit --full nmea |
| 62 | +# Update SONAR_SERIAL_PORT, SONAR_BAUD_RATE, and SONAR_SENTENCE_TYPE (dpt or dbt) |
| 63 | +sudo systemctl daemon-reload |
| 64 | +sudo systemctl restart nmea |
| 65 | +``` |
| 66 | + |
| 67 | +Option 2: export environment values before running manually. |
42 | 68 |
|
43 | | -to show the status of the service : sudo systemctl status nmea |
44 | | -to start the service : sudo systemctl start nmea |
45 | | -to stop the service : sudo systemctl stop nmea |
| 69 | +```bash |
| 70 | +SONAR_SERIAL_PORT=/dev/ttyUSB1 SONAR_BAUD_RATE=115200 SONAR_SENTENCE_TYPE=dbt bash Script/autolaunch.sh |
| 71 | +``` |
46 | 72 |
|
| 73 | +## Run Tests |
| 74 | +From repository root: |
47 | 75 |
|
| 76 | +```bash |
| 77 | +bash Script/unittest.sh |
| 78 | +``` |
48 | 79 |
|
| 80 | +## Notes |
| 81 | +- The simulator writes one frame per cycle terminated by `\r\n`. |
| 82 | +- If serial opening fails, the script logs the error and exits cleanly. |
0 commit comments