Beispiel #1
0
    protected override void OnMessage(MessageEventArgs e)
    {
        if (e.RawData.Length == 0 || e.IsPing)
        {
            // Debug.LogFormat("length:{0}, {1}", e.RawData.Length, e.IsPing);
            return;
        }

        var request = JsonConvert.DeserializeObject <SimulationControlRequest>(e.Data);

        if (request == null)
        {
            Debug.Log("Invalid JSON format");
            return;
        }

        request.Print();

        SimulationControlResponseBase output = null;

        if (request.command.Equals("reset"))
        {
            var wasSuccessful = modelLoaderService.TriggerResetService(request.command);
            var result        = (wasSuccessful)? SimulationService.SUCCESS:SimulationService.FAIL;

            output = new SimulationControlResponseNormal();
            (output as SimulationControlResponseNormal).result = result;
        }
        else if (request.command.Equals("device_list"))
        {
            var result = portDeviceService.GetSensorPortList();

            output = new SimulationControlResponseSensorPortList();
            (output as SimulationControlResponseSensorPortList).result = result;
        }
        else
        {
            output          = new SimulationControlResponseBase();
            request.command = "Invalid Command";
        }

        output.command = request.command;

        var responseJsonData = JsonConvert.SerializeObject(output, Formatting.Indented);

        Send(responseJsonData);
    }
    protected override void OnMessage(MessageEventArgs e)
    {
        if (e.RawData.Length == 0 || e.IsPing)
        {
            // Debug.LogFormat("length:{0}, {1}", e.RawData.Length, e.IsPing);
            return;
        }

        var request = JsonConvert.DeserializeObject <SimulationControlRequest>(e.Data);

        if (request == null)
        {
            Debug.Log("Invalid JSON format");
            return;
        }

        request.Print();

        SimulationControlResponseBase output = null;

        switch (request.command)
        {
        case "reset":
        {
            var wasSuccessful = main.TriggerResetService();
            var result        = (wasSuccessful) ? SimulationService.SUCCESS : SimulationService.FAIL;

            output = new SimulationControlResponseNormal();
            (output as SimulationControlResponseNormal).result = result;
        }
        break;

        case "device_list":
        {
            var result = bridgeManager.GetDeviceMapList(request.filter);
            output = new SimulationControlResponseDeviceList();
            (output as SimulationControlResponseDeviceList).result = result;
        }
        break;

        case "topic_list":
        {
            var result = bridgeManager.GetDevicePortList(request.filter);

            output = new SimulationControlResponseTopicList();
            (output as SimulationControlResponseTopicList).result = result;
        }
        break;

        default:
            output          = new SimulationControlResponseBase();
            request.command = "Invalid Command";
            break;
        }

        output.command = request.command;

        var responseJsonData = JsonConvert.SerializeObject(output, (request.indent) ? Formatting.Indented : Formatting.None);

        Send(responseJsonData);
    }