mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-02 20:12:07 +08:00
remove RTC time pull (#31829)
* remove RTC time pull * and syncing * bump panda * bump panda old-commit-hash: 78d72d7dc390984496dd6633fd588bfd06ae1939
This commit is contained in:
+1
-1
Submodule panda updated: 4b6f6ac162...895a7001c9
@@ -82,7 +82,6 @@ selfdrive/boardd/panda.h
|
||||
selfdrive/boardd/spi.cc
|
||||
selfdrive/boardd/panda_comms.h
|
||||
selfdrive/boardd/panda_comms.cc
|
||||
selfdrive/boardd/set_time.py
|
||||
selfdrive/boardd/pandad.py
|
||||
selfdrive/boardd/tests/test_boardd_loopback.py
|
||||
|
||||
|
||||
@@ -49,12 +49,6 @@ std::atomic<bool> ignition(false);
|
||||
|
||||
ExitHandler do_exit;
|
||||
|
||||
static std::string get_time_str(const struct tm &time) {
|
||||
char s[30] = {'\0'};
|
||||
std::strftime(s, std::size(s), "%Y-%m-%d %H:%M:%S", &time);
|
||||
return s;
|
||||
}
|
||||
|
||||
bool check_all_connected(const std::vector<Panda *> &pandas) {
|
||||
for (const auto& panda : pandas) {
|
||||
if (!panda->connected()) {
|
||||
@@ -65,36 +59,6 @@ bool check_all_connected(const std::vector<Panda *> &pandas) {
|
||||
return true;
|
||||
}
|
||||
|
||||
enum class SyncTimeDir { TO_PANDA, FROM_PANDA };
|
||||
|
||||
void sync_time(Panda *panda, SyncTimeDir dir) {
|
||||
if (!panda->has_rtc) return;
|
||||
|
||||
setenv("TZ", "UTC", 1);
|
||||
struct tm sys_time = util::get_time();
|
||||
struct tm rtc_time = panda->get_rtc();
|
||||
|
||||
if (dir == SyncTimeDir::TO_PANDA) {
|
||||
if (util::time_valid(sys_time)) {
|
||||
// Write time to RTC if it looks reasonable
|
||||
double seconds = difftime(mktime(&rtc_time), mktime(&sys_time));
|
||||
if (std::abs(seconds) > 1.1) {
|
||||
panda->set_rtc(sys_time);
|
||||
LOGW("Updating panda RTC. dt = %.2f System: %s RTC: %s",
|
||||
seconds, get_time_str(sys_time).c_str(), get_time_str(rtc_time).c_str());
|
||||
}
|
||||
}
|
||||
} else if (dir == SyncTimeDir::FROM_PANDA) {
|
||||
LOGW("System time: %s, RTC time: %s", get_time_str(sys_time).c_str(), get_time_str(rtc_time).c_str());
|
||||
|
||||
if (!util::time_valid(sys_time) && util::time_valid(rtc_time)) {
|
||||
const struct timeval tv = {mktime(&rtc_time), 0};
|
||||
settimeofday(&tv, 0);
|
||||
LOGE("System time wrong, setting from RTC.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool safety_setter_thread(std::vector<Panda *> pandas) {
|
||||
LOGD("Starting safety setter thread");
|
||||
|
||||
@@ -195,7 +159,6 @@ Panda *connect(std::string serial="", uint32_t index=0) {
|
||||
throw std::runtime_error("Panda firmware out of date. Run pandad.py to update.");
|
||||
}
|
||||
|
||||
sync_time(panda.get(), SyncTimeDir::FROM_PANDA);
|
||||
return panda.release();
|
||||
}
|
||||
|
||||
@@ -581,11 +544,6 @@ void peripheral_control_thread(Panda *panda, bool no_fan_control) {
|
||||
panda->set_ir_pwr(ir_pwr);
|
||||
prev_ir_pwr = ir_pwr;
|
||||
}
|
||||
|
||||
// Write to rtc once per minute when no ignition present
|
||||
if (!ignition && (sm.frame % 120 == 1)) {
|
||||
sync_time(panda, SyncTimeDir::TO_PANDA);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,10 +25,6 @@ Panda::Panda(std::string serial, uint32_t bus_offset) : bus_offset(bus_offset) {
|
||||
}
|
||||
|
||||
hw_type = get_hw_type();
|
||||
has_rtc = (hw_type == cereal::PandaState::PandaType::UNO) ||
|
||||
(hw_type == cereal::PandaState::PandaType::DOS) ||
|
||||
(hw_type == cereal::PandaState::PandaType::TRES);
|
||||
|
||||
can_reset_communications();
|
||||
|
||||
return;
|
||||
@@ -77,41 +73,6 @@ cereal::PandaState::PandaType Panda::get_hw_type() {
|
||||
return (cereal::PandaState::PandaType)(hw_query[0]);
|
||||
}
|
||||
|
||||
void Panda::set_rtc(struct tm sys_time) {
|
||||
// tm struct has year defined as years since 1900
|
||||
handle->control_write(0xa1, (uint16_t)(1900 + sys_time.tm_year), 0);
|
||||
handle->control_write(0xa2, (uint16_t)(1 + sys_time.tm_mon), 0);
|
||||
handle->control_write(0xa3, (uint16_t)sys_time.tm_mday, 0);
|
||||
// handle->control_write(0xa4, (uint16_t)(1 + sys_time.tm_wday), 0);
|
||||
handle->control_write(0xa5, (uint16_t)sys_time.tm_hour, 0);
|
||||
handle->control_write(0xa6, (uint16_t)sys_time.tm_min, 0);
|
||||
handle->control_write(0xa7, (uint16_t)sys_time.tm_sec, 0);
|
||||
}
|
||||
|
||||
struct tm Panda::get_rtc() {
|
||||
struct __attribute__((packed)) timestamp_t {
|
||||
uint16_t year; // Starts at 0
|
||||
uint8_t month;
|
||||
uint8_t day;
|
||||
uint8_t weekday;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint8_t second;
|
||||
} rtc_time = {0};
|
||||
|
||||
handle->control_read(0xa0, 0, 0, (unsigned char*)&rtc_time, sizeof(rtc_time));
|
||||
|
||||
struct tm new_time = { 0 };
|
||||
new_time.tm_year = rtc_time.year - 1900; // tm struct has year defined as years since 1900
|
||||
new_time.tm_mon = rtc_time.month - 1;
|
||||
new_time.tm_mday = rtc_time.day;
|
||||
new_time.tm_hour = rtc_time.hour;
|
||||
new_time.tm_min = rtc_time.minute;
|
||||
new_time.tm_sec = rtc_time.second;
|
||||
|
||||
return new_time;
|
||||
}
|
||||
|
||||
void Panda::set_fan_speed(uint16_t fan_speed) {
|
||||
handle->control_write(0xb1, fan_speed, 0);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ public:
|
||||
Panda(std::string serial="", uint32_t bus_offset=0);
|
||||
|
||||
cereal::PandaState::PandaType hw_type = cereal::PandaState::PandaType::UNKNOWN;
|
||||
bool has_rtc = false;
|
||||
const uint32_t bus_offset;
|
||||
|
||||
bool connected();
|
||||
@@ -64,8 +63,6 @@ public:
|
||||
cereal::PandaState::PandaType get_hw_type();
|
||||
void set_safety_model(cereal::CarParams::SafetyModel safety_model, uint16_t safety_param=0U);
|
||||
void set_alternative_experience(uint16_t alternative_experience);
|
||||
void set_rtc(struct tm sys_time);
|
||||
struct tm get_rtc();
|
||||
void set_fan_speed(uint16_t fan_speed);
|
||||
uint16_t get_fan_speed();
|
||||
void set_ir_pwr(uint16_t ir_pwr);
|
||||
|
||||
@@ -10,7 +10,6 @@ from functools import cmp_to_key
|
||||
from panda import Panda, PandaDFU, PandaProtocolMismatch, FW_PATH
|
||||
from openpilot.common.basedir import BASEDIR
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.selfdrive.boardd.set_time import set_time
|
||||
from openpilot.system.hardware import HARDWARE
|
||||
from openpilot.common.swaglog import cloudlog
|
||||
|
||||
@@ -154,10 +153,6 @@ def main() -> NoReturn:
|
||||
cloudlog.event("panda.som_reset_triggered", health=health, serial=panda.get_usb_serial())
|
||||
|
||||
if first_run:
|
||||
if panda.is_internal():
|
||||
# update time from RTC
|
||||
set_time(cloudlog)
|
||||
|
||||
# reset panda to ensure we're in a good state
|
||||
cloudlog.info(f"Resetting panda {panda.get_usb_serial()}")
|
||||
if panda.is_internal():
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import datetime
|
||||
from panda import Panda
|
||||
|
||||
from openpilot.common.time import MIN_DATE
|
||||
|
||||
def set_time(logger):
|
||||
sys_time = datetime.datetime.today()
|
||||
if sys_time > MIN_DATE:
|
||||
logger.info("System time valid")
|
||||
return
|
||||
|
||||
try:
|
||||
ps = Panda.list()
|
||||
if len(ps) == 0:
|
||||
logger.error("Failed to set time, no pandas found")
|
||||
return
|
||||
|
||||
for s in ps:
|
||||
with Panda(serial=s) as p:
|
||||
if not p.is_internal():
|
||||
continue
|
||||
|
||||
# Set system time from panda RTC time
|
||||
panda_time = p.get_datetime()
|
||||
if panda_time > MIN_DATE:
|
||||
logger.info(f"adjusting time from '{sys_time}' to '{panda_time}'")
|
||||
os.system(f"TZ=UTC date -s '{panda_time}'")
|
||||
break
|
||||
except Exception:
|
||||
logger.exception("Failed to fetch time from panda")
|
||||
|
||||
if __name__ == "__main__":
|
||||
import logging
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
set_time(logging)
|
||||
Reference in New Issue
Block a user