Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loading progress #792

Closed
wants to merge 16 commits into from
99 changes: 54 additions & 45 deletions selfdrive/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def unblock_stdout():
import selfdrive.crash as crash

from selfdrive.loggerd.config import ROOT
from selfdrive.ui.spinner.spinner_manager import Spinner

# comment out anything you don't want to run
managed_processes = {
Expand Down Expand Up @@ -305,32 +306,38 @@ def cleanup_all_processes(signal, frame):
# ****************** run loop ******************

def manager_init(should_register=True):
if should_register:
reg_res = register()
if reg_res:
dongle_id, dongle_secret = reg_res
params = Params()
spinner_text = "chffrplus" if params.get("Passive")=="1" else "openpilot"
init_text = "initializing {0}".format(spinner_text)
with Spinner() as spinner:
spinner.update(init_text)
if should_register:
reg_res = register()
if reg_res:
dongle_id, dongle_secret = reg_res
else:
raise Exception("server registration failed")
else:
raise Exception("server registration failed")
else:
dongle_id = "c"*16
dongle_id = "c"*16

# set dongle id
cloudlog.info("dongle id is " + dongle_id)
os.environ['DONGLE_ID'] = dongle_id
# set dongle id
cloudlog.info("dongle id is " + dongle_id)
os.environ['DONGLE_ID'] = dongle_id

cloudlog.info("dirty is %d" % dirty)
if not dirty:
os.environ['CLEAN'] = '1'
cloudlog.info("dirty is %d" % dirty)
if not dirty:
os.environ['CLEAN'] = '1'

cloudlog.bind_global(dongle_id=dongle_id, version=version, dirty=dirty, is_eon=True)
crash.bind_user(id=dongle_id)
crash.bind_extra(version=version, dirty=dirty, is_eon=True)
cloudlog.bind_global(dongle_id=dongle_id, version=version, dirty=dirty, is_eon=True)
crash.bind_user(id=dongle_id)
crash.bind_extra(version=version, dirty=dirty, is_eon=True)

os.umask(0)
try:
os.mkdir(ROOT, 0o777)
except OSError:
pass

os.umask(0)
try:
os.mkdir(ROOT, 0o777)
except OSError:
pass

def system(cmd):
try:
Expand Down Expand Up @@ -495,17 +502,31 @@ def update_ssh():
raise RuntimeError

def manager_update():
update_ssh()
update_apks()
params = Params()
spinner_text = "chffrplus" if params.get("Passive")=="1" else "openpilot"
update_text = "updating {0}".format(spinner_text)
with Spinner() as spinner:
spinner.update(update_text)
update_ssh()
update_apks()

def manager_prepare():
# build cereal first
subprocess.check_call(["make", "-j4"], cwd=os.path.join(BASEDIR, "cereal"))

# build all processes
os.chdir(os.path.dirname(os.path.abspath(__file__)))
for p in managed_processes:
prepare_managed_process(p)
params = Params()
spinner_text = "chffrplus" if params.get("Passive")=="1" else "openpilot"
loader_text = "loading {0}".format(spinner_text)
with Spinner() as spinner:
spinner.update(loader_text)
# build cereal first
subprocess.check_call(["make", "-j4"], cwd=os.path.join(BASEDIR, "cereal"))

# build all processes
os.chdir(os.path.dirname(os.path.abspath(__file__)))

process_cnt = len(managed_processes)
for n,p in enumerate(managed_processes):
loader_text = "loading {0}: {1}/{2} {3}".format(spinner_text, n+1, process_cnt, p)
spinner.update(loader_text)
prepare_managed_process(p)

def uninstall():
cloudlog.warning("uninstalling")
Expand Down Expand Up @@ -583,21 +604,9 @@ def main():
if params.get("Passive") is None:
raise Exception("Passive must be set to continue")

# put something on screen while we set things up
if os.getenv("PREPAREONLY") is not None:
spinner_proc = None
else:
spinner_text = "chffrplus" if params.get("Passive")=="1" else "openpilot"
spinner_proc = subprocess.Popen(["./spinner", "loading %s"%spinner_text],
cwd=os.path.join(BASEDIR, "selfdrive", "ui", "spinner"),
close_fds=True)
try:
manager_update()
manager_init()
manager_prepare()
finally:
if spinner_proc:
spinner_proc.terminate()
manager_update()
manager_init()
manager_prepare()

if os.getenv("PREPAREONLY") is not None:
return
Expand Down
Empty file added selfdrive/ui/__init__.py
Empty file.
Empty file.
Binary file modified selfdrive/ui/spinner/spinner
Binary file not shown.
26 changes: 15 additions & 11 deletions selfdrive/ui/spinner/spinner.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

#include "common/framebuffer.h"

int main(int argc, char** argv) {
int main() {
int err;

const char* spintext = NULL;
if (argc >= 2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep it backwards compatible? I'd like to initialize the text from the command line.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can. I'm not sure if it's as simple as adding that code back though. It was a little tricky to get stdin working correctly. I'd like to get ubuntu running again before I start fooling around in C.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be nice. That keeps the spinner versatile and easy to call from a shells script.

spintext = argv[1];
}
fd_set readfds;
FD_ZERO(&readfds);
struct timeval timeout;
timeout.tv_sec = 0;
timeout.tv_usec = 0;
char spintext[50];

// spinner
int fb_w, fb_h;
Expand All @@ -49,6 +50,11 @@ int main(int argc, char** argv) {
assert(spinner_comma_img >= 0);

for (int cnt = 0; ; cnt++) {
FD_SET(STDIN_FILENO, &readfds);
if (select(1, &readfds, NULL, NULL, &timeout)) {
fgets(spintext, sizeof spintext, stdin);
spintext[strcspn(spintext, "\n")] = 0;
}
glClearColor(0.1, 0.1, 0.1, 1.0);
glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND);
Expand Down Expand Up @@ -85,11 +91,9 @@ int main(int argc, char** argv) {
nvgFill(vg);

// message
if (spintext) {
nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
nvgFontSize(vg, 96.0f);
nvgText(vg, fb_w/2, (fb_h*2/3)+24, spintext, NULL);
}
nvgTextAlign(vg, NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
nvgFontSize(vg, 96.0f);
nvgText(vg, fb_w/2, (fb_h*2/3)+24, spintext, NULL);

nvgEndFrame(vg);
eglSwapBuffers(display, surface);
Expand Down
18 changes: 18 additions & 0 deletions selfdrive/ui/spinner/spinner_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
import subprocess
from common.basedir import BASEDIR

class Spinner(object):
def __enter__(self):
self.spinner_proc = subprocess.Popen(["./spinner"], stdin=subprocess.PIPE,
cwd=os.path.join(BASEDIR, "selfdrive", "ui", "spinner"),
close_fds=True)
return self

def update(self, spinner_text):
if os.getenv("PREPAREONLY") is None:
self.spinner_proc.stdin.write(spinner_text + "\n")

def __exit__(self, type, value, traceback):
self.spinner_proc.stdin.close()
self.spinner_proc.terminate()