-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Reconnect wifiandheadunit #50
Changes from 3 commits
6aac0ef
1ce70ae
de9a2d5
2d3a93c
8374562
09d66d2
3715306
0bb1a7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,29 @@ void AAWProxy::forward(ProxyDirection direction, std::atomic<bool>& should_exit) | |
void AAWProxy::handleClient(int server_sock) { | ||
struct sockaddr client_address; | ||
socklen_t client_addresslen = sizeof(client_address); | ||
int rc; | ||
struct timeval timeout; | ||
|
||
while (true) { | ||
fd_set rfds; | ||
timeout.tv_sec = 30; | ||
timeout.tv_usec = 0; | ||
|
||
FD_ZERO(&rfds); | ||
FD_SET(server_sock, &rfds); | ||
|
||
rc = select(server_sock+1,&rfds,NULL,NULL,&timeout); | ||
if (rc == 0) { | ||
Logger::instance()->info("Server socket timeout 30s\n"); | ||
close(server_sock); | ||
close(server_sock+1); | ||
return; | ||
} | ||
if (rc > 0) { | ||
break; | ||
} | ||
} | ||
|
||
if ((m_tcp_fd = accept(server_sock, &client_address, &client_addresslen)) < 0) { | ||
close(server_sock); | ||
Logger::instance()->info("accept failed: %s\n", strerror(errno)); | ||
|
@@ -138,13 +161,17 @@ void AAWProxy::handleClient(int server_sock) { | |
usb_tcp.join(); | ||
tcp_usb.join(); | ||
|
||
should_exit = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this help in any way? We've already joined both the threads by now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was no sure about this variable to control the threads in this moment is necessary to inform or no, you better knows the behavior |
||
|
||
close(m_usb_fd); | ||
m_usb_fd = -1; | ||
|
||
close(m_tcp_fd); | ||
m_tcp_fd = -1; | ||
|
||
Logger::instance()->info("Forwarding stopped\n"); | ||
Logger::instance()->info("Restart communication\n"); | ||
return; | ||
} | ||
|
||
std::optional<std::thread> AAWProxy::startServer(int32_t port) { | ||
|
@@ -160,7 +187,16 @@ std::optional<std::thread> AAWProxy::startServer(int32_t port) { | |
Logger::instance()->info("setsockopt failed: %s\n", strerror(errno)); | ||
return std::nullopt; | ||
} | ||
|
||
|
||
struct timeval tv = { | ||
.tv_sec = 30 | ||
}; | ||
|
||
if (setsockopt(server_sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious: If we're using select before There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. accept is a unlimited time blocking function as it read information while select can manage a timeout because select only detect that the is information but not read it |
||
Logger::instance()->info("setsockopt failed timeout set: %s\n", strerror(errno)); | ||
return std::nullopt; | ||
} | ||
|
||
struct sockaddr_in address; | ||
address.sin_family = AF_INET; | ||
address.sin_addr.s_addr = INADDR_ANY; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,9 @@ void UsbManager::disableGadget() { | |
disableGadget(accessoryGadgetName); | ||
|
||
Logger::instance()->info("USB Manager: Disabled all USB gadgets\n"); | ||
|
||
enableGadget(defaultGadgetName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this required? We generally want to keep usb disabled until we have the phone connection ready to work around headunit timeouts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it depends of the head unit makes the timeout, in my case, in hyundai, i need to have the usb connect (and disabled and enable) or it will never try again if you enabled after "large" time disabled. In this particular headunit works better without the "Connect to USB after phone connection is available" e511b7c commit ; but maybe it this not general behavior buy I don't have other cars to test. In my own personalization I managed/test this commit controlled by a enviroment variable with this code:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe its easier if file is present in /boot partition, as this can be edited from the pc prior to install the sdcard... touch /boot/HEADUNIT_FIRST There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's another way.
before start-stop-daemon -S -b -q -m -p "$PIDFILE" -x "/usr/bin/$DAEMON" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can have an env file in /boot or somewhere else and source it if that works. We should ideally have a nicer ini config file, but for now env variables might be easier to get started with. |
||
Logger::instance()->info("USB Manager: Start default gadget after restart\n"); | ||
} | ||
|
||
void UsbManager::enableDefaultAndWaitForAccessroy() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to set send and recieve timeouts to the client connection socket so that it closes when the phone goes away after connection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this break happens when there is data to read before timeout occurs, going out the while to the accept function