Compare commits
3 Commits
2ab245a4d1
...
c63ed31862
Author | SHA1 | Date |
---|---|---|
wpetit | c63ed31862 | |
wpetit | bea49c78a9 | |
wpetit | b2cdf23fb7 |
|
@ -0,0 +1,561 @@
|
||||||
|
{
|
||||||
|
"base_mode": {
|
||||||
|
"base_coordinates": {
|
||||||
|
"accumulation": 120,
|
||||||
|
"antenna_offset": 1.6692,
|
||||||
|
"coordinates": {
|
||||||
|
"height": 304.60692471224945,
|
||||||
|
"latitude": -72.40044303332428,
|
||||||
|
"longitude": 53.4671626779832
|
||||||
|
},
|
||||||
|
"mode": "manual"
|
||||||
|
},
|
||||||
|
"output": {
|
||||||
|
"io_type": "lora",
|
||||||
|
"settings": {
|
||||||
|
"lora": {
|
||||||
|
"air_rate": 9.11,
|
||||||
|
"frequency": 868000,
|
||||||
|
"output_power": 20
|
||||||
|
},
|
||||||
|
"ntripcaster": {
|
||||||
|
"mount_point": "REACH",
|
||||||
|
"password": "emlidreach",
|
||||||
|
"port": 2101,
|
||||||
|
"username": "reach"
|
||||||
|
},
|
||||||
|
"ntripsvr": {
|
||||||
|
"address": "caster.centipede.fr",
|
||||||
|
"mount_point": "centipede",
|
||||||
|
"password": "centipede",
|
||||||
|
"port": 2101
|
||||||
|
},
|
||||||
|
"serial": {
|
||||||
|
"baud_rate": 38400,
|
||||||
|
"device": "UART"
|
||||||
|
},
|
||||||
|
"tcpcli": {
|
||||||
|
"address": "localhost",
|
||||||
|
"port": 9001
|
||||||
|
},
|
||||||
|
"tcpsvr": {
|
||||||
|
"port": 9000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rtcm3_messages": {
|
||||||
|
"1004": {
|
||||||
|
"enabled": false,
|
||||||
|
"frequency": 1
|
||||||
|
},
|
||||||
|
"1006": {
|
||||||
|
"enabled": true,
|
||||||
|
"frequency": 0.1
|
||||||
|
},
|
||||||
|
"1008": {
|
||||||
|
"enabled": false,
|
||||||
|
"frequency": 0.1
|
||||||
|
},
|
||||||
|
"1012": {
|
||||||
|
"enabled": false,
|
||||||
|
"frequency": 1
|
||||||
|
},
|
||||||
|
"1033": {
|
||||||
|
"enabled": false,
|
||||||
|
"frequency": 0.1
|
||||||
|
},
|
||||||
|
"1074": {
|
||||||
|
"enabled": true,
|
||||||
|
"frequency": 0.5
|
||||||
|
},
|
||||||
|
"1084": {
|
||||||
|
"enabled": true,
|
||||||
|
"frequency": 0.5
|
||||||
|
},
|
||||||
|
"1094": {
|
||||||
|
"enabled": true,
|
||||||
|
"frequency": 0.5
|
||||||
|
},
|
||||||
|
"1124": {
|
||||||
|
"enabled": true,
|
||||||
|
"frequency": 0.5
|
||||||
|
},
|
||||||
|
"1230": {
|
||||||
|
"enabled": true,
|
||||||
|
"frequency": 0.1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bluetooth": {
|
||||||
|
"ble_enabled": true,
|
||||||
|
"enabled": true,
|
||||||
|
"pairing": {
|
||||||
|
"discoverable": false,
|
||||||
|
"no_input_no_output": true,
|
||||||
|
"pin": "123456"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"correction_input": {
|
||||||
|
"base_corrections": {
|
||||||
|
"io_type": "off",
|
||||||
|
"last_used": {
|
||||||
|
"ntrip": "ntripcli",
|
||||||
|
"radio": "lora",
|
||||||
|
"tcp": "tcpcli"
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"ble": {
|
||||||
|
"address": "",
|
||||||
|
"mount_point": "",
|
||||||
|
"password": "",
|
||||||
|
"port": -1,
|
||||||
|
"send_position_to_base": true,
|
||||||
|
"username": ""
|
||||||
|
},
|
||||||
|
"bluetooth": {
|
||||||
|
"send_position_to_base": false
|
||||||
|
},
|
||||||
|
"lora": {
|
||||||
|
"air_rate": 9.11,
|
||||||
|
"frequency": 868000,
|
||||||
|
"output_power": 20,
|
||||||
|
"send_position_to_base": false
|
||||||
|
},
|
||||||
|
"ntripcli": {
|
||||||
|
"address": "caster.centipede.fr",
|
||||||
|
"mount_point": "ASD21 ",
|
||||||
|
"password": "centipede",
|
||||||
|
"port": 2101,
|
||||||
|
"send_position_to_base": true,
|
||||||
|
"username": "centipede"
|
||||||
|
},
|
||||||
|
"serial": {
|
||||||
|
"baud_rate": 38400,
|
||||||
|
"device": "UART",
|
||||||
|
"send_position_to_base": false
|
||||||
|
},
|
||||||
|
"tcpcli": {
|
||||||
|
"address": "caster.centipede.fr",
|
||||||
|
"port": 2101,
|
||||||
|
"send_position_to_base": true
|
||||||
|
},
|
||||||
|
"tcpsvr": {
|
||||||
|
"port": 10000,
|
||||||
|
"send_position_to_base": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"device": {
|
||||||
|
"antenna_height": 1.6692,
|
||||||
|
"night_mode": false,
|
||||||
|
"onboarding_shown": false,
|
||||||
|
"power_on_bottom_connector": false,
|
||||||
|
"privacy_policy_accepted": true,
|
||||||
|
"role": "base",
|
||||||
|
"usage_analysis_accepted": false
|
||||||
|
},
|
||||||
|
"logging": {
|
||||||
|
"logs": {
|
||||||
|
"autostart": true,
|
||||||
|
"base": {
|
||||||
|
"enabled": true,
|
||||||
|
"format": "RTCM3"
|
||||||
|
},
|
||||||
|
"raw": {
|
||||||
|
"enabled": true,
|
||||||
|
"format": "RINEX",
|
||||||
|
"rinex_options": {
|
||||||
|
"logging_interval": 0,
|
||||||
|
"marker_name": null,
|
||||||
|
"preset": "default",
|
||||||
|
"satellite_systems": {
|
||||||
|
"beidou": true,
|
||||||
|
"galileo": true,
|
||||||
|
"glonass": true,
|
||||||
|
"gps": true,
|
||||||
|
"qzss": true,
|
||||||
|
"sbas": false
|
||||||
|
},
|
||||||
|
"time_adjustments_enabled": true
|
||||||
|
},
|
||||||
|
"version": "3.03"
|
||||||
|
},
|
||||||
|
"solution": {
|
||||||
|
"enabled": true,
|
||||||
|
"format": "LLH"
|
||||||
|
},
|
||||||
|
"started": true
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"archive_name": null,
|
||||||
|
"debug": false,
|
||||||
|
"interval": 24,
|
||||||
|
"overwrite": true,
|
||||||
|
"simultaneous_logging": false,
|
||||||
|
"split_at_midnight_utc": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"network": {
|
||||||
|
"tcp_over_modem": true
|
||||||
|
},
|
||||||
|
"position_output": {
|
||||||
|
"output1": {
|
||||||
|
"io_type": "bluetooth",
|
||||||
|
"last_used": {
|
||||||
|
"tcp": "tcpcli"
|
||||||
|
},
|
||||||
|
"nmea_settings": {
|
||||||
|
"bluetooth": {
|
||||||
|
"ebp": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gga": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 5
|
||||||
|
},
|
||||||
|
"gsa": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gst": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gsv": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"main_talker_id": "gn",
|
||||||
|
"rmc": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"vtg": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"zda": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"serial": {
|
||||||
|
"ebp": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gga": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 5
|
||||||
|
},
|
||||||
|
"gsa": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gst": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gsv": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"main_talker_id": "gn",
|
||||||
|
"rmc": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"vtg": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"zda": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tcpcli": {
|
||||||
|
"ebp": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gga": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 5
|
||||||
|
},
|
||||||
|
"gsa": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gst": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gsv": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"main_talker_id": "gn",
|
||||||
|
"rmc": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"vtg": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"zda": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tcpsvr": {
|
||||||
|
"ebp": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gga": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 5
|
||||||
|
},
|
||||||
|
"gsa": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gst": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gsv": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"main_talker_id": "gn",
|
||||||
|
"rmc": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"vtg": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"zda": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"bluetooth": {
|
||||||
|
"format": "NMEA"
|
||||||
|
},
|
||||||
|
"serial": {
|
||||||
|
"baud_rate": 38400,
|
||||||
|
"device": "UART",
|
||||||
|
"format": "ERB"
|
||||||
|
},
|
||||||
|
"tcpcli": {
|
||||||
|
"address": "localhost",
|
||||||
|
"format": "ERB",
|
||||||
|
"port": 9000
|
||||||
|
},
|
||||||
|
"tcpsvr": {
|
||||||
|
"format": "LLH",
|
||||||
|
"port": 9001
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"output2": {
|
||||||
|
"io_type": "tcpsvr",
|
||||||
|
"last_used": {
|
||||||
|
"tcp": "tcpcli"
|
||||||
|
},
|
||||||
|
"nmea_settings": {
|
||||||
|
"bluetooth": {
|
||||||
|
"ebp": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gga": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 5
|
||||||
|
},
|
||||||
|
"gsa": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gst": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gsv": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"main_talker_id": "gn",
|
||||||
|
"rmc": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"vtg": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"zda": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"serial": {
|
||||||
|
"ebp": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gga": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 5
|
||||||
|
},
|
||||||
|
"gsa": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gst": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gsv": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"main_talker_id": "gn",
|
||||||
|
"rmc": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"vtg": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"zda": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tcpcli": {
|
||||||
|
"ebp": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gga": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 5
|
||||||
|
},
|
||||||
|
"gsa": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gst": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gsv": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"main_talker_id": "gn",
|
||||||
|
"rmc": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"vtg": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"zda": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tcpsvr": {
|
||||||
|
"ebp": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gga": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 5
|
||||||
|
},
|
||||||
|
"gsa": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gst": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"gsv": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"main_talker_id": "gn",
|
||||||
|
"rmc": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"vtg": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
},
|
||||||
|
"zda": {
|
||||||
|
"enabled": true,
|
||||||
|
"update_rate": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"bluetooth": {
|
||||||
|
"format": "NMEA"
|
||||||
|
},
|
||||||
|
"serial": {
|
||||||
|
"baud_rate": 38400,
|
||||||
|
"device": "UART",
|
||||||
|
"format": "ERB"
|
||||||
|
},
|
||||||
|
"tcpcli": {
|
||||||
|
"address": "localhost",
|
||||||
|
"format": "ERB",
|
||||||
|
"port": 9000
|
||||||
|
},
|
||||||
|
"tcpsvr": {
|
||||||
|
"format": "LLH",
|
||||||
|
"port": 9001
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"positioning_settings": {
|
||||||
|
"elevation_mask_angle": 15,
|
||||||
|
"glonass_ar_mode": false,
|
||||||
|
"gnss_settings": {
|
||||||
|
"positioning_systems": {
|
||||||
|
"beidou": true,
|
||||||
|
"galileo": true,
|
||||||
|
"glonass": true,
|
||||||
|
"gps": true,
|
||||||
|
"qzss": true
|
||||||
|
},
|
||||||
|
"update_rate": 5
|
||||||
|
},
|
||||||
|
"gps_ar_mode": "fix-and-hold",
|
||||||
|
"max_horizontal_acceleration": 1,
|
||||||
|
"max_vertical_acceleration": 1,
|
||||||
|
"positioning_mode": "kinematic",
|
||||||
|
"snr_mask": 35
|
||||||
|
},
|
||||||
|
"sound": {
|
||||||
|
"mute": false,
|
||||||
|
"volume": 100
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
{
|
||||||
|
"device": {
|
||||||
|
"cloud": {
|
||||||
|
"supported": true,
|
||||||
|
"usage_analysis_accepted": false
|
||||||
|
},
|
||||||
|
"country_code": "FR",
|
||||||
|
"critical_self_tests_passed": true,
|
||||||
|
"is_first_time_setup": false,
|
||||||
|
"local_address": "Reach.local",
|
||||||
|
"manufacturing_timestamp": "1693633066",
|
||||||
|
"name": "Reach",
|
||||||
|
"privacy_policy_accepted": true,
|
||||||
|
"public_key": "378A5081F445771316A0563CFCC168C813261C6EE9C5C50DF70CC4503C6D8839BED7AA40146A9D8D72BFC4DB85382EEE51B90D03B6CC6DF34E860E15EFEA7D38",
|
||||||
|
"self_tests": {
|
||||||
|
"antenna_board_detected": true,
|
||||||
|
"audio": true,
|
||||||
|
"bluetooth_detected": true,
|
||||||
|
"crypto-chip": true,
|
||||||
|
"image_and_device": true,
|
||||||
|
"lora": true,
|
||||||
|
"modem": true,
|
||||||
|
"mpu": true,
|
||||||
|
"stm32": true,
|
||||||
|
"u-blox": true,
|
||||||
|
"wifi_detected": true
|
||||||
|
},
|
||||||
|
"serial_number": "8243276564AEA32D",
|
||||||
|
"statistics": {
|
||||||
|
"first_usage_timestamp": 4294967295
|
||||||
|
},
|
||||||
|
"time_sync_passed": true,
|
||||||
|
"type": "ReachRS2+",
|
||||||
|
"uptime": "4:19:11"
|
||||||
|
},
|
||||||
|
"firmware": {
|
||||||
|
"api_version": "10.2",
|
||||||
|
"app_mode": "default",
|
||||||
|
"onboarding_shown": false,
|
||||||
|
"version": "32.0",
|
||||||
|
"version_full": "32.0-r0"
|
||||||
|
},
|
||||||
|
"gnss_receiver": {
|
||||||
|
"firmware_version": "HPG_1.13"
|
||||||
|
},
|
||||||
|
"lora": {
|
||||||
|
"firmware_version": "F-0LR-1F-1912161"
|
||||||
|
},
|
||||||
|
"modem": {
|
||||||
|
"firmware_version": "MPSS.JO.2.0.2.c1.1-00098-9607_GENNS_PACK-1.402457.1 1 [May 18 2021 19:00:00]",
|
||||||
|
"imei": "350588283544948",
|
||||||
|
"modem_model": "\r\n^SYSSTART\r\n"
|
||||||
|
},
|
||||||
|
"pmu": {
|
||||||
|
"balancer_version": "190602",
|
||||||
|
"git_hash": "0a241756",
|
||||||
|
"version": "3.35"
|
||||||
|
},
|
||||||
|
"reachview": {
|
||||||
|
"api_version": "10.2",
|
||||||
|
"app_mode": "default",
|
||||||
|
"onboarding_shown": false,
|
||||||
|
"version": "32.0",
|
||||||
|
"version_full": "32.0-r0"
|
||||||
|
},
|
||||||
|
"storage": {
|
||||||
|
"free": 10897,
|
||||||
|
"total": 12374
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "embed"
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
"log/slog"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
socketio "github.com/googollee/go-socket.io"
|
||||||
|
"github.com/googollee/go-socket.io/engineio"
|
||||||
|
"github.com/googollee/go-socket.io/engineio/transport"
|
||||||
|
"github.com/googollee/go-socket.io/engineio/transport/polling"
|
||||||
|
"github.com/googollee/go-socket.io/engineio/transport/websocket"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed data/info.json
|
||||||
|
var info []byte
|
||||||
|
|
||||||
|
//go:embed data/configuration.json
|
||||||
|
var configuration []byte
|
||||||
|
|
||||||
|
func GetInfo(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Add("Content-Type", "application/json")
|
||||||
|
if _, err := w.Write(info); err != nil {
|
||||||
|
slog.Error("could not write info", slog.Any("error", errors.WithStack(err)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetConfiguration(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Add("Content-Type", "application/json")
|
||||||
|
if _, err := w.Write(configuration); err != nil {
|
||||||
|
slog.Error("could not write configuration", slog.Any("error", errors.WithStack(err)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func PostJSON(w http.ResponseWriter, r *http.Request) {
|
||||||
|
body, err := io.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("could not read body", slog.Any("error", errors.WithStack(err)))
|
||||||
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
defer r.Body.Close()
|
||||||
|
|
||||||
|
var payload any
|
||||||
|
|
||||||
|
if err := json.Unmarshal(body, &payload); err != nil {
|
||||||
|
slog.Error("could not unmarshal payload", slog.Any("error", errors.WithStack(err)))
|
||||||
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
formatted, err := json.MarshalIndent(payload, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("could not marshal payload", slog.Any("error", errors.WithStack(err)))
|
||||||
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("received payload", slog.Any("payload", string(formatted)))
|
||||||
|
|
||||||
|
if _, err := w.Write(formatted); err != nil {
|
||||||
|
slog.Error("could not write payload", slog.Any("error", errors.WithStack(err)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var allowOriginFunc = func(r *http.Request) bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSocketIOServer() *socketio.Server {
|
||||||
|
server := socketio.NewServer(&engineio.Options{
|
||||||
|
Transports: []transport.Transport{
|
||||||
|
&polling.Transport{
|
||||||
|
CheckOrigin: allowOriginFunc,
|
||||||
|
},
|
||||||
|
&websocket.Transport{
|
||||||
|
CheckOrigin: allowOriginFunc,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
server.OnConnect("/", func(s socketio.Conn) error {
|
||||||
|
s.SetContext("")
|
||||||
|
slog.Info("connected", slog.Any("id", s.ID()))
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
server.OnError("/", func(s socketio.Conn, err error) {
|
||||||
|
slog.Info("socketio error", slog.Any("id", s.ID()), slog.Any("error", errors.WithStack(err)))
|
||||||
|
})
|
||||||
|
|
||||||
|
server.OnDisconnect("/", func(s socketio.Conn, reason string) {
|
||||||
|
slog.Info("disconnected", slog.Any("id", s.ID()), slog.Any("reason", reason))
|
||||||
|
})
|
||||||
|
|
||||||
|
return server
|
||||||
|
}
|
|
@ -0,0 +1,162 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log/slog"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
|
||||||
|
"forge.cadoles.com/cadoles/go-emlid/reach/discovery"
|
||||||
|
socketio "github.com/googollee/go-socket.io"
|
||||||
|
"github.com/grandcat/zeroconf"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
sloghttp "github.com/samber/slog-http"
|
||||||
|
"github.com/wlynxg/anet"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
server, err := startHTTPServer(ctx)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("could not start http server", slog.Any("error", errors.WithStack(err)))
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
service, err := startMDNSService(ctx)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("could not start mdns service", slog.Any("error", errors.WithStack(err)))
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer service.Shutdown()
|
||||||
|
|
||||||
|
interrupt := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(interrupt, os.Interrupt)
|
||||||
|
|
||||||
|
slog.Info("Ctrl+C to interrupt")
|
||||||
|
|
||||||
|
<-interrupt
|
||||||
|
}
|
||||||
|
|
||||||
|
func startHTTPServer(ctx context.Context) (*http.Server, error) {
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
|
sioServer := NewSocketIOServer()
|
||||||
|
go func() {
|
||||||
|
if err := sioServer.Serve(); err != nil {
|
||||||
|
slog.Error("could not serve socketio", slog.Any("error", errors.WithStack(err)))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
sioServer.OnEvent("/", "action", func(s socketio.Conn, msg map[string]any) {
|
||||||
|
slog.Info("action event", slog.Any("id", s.ID()), slog.Any("message", msg))
|
||||||
|
|
||||||
|
name, ok := msg["name"]
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch name {
|
||||||
|
case "reboot":
|
||||||
|
if err := s.Close(); err != nil {
|
||||||
|
slog.Error("could not close connection", slog.Any("error", errors.WithStack(err)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
mux.Handle("/socket.io/", sioServer)
|
||||||
|
mux.HandleFunc("GET /info", GetInfo)
|
||||||
|
mux.HandleFunc("GET /configuration", GetConfiguration)
|
||||||
|
mux.HandleFunc("POST /configuration/base_mode/base_coordinates", PostJSON)
|
||||||
|
|
||||||
|
handler := sloghttp.Recovery(mux)
|
||||||
|
handler = sloghttp.New(slog.Default())(handler)
|
||||||
|
|
||||||
|
server := &http.Server{
|
||||||
|
Addr: ":8080",
|
||||||
|
Handler: handler,
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer sioServer.Close()
|
||||||
|
|
||||||
|
slog.Info("starting http server", slog.Any("address", server.Addr))
|
||||||
|
|
||||||
|
if err := server.ListenAndServe(); err != nil {
|
||||||
|
slog.Error("could not listen and serve http requests", slog.Any("error", errors.WithStack(err)))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return server, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func startMDNSService(ctx context.Context) (*zeroconf.Server, error) {
|
||||||
|
hostname, err := os.Hostname()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ifaces, err := anet.Interfaces()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ips, err := GetLANIPv4Addrs()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
info := []string{
|
||||||
|
fmt.Sprintf("local_name=%s", hostname),
|
||||||
|
"device=FakeReach",
|
||||||
|
"manufacturer_data=egoHIABggkMnZWSuoy0KAgAA",
|
||||||
|
}
|
||||||
|
|
||||||
|
slog.Info("announcing mdns service", slog.Any("ips", ips), slog.Any("info", info))
|
||||||
|
|
||||||
|
server, err := zeroconf.RegisterProxy("Reach", discovery.ReachService, "local.", 8080, hostname, ips, info, ifaces)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return server, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
_, lanA, _ = net.ParseCIDR("10.0.0.0/8")
|
||||||
|
_, lanB, _ = net.ParseCIDR("172.16.0.0/12")
|
||||||
|
_, lanC, _ = net.ParseCIDR("192.168.0.0/16")
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetLANIPv4Addrs() ([]string, error) {
|
||||||
|
ips := make([]string, 0)
|
||||||
|
|
||||||
|
addrs, err := anet.InterfaceAddrs()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, address := range addrs {
|
||||||
|
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||||
|
ipv4 := ipnet.IP.To4()
|
||||||
|
if ipv4 == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
isLAN := lanA.Contains(ipv4) || lanB.Contains(ipv4) || lanC.Contains(ipv4)
|
||||||
|
if !isLAN {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
ips = append(ips, ipv4.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ips, nil
|
||||||
|
}
|
26
go.mod
26
go.mod
|
@ -1,23 +1,31 @@
|
||||||
module forge.cadoles.com/cadoles/go-emlid
|
module forge.cadoles.com/cadoles/go-emlid
|
||||||
|
|
||||||
go 1.22.5
|
go 1.23
|
||||||
|
|
||||||
require (
|
require (
|
||||||
forge.cadoles.com/Pyxis/golang-socketio v0.0.0-20240805155359-f54949ba3a46
|
forge.cadoles.com/Pyxis/golang-socketio v0.0.0-20240805155359-f54949ba3a46
|
||||||
github.com/Masterminds/semver/v3 v3.2.1
|
github.com/Masterminds/semver/v3 v3.3.0
|
||||||
github.com/davecgh/go-spew v1.1.1
|
github.com/davecgh/go-spew v1.1.1
|
||||||
|
github.com/googollee/go-socket.io v1.7.0
|
||||||
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/grandcat/zeroconf v1.0.0
|
github.com/grandcat/zeroconf v1.0.0
|
||||||
|
github.com/miekg/dns v1.1.62
|
||||||
github.com/mitchellh/mapstructure v1.5.0
|
github.com/mitchellh/mapstructure v1.5.0
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
|
github.com/samber/slog-http v1.4.2
|
||||||
|
github.com/wlynxg/anet v0.0.4
|
||||||
|
golang.org/x/net v0.29.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
|
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
|
||||||
github.com/gorilla/websocket v1.5.3 // indirect
|
github.com/gofrs/uuid v4.4.0+incompatible // indirect
|
||||||
github.com/hashicorp/mdns v1.0.5 // indirect
|
github.com/gomodule/redigo v1.9.2 // indirect
|
||||||
github.com/miekg/dns v1.1.41 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/wlynxg/anet v0.0.4-0.20240806025826-e684438fc7c6 // indirect
|
go.opentelemetry.io/otel v1.30.0 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
|
go.opentelemetry.io/otel/trace v1.30.0 // indirect
|
||||||
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1 // indirect
|
golang.org/x/mod v0.21.0 // indirect
|
||||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 // indirect
|
golang.org/x/sync v0.8.0 // indirect
|
||||||
|
golang.org/x/sys v0.25.0 // indirect
|
||||||
|
golang.org/x/tools v0.25.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
77
go.sum
77
go.sum
|
@ -1,59 +1,76 @@
|
||||||
forge.cadoles.com/Pyxis/golang-socketio v0.0.0-20180919100209-bb857ced6b95 h1:o3G5+9RjczCK1xAYFaRMknk1kY9Ule6PNfiW6N6hEpg=
|
|
||||||
forge.cadoles.com/Pyxis/golang-socketio v0.0.0-20180919100209-bb857ced6b95/go.mod h1:I6kYOFWNkFlNeQLI7ZqfTRz4NdPHZxX0Bzizmzgchs0=
|
|
||||||
forge.cadoles.com/Pyxis/golang-socketio v0.0.0-20240805155359-f54949ba3a46 h1:vLTYHA4+pYeI9mZvCMrc29AmnNjeGEpEG1mTwtCOoDI=
|
forge.cadoles.com/Pyxis/golang-socketio v0.0.0-20240805155359-f54949ba3a46 h1:vLTYHA4+pYeI9mZvCMrc29AmnNjeGEpEG1mTwtCOoDI=
|
||||||
forge.cadoles.com/Pyxis/golang-socketio v0.0.0-20240805155359-f54949ba3a46/go.mod h1:bT+HWia42VRX1TzTUlEM645tPJEOtsEdzlKBiEqVchY=
|
forge.cadoles.com/Pyxis/golang-socketio v0.0.0-20240805155359-f54949ba3a46/go.mod h1:bT+HWia42VRX1TzTUlEM645tPJEOtsEdzlKBiEqVchY=
|
||||||
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
|
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0=
|
||||||
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
|
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
|
||||||
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
|
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
|
||||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||||
|
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
|
||||||
|
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||||
|
github.com/gomodule/redigo v1.8.4/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
|
||||||
|
github.com/gomodule/redigo v1.9.2 h1:HrutZBLhSIU8abiSfW8pj8mPhOyMYjZT/wcA4/L9L9s=
|
||||||
|
github.com/gomodule/redigo v1.9.2/go.mod h1:KsU3hiK/Ay8U42qpaJk+kuNa3C+spxapWpM+ywhcgtw=
|
||||||
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/googollee/go-socket.io v1.7.0 h1:ODcQSAvVIPvKozXtUGuJDV3pLwdpBLDs1Uoq/QHIlY8=
|
||||||
|
github.com/googollee/go-socket.io v1.7.0/go.mod h1:0vGP8/dXR9SZUMMD4+xxaGo/lohOw3YWMh2WRiWeKxg=
|
||||||
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/grandcat/zeroconf v1.0.0 h1:uHhahLBKqwWBV6WZUDAT71044vwOTL+McW0mBJvo6kE=
|
github.com/grandcat/zeroconf v1.0.0 h1:uHhahLBKqwWBV6WZUDAT71044vwOTL+McW0mBJvo6kE=
|
||||||
github.com/grandcat/zeroconf v1.0.0/go.mod h1:lTKmG1zh86XyCoUeIHSA4FJMBwCJiQmGfcP2PdzytEs=
|
github.com/grandcat/zeroconf v1.0.0/go.mod h1:lTKmG1zh86XyCoUeIHSA4FJMBwCJiQmGfcP2PdzytEs=
|
||||||
github.com/hashicorp/mdns v1.0.5 h1:1M5hW1cunYeoXOqHwEb/GBDDHAFo0Yqb/uz/beC6LbE=
|
|
||||||
github.com/hashicorp/mdns v1.0.5/go.mod h1:mtBihi+LeNXGtG8L9dX59gAEa12BDtBQSp4v/YAJqrc=
|
|
||||||
github.com/miekg/dns v1.1.27 h1:aEH/kqUzUxGJ/UHcEKdJY+ugH6WEzsEBBSPa8zuy1aM=
|
|
||||||
github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
github.com/miekg/dns v1.1.27/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
||||||
github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY=
|
github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ=
|
||||||
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
|
github.com/miekg/dns v1.1.62/go.mod h1:mvDlcItzm+br7MToIKqkglaGhlFMHJ9DTNNWONWXbNQ=
|
||||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/wlynxg/anet v0.0.3 h1:PvR53psxFXstc12jelG6f1Lv4MWqE0tI76/hHGjh9rg=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/wlynxg/anet v0.0.3/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/wlynxg/anet v0.0.4-0.20240806025826-e684438fc7c6 h1:c/wkXIJvpg2oot7iFqPESTBAO9UvhWTBnW97y9aPgyU=
|
github.com/samber/slog-http v1.4.2 h1:tOOhwE/rFpDzaSxdzttMFFaMDUM+ah7h2zppZ4UCNC0=
|
||||||
github.com/wlynxg/anet v0.0.4-0.20240806025826-e684438fc7c6/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
|
github.com/samber/slog-http v1.4.2/go.mod h1:n6h4x2ZBeTgLqMKf95EuNlU6mcJF1b/RVLxo1od5+V0=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
|
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||||
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/wlynxg/anet v0.0.4 h1:0de1OFQxnNqAu+x2FAKKCVIrnfGKQbs7FQz++tB0+Uw=
|
||||||
|
github.com/wlynxg/anet v0.0.4/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
|
||||||
|
go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts=
|
||||||
|
go.opentelemetry.io/otel v1.30.0/go.mod h1:tFw4Br9b7fOS+uEao81PJjVMjW/5fvNCbpsDIXqP0pc=
|
||||||
|
go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc=
|
||||||
|
go.opentelemetry.io/otel/trace v1.30.0/go.mod h1:5EyKqTzzmyqB9bwtCCq6pDLktPK6fmGf/Dph+8VI02o=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
|
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
|
golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0=
|
||||||
|
golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA=
|
|
||||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
|
||||||
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1 h1:4qWs8cYYH6PoEFy4dfhDFgoMGkwAcETd+MmPdCPMzUc=
|
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
|
||||||
golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
|
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M=
|
|
||||||
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||||
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 h1:Bli41pIlzTzf3KEY06n+xnzK/BESIg2ze4Pgfh/aI8c=
|
|
||||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
|
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
|
||||||
|
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -123,6 +123,21 @@ func (c *Client) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptionFun
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBaseInfo implements protocol.Operations.
|
||||||
|
func (c *Client) GetBaseInfo(ctx context.Context) (*protocol.BaseInfo, error) {
|
||||||
|
_, ops, err := c.getProtocol(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
baseInfo, err := ops.GetBaseInfo(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return baseInfo, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Reboot implements protocol.Operations.
|
// Reboot implements protocol.Operations.
|
||||||
func (c *Client) Reboot(ctx context.Context) error {
|
func (c *Client) Reboot(ctx context.Context) error {
|
||||||
_, ops, err := c.getProtocol(ctx)
|
_, ops, err := c.getProtocol(ctx)
|
||||||
|
|
|
@ -2,6 +2,14 @@ package protocol
|
||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
||||||
|
type BaseInfo struct {
|
||||||
|
Mode string
|
||||||
|
AntennaOffset float64
|
||||||
|
Latitude float64
|
||||||
|
Longitude float64
|
||||||
|
Height float64
|
||||||
|
}
|
||||||
|
|
||||||
type Operations interface {
|
type Operations interface {
|
||||||
// Connect initiates a new connection to the ReachView service
|
// Connect initiates a new connection to the ReachView service
|
||||||
// It should be called before any other operation
|
// It should be called before any other operation
|
||||||
|
@ -29,6 +37,8 @@ type Operations interface {
|
||||||
// SetBase updates the base configuration
|
// SetBase updates the base configuration
|
||||||
SetBase(ctx context.Context, funcs ...SetBaseOptionFunc) error
|
SetBase(ctx context.Context, funcs ...SetBaseOptionFunc) error
|
||||||
|
|
||||||
|
GetBaseInfo(ctx context.Context) (*BaseInfo, error)
|
||||||
|
|
||||||
// Reboot restarts the module
|
// Reboot restarts the module
|
||||||
Reboot(ctx context.Context) error
|
Reboot(ctx context.Context) error
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package testsuite
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -156,7 +157,7 @@ var testCases = []operationTestCase{
|
||||||
latitude := -90 + rand.Float64()*180
|
latitude := -90 + rand.Float64()*180
|
||||||
longitude := -180 + rand.Float64()*360
|
longitude := -180 + rand.Float64()*360
|
||||||
height := rand.Float64() * 1000
|
height := rand.Float64() * 1000
|
||||||
antennaOffset := rand.Float64() * 2
|
antennaOffset := toFixed(rand.Float64()*2, 3)
|
||||||
|
|
||||||
opts := []protocol.SetBaseOptionFunc{
|
opts := []protocol.SetBaseOptionFunc{
|
||||||
protocol.WithBaseLatitude(latitude),
|
protocol.WithBaseLatitude(latitude),
|
||||||
|
@ -173,6 +174,30 @@ var testCases = []operationTestCase{
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
baseInfo, err := ops.GetBaseInfo(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%+v", errors.WithStack(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Logf("base info: %v", spew.Sdump(baseInfo))
|
||||||
|
|
||||||
|
if e, g := latitude, baseInfo.Latitude; e != g {
|
||||||
|
t.Errorf("baseInfo.Latitude: expected '%v', got '%v'", e, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e, g := longitude, baseInfo.Longitude; e != g {
|
||||||
|
t.Errorf("baseInfo.Longitude: expected '%v', got '%v'", e, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e, g := height, baseInfo.Height; e != g {
|
||||||
|
t.Errorf("baseInfo.Height: expected '%v', got '%v'", e, g)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e, g := antennaOffset, baseInfo.AntennaOffset; e != g {
|
||||||
|
t.Errorf("baseInfo.AntennaOffset: expected '%v', got '%v'", e, g)
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -239,3 +264,9 @@ func TestOperations(t *testing.T, opsFactory OperationsFactoryFunc) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toFixed(n float64, precision int) float64 {
|
||||||
|
scale := math.Pow(10, float64(precision))
|
||||||
|
|
||||||
|
return math.Round(n*scale) / scale
|
||||||
|
}
|
||||||
|
|
|
@ -297,6 +297,52 @@ func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptio
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBaseInfo implements protocol.Operations.
|
||||||
|
func (o *Operations) GetBaseInfo(ctx context.Context) (*protocol.BaseInfo, error) {
|
||||||
|
rawConfig, err := o.Configuration(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
config := rawConfig.(*model.Configuration)
|
||||||
|
baseMode := config.BaseMode
|
||||||
|
|
||||||
|
var baseCoordinates *model.BaseCoordinates
|
||||||
|
if baseMode != nil && baseMode.BaseCoordinates != nil {
|
||||||
|
baseCoordinates = baseMode.BaseCoordinates
|
||||||
|
}
|
||||||
|
|
||||||
|
antennaOffset, err := strconv.ParseFloat(*baseCoordinates.AntennaOffset.Up, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
latitude, err := strconv.ParseFloat(*baseCoordinates.Coordinates[0], 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
longitude, err := strconv.ParseFloat(*baseCoordinates.Coordinates[1], 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
height, err := strconv.ParseFloat(*baseCoordinates.Coordinates[2], 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
baseInfo := &protocol.BaseInfo{
|
||||||
|
Mode: *config.BaseMode.BaseCoordinates.Mode,
|
||||||
|
AntennaOffset: antennaOffset,
|
||||||
|
Height: height,
|
||||||
|
Latitude: latitude,
|
||||||
|
Longitude: longitude,
|
||||||
|
}
|
||||||
|
|
||||||
|
return baseInfo, nil
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
eventGetReachViewVersion = "get reachview version"
|
eventGetReachViewVersion = "get reachview version"
|
||||||
eventReachViewVersionResults = "current reachview version"
|
eventReachViewVersionResults = "current reachview version"
|
||||||
|
|
|
@ -116,6 +116,16 @@ func (o *Operations) PostBaseCoordinates(ctx context.Context, base *model.Base)
|
||||||
return &updated, nil
|
return &updated, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *Operations) PostDevice(ctx context.Context, device *model.ConfigurationDevice) (*model.ConfigurationDevice, error) {
|
||||||
|
var updated model.ConfigurationDevice
|
||||||
|
|
||||||
|
if err := o.PostJSON("/configuration/device", device, &updated); err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &updated, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (o *Operations) GetUpdater(ctx context.Context) (*model.Updater, error) {
|
func (o *Operations) GetUpdater(ctx context.Context) (*model.Updater, error) {
|
||||||
updater := &model.Updater{}
|
updater := &model.Updater{}
|
||||||
if err := o.GetJSON("/updater", updater); err != nil {
|
if err := o.GetJSON("/updater", updater); err != nil {
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
type Base struct {
|
type Base struct {
|
||||||
Accumulation int `json:"accumulation,omitempty"`
|
Accumulation int `json:"accumulation"`
|
||||||
AntennaOffset float64 `json:"antenna_offset,omitempty"`
|
AntennaOffset float64 `json:"antenna_offset"`
|
||||||
Coordinates BaseCoordinates `json:"coordinates,omitempty"`
|
Coordinates BaseCoordinates `json:"coordinates"`
|
||||||
Mode string `json:"mode,omitempty"`
|
Mode string `json:"mode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BaseCoordinates struct {
|
type BaseCoordinates struct {
|
||||||
Height float64 `json:"height,omitempty"`
|
Height float64 `json:"height"`
|
||||||
Latitude float64 `json:"latitude,omitempty"`
|
Latitude float64 `json:"latitude"`
|
||||||
Longitude float64 `json:"longitude,omitempty"`
|
Longitude float64 `json:"longitude"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,15 +148,7 @@ type Configuration struct {
|
||||||
} `json:"settings,omitempty"`
|
} `json:"settings,omitempty"`
|
||||||
} `json:"base_corrections,omitempty"`
|
} `json:"base_corrections,omitempty"`
|
||||||
} `json:"correction_input,omitempty"`
|
} `json:"correction_input,omitempty"`
|
||||||
Device struct {
|
Device ConfigurationDevice `json:"device,omitempty"`
|
||||||
AntennaHeight float64 `json:"antenna_height,omitempty"`
|
|
||||||
NightMode bool `json:"night_mode,omitempty"`
|
|
||||||
OnboardingShown bool `json:"onboarding_shown,omitempty"`
|
|
||||||
PowerOnBottomConnector bool `json:"power_on_bottom_connector,omitempty"`
|
|
||||||
PrivacyPolicyAccepted bool `json:"privacy_policy_accepted,omitempty"`
|
|
||||||
Role string `json:"role,omitempty"`
|
|
||||||
UsageAnalysisAccepted bool `json:"usage_analysis_accepted,omitempty"`
|
|
||||||
} `json:"device,omitempty"`
|
|
||||||
Logging struct {
|
Logging struct {
|
||||||
Logs struct {
|
Logs struct {
|
||||||
Autostart bool `json:"autostart,omitempty"`
|
Autostart bool `json:"autostart,omitempty"`
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package model
|
||||||
|
|
||||||
|
type ConfigurationDevice struct {
|
||||||
|
AntennaHeight float64 `json:"antenna_height,omitempty"`
|
||||||
|
NightMode bool `json:"night_mode,omitempty"`
|
||||||
|
OnboardingShown bool `json:"onboarding_shown,omitempty"`
|
||||||
|
PowerOnBottomConnector bool `json:"power_on_bottom_connector,omitempty"`
|
||||||
|
PrivacyPolicyAccepted bool `json:"privacy_policy_accepted,omitempty"`
|
||||||
|
Role string `json:"role,omitempty"`
|
||||||
|
UsageAnalysisAccepted bool `json:"usage_analysis_accepted,omitempty"`
|
||||||
|
}
|
|
@ -60,6 +60,8 @@ func (o *Operations) Reboot(ctx context.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DeviceHeight = 0.134
|
||||||
|
|
||||||
// SetBase implements protocol.Operations.
|
// SetBase implements protocol.Operations.
|
||||||
func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
||||||
config, err := o.GetConfiguration(ctx)
|
config, err := o.GetConfiguration(ctx)
|
||||||
|
@ -96,17 +98,41 @@ func (o *Operations) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptio
|
||||||
base.Coordinates.Longitude = *opts.Longitude
|
base.Coordinates.Longitude = *opts.Longitude
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.AntennaOffset != nil {
|
|
||||||
base.AntennaOffset = *opts.AntennaOffset
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := o.PostBaseCoordinates(ctx, base); err != nil {
|
if _, err := o.PostBaseCoordinates(ctx, base); err != nil {
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opts.AntennaOffset != nil {
|
||||||
|
device := &model.ConfigurationDevice{
|
||||||
|
AntennaHeight: *opts.AntennaOffset + DeviceHeight,
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := o.PostDevice(ctx, device); err != nil {
|
||||||
|
return errors.WithStack(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetBaseInfo implements protocol.Operations.
|
||||||
|
func (o *Operations) GetBaseInfo(ctx context.Context) (*protocol.BaseInfo, error) {
|
||||||
|
config, err := o.GetConfiguration(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithStack(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
baseInfo := &protocol.BaseInfo{
|
||||||
|
Mode: config.BaseMode.BaseCoordinates.Mode,
|
||||||
|
AntennaOffset: config.BaseMode.BaseCoordinates.AntennaOffset - DeviceHeight,
|
||||||
|
Height: config.BaseMode.BaseCoordinates.Coordinates.Height,
|
||||||
|
Latitude: config.BaseMode.BaseCoordinates.Coordinates.Latitude,
|
||||||
|
Longitude: config.BaseMode.BaseCoordinates.Coordinates.Longitude,
|
||||||
|
}
|
||||||
|
|
||||||
|
return baseInfo, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Configuration implements protocol.Operations.
|
// Configuration implements protocol.Operations.
|
||||||
func (o *Operations) Configuration(ctx context.Context) (any, error) {
|
func (o *Operations) Configuration(ctx context.Context) (any, error) {
|
||||||
config, err := o.GetConfiguration(ctx)
|
config, err := o.GetConfiguration(ctx)
|
||||||
|
|
Loading…
Reference in New Issue