private (bool isSuccess, string msg) askVhToCharging(AVEHICLE vh)
        {
            string   vh_current_address = vh.CUR_ADR_ID;
            AADDRESS current_adr        = addressesBLL.cache.GetAddress(vh.CUR_ADR_ID);

            if (current_adr != null &&
                current_adr is CouplerAddress && (current_adr as CouplerAddress).IsWork(unitBLL))
            {
                ICpuplerType cpupler = (current_adr as CouplerAddress);
                string       meg     = $"ask vh:{vh.VEHICLE_ID} to charging. but it is already in charger:{cpupler.ChargerID} ,cpupler num:{cpupler.CouplerNum}";
                LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(VehicleChargerModule), Device: DEVICE_NAME,
                              Data: meg,
                              VehicleID: vh.VEHICLE_ID);
                return(false, meg);
            }
            bool   is_need_to_long_charge = vh.IsNeedToLongCharge();
            string best_coupler_adr       = findBestCoupler(vh_current_address, is_need_to_long_charge);

            LogHelper.Log(logger: logger, LogLevel: LogLevel.Info, Class: nameof(VehicleChargerModule), Device: DEVICE_NAME,
                          Data: $"ask vh:{vh.VEHICLE_ID} to charging. coupler adr:{best_coupler_adr} ",
                          VehicleID: vh.VEHICLE_ID);
            if (!SCUtility.isEmpty(best_coupler_adr))
            {
                bool is_success = vehicleService.Command.MoveToCharge(vh.VEHICLE_ID, best_coupler_adr);
                return(is_success, "");
            }
            else
            {
                lineService.ProcessAlarmReport(vh, AlarmBLL.VEHICLE_CAN_NOT_FIND_THE_COUPLER_TO_CHARGING, ErrorStatus.ErrSet, $"vehicle:{vh.VEHICLE_ID} can't find coupler to charging");
                return(false, $"vehicle:{vh.VEHICLE_ID} can't find coupler to charging");
            }
        }
Esempio n. 2
0
        private void AddressVehicleRelease(object sender, string vhID)
        {
            AADDRESS adr = sender as AADDRESS;

            scApp.AddressesBLL.redis.setReleaseAddressInfo(vhID, adr.ADR_ID);
            scApp.AddressesBLL.redis.AddressRelease(vhID, adr.ADR_ID);
        }
