/// <summary> /// This method is called to handle a message containing a Link_Capability_Discover, returning to the MIHF the appropriate response. /// </summary> /// <param name="m">The received Link_Capability_Discover message object</param> public static void HandleCapabilityDiscover(Message m) { Payload.TLVIterator it = m.Payload.GetTLVIterator(); ID srcID = new ID(new OctetString(it.Next().Value)); ID dstID = new ID(new OctetString(it.Next().Value)); Program.toMihf.Send(ResponseBuilders.Link_Capability_Discover_Response_Builder(dstID, srcID, STATUS.SUCCESS, Capabilities.CapabilitiesHandler.SupportedEventList, Capabilities.CapabilitiesHandler.SupportedCommandsList).ByteValue); }
public static void LinkActionCallback(Object stateInfo) { Message m = (Message)stateInfo; ConnectionHelper ch = Program.toMihf; ushort transactionID = m.MIHHeader.TransactionID; Payload.TLVIterator it = m.Payload.GetTLVIterator(); ID srcID = new ID(new OctetString(it.Next().Value)); ID dstID = new ID(new OctetString(it.Next().Value)); Link_Action_Request lar = new Link_Action_Request(MIHDeserializer.DeserializeLinkAction(it.Next()), MIHDeserializer.DeserializeTimeInterval(it.Next()), MIHDeserializer.DeserializePoA(it.Next())); Link_Action_Response laresp = new Link_Action_Response(); laresp.Status = STATUS.UNSPECIFIED_FAILURE; laresp.Result = Link_Ac_Result.INCAPABLE; NativeWifi.WlanClient.WlanInterface iface = null; try { iface = Information.GenericInfo.WlanInterfaceInstance; } catch (Exception e) { /*nothing*/ } switch (lar.LinkAction.LinkAcType) { case Link_Ac_Type.LINK_DISCONNECT: ActionsInterface.Action_Disconnect(ref laresp, ref iface); break; case Link_Ac_Type.NONE: Console.WriteLine("No action performed."); laresp.Status = STATUS.SUCCESS; laresp.Result = Link_Ac_Result.SUCCESS; break; case Link_Ac_Type.LINK_POWER_DOWN: ActionsInterface.Action_Power_Down(ref laresp, ref iface); break; case Link_Ac_Type.LINK_POWER_UP: ActionsInterface.Action_Power_Up(ref laresp, ref iface); break; default: throw new InvalidOperationException("Unsupported Operation"); } laresp.ScanResults = new List <Link_Scan_Rsp>(); if (lar.LinkAction.LinkAcAttr.Link_Scan) { ActionsInterface.Action_Scan(laresp, iface, m);//Message is sent inside this branch, after the scan is complete. } else { ch.Send(ResponseBuilders.Link_Action_Response_Builder(srcID, dstID, transactionID, laresp).ByteValue); } }
/// <summary> /// This method is called to handle a Threshold configuration request message /// </summary> /// <param name="m">The serialized Config_Thresholds message</param> public static void HandleConfigThresholds(Message m) { ConnectionHelper ch = Program.toMihf; ushort transactionID = m.MIHHeader.TransactionID; Payload.TLVIterator it = m.Payload.GetTLVIterator(); ID srcID = new ID(new OctetString(it.Next().Value)); ID dstID = new ID(new OctetString(it.Next().Value)); List <Link_Cfg_Param> lcparams = MIHDeserializer.DeserializeLinkCfgParamList(it.Next()); List <Link_Cfg_Status> lcstatus = new List <Link_Cfg_Status>(); foreach (Link_Cfg_Param param in lcparams) { if (param.Timer_Interval > 0 && param.Th_Action != TH_Action.CANCEL_THRESHOLD) { Reports.TimedReports.Add(new TimedReport(param.Link_Param_Type.AbsoluteType, param.Timer_Interval)); } switch (param.Th_Action) { case TH_Action.ONE_SHOT_THRESHOLD: foreach (Threshold t in param.ThresholdList) { try { Reports.OneShotThresholds.Add(new ActiveThreshold(t, param.Link_Param_Type.AbsoluteType)); lcstatus.Add(new Link_Cfg_Status(param.Link_Param_Type, t, true)); } catch (Exception e) { lcstatus.Add(new Link_Cfg_Status(param.Link_Param_Type, t, false)); } } break; case TH_Action.NORMAL_THRESHOLD: foreach (Threshold t in param.ThresholdList) { try { Reports.ActiveThresholds.Add(new ActiveThreshold(t, param.Link_Param_Type.AbsoluteType)); lcstatus.Add(new Link_Cfg_Status(param.Link_Param_Type, t, true)); } catch (Exception e) { lcstatus.Add(new Link_Cfg_Status(param.Link_Param_Type, t, false)); } } break; case TH_Action.CANCEL_THRESHOLD: Reports.Cancel(param); //TODO MORE break; } } ch.Send(ResponseBuilders.Configure_Thresholds_Response_Builder(dstID, srcID, m.MIHHeader.TransactionID, new Link_Configure_Thresholds_Confirm(STATUS.SUCCESS, lcstatus)).ByteValue); }
/// <summary> /// This method is called to handle an unsubscribe request message /// </summary> /// <param name="m">The serialized unsubscribe request message</param> public static void HandleUnsubscribe(Message m) { ConnectionHelper ch = Program.toMihf; ushort transactionID = m.MIHHeader.TransactionID; Payload.TLVIterator it = m.Payload.GetTLVIterator(); ID srcID = new ID(new OctetString(it.Next().Value)); ID dstID = new ID(new OctetString(it.Next().Value)); Link_Event_Unsubscribe_Request leur = new Link_Event_Unsubscribe_Request(MIHDeserializer.DeserializeLinkEventList(it.Next())); Subscriptions.Unsubscribe(leur.EventList); Link_Event_Unsubscribe_Confirm leuc = new Link_Event_Unsubscribe_Confirm(STATUS.SUCCESS, leur.EventList); ch.Send(ResponseBuilders.Event_Unsubscribe_Response_Builder(dstID, srcID, m.MIHHeader.TransactionID, leuc).ByteValue); }
/// <summary> /// To be called when a requested scan was complete. This method sends all pending Link_Action_Responses that were waiting for a scan result. /// </summary> public static void FinishScanAction() { List <Link_Scan_Rsp> scanResults = new List <Link_Scan_Rsp>(); foreach (NativeWifi.Wlan.WlanBssEntry entry in Information.GenericInfo.WlanInterfaceInstance.Connections) { PhysicalAddress pa = new PhysicalAddress(entry.dot11Bssid); scanResults.Add(new Link_Scan_Rsp(new Link_Addr(Link_Addr.Address_Type.MAC_ADDR, Utilities.PhysicalAddressToString(pa)), new OctetString(new String(Encoding.ASCII.GetChars(entry.dot11Ssid.SSID))), (ushort)entry.linkQuality)); } foreach (Message m in Information.MiscData.PendingLinkActionResponses.Keys) { Link_Action_Response laresp; Information.MiscData.PendingLinkActionResponses.TryGetValue(m, out laresp); laresp.ScanResults = scanResults; Payload.TLVIterator it = m.Payload.GetTLVIterator(); ID srcID = new ID(new OctetString(it.Next().Value)); ID dstID = new ID(new OctetString(it.Next().Value)); Program.toMihf.Send(ResponseBuilders.Link_Action_Response_Builder(srcID, dstID, m.MIHHeader.TransactionID, laresp).ByteValue); } Information.MiscData.PendingLinkActionResponses.Clear(); }
public SkillResponse FunctionHandler(JObject inputObj, ILambdaContext context) { Log.logger = context.Logger; APLSkillRequest input = new APLSkillRequest(); SkillResponse respond = ResponseBuilders.BuildResponse(null, false, null, null, null); try { new SystemRequestTypeConverter().AddToRequestConverter(); new UserEventRequestHandler().AddToRequestConverter(); //new APLRequestTypeConverter().AddToRequestConverter(); //Getting input string inputString = JsonConvert.SerializeObject(inputObj); input = JsonConvert.DeserializeObject <APLSkillRequest>(inputString); //Logging input Log.Output("---INPUT---"); context.Logger.LogLine(JsonConvert.SerializeObject(input)); // Initialise data var requestType = input.GetRequestType(); // Get type of request bool VideoSupport = input.Context.System.Device.IsInterfaceSupported("VideoApp"); bool APLSupport = input.Context.System.Device.IsInterfaceSupported("Alexa.Presentation.APL"); Log.Output("Video Support - APL - is: " + APLSupport); // ***REQUESTS*** // if (input.Request is LaunchRequest && APLSupport) // Launch Request for Video { // Launch request for echo spot/show -> Return APL + Ask Log.Output("Video App Launch Request"); respond = Dependencies.CreateAPL(); } else if (input.Request is LaunchRequest && !APLSupport) // Launch Request for speakers { Log.Output("Launch Request for smart speaker"); Reprompt reprompt = new Reprompt("How can I help you today?"); respond = ResponseBuilder.Ask("Welcome to ASMR video. Please ask for the list of songs or ask me to play a song", reprompt); } else if (input.Request is SessionEndedRequest) // SessionEndedRequest { // End Session by playing message Log.Output("Session Ended Request Called"); respond = ResponseBuilder.Tell("Thank you for using this skill. Goodbye."); respond.Response.ShouldEndSession = true; } else if (input.Request is UserEventRequest usrEvent && APLSupport) // User Event Request for TouchWrappers { Log.Output("User Event Launch requst"); var Id = Convert.ToInt32(usrEvent.Source.ComponentId); // Take ID as integer Id = Id - 1; Log.Output("ID of touchwrapper is : " + (Id + 1) + " , Index of number is: " + Id); respond = Dependencies.BuildVideoResonse(videoUrls[Id]); context.Logger.LogLine(JsonConvert.SerializeObject(respond)); } else if (input.Request is PlaybackControllerRequest) // Playback controller request { Log.Output("Playback Controller Request Called"); var playbackReq = input.Request as PlaybackControllerRequest; switch (playbackReq.PlaybackRequestType) { case PlaybackControllerRequestType.Next: break; case PlaybackControllerRequestType.Pause: break; case PlaybackControllerRequestType.Play: break; case PlaybackControllerRequestType.Previous: break; } respond = ResponseBuilder.AudioPlayerStop(); } // ***INTENTS*** else if (requestType == typeof(IntentRequest)) // INTENTS { var intentRequest = input.Request as IntentRequest; // Get intent request var intentName = intentRequest.Intent.Name; Log.Output("Intent Requests"); //Check request switch (intentName) { // Play Song Intent case "PlaySongIntent": Log.Output("Play a song Intent"); var songSlot = intentRequest.Intent.Slots["songName"].Value; // get slot //int songNumIndex= Dependencies.SlotConverter(songSlot); int songNumIndex = Convert.ToInt32(songSlot); songNumIndex -= 1; Log.Output("Song Slot is: " + songSlot + " , song Number index is : " + songNumIndex); if (songNumIndex != -1) // -1 = NOT FOUND { var audioRes = ResponseBuilders.AudioPlayerPlay(Alexa.NET.Response.Directive.PlayBehavior.ReplaceAll, audioUrls[songNumIndex], names[songNumIndex], null, 0); respond = audioRes; respond.Response.OutputSpeech = new PlainTextOutputSpeech { Text = "Playing the song." }; } else //Found { respond.Response.OutputSpeech = new PlainTextOutputSpeech { Text = "I did not understand which song you asked me to pplay. Could you please repeat?" }; } break; // ListSongsIntent case "ListSongsIntent": Log.Output("List Song Intent Request Called"); string text = "The ASMR songs are: "; for (int i = 0; i < names.Length; i++) { string ch = " , "; if (i == (names.Length - 1)) { ch = "."; } text += ((i + 1) + ". " + names[i] + ch); } text += " Which song do you want me to play? Say \"Alexa, play song 1 \"."; Reprompt reprompt = new Reprompt("Which song should I play?"); respond = ResponseBuilder.Ask(text, reprompt); break; // Help Intent case "AMAZON.HelpIntent": Log.Output("Help Intent Request Called"); respond = ResponseBuilder.Tell("You can ask me 'What is ASMR' or ask me to play one of ASMR Darling's top ten videos or ask for a list of ASMR's top ten videos"); break; //AMAZON StopIntent case "AMAZON.StopIntent": Log.Output("Stop Intent Request Called"); if (APLSupport) { // Stop when Video Present respond = Dependencies.CreateAPL(); } else { // Stop when Audio Present Reprompt re = new Reprompt("How can I help you today?"); respond = ResponseBuilder.Ask("Welcome to ASMR video. Please ask for the list of songs or ask me to play a song", re); respond.Response.Directives.Add(new StopDirective()); } break; case "AMAZON.CancelIntent": if (APLSupport) { Log.Output("---CancelIntent with video Support---"); respond = Dependencies.CreateAPL();; } else { Log.Output("Cancel Intent Request(Audio Player) Called"); Reprompt re = new Reprompt("How can I help you today?"); respond = ResponseBuilder.Ask("Welcome to ASMR video. Please ask for the list of songs or ask me to play a song", re); respond.Response.Directives.Add(new StopDirective()); } break; case "AMAZON.PauseIntent": Log.Output("Pause Intent Request Called"); respond = ResponseBuilder.AudioPlayerStop(); break; case "WhatIsASMRIntent": // What is ASMR? if (APLSupport) { Log.Output("What is ASMR Intent - VideoApp played"); respond = Dependencies.BuildVideoResonse(whatIsASMRvideo); // Return response to play Video } else { Log.Output("What is ASMR- Audio played"); respond = ResponseBuilders.AudioPlayerPlay(Alexa.NET.Response.Directive.PlayBehavior.ReplaceAll, whatIsASMRaudio, "What is ASMR?", null, 0);; } break; case "PlayVideoIntent": Log.Output("Play a Video Intent - \"Alexa play video\""); var videoSlot = intentRequest.Intent.Slots["songName"].Value; // get slot int videoNumIndex = Dependencies.SlotConverter(videoSlot); respond = Dependencies.BuildVideoResonse(videoUrls[videoNumIndex]); context.Logger.LogLine(JsonConvert.SerializeObject(respond)); break; default: Log.Output("Did not understand the intent request / Unexpected intent request"); respond = ResponseBuilder.Tell("I dont understand. Please ask me to list all songs or you can ask for help"); break; } } else { Log.Output("Unknown Request or Intent."); Log.Output(JsonConvert.SerializeObject(input)); respond = ResponseBuilder.Tell("I dont understand. Please ask me to list all songs or ask for help"); } return(respond); }
/// <summary> /// This method is called to handle a Get_Parameters request /// </summary> /// <param name="m">The serialized Get_Parameters_Request message.</param> public static void HandleGetParameters(Message m) { ConnectionHelper ch = Program.toMihf; ushort transactionID = m.MIHHeader.TransactionID; Payload.TLVIterator it = m.Payload.GetTLVIterator(); ID srcID = new ID(new OctetString(it.Next().Value)); ID dstID = new ID(new OctetString(it.Next().Value)); Link_Get_Parameters_Request lgpr = new Link_Get_Parameters_Request(MIHDeserializer.DeserializeLinkParamRequest(it.Next()), new System.Collections.BitArray(it.Next().Value.Reverse().ToArray()), new System.Collections.BitArray(it.Next().Value.Reverse().ToArray())); Link_Get_Parameters_Confirm lgpc = new Link_Get_Parameters_Confirm(); try { lgpc.LinkParametersStatusList = new List <Link_Param>(lgpr.LinkParametersRequest.Count); lgpc.LinkStatesRspList = new List <Link_Get_Parameters_Confirm.Link_States_Rsp>(); lgpc.LinkDescRspList = new List <Link_Get_Parameters_Confirm.Link_Desc_Rsp>(); foreach (Link_Param_Type lpt in lgpr.LinkParametersRequest) { switch (lpt.AbsoluteType) { case Link_Param_Abs_Type.P80211_RSSI: lgpc.LinkParametersStatusList.Add(new Link_Param(lpt, Link_Param_802_11.GetRSSI_0)); break; case Link_Param_Abs_Type.GEN_Data_Rate: lgpc.LinkParametersStatusList.Add(new Link_Param(lpt, Link_Param_Gen.DataRate_0)); break; case Link_Param_Abs_Type.GEN_Sig_Strenth: lgpc.LinkParametersStatusList.Add(new Link_Param(lpt, Link_Param_Gen.SignalStrength_1)); break; case Link_Param_Abs_Type.GEN_Packet_Error_Rate: lgpc.LinkParametersStatusList.Add(new Link_Param(lpt, Link_Param_Gen.PacketErrorRate_4)); break; } } //-------LinkStates if (lgpr.LinkStatesRequest[0]) //OP_MODE { lgpc.LinkStatesRspList.Add(new Link_Get_Parameters_Confirm.Link_States_Rsp(Link_Get_Parameters_Confirm.Link_States_Rsp.Type.OP_MODE, (ushort)GenericInfo.WlanInterfaceInstance.OP_Mode_802_21)); } if (lgpr.LinkStatesRequest[1]) { lgpc.LinkStatesRspList.Add(new Link_Get_Parameters_Confirm.Link_States_Rsp(Link_Get_Parameters_Confirm.Link_States_Rsp.Type.CHANNEL_ID, (ushort)GenericInfo.WlanInterfaceInstance.Channel)); } //----------- //-------LinkDesc if (lgpr.LinkDescriptorsRequest[0]) { lgpc.LinkDescRspList.Add(new Link_Get_Parameters_Confirm.Link_Desc_Rsp(Link_Get_Parameters_Confirm.Link_Desc_Rsp.Type.NUM_CoS, 0)); //TODO (not supported) } if (lgpr.LinkDescriptorsRequest[1]) { lgpc.LinkDescRspList.Add(new Link_Get_Parameters_Confirm.Link_Desc_Rsp(Link_Get_Parameters_Confirm.Link_Desc_Rsp.Type.NUM_QUEUE, 1)); //TODO (not supported) } //----------- lgpc.Status = STATUS.SUCCESS; } catch (Exception e) { lgpc.Status = STATUS.UNSPECIFIED_FAILURE; } Message toSend = ResponseBuilders.Get_Parameters_Response_Builder(dstID, srcID, m.MIHHeader.TransactionID, lgpc); if (Program.MESSAGE_DETAILS) { Console.WriteLine("Sending message: (" + m.MIHHeader.MID.AID + ")"); Connection.MIHProtocol.PacketReader.PrintMessage(toSend); } ch.Send(toSend.ByteValue); }