Ejemplo n.º 1
0
        public void CouplerTimingCheck()
        {
            //List<CouplerAddress> coupler_addresses = addressesBLL.cache.GetCouplerAddresses();
            List <CouplerAddress> coupler_addresses = addressesBLL.cache.GetEnableCouplerAddresses(unitBLL);

            foreach (CouplerAddress coupler_address in coupler_addresses)
            {
                if (coupler_address.hasVh(vehicleBLL))
                {
                    AVEHICLE ChargingVh = vehicleBLL.getVhOnAddress(coupler_address.ADR_ID);

                    //1.如果N分鐘前,都沒有充飽過,就要等他充飽以後才可以再叫他回去工作
                    //if (ChargingVh.LAST_FULLY_CHARGED_TIME.HasValue &&
                    //   DateTime.Now > ChargingVh.LAST_FULLY_CHARGED_TIME?.AddMinutes(SystemParameter.TheLongestFullyChargedIntervalTime_Mim))
                    if (!ChargingVh.LAST_FULLY_CHARGED_TIME.HasValue ||
                        DateTime.Now > ChargingVh.LAST_FULLY_CHARGED_TIME?.AddMinutes(SystemParameter.TheLongestFullyChargedIntervalTime_Mim))
                    {
                        if (ChargingVh.BatteryLevel == BatteryLevel.Full &&
                            ChargingVh.MODE_STATUS == VHModeStatus.AutoCharging)
                        {
                            LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(VehicleChargerModule), Device: DEVICE_NAME,
                                          Data: $"ask vh:{ChargingVh.VEHICLE_ID} recover to auto remmote " +
                                          $"and unban segment id:{string.Join(",", coupler_address.TrafficControlSegment)} ",
                                          VehicleID: ChargingVh.VEHICLE_ID);
                            vehicleService.changeVhStatusToAutoRemote(ChargingVh.VEHICLE_ID);
                            RoadControl(ChargingVh.VEHICLE_ID, ChargingVh.CUR_ADR_ID, true);
                        }
                        else
                        {
                            LogHelper.Log(logger: logger, LogLevel: LogLevel.Debug, Class: nameof(VehicleChargerModule), Device: DEVICE_NAME,
                                          Data: $"ChargingVh:{ChargingVh},Not yet charging condition." +
                                          $"a.charged time interval(min){SystemParameter.TheLongestFullyChargedIntervalTime_Mim}" +
                                          $"b.current battrty level:{ChargingVh.BatteryLevel} (need to be full)",
                                          VehicleID: ChargingVh.VEHICLE_ID);
                        }
                    }
                    else
                    {
                        //if (ChargingVh.BatteryLevel > BatteryLevel.Low &&
                        //    ChargingVh.MODE_STATUS == VHModeStatus.AutoCharging)
                        //if (ChargingVh.BatteryLevel > BatteryLevel.High &&
                        if (ChargingVh.BatteryLevel >= BatteryLevel.High &&
                            ChargingVh.MODE_STATUS == VHModeStatus.AutoCharging)
                        {
                            LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(VehicleChargerModule), Device: DEVICE_NAME,
                                          Data: $"ask vh:{ChargingVh.VEHICLE_ID} recover to auto remmote " +
                                          $"and unban segment id:{string.Join(",", coupler_address.TrafficControlSegment)} ",
                                          VehicleID: ChargingVh.VEHICLE_ID);
                            vehicleService.changeVhStatusToAutoRemote(ChargingVh.VEHICLE_ID);
                            RoadControl(ChargingVh.VEHICLE_ID, ChargingVh.CUR_ADR_ID, true);
                        }
                        else
                        {
                            LogHelper.Log(logger: logger, LogLevel: LogLevel.Debug, Class: nameof(VehicleChargerModule), Device: DEVICE_NAME,
                                          Data: $"ChargingVh:{ChargingVh},Not yet charging condition." +
                                          $"a.current battrty level:{ChargingVh.BatteryLevel} (need to be above High)",
                                          VehicleID: ChargingVh.VEHICLE_ID);
                        }
                    }
                }
            }

            //找出所有低電量的VH
            //List<AVEHICLE> low_level_battrty_vh = vehicleBLL.cache.loadLowBattrtyVh();
            //if (low_level_battrty_vh != null)
            //{
            //    foreach (AVEHICLE low_level_vh in low_level_battrty_vh)
            //    {
            //        AADDRESS current_adr = addressesBLL.cache.GetAddress(low_level_vh.CUR_ADR_ID);
            //        //確定它是在Auto charge mode 且 已經沒有在執行命令 且 目前所在的Addres不在充電站上
            //        if (low_level_vh.MODE_STATUS == VHModeStatus.AutoCharging &&
            //            low_level_vh.ACT_STATUS == VHActionStatus.NoCommand &&
            //            !SCUtility.isEmpty(low_level_vh.CUR_ADR_ID) &&
            //            !(current_adr is CouplerAddress))
            //        {
            //            LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(VehicleChargerModule), Device: DEVICE_NAME,
            //                     Data: $"ask vh:{low_level_vh.VEHICLE_ID} to charging by timer. ",
            //                     VehicleID: low_level_vh.VEHICLE_ID);
            //            askVhToCharging(low_level_vh);
            //        }
            //    }
            //}

            //找出目前線內的VH,如果Mode = AutoCharging、No command的狀態且不在Coupler
            //1.如果處於低電位的話,則將他派送至Coupler,進行充電
            //2.如果是高於低電位的話,則將它切換回AutoRemote
            List <AVEHICLE> vhs = vehicleBLL.cache.loadAllVh();

            foreach (AVEHICLE vh in vhs)
            {
                if (SCUtility.isEmpty(vh.CUR_ADR_ID))
                {
                    continue;
                }
                AADDRESS current_adr = addressesBLL.cache.GetAddress(vh.CUR_ADR_ID);
                if (vh.BatteryLevel == BatteryLevel.Low)
                {
                    //確定它是在Auto charge mode 且 已經沒有在執行命令 且 目前所在的Addres不在充電站上
                    if (vh.MODE_STATUS == VHModeStatus.AutoCharging &&
                        vh.ACT_STATUS == VHActionStatus.NoCommand &&
                        (!(current_adr is CouplerAddress) ||
                         //((current_adr is CouplerAddress) && !(current_adr as CouplerAddress).IsEnable))
                         ((current_adr is CouplerAddress) && !addressesBLL.cache.IsCouplerWork(current_adr as CouplerAddress, unitBLL)))
                        )
                    {
                        LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(VehicleChargerModule), Device: DEVICE_NAME,
                                      Data: $"ask vh:{vh.VEHICLE_ID} to charging by timer. ",
                                      VehicleID: vh.VEHICLE_ID);
                        askVhToCharging(vh);
                    }
                }
                //如果不是在充電站上,但他的電量卻回復到大於低電壓時,就再讓它恢復成Auto remote繼續服務
                else if (vh.BatteryLevel > BatteryLevel.Low)
                {
                    if (vh.MODE_STATUS == VHModeStatus.AutoCharging &&
                        vh.ACT_STATUS == VHActionStatus.NoCommand &&
                        (!(current_adr is CouplerAddress) ||
                         //((current_adr is CouplerAddress) && !(current_adr as CouplerAddress).IsEnable))
                         ((current_adr is CouplerAddress) && !addressesBLL.cache.IsCouplerWork(current_adr as CouplerAddress, unitBLL)))
                        )
                    {
                        LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(VehicleChargerModule), Device: DEVICE_NAME,
                                      Data: $"ask vh:{vh.VEHICLE_ID} recover to auto remmote by timer",
                                      VehicleID: vh.VEHICLE_ID);
                        vehicleService.changeVhStatusToAutoRemote(vh.VEHICLE_ID);
                    }
                }
            }
        }