예제 #1
0
파일: MainFrm.cs 프로젝트: wyx1994/1111111
        /// <summary>
        /// 设备回调需回应回调函数
        /// </summary>
        /// <param name="deviceID">4位厂商编号+4位主设备编号+12位MAC地址数(或者唯一编号)共20位</param>
        /// <param name="cmd">命令字</param>
        /// <param name="json">设备上传的json数据</param>
        /// <param name="len">设备上传的json数据长度</param>
        /// <param name="jsonResponse">返回给设备的json数据</param>
        /// <param name="lenResponse">返回给设备的json数据长度</param>
        /// <returns>无</returns>
        unsafe private bool mySmartDeviceNeedResponse_CallBack(string deviceID,
                                                               UInt16 cmd,
                                                               string json,
                                                               Int32 len,
                                                               char *jsonResponse,
                                                               ref Int32 lenResponse)
        {
            bool bResult = true;

            UpdateMsg("接收数据:设备ID=" + deviceID + json);
            string strJsonResponse = "";

            switch (cmd)
            {
            case SmartDeviceInterface.COM_DEV_REGISTER_JS:
                byte[] byteDefault = Encoding.Convert(Encoding.UTF8,
                                                      Encoding.Default, UTF8Encoding.Default.GetBytes(json));
                json = Encoding.Default.GetString(byteDefault);
                DeviceRegister dr = (DeviceRegister)JsonConvert.DeserializeObject <DeviceRegister>(json);
                GloablInfo.devMgr.AddDevice(dr.data[0]);
                UpdateDeviceTree();
                DeviceRegisterResponse drr = new DeviceRegisterResponse();
                drr.command        = SmartDeviceInterface.COM_DEV_REGISTER_JS_;
                drr.result         = 0;
                drr.errorCode      = ErrorCodeType.NO_ERR;
                drr.errorMessage   = "";
                drr.data           = new DeviceRegisterResponseInfo[1];
                drr.data[0]        = new DeviceRegisterResponseInfo();
                drr.data[0].aesKey = "1234567890123456";
                strJsonResponse    = JsonConvert.SerializeObject(drr);
                lenResponse        = strJsonResponse.Length;
                UpdateMsg("发送数据:设备ID=" + deviceID + strJsonResponse);
                byte[] byteJsonResponse = System.Text.UTF8Encoding.Default.GetBytes(strJsonResponse);
                Marshal.Copy(byteJsonResponse, 0, new IntPtr(jsonResponse), lenResponse);
                break;
            }
            return(bResult);
        }
예제 #2
0
 public DeviceController(ILogger <DeviceController> logger, DeviceRegister register)
 {
     _logger  = logger;
     Register = register;
 }
예제 #3
0
 public DeviceInfo_v1_Interface(DeviceRegister deviceRegister)
 {
     dreg = deviceRegister ?? throw new ArgumentNullException(nameof(deviceRegister));
 }
예제 #4
0
        public static void Main(string[] args)
        {
            Logger.Init();

            // LOAD REFERENCES CONF
            FactoryConf fc = null;

            using (StreamReader file = File.OpenText("resources/reference.conf"))
            {
                JsonSerializer serializer = new JsonSerializer();
                fc = (FactoryConf)serializer.Deserialize(file, typeof(FactoryConf));
            }

            // Authentication
            AuthenticationHelper authenticationHelper = new AuthenticationHelper(fc.authenticationConf);

            authenticationHelper.Authenticate().Wait();
            //authenticationHelper.AuthenticateWithInput();

            // Register Device model and device
            DeviceRegister deviceRegister = new DeviceRegister(fc.deviceRegisterConf, authenticationHelper.GetOAuthCredentials().access_token);

            deviceRegister.Register();

            // Build the client (stub)
            AssistantClient assistantClient = new AssistantClient(authenticationHelper.GetOAuthCredentials(), fc.authenticationConf, fc.assistantConf,
                                                                  deviceRegister.GetDeviceModel(), deviceRegister.GetDevice());

            // Main loop
            bool isDone = false;

            while (!isDone)
            {
                // Check if we need to refresh the access token to request the api
                if (authenticationHelper.Expired())
                {
                    authenticationHelper.RefreshAccessToken();

                    assistantClient.UpdateCredentials(authenticationHelper.GetOAuthCredentials());
                }

                {
                    Logger.Get().Debug("Tap your request and press enter... (Tap quit to exit)");

                    string query = Console.ReadLine();

                    if (query.ToLower().Equals("quit"))
                    {
                        break;
                    }
                    if (query.Length == 0)
                    {
                        continue;
                    }

                    // requesting assistant with text query
                    assistantClient.TextRequestAssistant(query).Wait();

                    Logger.Get().Debug(">> " + assistantClient.GetTextResponse());
                    Logger.Get().Debug("   (AUDIO : " + (assistantClient.GetAudioResponse() != null ? assistantClient.GetAudioResponse().Length:0) + ")");
                }
            }

            Logger.Get().Debug("FINISH");
        }