Esempio n. 3
0
 public void update(DBConnection_EF con, AADDRESS rail)
 {
     //bool isDetached = con.Entry(rail).State == EntityState.Detached;
     //if (isDetached)
     con.AADDRESS.Attach(rail);
     con.SaveChanges();
 }
        private void setCouplerTypeAddressInfo(AADDRESS couplerAddress)
        {
            //  CouplerInfo coupler_info = GetCouplerInfo(couplerAddress.ADR_ID);
            CouplerInfo coupler_info = scApp.CouplerInfoDao.getCouplerInfo(scApp, couplerAddress.ADR_ID);

            if (coupler_info == null)
            {
                throw new Exception($"CouplerInfo not exist!,Adr id:{couplerAddress.ADR_ID}");
            }
            (couplerAddress as ICpuplerType).ChargerID             = coupler_info.ChargerID;
            (couplerAddress as ICpuplerType).CouplerNum            = (CouplerNum)coupler_info.CouplerNum;
            (couplerAddress as ICpuplerType).Priority              = coupler_info.Priority;
            (couplerAddress as ICpuplerType).Priority              = coupler_info.Priority;
            (couplerAddress as ICpuplerType).TrafficControlSegment = coupler_info.TrafficControlSegment.Split('-');
            //if (!SCUtility.isMatche(couplerAddress.ADR_ID, "24002"))
            (couplerAddress as ICpuplerType).IsEnable = true;
            //AUNIT charger = scApp.getEQObjCacheManager().getUnitByUnitID(coupler_info.ChargerID);
            //if (charger != null)
            //{
            //    if(coupler_info.CouplerNum == 1)
            //    {
            //        charger.Coupler1Address = couplerAddress.ADR_ID;
            //    }
            //    else if(coupler_info.CouplerNum == 2)
            //    {
            //        charger.Coupler2Address = couplerAddress.ADR_ID;
            //    }
            //    else if (coupler_info.CouplerNum == 3)
            //    {
            //        charger.Coupler3Address = couplerAddress.ADR_ID;
            //    }
            //}
        }
        private void setReserveEnhanceAddressInfo(AADDRESS reserveEnhanceAddress)
        {
            ReserveEnhanceInfo enhanceInfo = GetReserveEnhanceInfo(reserveEnhanceAddress.ADR_ID);

            //(reserveEnhanceAddress as IReserveEnhance).EnhanceControlAddress = enhanceInfo.EnhanceControlAddress.Split('-');
            (reserveEnhanceAddress as IReserveEnhance).EnhanceControlAddress = enhanceInfo.EnhanceControlAddress;
            (reserveEnhanceAddress as IReserveEnhance).infos = GetReserveEnhanceInfos(reserveEnhanceAddress.ADR_ID);
            EnhanceSubAddresses.AddRange(enhanceInfo.EnhanceControlAddress);
        }
        public void start(SCApplication _app)
        {
            scApp = _app;

            Segments  = scApp.MapBLL.loadAllSegments();
            Sections  = scApp.MapBLL.loadAllSection();
            Addresses = scApp.MapBLL.loadAllAddress();

            ReserveEnhanceInfosSections = scApp.ReserveEnhanceInfoDao.getReserveEnhanceInfoSections(scApp);
            TrafficControlInfos         = scApp.TrafficControlInfoDao.getTrafficControlInfos(scApp);

            for (int i = 0; i < Addresses.Count; i++)
            {
                AADDRESS address = Addresses[i];
                address.initialAddressType();
                //address.initialSegmentID(scApp.SectionBLL);

                bool isReserveEnhanceAddress = GetReserveEnhanceInfo(address.ADR_ID) != null;
                if (isReserveEnhanceAddress && address.IsCoupler)
                {
                    AADDRESS couplerAndReserveEnhanceAddress = new CouplerAndReserveEnhanceAddress();
                    BCFUtility.setValueToPropety(ref address, ref couplerAndReserveEnhanceAddress);
                    setReserveEnhanceAddressInfo(couplerAndReserveEnhanceAddress);
                    setCouplerTypeAddressInfo(couplerAndReserveEnhanceAddress);
                    Addresses[i] = couplerAndReserveEnhanceAddress;
                }
                else if (address.IsCoupler)
                {
                    AADDRESS couplerAddress = new CouplerAddress();
                    BCFUtility.setValueToPropety(ref address, ref couplerAddress);
                    setCouplerTypeAddressInfo(couplerAddress);
                    Addresses[i] = couplerAddress;
                }
                else if (isReserveEnhanceAddress)
                {
                    AADDRESS couplerAndReserveEnhanceAddress = new ReserveEnhanceAddress();
                    BCFUtility.setValueToPropety(ref address, ref couplerAndReserveEnhanceAddress);
                    setReserveEnhanceAddressInfo(couplerAndReserveEnhanceAddress);
                    Addresses[i] = couplerAndReserveEnhanceAddress;
                }
            }

            foreach (ASECTION section in Sections)
            {
                section.setOnSectionAddress(scApp.AddressesBLL);
            }

            foreach (ASEGMENT segment in Segments)
            {
                segment.SetSectionList(scApp.SectionBLL);
            }


            CommonInfo = new CommonInfo();
            initialCommunationInfo();
        }
        public AADDRESS getAddressByPortID(string port_id)
        {
            AADDRESS adr = null;

            using (DBConnection_EF con = new DBConnection_EF())
            {
                adr = adrDAO.getByPortID(con, port_id);
            }
            return(adr);
        }
        public AADDRESS getAddressByID(string adr_id)
        {
            AADDRESS adr = null;

            //DBConnection_EF con = DBConnection_EF.GetContext();
            using (DBConnection_EF con = new DBConnection_EF())
            {
                adr = adrDAO.getByID(con, adr_id);
            }
            return(adr);
        }
        private void setCouplerTypeAddressInfo(AADDRESS couplerAddress)
        {
            //  CouplerInfo coupler_info = GetCouplerInfo(couplerAddress.ADR_ID);
            CouplerData coupler_info = scApp.CouplerInfoDao.getCouplerInfo(scApp, couplerAddress.ADR_ID);

            if (coupler_info == null)
            {
                throw new Exception($"CouplerInfo not exist!,Adr id:{couplerAddress.ADR_ID}");
            }
            (couplerAddress as ICpuplerType).ChargerID             = coupler_info.ChargerID;
            (couplerAddress as ICpuplerType).CouplerNum            = (CouplerNum)coupler_info.CouplerNum;
            (couplerAddress as ICpuplerType).Priority              = coupler_info.Priority;
            (couplerAddress as ICpuplerType).Priority              = coupler_info.Priority;
            (couplerAddress as ICpuplerType).TrafficControlSegment = coupler_info.TrafficControlSegment.Split('-');
            //if (!SCUtility.isMatche(couplerAddress.ADR_ID, "24002"))
            (couplerAddress as ICpuplerType).IsEnable = true;
        }
        private void Vh_CommandComplete(object sender, CompleteStatus e)
        {
            AVEHICLE vh = sender as AVEHICLE;

            try
            {
                string cur_segment_id = vh.CUR_SEG_ID;
                string cur_section_id = vh.CUR_SEC_ID;
                string cur_adr_id     = vh.CUR_ADR_ID;
                string vh_id          = vh.VEHICLE_ID;

                if (e == CompleteStatus.MoveToCharger)
                {
                    //if (vh.BatteryLevel == BatteryLevel.Low)
                    if (vh.MODE_STATUS == VHModeStatus.AutoCharging)
                    {
                        RoadControl(vh_id, cur_adr_id, false);
                    }
                }
                else
                {
                    //if (vh.BatteryLevel == BatteryLevel.Low)
                    if (vh.MODE_STATUS == VHModeStatus.AutoCharging)
                    {
                        AADDRESS vh_on_address = addressesBLL.cache.GetAddress(cur_adr_id);
                        if (vh_on_address.IsCoupler)
                        {
                            RoadControl(vh_id, cur_adr_id, false);
                        }
                        else
                        {
                            askVhToCharging(vh);
                        }
                    }
                }
                lineService.ProcessAlarmReport(vh, AlarmBLL.VEHICLE_CAN_NOT_FIND_THE_COUPLER_TO_CHARGING, ErrorStatus.ErrReset, $"vehicle:{vh.VEHICLE_ID} can't find coupler to charging");
            }
            catch (Exception ex)
            {
                LogHelper.Log(logger: logger, LogLevel: LogLevel.Warn, Class: nameof(VehicleChargerModule), Device: DEVICE_NAME,
                              Data: ex,
                              VehicleID: vh?.VEHICLE_ID);
            }
        }
