|
1 | | --Generate data |
2 | | --Store data in bufferarray |
3 | | --Send data through TCP to |
| 1 | +# DataGenerator |
| 2 | + |
| 3 | +The DataGenerator simulates live solar car telemetry data by generating realistic sensor readings and GPS coordinates, then transmitting them via UDP packets to the backend dashboard system. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Realistic Data Simulation**: Generates mathematically varied sensor readings using sine wave functions |
| 8 | +- **GPS Route Simulation**: Cycles through real GPS coordinates from `gps_dataset/dataset1.csv` |
| 9 | +- **Real-time Timestamps**: Automatically generates current timestamps for live dashboard compatibility |
| 10 | +- **UDP Transmission**: Sends data packets at 31Hz (32ms intervals) to match real telemetry rates |
| 11 | +- **Binary Protocol**: Uses the same binary format as live car data (`<bsr>` header/footer) |
| 12 | +- **Comprehensive Sensors**: Simulates all solar car systems (battery, motor, GPS, temperatures, etc.) |
| 13 | + |
| 14 | +## Data Sources |
| 15 | + |
| 16 | +### GPS Dataset |
| 17 | +- **File**: `gps_dataset/dataset1.csv` (21,435 coordinate points) |
| 18 | +- **Format**: CSV with columns: `time`, `latitude`, `longitude`, `elevation` |
| 19 | +- **Coverage**: Real GPS route data for realistic car movement simulation |
| 20 | +- **Cycling**: Automatically loops through coordinates when reaching the end |
| 21 | + |
| 22 | +### Sensor Simulation |
| 23 | +- **Algorithm**: Mathematical sine wave generation for realistic sensor variation |
| 24 | +- **Scope**: All fields defined in `../../Backend/Data/sc1-data-format/format.json` |
| 25 | +- **Timestamps**: Live system time (hour, minute, second, millisecond, Unix timestamp) |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +1. Ensure GPS dataset is available in `gps_dataset/dataset1.csv` |
| 30 | +2. Navigate to the DataGenerator directory and run: |
| 31 | + ```bash |
| 32 | + cd DataGenerator |
| 33 | + npm install |
| 34 | + npm start |
| 35 | + ``` |
| 36 | +3. The generator will: |
| 37 | + - Build the project using Babel |
| 38 | + - Start generating and sending UDP packets to `localhost:4003` |
| 39 | + - Cycle through GPS coordinates continuously |
| 40 | + - Generate varied sensor readings in real-time |
| 41 | + |
| 42 | +## Installation |
| 43 | + |
| 44 | +Install the required dependencies: |
| 45 | +```bash |
| 46 | +npm install |
| 47 | +``` |
| 48 | + |
| 49 | +### Dependencies |
| 50 | +- **luxon**: Date/time manipulation for accurate timestamps |
| 51 | +- **express**: Web framework (used for potential future HTTP endpoints) |
| 52 | + |
| 53 | +### Development Dependencies |
| 54 | +- **@babel/cli**: Command-line interface for Babel transpilation |
| 55 | +- **@babel/core**: Core Babel functionality |
| 56 | +- **@babel/preset-env**: Smart preset for modern JavaScript features |
| 57 | + |
| 58 | +## Data Flow |
| 59 | + |
| 60 | +``` |
| 61 | +GPS Dataset + Sensor Simulation → Binary Buffer → UDP Packet → Backend (port 4003) |
| 62 | +``` |
| 63 | + |
| 64 | +The generator: |
| 65 | +1. Loads GPS coordinates from the CSV dataset |
| 66 | +2. Generates sensor readings using mathematical functions |
| 67 | +3. Applies current timestamps to all time-related fields |
| 68 | +4. Packs data into binary format matching the solar car protocol |
| 69 | +5. Transmits UDP packets at 31Hz to simulate real telemetry |
| 70 | + |
| 71 | +## Binary Protocol |
| 72 | + |
| 73 | +The DataGenerator follows the exact binary format used by the actual solar car: |
| 74 | + |
| 75 | +- **Header**: `<bsr>` (5 bytes) |
| 76 | +- **Data**: Binary encoded according to field types defined in the format specification |
| 77 | +- **Footer**: `</bsr>` (6 bytes) |
| 78 | + |
| 79 | +### Supported Data Types |
| 80 | +- `float`: 32-bit floating point (Little Endian) |
| 81 | +- `uint8`: 8-bit unsigned integer |
| 82 | +- `uint16`: 16-bit unsigned integer (Little Endian) |
| 83 | +- `uint64`: 64-bit unsigned integer (Little Endian) |
| 84 | +- `char`: 8-bit character |
| 85 | +- `bool`: Boolean (0 or 1) |
| 86 | + |
| 87 | +## Special Field Handling |
| 88 | + |
| 89 | +### GPS Coordinates |
| 90 | +- `lat`: Latitude from GPS dataset |
| 91 | +- `lon`: Longitude from GPS dataset |
| 92 | +- `elev`: Elevation from GPS dataset |
| 93 | + |
| 94 | +### Timestamps |
| 95 | +- `tstamp_hr`: Current hour (0-23) |
| 96 | +- `tstamp_mn`: Current minute (0-59) |
| 97 | +- `tstamp_sc`: Current second (0-59) |
| 98 | +- `tstamp_ms`: Current millisecond (0-999) |
| 99 | +- `tstamp_unix`: Current Unix timestamp |
| 100 | + |
| 101 | +### Sensor Values |
| 102 | +All other fields are generated using `Math.abs(Math.sin(nextValue)) * 100` to create realistic, continuously varying sensor readings. |
| 103 | + |
| 104 | +## Build Process |
| 105 | + |
| 106 | +The project uses Babel to transpile modern JavaScript: |
| 107 | +1. Source code in `src/` is transpiled to `dist/` |
| 108 | +2. Node.js executes the transpiled code from `dist/server.js` |
| 109 | +3. Babel configuration in `.babelrc` targets current Node.js version |
| 110 | + |
| 111 | +## Architecture |
| 112 | + |
| 113 | +### Core Components |
| 114 | +- **server.js**: Main UDP server and data generation logic |
| 115 | +- **car.js**: Car simulation class (future expansion capability) |
| 116 | +- **constants.json**: Configuration constants (port numbers, etc.) |
| 117 | + |
| 118 | +### Data Format Integration |
| 119 | +- Reads format specification from `../../Backend/Data/sc1-data-format/format.json` |
| 120 | +- Dynamically calculates buffer sizes based on data types |
| 121 | +- Ensures perfect compatibility with backend data parsing |
| 122 | + |
| 123 | +## Development |
| 124 | + |
| 125 | +### Adding New Sensors |
| 126 | +1. Update the format specification in the backend |
| 127 | +2. Add special handling in `server.js` if needed |
| 128 | +3. The generator will automatically include new fields |
| 129 | + |
| 130 | +### Modifying GPS Routes |
| 131 | +1. Replace `gps_dataset/dataset1.csv` with new GPS data |
| 132 | +2. Ensure CSV format: `time,latitude,longitude,elevation` |
| 133 | +3. Update `dataset1.json` if using JSON format instead |
| 134 | + |
| 135 | +## Stopping |
| 136 | + |
| 137 | +Press `Ctrl+C` to gracefully stop the data generator. |
0 commit comments