Ejemplo n.º 1
0
    private void SocketObj_OnDataInvoke(BasePacket basePacket)
    {
        switch (basePacket.packetType)
        {
        case PacketType.CamReceived:
            if (SendCamTexture == true)
            {
                StartCoroutine(SendCamDataWithDelay());
            }
            break;

        case PacketType.CamResolutionReq:
            CamResolutionReqPacket crrp = (CamResolutionReqPacket)basePacket;
            if (1 <= crrp.Resolution && crrp.Resolution <= 16)
            {
                CamQuality = crrp.Resolution;
                clientSender.SendPacket(new CamResolutionPacket(CamQuality));
            }
            break;

        case PacketType.CamConfig:
            CamConfigPacket ccp = (CamConfigPacket)basePacket;
            switch (ccp.camaraConfigType)
            {
            case CamaraConfigType.ChangeCamara:
                camManager.SwitchCam();
                break;

            case CamaraConfigType.SendFrame:
                if (ccp.enable)
                {
                    SendCamTexture = true;
                    StartCoroutine(SendCamDataWithDelay());
                }
                else
                {
                    SendCamTexture = false;
                }
                break;

            default:
                break;
            }
            break;

        case PacketType.CarStatusChangeReq:
            CarStatusChangeReqPacket cscrp = (CarStatusChangeReqPacket)basePacket;

            if (cscrp.ReqCarDevice.RF_LEDChanged)
            {
                baseCarDivice.rf_LED = cscrp.ReqCarDevice.RF_LED;
            }

            if (cscrp.ReqCarDevice.LF_LEDChanged)
            {
                baseCarDivice.lf_LED = cscrp.ReqCarDevice.LF_LED;
            }

            if (cscrp.ReqCarDevice.RB_LEDChanged)
            {
                baseCarDivice.rb_LED = cscrp.ReqCarDevice.RB_LED;
            }

            if (cscrp.ReqCarDevice.LB_LEDChanged)
            {
                baseCarDivice.lb_LED = cscrp.ReqCarDevice.LB_LED;
            }

            if (tracerObj.gPSMover.EnableTraceMode == false)
            {
                if (cscrp.ReqCarDevice.R_motorDIRChanged)
                {
                    baseCarDivice.r_motorDIR = cscrp.ReqCarDevice.R_motorDIR;
                }

                if (cscrp.ReqCarDevice.L_motorDIRChanged)
                {
                    baseCarDivice.l_motorDIR = cscrp.ReqCarDevice.L_motorDIR;
                }

                if (cscrp.ReqCarDevice.R_motorpowerChanged)
                {
                    baseCarDivice.r_motorpower = cscrp.ReqCarDevice.R_motorpower;
                }

                if (cscrp.ReqCarDevice.L_motorpowerChanged)
                {
                    baseCarDivice.l_motorpower = cscrp.ReqCarDevice.L_motorpower;
                }
            }
            break;

        case PacketType.CarStatusReceived:
            StartCoroutine(SendCarDataWithDelay());
            break;

        case PacketType.CarGPSSpotStatusChangeReq:
            CarGPSSpotStatusChangeReqPacket cgscrp = (CarGPSSpotStatusChangeReqPacket)basePacket;
            switch (cgscrp.GPSSpotManagerChangeType)
            {
            case GPSSpotManagerChangeType.AddSpot:
                tracerObj.gPSMover.GPSSpotManager.AddPos(cgscrp.GPSPosition);
                clientSender.SendPacket(new CarGPSSpotStatusPacket(GPSSpotManagerChangeType.AddSpot, cgscrp.GPSPosition));
                break;

            case GPSSpotManagerChangeType.RemoveSpot:
                tracerObj.gPSMover.GPSSpotManager.RemovePos(cgscrp.Index);
                clientSender.SendPacket(new CarGPSSpotStatusPacket(GPSSpotManagerChangeType.RemoveSpot, cgscrp.Index));
                break;

            case GPSSpotManagerChangeType.SetCurrentPos:
                tracerObj.gPSMover.GPSSpotManager.CurrentMovePosIndex = cgscrp.Index;
                clientSender.SendPacket(new CarGPSSpotStatusPacket(GPSSpotManagerChangeType.SetCurrentPos, cgscrp.Index));
                break;

            case GPSSpotManagerChangeType.OverWrite:
                tracerObj.gPSMover.ChangeSpotManager(cgscrp.GPSMover);
                clientSender.SendPacket(new CarGPSSpotStatusPacket(GPSSpotManagerChangeType.OverWrite, cgscrp.GPSMover));
                break;

            default:
                break;
            }
            break;

        case PacketType.UpdateDataReq:
            DataUpdatePacket dup = (DataUpdatePacket)basePacket;

            switch (dup.modeType)
            {
            case ModeType.AutoDriveMode:
                tracerObj.gPSMover.EnableTraceMode = true;
                baseCarDivice.HalfManualMode       = false;
                break;

            case ModeType.ManualDriveMode:
                tracerObj.gPSMover.EnableTraceMode = false;
                baseCarDivice.HalfManualMode       = false;
                break;

            case ModeType.HaifManualDriveMode:
                tracerObj.gPSMover.EnableTraceMode = false;
                baseCarDivice.HalfManualMode       = true;
                break;

            default:
                break;
            }
            clientSender.SendPacket(new DataUpdatedPacket(dup.modeType));
            break;

        default:
            break;
        }
    }