Esempio n. 11
0
        private void Vh_CommandComplete(object sender, CompleteStatus e)
        {
            AVEHICLE vh = sender as AVEHICLE;

            try
            {
                string cur_segment_id = vh.CUR_SEG_ID;
                string cur_section_id = vh.CUR_SEC_ID;
                string cur_adr_id     = vh.CUR_ADR_ID;
                string vh_id          = vh.VEHICLE_ID;

                if (e == CompleteStatus.CmpStatusMoveToCharger)
                {
                    //if (vh.BatteryLevel == BatteryLevel.Low)
                    if (vh.MODE_STATUS == VHModeStatus.AutoCharging)
                    {
                        RoadControl(vh_id, cur_adr_id, false);
                    }
                }
                else
                {
                    //if (vh.BatteryLevel == BatteryLevel.Low)
                    if (vh.MODE_STATUS == VHModeStatus.AutoCharging)
                    {
                        AADDRESS vh_on_address = addressesBLL.cache.GetAddress(cur_adr_id);
                        if (vh_on_address.IsCoupler)
                        {
                            RoadControl(vh_id, cur_adr_id, false);
                        }
                        else
                        {
                            askVhToCharging(vh);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Log(logger: logger, LogLevel: LogLevel.Warn, Class: nameof(VehicleChargerModule), Device: DEVICE_NAME,
                              Data: ex,
                              VehicleID: vh?.VEHICLE_ID);
            }
        }
Esempio n. 12
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);
                    }
                }
            }
        }
Esempio n. 13
0
 public void add(DBConnection_EF con, AADDRESS rail)
 {
     con.AADDRESS.Add(rail);
     con.SaveChanges();
 }