Permalink
Browse files

Actually initialize variables, add some BT messages just incase since…

… we were getting unknown message 0x8001 sometimes on that channel. I'm assuming this is a pairing request but have no way of knowing really. Let's try that for now. Alos using InfoUser type makes the focus work correctly since CMU doesn't go back to MLENT after BTHF so no hack needed.
  • Loading branch information...
lmagder committed Dec 17, 2017
1 parent ba43e50 commit b1094813efed323d3d459d5d6220c6a847b1192c
Showing with 111 additions and 30 deletions.
  1. +30 −7 hu/hu.proto
  2. +50 −3 hu/hu_aap.cpp
  3. +11 −0 hu/hu_aap.h
  4. +19 −20 mazda/callbacks.cpp
  5. +1 −0 mazda/main.cpp
View
@@ -297,6 +297,14 @@ message AudioCofig
required uint32 channel_count = 3;
}
enum BluetoothPairingMethod
{
BLUETOOTH_PARING_METHOD_1 = 1;
BLUETOOTH_PARING_METHOD_A2DP = 2;
BLUETOOTH_PARING_METHOD_3 = 3;
BLUETOOTH_PARING_METHOD_HFP = 4;
}
message ChannelDescriptor
{
required uint32 channel_id = 1;
@@ -367,13 +375,6 @@ message ChannelDescriptor
message BluetoothService
{
enum BluetoothPairingMethod
{
BLUETOOTH_PARING_METHOD_1 = 1;
BLUETOOTH_PARING_METHOD_A2DP = 2;
BLUETOOTH_PARING_METHOD_3 = 3;
BLUETOOTH_PARING_METHOD_HFP = 4;
}
required string car_address = 1;
repeated BluetoothPairingMethod supported_pairing_methods = 2;
}
@@ -671,3 +672,25 @@ message StartGenericNotifications
message StopGenericNotifications
{
}
message BluetoothPairingRequest
{
required string phone_address = 1;
optional BluetoothPairingMethod pairing_method = 2;
}
message BluetoothPairingResponse
{
enum PAIRING_STATUS
{
PAIRING_STATUS_1 = 1;
PAIRING_STATUS_2 = 2;
}
optional bool already_paired = 1;
optional PAIRING_STATUS status = 2;
}
message BluetoothAuthData
{
optional string data = 1;
}
View
@@ -531,12 +531,15 @@
callbacks.CustomizeInputChannel(AA_CH_MIC, *inner);
}
//Doesn't work yet
/*
HU::ChannelDescriptor* notificationChannel = carInfo.add_channels();
notificationChannel->set_channel_id(AA_CH_NOT);
{
auto inner = notificationChannel->mutable_generic_notification_service();
//nothing to set here actually
}
*/
std::string carBTAddress = callbacks.GetCarBluetoothAddress();
if (carBTAddress.size() > 0)
@@ -547,8 +550,8 @@
{
auto inner = btChannel->mutable_bluetooth_service();
inner->set_car_address(carBTAddress);
inner->add_supported_pairing_methods(HU::ChannelDescriptor_BluetoothService::BLUETOOTH_PARING_METHOD_A2DP);
inner->add_supported_pairing_methods(HU::ChannelDescriptor_BluetoothService::BLUETOOTH_PARING_METHOD_HFP);
inner->add_supported_pairing_methods(HU::BLUETOOTH_PARING_METHOD_A2DP);
inner->add_supported_pairing_methods(HU::BLUETOOTH_PARING_METHOD_HFP);
callbacks.CustomizeBluetoothService(AA_CH_BT, *inner);
}
@@ -880,6 +883,41 @@
return 0;
}
int HUServer::hu_handle_BluetoothPairingRequest(int chan, byte * buf, int len){
HU::BluetoothPairingRequest request;
if (!request.ParseFromArray(buf, len))
{
loge ("BluetoothPairingRequest Focus Request");
return -1;
}
else
{
logd ("BluetoothPairingRequest Focus Request");
}
printf("BluetoothPairingRequest: %s\n",request.DebugString().c_str());
HU::BluetoothPairingResponse response;
response.set_already_paired(true);
response.set_status(HU::BluetoothPairingResponse::PAIRING_STATUS_1);
return hu_aap_enc_send_message(0, chan, HU_BLUETOOTH_CHANNEL_MESSAGE::BluetoothPairingResponse, response);
}
int HUServer::hu_handle_BluetoothAuthData(int chan, byte * buf, int len) {
HU::BluetoothAuthData request;
if (!request.ParseFromArray(buf, len))
{
loge ("BluetoothAuthData Focus Request");
return -1;
}
else
{
logd ("BluetoothAuthData Focus Request");
}
printf("BluetoothAuthData: %s\n",request.DebugString().c_str());
return 0;
}
int HUServer::iaap_msg_process (int chan, uint16_t msg_type, byte * buf, int len) {
if (ena_log_verbo)
@@ -963,7 +1001,16 @@
}
else if (chan == AA_CH_BT)
{
logw("BLUETOOTH CHANNEL MESSAGE = chan %d - msg_type: %d", chan, msg_type);
switch((HU_BLUETOOTH_CHANNEL_MESSAGE)msg_type)
{
case HU_BLUETOOTH_CHANNEL_MESSAGE::BluetoothPairingRequest:
return hu_handle_BluetoothPairingRequest(chan, buf, len);
case HU_BLUETOOTH_CHANNEL_MESSAGE::BluetoothAuthData:
return hu_handle_BluetoothAuthData(chan, buf, len);
default:
logw("BLUETOOTH CHANNEL MESSAGE = chan %d - msg_type: %d", chan, msg_type);
return (0);
}
}
else if (chan == AA_CH_PSTAT)
{
View
@@ -266,6 +266,10 @@ class HUServer : protected IHUConnectionThreadInterface
int hu_handle_GenericNotificationResponse(int chan, byte * buf, int len);
int hu_handle_StartGenericNotifications(int chan, byte * buf, int len);
int hu_handle_StopGenericNotifications(int chan, byte * buf, int len);
int hu_handle_BluetoothPairingRequest(int chan, byte * buf, int len);
int hu_handle_BluetoothAuthData(int chan, byte * buf, int len);
//Can be called from any thread
virtual int hu_queue_command(IHUAnyThreadInterface::HUThreadCommand&& command) override;
@@ -331,6 +335,13 @@ enum class HU_PHONE_STATUS_CHANNEL_MESSAGE : uint16_t
PhoneStatusInput = 0x8002,
};
enum class HU_BLUETOOTH_CHANNEL_MESSAGE : uint16_t
{
BluetoothPairingRequest = 0x8001,
BluetoothPairingResponse = 0x8002,
BluetoothAuthData = 0x8003,
};
//Not sure if these are right
enum class HU_GENERIC_NOTIFICATIONS_CHANNEL_MESSAGE : uint16_t
{
View
@@ -14,6 +14,7 @@ MazdaEventCallbacks::MazdaEventCallbacks(DBus::Connection& serviceBus, DBus::Con
, hmiBus(hmiBus)
, connected(false)
, videoFocus(false)
, inCall(false)
, audioFocus(AudioManagerClient::FocusType::NONE)
{
//no need to create/destroy this
@@ -347,7 +348,7 @@ void AudioManagerClient::aaRegisterStream()
{ "streamName", aaStreamName },
//{ "streamModeName", aaStreamName },
{ "focusType", "transient" },
{ "streamType", "Media" }
{ "streamType", "InfoUser" }
};
std::string regString = Request("registerAudioStream", regArgs.dump());
printf("registerAudioStream(%s)\n%s\n", regArgs.dump().c_str(), regString.c_str());
@@ -412,15 +413,18 @@ void AudioManagerClient::populateStreamTable()
}
printf("Found stream %s session id %i\n", streamName.c_str(), sessionId);
streamToSessionIds[streamName] = sessionId;
if(streamName == aaStreamName)
{
if (aaSessionID < 0)
aaSessionID = sessionId;
else
aaTransientSessionID = sessionId;
}
else
{
//We have two so this doesn't work
streamToSessionIds[streamName] = sessionId;
}
}
// Create and register stream (only if we need to)
if (aaSessionID < 0 || aaTransientSessionID < 0)
@@ -488,7 +492,7 @@ void AudioManagerClient::audioMgrRequestAudioFocus(FocusType type)
return;
}
if (currentFocus == FocusType::NONE)
if (currentFocus == FocusType::NONE && type == FocusType::PERMANENT)
{
waitingForFocusLostEvent = true;
previousSessionID = -1;
@@ -505,17 +509,22 @@ void AudioManagerClient::audioMgrReleaseAudioFocus()
{
//nothing to do
callbacks.AudioFocusHappend(currentFocus);
return;
}
bool hadFocus = currentFocus != FocusType::NONE;
if (hadFocus && previousSessionID >= 0)
}
else if (currentFocus == FocusType::PERMANENT && previousSessionID >= 0)
{
//We released the last one, give up audio focus for real
json args = { { "sessionId", previousSessionID } };
std::string result = Request("requestAudioFocus", args.dump());
printf("requestAudioFocus(%s)\n%s\n", args.dump().c_str(), result.c_str());
previousSessionID = -1;
}
else if (currentFocus == FocusType::TRANSIENT)
{
json args = { { "sessionId", aaTransientSessionID } };
std::string result = Request("abandonAudioFocus", args.dump());
printf("abandonAudioFocus(%s)\n%s\n", args.dump().c_str(), result.c_str());
previousSessionID = -1;
}
else
{
currentFocus = FocusType::NONE;
@@ -535,16 +544,6 @@ void AudioManagerClient::Notify(const std::string &signalName, const std::string
std::string newFocus = result["newFocus"].get<std::string>();
std::string focusType = result["focusType"].get<std::string>();
if (currentFocus == FocusType::TRANSIENT && callbacks.inCall &&
(streamName == "BTHF" || streamName == aaStreamName))
{
//If we are in a phone call, initially AA takes transient focus, but CMU switches to BTHF however
//AA needs to believe it still has focus to prevent it from not releasing the focus correctly at the end
//so don't pass on this information to AA, let it think it still has audio focus.
logw("Ignoring focus change due to call");
return;
}
int eventSessionID = -1;
if (streamName == aaStreamName)
{
@@ -556,15 +555,15 @@ void AudioManagerClient::Notify(const std::string &signalName, const std::string
{
eventSessionID = aaTransientSessionID;
}
printf("Found audio sessionId %i for stream %s\n", aaSessionID, streamName.c_str());
logd("Found audio sessionId %i for stream %s\n", aaSessionID, streamName.c_str());
}
else
{
auto findIt = streamToSessionIds.find(streamName);
if (findIt != streamToSessionIds.end())
{
eventSessionID = findIt->second;
printf("Found audio sessionId %i for stream %s\n", eventSessionID, streamName.c_str());
logd("Found audio sessionId %i for stream %s\n", eventSessionID, streamName.c_str());
}
else
{
View
@@ -227,6 +227,7 @@ int main (int argc, char *argv[])
callbacks.connected = false;
callbacks.videoFocus = false;
callbacks.audioFocus = AudioManagerClient::FocusType::NONE;
callbacks.inCall = false;
printf("quitting...\n");
//wake up night mode and gps polling threads

7 comments on commit b109481

@Trevelopment

This comment has been minimized.

Show comment
Hide comment
@Trevelopment

Trevelopment Dec 18, 2017

Collaborator

@lmagder Now this works perfect for me 👍 👍

Collaborator

Trevelopment replied Dec 18, 2017

@lmagder Now this works perfect for me 👍 👍

@Trevelopment

This comment has been minimized.

Show comment
Hide comment
@Trevelopment

Trevelopment Dec 18, 2017

Collaborator

@lmagder It works so perfectly I think it may be time for a release my friend but I don't know about the GPS issue since mine works just fine, did that ever get resolved?

Collaborator

Trevelopment replied Dec 18, 2017

@lmagder It works so perfectly I think it may be time for a release my friend but I don't know about the GPS issue since mine works just fine, did that ever get resolved?

@lmagder

This comment has been minimized.

Show comment
Hide comment
@lmagder

lmagder Dec 19, 2017

Collaborator

@Trevelopment yeah seems like it's time for a release. At least there are no unresolved problems AFAIK. I fixed the GPS being sketchy by polling more often and passing the speed in the right units so the interpolation works correctly. I never saw the issue with it facing the wrong direction though. Maybe it was the same issue? I don't have a way of confirming. I don't think it would block making a release though since it's only getting less buggy over time in general.

Collaborator

lmagder replied Dec 19, 2017

@Trevelopment yeah seems like it's time for a release. At least there are no unresolved problems AFAIK. I fixed the GPS being sketchy by polling more often and passing the speed in the right units so the interpolation works correctly. I never saw the issue with it facing the wrong direction though. Maybe it was the same issue? I don't have a way of confirming. I don't think it would block making a release though since it's only getting less buggy over time in general.

@mishaaq

This comment has been minimized.

Show comment
Hide comment
@mishaaq

mishaaq Dec 19, 2017

Tested yesterday. I wasn't able to make a call, that means, listening to radio I chose the person in AA and observed "Bluetooth not available" or something like that (it was in polish so I'm not sure how it looks like in english) on AA call screen. Ringer sound and phone call was through the phone speaker. I'm pretty sure the radio was silenced.
It started to be funny :D.

mishaaq replied Dec 19, 2017

Tested yesterday. I wasn't able to make a call, that means, listening to radio I chose the person in AA and observed "Bluetooth not available" or something like that (it was in polish so I'm not sure how it looks like in english) on AA call screen. Ringer sound and phone call was through the phone speaker. I'm pretty sure the radio was silenced.
It started to be funny :D.

@lmagder

This comment has been minimized.

Show comment
Hide comment
@lmagder

lmagder Dec 19, 2017

Collaborator

@mishaaq Was the phone connected via BT outside of AA? I noticed issues on my 2XL and also on the my old 6P after it upgraded to 8.0 with BT not connecting right sometimes with my car. It had similar weird results and I had to turn BT on and off until it connected correctly.

Collaborator

lmagder replied Dec 19, 2017

@mishaaq Was the phone connected via BT outside of AA? I noticed issues on my 2XL and also on the my old 6P after it upgraded to 8.0 with BT not connecting right sometimes with my car. It had similar weird results and I had to turn BT on and off until it connected correctly.

@mishaaq

This comment has been minimized.

Show comment
Hide comment
@mishaaq

mishaaq Dec 19, 2017

@lmagder hmm, I'm on a 5X and Oreo 8.1 so it may fit. It strange I haven't any problems like this before. I'll check it out and post the results.

mishaaq replied Dec 19, 2017

@lmagder hmm, I'm on a 5X and Oreo 8.1 so it may fit. It strange I haven't any problems like this before. I'll check it out and post the results.

@mishaaq

This comment has been minimized.

Show comment
Hide comment
@mishaaq

mishaaq Dec 20, 2017

@lmagder you're right. Next time everything worked properly.

mishaaq replied Dec 20, 2017

@lmagder you're right. Next time everything worked properly.

Please sign in to comment.