示例#1
0
        public static void DecodeMessage(CcamMsg msg)
        {
            switch (msg.CommandTag)
            {
            case MsgTypes.MsgCardDel:
            case MsgTypes.MsgCliInfo:
                break;

            case MsgTypes.MsgCardAdd:
                if ((msg.CustomData[20] & 0xff) > 0)
                {
                    var card = new CcCardData
                    {
                        RemoteId      = string.Join("", msg.CustomData.Take(4).Select(s => s.ToString("X"))),
                        Uphops        = (msg.CustomData[10] & 0xff) + 1,
                        NodeId        = msg.CustomData.Skip(22 + msg.CustomData[20] * 7).Take(8 + 22 + msg.CustomData[20] * 7).ToArray(),
                        CaId          = (((msg.CustomData[8]) << 8) | (msg.CustomData[9])).ToString("X"),
                        ProviderCount = msg.CustomData[20] & 0xff,
                        Serial        = msg.CustomData.Skip(12).Take(12 + 8).ToArray()
                    };

                    var providers = new int[msg.CustomData[20]];
                    for (var i = 0; i < msg.CustomData[20]; i++)
                    {
                        var provid = ((msg.CustomData[21 + i * 7] & 0xff) << 16) |
                                     ((msg.CustomData[22 + i * 7] & 0xff) << 8) |
                                     (msg.CustomData[23 + i * 7] & 0xff);

                        providers[i] = provid;
                    }
                    card.Providers = providers.Select(p => p.ToString("X")).ToArray();
                    Console.WriteLine($"Card: {card}");
                    Cards.Add(card);
                }
                break;

            case MsgTypes.MsgSrvInfo:

                CcamServerInfo.NodeId  = string.Join("", msg.CustomData.Take(8).Select(n => n.ToString("X")));
                CcamServerInfo.Version = Encoding.Default.GetString(msg.CustomData.Skip(8).Take(31).ToArray());
                CcamServerInfo.Build   = Encoding.Default.GetString(msg.CustomData.Skip(40).Take(31).ToArray());

                Console.WriteLine($"Server information: NodeId: {CcamServerInfo.NodeId} " +
                                  $"Version:{CcamServerInfo.Version.Replace("\0", "").Trim()} " +
                                  $"Build: {CcamServerInfo.Build.Trim()}");
                break;

            case MsgTypes.MsgEcmNok1:
            case MsgTypes.MsgEcmNok2:
                Socket.Close();
                break;

            default:
                Socket.Close();
                throw new IOException();
            }
        }
示例#2
0
 private static void ReadCardsInformation()
 {
     while (true)
     {
         try
         {
             var msgBytes = ReadMessage();
             if (msgBytes != null)
             {
                 var msg = new CcamMsg(msgBytes);
                 DecodeMessage(msg);
             }
         }
         catch (Exception)
         {
             return;
         }
     }
 }