JeVois  1.18
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
jevois-restore-console.C
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2020 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #include <jevois/Util/Console.H>
19 #include <jevois/Debug/Log.H>
20 #include <linux/input.h>
21 #include <linux/kd.h>
22 #include <linux/keyboard.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <unistd.h>
27 #include <cctype>
28 
29 //! Restore console operation after a violent crash of jevoispro-daemon
30 /*! This utility is useful when debugging jevoispro-daemon on JeVois-Pro platform, as it mutes the keyboard and console
31  framebuffer for direct access to the framebuffer device and keyboard/mouse/etc. */
32 int main(int JEVOIS_UNUSED_PARAM(argc), char const * JEVOIS_UNUSED_PARAM(argv[]))
33 {
34  int ret = 0;
35  jevois::logLevel = LOG_CRIT;
36 
37 #ifdef JEVOIS_PRO
38  try
39  {
40  int cfd = jevois::getConsoleFd();
41  ioctl(cfd, KDSETMODE, KD_TEXT);
42  close(cfd);
43  }
44  catch (...) { ++ret; }
45 
46  try
47  {
48  jevois::unMuteKeyboard(STDIN_FILENO, K_UNICODE);
49  }
50  catch (...)
51  {
52  // stdin is not a tty, probably we were launched remotely, so we try to disable the active tty:
53  try
54  {
55  int tty = jevois::getActiveTTY();
56  jevois::unMuteKeyboard(tty, K_UNICODE);
57  close(tty);
58  }
59  catch (...) { ret += 2; }
60  }
61 #endif
62 
63  // Terminate logger:
65 
66  return ret;
67 }
jevois::unMuteKeyboard
void unMuteKeyboard(int tty, int kb_mode)
Restore the keyboard mode for given tty.
Definition: Console.C:114
Console.H
jevois::getActiveTTY
int getActiveTTY()
Get current active tty.
Definition: Console.C:121
Log.H
jevois::logLevel
int logLevel
Current log level.
Definition: Log.C:29
jevois::logEnd
void logEnd()
Terminate log service.
Definition: Log.C:125
jevois::getConsoleFd
int getConsoleFd()
Get a file descriptor to the console.
Definition: Console.C:85
main
int main(int JEVOIS_UNUSED_PARAM(argc), char const *JEVOIS_UNUSED_PARAM(argv[]))
Restore console operation after a violent crash of jevoispro-daemon.
Definition: jevois-restore-console.C:32