Ejemplo n.º 1
0
        public static bool TryConvertPcs(DUT_MQTT_ESS packet, out DataMessage[] pcs_messages,
                                         out DataMessage[] bat_messages, out DataMessage dc_message)
        {
            pcs_messages = new DataMessage[ENV.PcsCount];
            bat_messages = new DataMessage[ENV.PcsCount];
            dc_message   = new DataMessage();
            try
            {
                DUT_MQTT_PCS[] pcsPackets = packet.PCS;
                DUT_MQTT_BAT[] bmsPackets = packet.BAT;
                DUT_MQTT_DC    dcPacket   = packet.DC;
                int            siteid     = ENV.SiteId;
                int            rccid      = ENV.RccId;

                DateTime timestamp        = DateTime.Now;
                string   timestamp_string = timestamp.ToString("yyyyMMddHHmmss");
                string   dc_topic_name    = $"hubbub/{siteid}/DC/AI";

                for (int pcsIdx = 0; pcsIdx < ENV.PcsCount; pcsIdx++)
                {
                    DUT_MQTT_PCS pcsPacket = pcsPackets[pcsIdx];
                    DUT_MQTT_BAT batPacket = bmsPackets[pcsIdx];

                    int pcsNo = pcsIdx + 1;

                    string pcs_topic_name = $"hubbub/{siteid}/PCS{pcsNo}/AI";
                    string bat_topic_name = $"hubbub/{siteid}/BMS{pcsNo}/AI";

                    JObject obj = CreateTemporary(1, "PCS_SYSTEM", $"PCS{pcsNo}", siteid, rccid, timestamp_string);
                    obj.Add("freq", pcsPacket.Frequency);
                    obj.Add("acGridVlt", 0);
                    obj.Add("acGridCrtLow", 0);
                    obj.Add("acGridCrtHigh", 0);
                    obj.Add("acGridPwr", 0);
                    obj.Add("actPwrKw", pcsPacket.ActivePower);
                    obj.Add("rctPwrKw", pcsPacket.ReactivePower);
                    obj.Add("pwrFact", pcsPacket.PowerFactor);
                    obj.Add("acGridVltR", pcsPacket.AC_PhaseVoltage.R);
                    obj.Add("acGridVltS", pcsPacket.AC_PhaseVoltage.S);
                    obj.Add("acGridVltT", pcsPacket.AC_PhaseVoltage.T);
                    obj.Add("acGridCrtR", pcsPacket.AC_PhaseCurrent.R);
                    obj.Add("acGridCrtS", pcsPacket.AC_PhaseCurrent.S);
                    obj.Add("acGridCrtT", pcsPacket.AC_PhaseCurrent.T);
                    obj.Add("actCmdLimitLowChg", 0);
                    obj.Add("actCmdLimitLowDhg", 0);
                    obj.Add("actCmdLimitHighChg", batPacket.ChargePowerLimit);
                    obj.Add("actCmdLimitHighDhg", batPacket.DischargePowerLimit);
                    pcs_messages[pcsIdx] = CreateMessage(obj.ToString(), pcsPacket, 0, pcs_topic_name, timestamp);

                    obj = CreateTemporary(2, "PCS_BATTERY", $"BMS{pcsNo}", siteid, rccid, timestamp_string);
                    obj.Add("bms_soc", batPacket.SOC);
                    obj.Add("bms_soh", batPacket.SOH);
                    obj.Add("dcCellPwr", pcsPacket.DC_BatteryPower);
                    obj.Add("dcCellVlt", pcsPacket.DC_BatteryVoltage);
                    obj.Add("dcCellCrt", pcsPacket.DC_BatteryCurrent);
                    obj.Add("dcCellTmpMx", batPacket.ModuleTemp.Max);
                    obj.Add("dcCellTmpMn", batPacket.ModuleTemp.Min);
                    obj.Add("dcCellVltMx", batPacket.CellVoltage.Max);
                    obj.Add("dcCellVltMn", batPacket.CellVoltage.Min);
                    bat_messages[pcsIdx] = CreateMessage(obj.ToString(), batPacket, 1, bat_topic_name, timestamp);
                }

                JObject dc_obj = CreateTemporary(5, "DC", $"DC", siteid, rccid, timestamp_string);
                dc_obj.Add("KepcoTimer", dcPacket.KepcoTimer);
                dc_obj.Add("CurrentLoad", dcPacket.CurrentLoad);
                dc_obj.Add("ForecastingPower", dcPacket.ForecastingPower);
                dc_obj.Add("PreviousDemandPower", dcPacket.PreviousDemandPower);
                dc_obj.Add("AccumulatedPower", dcPacket.AccumulatedPower);
                dc_message = CreateMessage(dc_obj.ToString(), dcPacket, 5, dc_topic_name, timestamp);

                //obj = CreateTemporary(4, "PV_SYSTEM", $"PV{pv_pack.PmsIndex}", packet.sSiteId, timestamp);
                //obj.Add("TotalActivePower", pv_pack.TotalActivePower);
                //obj.Add("TotalReactivePower", pv_pack.TotalReactivePower);
                //obj.Add("ReverseActivePower", pv_pack.ReverseActivePower);
                //obj.Add("ReverseReactivePower", pv_pack.ReverseReactivePower);
                //obj.Add("vltR", pv_pack.Voltage.R);
                //obj.Add("vltS", pv_pack.Voltage.S);
                //obj.Add("vltT", pv_pack.Voltage.T);
                //obj.Add("crtR", pv_pack.Current.R);
                //obj.Add("crtS", pv_pack.Current.S);
                //obj.Add("crtT", pv_pack.Current.T);
                //obj.Add("Frequency", pv_pack.Frequency);
                //if (pv_pack.EnergyTotalActivePower != 0)
                //{

                //}
                //obj.Add("EnergyTotalActivePower", pv_pack.EnergyTotalActivePower);
                //obj.Add("EnergyTotalReactivePower", pv_pack.EnergyTotalReactivePower);
                //obj.Add("EnergyTotalReverseActivePower", pv_pack.EnergyTotalReverseActivePower);
                //pv_string = obj.ToString();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public static void DataProcessing(DUT_MQTT_ESS packet, ConcurrentQueue <DataMessage> queue)
        {
            DUT_MQTT_PCS[] pcsPackets = packet.PCS;
            DUT_MQTT_BAT[] bmsPackets = packet.BAT;
            DUT_MQTT_DC    dcPacket   = packet.DC;

            int siteid = ENV.SiteId;
            int rccid  = ENV.RccId;

            string   dc_topic_name = $"hubbub/{siteid}/DC/AI";
            DateTime timestamp     = DateTime.FromFileTime(packet.Header.Timestamp);
            //DateTime timestamp_utc = DateTime.FromFileTimeUtc(packet.Header.Timestamp);

            /// UTC 시간으로 변경
            string timestamp_string = timestamp.AddHours(-18).ToString("yyyyMMddHHmmss");

            for (int pcsIdx = 0; pcsIdx < ENV.PcsCount; pcsIdx++)
            {
                DUT_MQTT_PCS pcsPacket = pcsPackets[pcsIdx];
                DUT_MQTT_BAT batPacket = bmsPackets[pcsIdx];
                int          pcsNo     = pcsIdx + 1;

                string pcs_topic_name        = $"hubbub/{siteid}/PCS{pcsNo}/AI";
                string pcs_status_topic_name = $"hubbub/{siteid}/0/{pcsNo}/stat";
                string bat_topic_name        = $"hubbub/{siteid}/BMS{pcsNo}/AI";

                JObject obj     = CreateTemporary(1, "PCS_SYSTEM", $"PCS{pcsNo}", siteid, rccid, timestamp_string);
                JObject pcs_obj = CreatePcsStatusModel(pcsNo, pcsPacket);
                obj.Add("freq", pcsPacket.Frequency);
                obj.Add("acGridVlt", 0);
                obj.Add("acGridCrtLow", 0);
                obj.Add("acGridCrtHigh", 0);
                obj.Add("acGridPwr", 0);
                obj.Add("actPwrKw", pcsPacket.ActivePower);
                obj.Add("rctPwrKw", pcsPacket.ReactivePower);
                obj.Add("pwrFact", pcsPacket.PowerFactor);
                obj.Add("acGridVltR", pcsPacket.AC_PhaseVoltage.R);
                obj.Add("acGridVltS", pcsPacket.AC_PhaseVoltage.S);
                obj.Add("acGridVltT", pcsPacket.AC_PhaseVoltage.T);
                obj.Add("acGridCrtR", pcsPacket.AC_PhaseCurrent.R);
                obj.Add("acGridCrtS", pcsPacket.AC_PhaseCurrent.S);
                obj.Add("acGridCrtT", pcsPacket.AC_PhaseCurrent.T);
                obj.Add("actCmdLimitLowChg", 0);
                obj.Add("actCmdLimitLowDhg", 0);
                obj.Add("actCmdLimitHighChg", batPacket.ChargePowerLimit);
                obj.Add("actCmdLimitHighDhg", batPacket.DischargePowerLimit);
                queue.Enqueue(CreateMessage(obj.ToString(), pcsPacket, 0, pcs_topic_name, pcs_obj, pcs_status_topic_name, timestamp));

                obj = CreateTemporary(2, "PCS_BATTERY", $"BMS{pcsNo}", siteid, rccid, timestamp_string);
                obj.Add("bms_soc", batPacket.SOC);
                obj.Add("bms_soh", batPacket.SOH);
                obj.Add("dcCellPwr", pcsPacket.DC_BatteryPower);
                obj.Add("dcCellVlt", pcsPacket.DC_BatteryVoltage);
                obj.Add("dcCellCrt", pcsPacket.DC_BatteryCurrent);
                obj.Add("dcCellTmpMx", batPacket.ModuleTemp.Max);
                obj.Add("dcCellTmpMn", batPacket.ModuleTemp.Min);
                obj.Add("dcCellVltMx", batPacket.CellVoltage.Max);
                obj.Add("dcCellVltMn", batPacket.CellVoltage.Min);
                queue.Enqueue(CreateMessage(obj.ToString(), batPacket, 1, bat_topic_name, timestamp));
            }
            if (dcPacket.DemandControllerError != 0)
            {
                return;
            }
            JObject dc_obj = CreateTemporary(5, "DC", $"DC", siteid, rccid, timestamp_string);

            dc_obj.Add("KepcoTimer", dcPacket.KepcoTimer);
            dc_obj.Add("CurrentLoad", dcPacket.CurrentLoad);
            dc_obj.Add("ForecastingPower", dcPacket.ForecastingPower);
            dc_obj.Add("PreviousDemandPower", dcPacket.PreviousDemandPower);
            dc_obj.Add("AccumulatedPower", dcPacket.AccumulatedPower);
            queue.Enqueue(CreateMessage(dc_obj.ToString(), dcPacket, 5, dc_topic_name, timestamp));
        }