Newer
Older
SensorHub / SensorHub.LampNB / LampServer.cs
root on 17 Sep 2021 3 KB first commit
using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Protocol;
using System.Collections.Generic;
using System;
using SensorHub.Utility;
using System.Timers;
using SensorHub.Servers.JsonFormat;
using SensorHub.Servers.Commands.CASICCommands;
using System.Threading;
using System.Diagnostics;
using SensorHub.Servers;
using System.Collections;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace SensorHub.LampNBServer
{
    public class LampServer : AppServer<CasicSession>
    {
        public LampServer()
            : base(new DefaultReceiveFilterFactory<TelecomReceiveFilter, StringRequestInfo>())
        {

        }

        //public void DispatchMessage(String key, String message)
        //{
        //    JObject jo = (JObject)JsonConvert.DeserializeObject(message);
        //    String deviceId = jo["teleDeviceId"].ToString();//电信平台设备id
        //    String devCode = jo["devcode"].ToString();//设备编号
        //    String configItem = jo["config"].ToString();//配置项
        //    String controlItem = jo["control"].ToString();//控制项

        //    byte[] config = null;
        //    if(controlItem != null)
        //    {
        //        config = ConfigBuild.buildConfigFrame(devCode, controlItem);
        //    }
        //    else if(configItem != null)
        //    {
        //        config = ConfigBuild.buildConfigFrame(devCode, configItem);
        //    }
        //    else
        //    {
        //        Logger.Info("无效的下发信息!");
        //        return;
        //    }

        //    Logger.Info("下发配置控制信息:" + BitConverter.ToString(config).Replace("-", ""));

        //    byte[] tag = new byte[config.Length - 16];
        //    byte[] enTag;

        //    Array.Copy(config, 16, tag, 0, config.Length - 16);

        //    int a = tag.Length % 8;
        //    if (a != 0)
        //    {
        //        enTag = new byte[tag.Length + 8 - a];
        //        tag.CopyTo(enTag, 0);
        //        for (int i = 0; i < 8 - a; i++)
        //        {
        //            enTag[tag.Length + i] = 0;
        //        }
        //    }
        //    else
        //    {
        //        enTag = new byte[tag.Length];
        //        tag.CopyTo(enTag, 0);
        //    }

        //    TEA.encrypt(ref enTag, enTag.Length);

        //    byte[] result = new byte[1 + 1 + 2 + 6 + 1 + 2 + 2 + 1 + enTag.Length];
        //    Array.Copy(config, result, 16);
        //    enTag.CopyTo(result, 16);

        //    byte[] afcrc = Common.CRC(result);

        //    //TODO:发送数据
        //    String strBase64Value = Convert.ToBase64String(afcrc);
        //    NASDK currsdk = new NASDK();
        //    TokenResult token = currsdk.getToken();
        //    if (token == null)
        //    {
        //        Logger.Error("获取Token失败!");
        //        return;
        //    }
        //    string strToken = token.accessToken;
        //    Logger.Info("获取Token成功:" + strToken);

        //    CommandPara cp = new CommandPara();
        //    cp.paraName = "Value";
        //    cp.paraValue = strBase64Value;

        //    int ret = currsdk.sendCommand(strToken, deviceId, null, "Config", "Config", cp, null);
        //    if (ret != 201)
        //    {
        //        Logger.Info("电信平台下发配置信息失败,返回的Http状态码:" + ret);
        //    }
        //    else
        //    {
        //        Logger.Info("电信平台下发配置信息成功!");
        //    }
        //}

    }
}