Open Satyampatil513 opened 1 month ago
import sys import csv import random import time from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget, QTextEdit, QFileDialog from PyQt5.QtCore import QTimer
class TelemetryApp(QMainWindow): def init(self): super().init()
self.initUI() self.telemetry_data = [] self.timer = QTimer() self.timer.timeout.connect(self.generate_dummy_data) self.timer.start(1000) # Generate data every second def initUI(self): self.setWindowTitle('Telemetry Data Logger') self.textEdit = QTextEdit(self) self.textEdit.setReadOnly(True) self.saveButton = QPushButton('Save Data to CSV', self) self.saveButton.clicked.connect(self.save_to_csv) layout = QVBoxLayout() layout.addWidget(self.textEdit) layout.addWidget(self.saveButton) container = QWidget() container.setLayout(layout) self.setCentralWidget(container) self.setGeometry(100, 100, 400, 300) self.show() def generate_dummy_data(self): gnss_time = int(time.time()) latitude = round(random.uniform(-90.0, 90.0), 4) longitude = round(random.uniform(-180.0, 180.0), 4) altitude = round(random.uniform(0.0, 10000.0), 1) satellites = random.randint(1, 12) data = [gnss_time, latitude, longitude, altitude, satellites] self.telemetry_data.append(data) self.textEdit.append(f"Time: {gnss_time}, Lat: {latitude}, Long: {longitude}, Alt: {altitude}, Sats: {satellites}") def save_to_csv(self): options = QFileDialog.Options() fileName, _ = QFileDialog.getSaveFileName(self, "Save Telemetry Data", "", "CSV Files (*.csv);;All Files (*)", options=options) if fileName: with open(fileName, mode='w', newline='') as file: writer = csv.writer(file) writer.writerow(["GNSS Time", "Latitude", "Longitude", "Altitude", "Satellites"]) writer.writerows(self.telemetry_data) self.textEdit.append(f"Data saved to {fileName}")
if name == 'main': app = QApplication(sys.argv) ex = TelemetryApp() sys.exit(app.exec_())
import sys import csv import random import time from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget, QTextEdit, QFileDialog from PyQt5.QtCore import QTimer
class TelemetryApp(QMainWindow): def init(self): super().init()
if name == 'main': app = QApplication(sys.argv) ex = TelemetryApp() sys.exit(app.exec_())