From 1bc0fe69d5f5f505c978a0c6e32c860e820fa8f6 Mon Sep 17 00:00:00 2001 From: Cole Brinsfield Date: Sun, 26 Dec 2021 11:48:56 -0800 Subject: [PATCH] add media and navigation status (#22) * Implemented media status service, working on navigation service * Navigation Status Service support --- aasdk_proto/ChannelDescriptorData.proto | 2 +- aasdk_proto/DistanceUnitEnum.proto | 36 ++++ aasdk_proto/ManeuverDirectionEnum.proto | 32 ++++ aasdk_proto/ManeuverTypeEnum.proto | 46 +++++ ...lData.proto => MediaInfoChannelData.proto} | 0 .../MediaInfoChannelMessageIdsEnum.proto | 31 ++++ .../MediaInfoChannelMetadataData.proto | 31 ++++ .../MediaInfoChannelPlaybackData.proto | 39 +++++ aasdk_proto/NavigationChannelData.proto | 3 +- .../NavigationChannelMessageIdsEnum.proto | 32 ++++ .../NavigationDistanceEventMessage.proto | 32 ++++ aasdk_proto/NavigationImageOptionsData.proto | 1 + aasdk_proto/NavigationStatusMessage.proto | 33 ++++ aasdk_proto/NavigationTurnEventMessage.proto | 34 ++++ aasdk_proto/NavigationTurnTypeEnum.proto | 31 ++++ aasdk_proto/VideoResolutionEnum.proto | 4 + .../Channel/AV/IMediaStatusServiceChannel.hpp | 50 ++++++ ...IMediaStatusServiceChannelEventHandler.hpp | 50 ++++++ .../Channel/AV/MediaStatusServiceChannel.hpp | 52 ++++++ .../INavigationStatusServiceChannel.hpp | 50 ++++++ ...gationStatusServiceChannelEventHandler.hpp | 52 ++++++ .../NavigationStatusServiceChannel.hpp | 52 ++++++ include/aasdk/Messenger/ChannelId.hpp | 2 + src/Channel/AV/MediaStatusServiceChannel.cpp | 146 ++++++++++++++++ .../NavigationStatusServiceChannel.cpp | 162 ++++++++++++++++++ src/Common/Data.cpp | 19 +- src/Messenger/ChannelId.cpp | 2 + 27 files changed, 1021 insertions(+), 3 deletions(-) create mode 100644 aasdk_proto/DistanceUnitEnum.proto create mode 100644 aasdk_proto/ManeuverDirectionEnum.proto create mode 100644 aasdk_proto/ManeuverTypeEnum.proto rename aasdk_proto/{MediaChannelData.proto => MediaInfoChannelData.proto} (100%) create mode 100644 aasdk_proto/MediaInfoChannelMessageIdsEnum.proto create mode 100644 aasdk_proto/MediaInfoChannelMetadataData.proto create mode 100644 aasdk_proto/MediaInfoChannelPlaybackData.proto create mode 100644 aasdk_proto/NavigationChannelMessageIdsEnum.proto create mode 100644 aasdk_proto/NavigationDistanceEventMessage.proto create mode 100644 aasdk_proto/NavigationStatusMessage.proto create mode 100644 aasdk_proto/NavigationTurnEventMessage.proto create mode 100644 aasdk_proto/NavigationTurnTypeEnum.proto create mode 100644 include/aasdk/Channel/AV/IMediaStatusServiceChannel.hpp create mode 100644 include/aasdk/Channel/AV/IMediaStatusServiceChannelEventHandler.hpp create mode 100644 include/aasdk/Channel/AV/MediaStatusServiceChannel.hpp create mode 100644 include/aasdk/Channel/Navigation/INavigationStatusServiceChannel.hpp create mode 100644 include/aasdk/Channel/Navigation/INavigationStatusServiceChannelEventHandler.hpp create mode 100644 include/aasdk/Channel/Navigation/NavigationStatusServiceChannel.hpp create mode 100644 src/Channel/AV/MediaStatusServiceChannel.cpp create mode 100644 src/Channel/Navigation/NavigationStatusServiceChannel.cpp diff --git a/aasdk_proto/ChannelDescriptorData.proto b/aasdk_proto/ChannelDescriptorData.proto index 8270927..786f408 100644 --- a/aasdk_proto/ChannelDescriptorData.proto +++ b/aasdk_proto/ChannelDescriptorData.proto @@ -27,7 +27,7 @@ import "AVInputChannelData.proto"; import "BluetoothChannelData.proto"; import "NavigationChannelData.proto"; import "VendorExtensionChannelData.proto"; -import "MediaChannelData.proto"; +import "MediaInfoChannelData.proto"; import "WifiChannelData.proto"; package aasdk.proto.data; diff --git a/aasdk_proto/DistanceUnitEnum.proto b/aasdk_proto/DistanceUnitEnum.proto new file mode 100644 index 0000000..acfbf84 --- /dev/null +++ b/aasdk_proto/DistanceUnitEnum.proto @@ -0,0 +1,36 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +syntax="proto2"; + +package aasdk.proto.enums; + +message DistanceUnit +{ + enum Enum + { + UNKNOWN = 0; + METERS = 1; + KILOMETERS = 2; + KILOMETERS_PARTIAL = 3; + MILES = 4; + MILES_PARTIAL = 5; + FEET = 6; + YARDS = 7; + } +} diff --git a/aasdk_proto/ManeuverDirectionEnum.proto b/aasdk_proto/ManeuverDirectionEnum.proto new file mode 100644 index 0000000..a1ee0b0 --- /dev/null +++ b/aasdk_proto/ManeuverDirectionEnum.proto @@ -0,0 +1,32 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +syntax="proto2"; + +package aasdk.proto.enums; + +message ManeuverDirection +{ + enum Enum + { + UNKNOWN = 0; + LEFT = 1; + RIGHT = 2; + UNSPECIFIED = 3; + } +} diff --git a/aasdk_proto/ManeuverTypeEnum.proto b/aasdk_proto/ManeuverTypeEnum.proto new file mode 100644 index 0000000..bf37d94 --- /dev/null +++ b/aasdk_proto/ManeuverTypeEnum.proto @@ -0,0 +1,46 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +syntax="proto2"; + +package aasdk.proto.enums; + +message ManeuverType +{ + enum Enum + { + UNKNOWN = 0; + DEPART = 1; + NAME_CHANGE = 2; + SLIGHT_TURN = 3; + TURN = 4; + SHARP_TURN = 5; + U_TURN = 6; + ON_RAMP = 7; + OFF_RAMP = 8; + FORK = 9; + MERGE = 10; + ROUNDABOUT_ENTER = 11; + ROUNDABOUT_EXIT = 12; + ROUNDABOUT_ENTER_AND_EXIT = 13; + STRAIGHT = 14; + FERRY_BOAT = 16; + FERRY_TRAIN = 17; + DESTINATION = 19; + } +} diff --git a/aasdk_proto/MediaChannelData.proto b/aasdk_proto/MediaInfoChannelData.proto similarity index 100% rename from aasdk_proto/MediaChannelData.proto rename to aasdk_proto/MediaInfoChannelData.proto diff --git a/aasdk_proto/MediaInfoChannelMessageIdsEnum.proto b/aasdk_proto/MediaInfoChannelMessageIdsEnum.proto new file mode 100644 index 0000000..90d0bbe --- /dev/null +++ b/aasdk_proto/MediaInfoChannelMessageIdsEnum.proto @@ -0,0 +1,31 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +syntax="proto2"; + +package aasdk.proto.ids; + +message MediaInfoChannelMessage +{ + enum Enum + { + NONE = 0x0000; + PLAYBACK = 0x8001; + METADATA = 0x8003; + } +} diff --git a/aasdk_proto/MediaInfoChannelMetadataData.proto b/aasdk_proto/MediaInfoChannelMetadataData.proto new file mode 100644 index 0000000..b3e68dd --- /dev/null +++ b/aasdk_proto/MediaInfoChannelMetadataData.proto @@ -0,0 +1,31 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +syntax="proto2"; + +package aasdk.proto.messages; + +message MediaInfoChannelMetadataData +{ + required string track_name = 1; + optional string artist_name = 2; + optional string album_name = 3; + optional bytes album_art = 4; + required int32 track_length = 6; + required int32 unknown1 = 7; +} diff --git a/aasdk_proto/MediaInfoChannelPlaybackData.proto b/aasdk_proto/MediaInfoChannelPlaybackData.proto new file mode 100644 index 0000000..e6f2d00 --- /dev/null +++ b/aasdk_proto/MediaInfoChannelPlaybackData.proto @@ -0,0 +1,39 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +syntax="proto2"; + +package aasdk.proto.messages; + +message MediaInfoChannelPlaybackData +{ + enum PlaybackState + { + NONE = 0x0000; + TRACK_CHANGE = 1; + PLAY = 2; + PAUSE = 3; + } + required PlaybackState playback_state = 1; + required string media_source = 2; + required int32 track_progress = 3; + required int32 unknown1 = 4; + required int32 unknown2 = 5; + required int32 unknown3 = 6; + +} diff --git a/aasdk_proto/NavigationChannelData.proto b/aasdk_proto/NavigationChannelData.proto index 8aa7b72..5c18a04 100644 --- a/aasdk_proto/NavigationChannelData.proto +++ b/aasdk_proto/NavigationChannelData.proto @@ -18,6 +18,7 @@ syntax="proto2"; +import "NavigationTurnTypeEnum.proto"; import "NavigationImageOptionsData.proto"; package aasdk.proto.data; @@ -25,6 +26,6 @@ package aasdk.proto.data; message NavigationChannel { required uint32 minimum_interval_ms = 1; - required uint32 type = 2; + required enums.NavigationTurnType.Enum type = 2; required NavigationImageOptions image_options = 3; } diff --git a/aasdk_proto/NavigationChannelMessageIdsEnum.proto b/aasdk_proto/NavigationChannelMessageIdsEnum.proto new file mode 100644 index 0000000..ba44dd6 --- /dev/null +++ b/aasdk_proto/NavigationChannelMessageIdsEnum.proto @@ -0,0 +1,32 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +syntax="proto2"; + +package aasdk.proto.ids; + +message NavigationChannelMessage +{ + enum Enum + { + NONE = 0x0000; + STATUS = 0x8003; + TURN_EVENT = 0x8004; + DISTANCE_EVENT = 0x8005; + } +} diff --git a/aasdk_proto/NavigationDistanceEventMessage.proto b/aasdk_proto/NavigationDistanceEventMessage.proto new file mode 100644 index 0000000..74920b9 --- /dev/null +++ b/aasdk_proto/NavigationDistanceEventMessage.proto @@ -0,0 +1,32 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +syntax="proto2"; + +import "DistanceUnitEnum.proto"; + +package aasdk.proto.messages; + +message NavigationDistanceEvent +{ + required uint32 meters = 1; + required uint32 timeToStepSeconds = 2; + required uint32 distanceToStepMillis = 3; + required enums.DistanceUnit.Enum distanceUnit = 4; + +} diff --git a/aasdk_proto/NavigationImageOptionsData.proto b/aasdk_proto/NavigationImageOptionsData.proto index 6ac76c7..bb38a2f 100644 --- a/aasdk_proto/NavigationImageOptionsData.proto +++ b/aasdk_proto/NavigationImageOptionsData.proto @@ -25,4 +25,5 @@ message NavigationImageOptions required int32 width = 1; required int32 height = 2; required int32 colour_depth_bits = 3; + required int32 dunno = 4; } diff --git a/aasdk_proto/NavigationStatusMessage.proto b/aasdk_proto/NavigationStatusMessage.proto new file mode 100644 index 0000000..a5b6a22 --- /dev/null +++ b/aasdk_proto/NavigationStatusMessage.proto @@ -0,0 +1,33 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +syntax="proto2"; + +package aasdk.proto.messages; + +message NavigationStatus +{ + required Enum status = 1; + enum Enum + { + UNAVAILABLE = 0; + ACTIVE = 1; + INACTIVE = 2; + REROUTING = 3; + } +} diff --git a/aasdk_proto/NavigationTurnEventMessage.proto b/aasdk_proto/NavigationTurnEventMessage.proto new file mode 100644 index 0000000..e9fefbd --- /dev/null +++ b/aasdk_proto/NavigationTurnEventMessage.proto @@ -0,0 +1,34 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +syntax="proto2"; + +import "ManeuverTypeEnum.proto"; +import "ManeuverDirectionEnum.proto"; + +package aasdk.proto.messages; + +message NavigationTurnEvent +{ + required string street_name = 1; + required enums.ManeuverDirection.Enum maneuverDirection = 2; + required enums.ManeuverType.Enum maneuverType = 3; + required bytes turnImage = 4; + required uint32 roundaboutExitNumber = 5; + required uint32 roundaboutExitAngle = 6; +} diff --git a/aasdk_proto/NavigationTurnTypeEnum.proto b/aasdk_proto/NavigationTurnTypeEnum.proto new file mode 100644 index 0000000..bd35502 --- /dev/null +++ b/aasdk_proto/NavigationTurnTypeEnum.proto @@ -0,0 +1,31 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +syntax="proto2"; + +package aasdk.proto.enums; + +message NavigationTurnType +{ + enum Enum + { + UNKNOWN = 0; + IMAGE = 1; + ENUM = 2; + } +} diff --git a/aasdk_proto/VideoResolutionEnum.proto b/aasdk_proto/VideoResolutionEnum.proto index 32b582c..061393b 100644 --- a/aasdk_proto/VideoResolutionEnum.proto +++ b/aasdk_proto/VideoResolutionEnum.proto @@ -28,5 +28,9 @@ message VideoResolution _480p = 1; _720p = 2; _1080p = 3; + _1440p = 4; + _720p_p = 5; + _1080pp = 6; + _108s0p_p = 7; } } diff --git a/include/aasdk/Channel/AV/IMediaStatusServiceChannel.hpp b/include/aasdk/Channel/AV/IMediaStatusServiceChannel.hpp new file mode 100644 index 0000000..e388f60 --- /dev/null +++ b/include/aasdk/Channel/AV/IMediaStatusServiceChannel.hpp @@ -0,0 +1,50 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +#pragma once + +#include +#include +#include +#include +#include + + +namespace aasdk +{ +namespace channel +{ +namespace av +{ + +class IMediaStatusServiceChannel +{ +public: + typedef std::shared_ptr Pointer; + + IMediaStatusServiceChannel() = default; + virtual ~IMediaStatusServiceChannel() = default; + + virtual void receive(IMediaStatusServiceChannelEventHandler::Pointer eventHandler) = 0; + virtual void sendChannelOpenResponse(const proto::messages::ChannelOpenResponse& response, SendPromise::Pointer promise) = 0; + virtual messenger::ChannelId getId() const = 0; +}; + +} +} +} diff --git a/include/aasdk/Channel/AV/IMediaStatusServiceChannelEventHandler.hpp b/include/aasdk/Channel/AV/IMediaStatusServiceChannelEventHandler.hpp new file mode 100644 index 0000000..56e068d --- /dev/null +++ b/include/aasdk/Channel/AV/IMediaStatusServiceChannelEventHandler.hpp @@ -0,0 +1,50 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +#pragma once + +#include +#include +#include +#include + + +namespace aasdk +{ +namespace channel +{ +namespace av +{ + +class IMediaStatusServiceChannelEventHandler +{ +public: + typedef std::shared_ptr Pointer; + + IMediaStatusServiceChannelEventHandler() = default; + virtual ~IMediaStatusServiceChannelEventHandler() = default; + + virtual void onChannelOpenRequest(const proto::messages::ChannelOpenRequest& request) = 0; + virtual void onChannelError(const error::Error& e) = 0; + virtual void onMetadataUpdate(const proto::messages::MediaInfoChannelMetadataData& metadata) = 0; + virtual void onPlaybackUpdate(const proto::messages::MediaInfoChannelPlaybackData& playback) = 0; +}; + +} +} +} diff --git a/include/aasdk/Channel/AV/MediaStatusServiceChannel.hpp b/include/aasdk/Channel/AV/MediaStatusServiceChannel.hpp new file mode 100644 index 0000000..0b02992 --- /dev/null +++ b/include/aasdk/Channel/AV/MediaStatusServiceChannel.hpp @@ -0,0 +1,52 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +#pragma once + +#include +#include + + +namespace aasdk +{ +namespace channel +{ +namespace av +{ + +class MediaStatusServiceChannel: public IMediaStatusServiceChannel, public ServiceChannel, public std::enable_shared_from_this +{ +public: + MediaStatusServiceChannel(boost::asio::io_service::strand& strand, messenger::IMessenger::Pointer messenger); + + void receive(IMediaStatusServiceChannelEventHandler::Pointer eventHandler) override; + messenger::ChannelId getId() const override; + void sendChannelOpenResponse(const proto::messages::ChannelOpenResponse& response, SendPromise::Pointer promise) override; + +private: + using std::enable_shared_from_this::shared_from_this; + void messageHandler(messenger::Message::Pointer message, IMediaStatusServiceChannelEventHandler::Pointer eventHandler); + void handleChannelOpenRequest(const common::DataConstBuffer& payload, IMediaStatusServiceChannelEventHandler::Pointer eventHandler); + void handleMetadataUpdate(const common::DataConstBuffer& payload, IMediaStatusServiceChannelEventHandler::Pointer eventHandler); + void handlePlaybackUpdate(const common::DataConstBuffer& payload, IMediaStatusServiceChannelEventHandler::Pointer eventHandler); + +}; + +} +} +} diff --git a/include/aasdk/Channel/Navigation/INavigationStatusServiceChannel.hpp b/include/aasdk/Channel/Navigation/INavigationStatusServiceChannel.hpp new file mode 100644 index 0000000..87c4910 --- /dev/null +++ b/include/aasdk/Channel/Navigation/INavigationStatusServiceChannel.hpp @@ -0,0 +1,50 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +#pragma once + +#include +#include +#include +#include +#include + + +namespace aasdk +{ +namespace channel +{ +namespace navigation +{ + +class INavigationStatusServiceChannel +{ +public: + typedef std::shared_ptr Pointer; + + INavigationStatusServiceChannel() = default; + virtual ~INavigationStatusServiceChannel() = default; + + virtual void receive(INavigationStatusServiceChannelEventHandler::Pointer eventHandler) = 0; + virtual void sendChannelOpenResponse(const proto::messages::ChannelOpenResponse& response, SendPromise::Pointer promise) = 0; + virtual messenger::ChannelId getId() const = 0; +}; + +} +} +} diff --git a/include/aasdk/Channel/Navigation/INavigationStatusServiceChannelEventHandler.hpp b/include/aasdk/Channel/Navigation/INavigationStatusServiceChannelEventHandler.hpp new file mode 100644 index 0000000..8c9a1a5 --- /dev/null +++ b/include/aasdk/Channel/Navigation/INavigationStatusServiceChannelEventHandler.hpp @@ -0,0 +1,52 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +#pragma once + +#include +#include +#include +#include +#include + + +namespace aasdk +{ +namespace channel +{ +namespace navigation +{ + +class INavigationStatusServiceChannelEventHandler +{ +public: + typedef std::shared_ptr Pointer; + + INavigationStatusServiceChannelEventHandler() = default; + virtual ~INavigationStatusServiceChannelEventHandler() = default; + + virtual void onChannelOpenRequest(const proto::messages::ChannelOpenRequest& request) = 0; + virtual void onChannelError(const error::Error& e) = 0; + virtual void onStatusUpdate(const proto::messages::NavigationStatus& navStatus) = 0; + virtual void onTurnEvent(const proto::messages::NavigationTurnEvent& turnEvent) = 0; + virtual void onDistanceEvent(const proto::messages::NavigationDistanceEvent& distanceEvent) = 0; +}; + +} +} +} diff --git a/include/aasdk/Channel/Navigation/NavigationStatusServiceChannel.hpp b/include/aasdk/Channel/Navigation/NavigationStatusServiceChannel.hpp new file mode 100644 index 0000000..b74b974 --- /dev/null +++ b/include/aasdk/Channel/Navigation/NavigationStatusServiceChannel.hpp @@ -0,0 +1,52 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +#pragma once + +#include +#include + + +namespace aasdk +{ +namespace channel +{ +namespace navigation +{ + +class NavigationStatusServiceChannel: public INavigationStatusServiceChannel, public ServiceChannel, public std::enable_shared_from_this +{ +public: + NavigationStatusServiceChannel(boost::asio::io_service::strand& strand, messenger::IMessenger::Pointer messenger); + + void receive(INavigationStatusServiceChannelEventHandler::Pointer eventHandler) override; + messenger::ChannelId getId() const override; + void sendChannelOpenResponse(const proto::messages::ChannelOpenResponse& response, SendPromise::Pointer promise) override; + +private: + using std::enable_shared_from_this::shared_from_this; + void messageHandler(messenger::Message::Pointer message, INavigationStatusServiceChannelEventHandler::Pointer eventHandler); + void handleChannelOpenRequest(const common::DataConstBuffer& payload, INavigationStatusServiceChannelEventHandler::Pointer eventHandler); + void handleStatusUpdate(const common::DataConstBuffer& payload, INavigationStatusServiceChannelEventHandler::Pointer eventHandler); + void handleTurnEvent(const common::DataConstBuffer& payload, INavigationStatusServiceChannelEventHandler::Pointer eventHandler); + void handleDistanceEvent(const common::DataConstBuffer& payload, INavigationStatusServiceChannelEventHandler::Pointer eventHandler); +}; + +} +} +} diff --git a/include/aasdk/Messenger/ChannelId.hpp b/include/aasdk/Messenger/ChannelId.hpp index 16c922f..29b70c9 100644 --- a/include/aasdk/Messenger/ChannelId.hpp +++ b/include/aasdk/Messenger/ChannelId.hpp @@ -37,6 +37,8 @@ enum class ChannelId SYSTEM_AUDIO, AV_INPUT, BLUETOOTH, + NAVIGATION, + MEDIA_STATUS, NONE = 255 }; diff --git a/src/Channel/AV/MediaStatusServiceChannel.cpp b/src/Channel/AV/MediaStatusServiceChannel.cpp new file mode 100644 index 0000000..d5563b1 --- /dev/null +++ b/src/Channel/AV/MediaStatusServiceChannel.cpp @@ -0,0 +1,146 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace aasdk +{ +namespace channel +{ +namespace av +{ + +MediaStatusServiceChannel::MediaStatusServiceChannel(boost::asio::io_service::strand& strand, messenger::IMessenger::Pointer messenger) + : ServiceChannel(strand, std::move(messenger), messenger::ChannelId::MEDIA_STATUS) +{ + +} + +void MediaStatusServiceChannel::receive(IMediaStatusServiceChannelEventHandler::Pointer eventHandler) +{ + auto receivePromise = messenger::ReceivePromise::defer(strand_); + receivePromise->then(std::bind(&MediaStatusServiceChannel::messageHandler, this->shared_from_this(), std::placeholders::_1, eventHandler), + std::bind(&IMediaStatusServiceChannelEventHandler::onChannelError, eventHandler,std::placeholders::_1)); + + messenger_->enqueueReceive(channelId_, std::move(receivePromise)); +} + +messenger::ChannelId MediaStatusServiceChannel::getId() const +{ + return channelId_; +} + +void MediaStatusServiceChannel::sendChannelOpenResponse(const proto::messages::ChannelOpenResponse& response, SendPromise::Pointer promise) +{ + AASDK_LOG(info) << "[MediaStatusServiceChannel] channel open response "; + auto message(std::make_shared(channelId_, messenger::EncryptionType::ENCRYPTED, messenger::MessageType::CONTROL)); + message->insertPayload(messenger::MessageId(proto::ids::ControlMessage::CHANNEL_OPEN_RESPONSE).getData()); + message->insertPayload(response); + + this->send(std::move(message), std::move(promise)); +} + + +void MediaStatusServiceChannel::messageHandler(messenger::Message::Pointer message, IMediaStatusServiceChannelEventHandler::Pointer eventHandler) +{ + messenger::MessageId messageId(message->getPayload()); + common::DataConstBuffer payload(message->getPayload(), messageId.getSizeOf()); + + switch(messageId.getId()) + { + case proto::ids::ControlMessage::CHANNEL_OPEN_REQUEST: + this->handleChannelOpenRequest(payload, std::move(eventHandler)); + break; + + case proto::ids::MediaInfoChannelMessage::METADATA: + this->handleMetadataUpdate(payload, std::move(eventHandler)); + break; + + case proto::ids::MediaInfoChannelMessage::PLAYBACK: + this->handlePlaybackUpdate(payload, std::move(eventHandler)); + break; + + default: + AASDK_LOG(error) << "[MediaStatusServiceChannel] message not handled: " << messageId.getId() << " : " << dump(payload); + this->receive(std::move(eventHandler)); + break; + } + + + +} + +void MediaStatusServiceChannel::handleMetadataUpdate(const common::DataConstBuffer& payload, IMediaStatusServiceChannelEventHandler::Pointer eventHandler) +{ + proto::messages::MediaInfoChannelMetadataData metadata; + if(metadata.ParseFromArray(payload.cdata, payload.size)) + { + eventHandler->onMetadataUpdate(metadata); + } + else + { + eventHandler->onChannelError(error::Error(error::ErrorCode::PARSE_PAYLOAD)); + AASDK_LOG(error) << "[MediaStatusServiceChannel] encountered error with message: " << dump(payload); + } + +} + + +void MediaStatusServiceChannel::handlePlaybackUpdate(const common::DataConstBuffer& payload, IMediaStatusServiceChannelEventHandler::Pointer eventHandler) +{ + proto::messages::MediaInfoChannelPlaybackData playback; + if(playback.ParseFromArray(payload.cdata, payload.size)) + { + eventHandler->onPlaybackUpdate(playback); + } + else + { + eventHandler->onChannelError(error::Error(error::ErrorCode::PARSE_PAYLOAD)); + AASDK_LOG(error) << "[MediaStatusServiceChannel] encountered error with message: " << dump(payload); + } + +} + +void MediaStatusServiceChannel::handleChannelOpenRequest(const common::DataConstBuffer& payload, IMediaStatusServiceChannelEventHandler::Pointer eventHandler) +{ + AASDK_LOG(info) << "[MediaStatusServiceChannel] channel open request "; + + proto::messages::ChannelOpenRequest request; + if(request.ParseFromArray(payload.cdata, payload.size)) + { + eventHandler->onChannelOpenRequest(request); + } + else + { + eventHandler->onChannelError(error::Error(error::ErrorCode::PARSE_PAYLOAD)); + } +} + + +} +} +} diff --git a/src/Channel/Navigation/NavigationStatusServiceChannel.cpp b/src/Channel/Navigation/NavigationStatusServiceChannel.cpp new file mode 100644 index 0000000..726837a --- /dev/null +++ b/src/Channel/Navigation/NavigationStatusServiceChannel.cpp @@ -0,0 +1,162 @@ +/* +* This file is part of aasdk library project. +* Copyright (C) 2018 f1x.studio (Michal Szwaj) +* +* aasdk is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. + +* aasdk is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with aasdk. If not, see . +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace aasdk +{ +namespace channel +{ +namespace navigation +{ + +NavigationStatusServiceChannel::NavigationStatusServiceChannel(boost::asio::io_service::strand& strand, messenger::IMessenger::Pointer messenger) + : ServiceChannel(strand, std::move(messenger), messenger::ChannelId::NAVIGATION) +{ + +} + +void NavigationStatusServiceChannel::receive(INavigationStatusServiceChannelEventHandler::Pointer eventHandler) +{ + AASDK_LOG(info) << "[NavigationStatusServiceChannel] receive "; + + auto receivePromise = messenger::ReceivePromise::defer(strand_); + receivePromise->then(std::bind(&NavigationStatusServiceChannel::messageHandler, this->shared_from_this(), std::placeholders::_1, eventHandler), + std::bind(&INavigationStatusServiceChannelEventHandler::onChannelError, eventHandler,std::placeholders::_1)); + + messenger_->enqueueReceive(channelId_, std::move(receivePromise)); +} + +messenger::ChannelId NavigationStatusServiceChannel::getId() const +{ + return channelId_; +} + +void NavigationStatusServiceChannel::sendChannelOpenResponse(const proto::messages::ChannelOpenResponse& response, SendPromise::Pointer promise) +{ + AASDK_LOG(info) << "[NavigationStatusServiceChannel] channel open response "; + + auto message(std::make_shared(channelId_, messenger::EncryptionType::ENCRYPTED, messenger::MessageType::CONTROL)); + message->insertPayload(messenger::MessageId(proto::ids::ControlMessage::CHANNEL_OPEN_RESPONSE).getData()); + message->insertPayload(response); + + this->send(std::move(message), std::move(promise)); +} + + +void NavigationStatusServiceChannel::messageHandler(messenger::Message::Pointer message, INavigationStatusServiceChannelEventHandler::Pointer eventHandler) +{ + AASDK_LOG(info) << "[NavigationStatusServiceChannel] message handler "; + + messenger::MessageId messageId(message->getPayload()); + common::DataConstBuffer payload(message->getPayload(), messageId.getSizeOf()); + + switch(messageId.getId()) + { + case proto::ids::ControlMessage::CHANNEL_OPEN_REQUEST: + this->handleChannelOpenRequest(payload, std::move(eventHandler)); + break; + case proto::ids::NavigationChannelMessage::STATUS: + this->handleStatusUpdate(payload, std::move(eventHandler)); + break; + case proto::ids::NavigationChannelMessage::TURN_EVENT: + this->handleTurnEvent(payload, std::move(eventHandler)); + break; + case proto::ids::NavigationChannelMessage::DISTANCE_EVENT: + this->handleDistanceEvent(payload, std::move(eventHandler)); + break; + + + default: + AASDK_LOG(error) << "[NavigationStatusServiceChannel] message not handled: " << messageId.getId() << " : " << dump(payload); + this->receive(std::move(eventHandler)); + break; + } +} + +void NavigationStatusServiceChannel::handleChannelOpenRequest(const common::DataConstBuffer& payload, INavigationStatusServiceChannelEventHandler::Pointer eventHandler) +{ + AASDK_LOG(info) << "[NavigationStatusServiceChannel] channel open request "; + + proto::messages::ChannelOpenRequest request; + if(request.ParseFromArray(payload.cdata, payload.size)) + { + eventHandler->onChannelOpenRequest(request); + } + else + { + eventHandler->onChannelError(error::Error(error::ErrorCode::PARSE_PAYLOAD)); + } +} + +void NavigationStatusServiceChannel::handleStatusUpdate(const common::DataConstBuffer& payload, INavigationStatusServiceChannelEventHandler::Pointer eventHandler) +{ + proto::messages::NavigationStatus navStatus; + if(navStatus.ParseFromArray(payload.cdata, payload.size)) + { + eventHandler->onStatusUpdate(navStatus); + } + else + { + eventHandler->onChannelError(error::Error(error::ErrorCode::PARSE_PAYLOAD)); + AASDK_LOG(error) << "[NavigationStatusServiceChannel] encountered error with message: " << dump(payload); + } + +} + +void NavigationStatusServiceChannel::handleTurnEvent(const common::DataConstBuffer& payload, INavigationStatusServiceChannelEventHandler::Pointer eventHandler) +{ + proto::messages::NavigationTurnEvent turnEvent; + if(turnEvent.ParseFromArray(payload.cdata, payload.size)) + { + eventHandler->onTurnEvent(turnEvent); + } + else + { + eventHandler->onChannelError(error::Error(error::ErrorCode::PARSE_PAYLOAD)); + AASDK_LOG(error) << "[NavigationStatusServiceChannel] encountered error with message: " << dump(payload); + } + +} + +void NavigationStatusServiceChannel::handleDistanceEvent(const common::DataConstBuffer& payload, INavigationStatusServiceChannelEventHandler::Pointer eventHandler) +{ + proto::messages::NavigationDistanceEvent distanceEvent; + if(distanceEvent.ParseFromArray(payload.cdata, payload.size)) + { + eventHandler->onDistanceEvent(distanceEvent); + } + else + { + eventHandler->onChannelError(error::Error(error::ErrorCode::PARSE_PAYLOAD)); + AASDK_LOG(error) << "[NavigationStatusServiceChannel] encountered error with message: " << dump(payload); + } + +} + +} +} +} diff --git a/src/Common/Data.cpp b/src/Common/Data.cpp index 397752f..ec689f1 100644 --- a/src/Common/Data.cpp +++ b/src/Common/Data.cpp @@ -19,6 +19,9 @@ #include #include #include +#include +#include +#include namespace aasdk @@ -130,6 +133,20 @@ std::string dump(const Data& data) return dump(DataConstBuffer(data)); } + +std::string uint8_to_hex_string(const uint8_t *v, const size_t s) { + std::stringstream ss; + + ss << std::hex << std::setfill('0'); + + for (int i = 0; i < s; i++) { + ss << " "; + ss << std::hex << std::setw(2) << static_cast(v[i]); + } + + return ss.str(); +} + std::string dump(const DataConstBuffer& buffer) { if(buffer.size == 0) @@ -138,7 +155,7 @@ std::string dump(const DataConstBuffer& buffer) } else { - std::string hexDump = "[" + std::to_string(buffer.size) + "] "; + std::string hexDump = "[" + uint8_to_hex_string(buffer.cdata, buffer.size) + " ] "; //boost::algorithm::hex(bufferBegin(buffer), bufferEnd(buffer), back_inserter(hexDump)); return hexDump; } diff --git a/src/Messenger/ChannelId.cpp b/src/Messenger/ChannelId.cpp index a54b701..66ca3ca 100644 --- a/src/Messenger/ChannelId.cpp +++ b/src/Messenger/ChannelId.cpp @@ -46,6 +46,8 @@ std::string channelIdToString(ChannelId channelId) return "AV_INPUT"; case ChannelId::BLUETOOTH: return "BLUETOOTH"; + case ChannelId::NAVIGATION: + return "NAVIGATION"; case ChannelId::NONE: return "NONE"; default: