25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

  1. using System.Collections.Generic;
  2. using System.Diagnostics;
  3. using System.IO.Ports;
  4. using System.Linq;
  5. using System.Windows.Forms;
  6. namespace ThunderboltTimeSync {
  7. public partial class FormMain : Form {
  8. public FormMain() {
  9. // Check for admin rights
  10. // If running as admin:
  11. // Ask for COM port with dialog
  12. // Connect to COM port
  13. // When time message received:
  14. // If (time in UTC) AND (last time change was more than $MIN_UPDATE_INTERVAL ago) AND (error is less than $ERROR_THRESHOLD)
  15. // Change system time to GPS time
  16. // Else:
  17. // Display message to tell user to run as admin
  18. // Quit
  19. InitializeComponent();
  20. ThunderboltSerialPort tbsp = new ThunderboltSerialPort(new SerialPort("COM3"));
  21. tbsp.PacketReceived += (ThunderboltPacket packet) => {
  22. if (packet.IsPacketValid) {
  23. if (packet.ID == 0x8F && packet.Data.Count == 17 && packet.Data[0] == 0xAB) {
  24. ushort year = (ushort) (packet.Data[15] << 8 | packet.Data[16]);
  25. Debug.WriteLine(year);
  26. }
  27. }
  28. };
  29. tbsp.Open();
  30. }
  31. }
  32. }