Improved error handling.
This commit is contained in:
@@ -12,10 +12,15 @@ Controller::Controller(const uint32_t startChannel)
|
||||
|
||||
void Controller::handleTransaction()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (channels.size() != 0 && chrono::duration_cast<chrono::seconds>(chrono::system_clock::now() - lastMessage) < 5s)
|
||||
toggleACTLED();
|
||||
else
|
||||
enableACTLED(false);
|
||||
}
|
||||
catch (runtime_error)
|
||||
{}
|
||||
|
||||
auto msg = U2FMessage::readNonBlock();
|
||||
|
||||
|
||||
5
Makefile
5
Makefile
@@ -13,6 +13,9 @@ OBJECTS := $(MODULES:$(SRC_DIR)/%.cpp=$(OBJ_DIR)/%.o)
|
||||
U2FDevice: $(OBJECTS) libuECC.o libcppb64.o
|
||||
g++ $(LDFLAGS) -o $@ $^
|
||||
|
||||
install: U2FDevice
|
||||
install -m775 -t /usr/bin U2FDevice
|
||||
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
|
||||
g++ $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
@@ -22,7 +25,7 @@ clean:
|
||||
rm $(OBJ_DIR)/*
|
||||
rm U2FDevice
|
||||
|
||||
.PHONY: libuECC.o libcppb64.so clean
|
||||
.PHONY: libuECC.o libcppb64.so clean install
|
||||
libuECC.o:
|
||||
$(MAKE) -C micro-ecc
|
||||
cp micro-ecc/libuECC.o libuECC.o
|
||||
|
||||
@@ -11,7 +11,7 @@ void signalCallback(int signum);
|
||||
|
||||
volatile bool contProc = true;
|
||||
|
||||
int main()
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -21,6 +21,9 @@ int main()
|
||||
catch (runtime_error &e)
|
||||
{
|
||||
cerr << e.what() << endl;
|
||||
|
||||
if (getuid() != 0)
|
||||
cerr << "Try running as root, using \'sudo " << argv[0] << "\'" << endl;
|
||||
}
|
||||
|
||||
signal(SIGINT, signalCallback);
|
||||
@@ -29,8 +32,20 @@ int main()
|
||||
Controller ch{ 0xF1D00000 };
|
||||
|
||||
while (contProc)
|
||||
{
|
||||
try
|
||||
{
|
||||
ch.handleTransaction();
|
||||
}
|
||||
catch (const runtime_error &e)
|
||||
{
|
||||
cerr << e.what() << endl;
|
||||
|
||||
if (getuid() != 0)
|
||||
cerr << "Try running as root, using \'sudo " << argv[0] << "\'" << endl;
|
||||
raise(SIGINT);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
usleep(10000);
|
||||
}
|
||||
|
||||
@@ -52,5 +67,5 @@ int main()
|
||||
void signalCallback([[maybe_unused]] int signum)
|
||||
{
|
||||
contProc = false;
|
||||
clog << "\nCaught SIGINT signal" << endl;
|
||||
clog << "\nClosing" << endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user