Beispiel #1
0
        /// <summary>
        /// Method is called, whenever a IR Comand is received via the IRTrans Server connection.
        /// </summary>
        /// <param name="asyn"></param>
        private void OnDataReceived(IAsyncResult asyn)
        {
            try
            {
                CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState;
                //Do an end receive first
                int bytesReceived = 0;
                bytesReceived = theSockId.thisSocket.EndReceive(asyn);
                // Map the received data to the structure
                IntPtr ptrReceive = Marshal.AllocHGlobal(bytesReceived);
                Marshal.Copy(theSockId.receiveBuffer, 0, ptrReceive, bytesReceived);
                NETWORKRECV netrecv = (NETWORKRECV)Marshal.PtrToStructure(ptrReceive, typeof(NETWORKRECV));
                if (logVerbose)
                {
                    Log.Info("IRTrans: Command Start --------------------------------------------");
                    Log.Info("IRTrans: Client       = {0}", netrecv.clientid);
                    Log.Info("IRTrans: Status       = {0}", (IrTransStatus)netrecv.statustype);
                    Log.Info("IRTrans: Remote       = {0}", netrecv.remote);
                    Log.Info("IRTrans: Command Num. = {0}", netrecv.command_num.ToString());
                    Log.Info("IRTrans: Command      = {0}", netrecv.command);
                    Log.Info("IRTrans: Data         = {0}", netrecv.data);
                    Log.Info("IRTrans: Command End ----------------------------------------------");
                }

                // Do an action only on Receive and if the command came from the selected Remote
                if ((IrTransStatus)netrecv.statustype == IrTransStatus.STATUS_RECEIVE)
                {
                    if (netrecv.remote.Trim() == remoteModel)
                    {
                        try
                        {
                            if (irtransHandler.MapAction(netrecv.command.Trim()))
                            {
                                if (logVerbose)
                                {
                                    Log.Info("IRTrans: Action mapped");
                                }
                            }
                            else
                            {
                                if (logVerbose)
                                {
                                    Log.Info("IRTrans: Action not mapped");
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (logVerbose)
                            {
                                Log.Info("IRTrans: Exception in IRTranshandler: {0}", ex.Message);
                            }
                        }
                    }
                }

                Marshal.FreeHGlobal(ptrReceive);
                WaitForData();
            }
            catch (ObjectDisposedException) {}
            catch (SocketException se)
            {
                if (logVerbose)
                {
                    Log.Info("IRTrans: Error on receive from socket: {0}", se.Message);
                }
            }
        }
Beispiel #2
0
 private void IRReceived(object sender, EventArgs e, NETWORKRECV recv)
 {
     RaiseDeviceEvent(this, new FeedbackReceivedFromDeviceEventArgs(recv.command, null));
 }