Esempio n. 1
0
        protected override void OnMessage(MessageEventArgs e)
        {
            if (e.Data == "STATUS")
            {
                Random           rand     = new Random();
                BmsDisplayValues bms_data = GetBmsStatusFunc();
                if (bms_data == null)
                {
                    bms_data = new BmsDisplayValues() //test data.
                    {
                        CellTemp       = new double[15],
                        CellVoltage    = new double[15],
                        ChargeCurrent  = 0.124 + (rand.NextDouble() / 45),
                        Humidity       = 0.34,
                        PackAmpHours   = 39.2452,
                        PackVoltage    = 48.62,
                        PrimaryCurrent = 15.46,
                        Temperture     = 81.6
                    };
                    for (int i = 0; i < bms_data.CellTemp.Length; ++i)
                    {
                        bms_data.CellTemp[i]    = rand.Next(55, 65);
                        bms_data.CellVoltage[i] = rand.Next(310, 350) / 100.0;
                    }
                }
                if (bms_data != null)
                {
                    Send(bms_data.GetJson());
                }
                else
                {
                    Send(JsonConvert.SerializeObject(new { error = "BMS data not loaded" }));
                }
                return;
            }

            if (e.Data.StartsWith("LED"))
            {
                string command = e.Data.Substring("LED".Length).Trim();
                SetLedFunc(command);
                Send(JsonConvert.SerializeObject(new { success = true }));
                return;
            }

            Send(JsonConvert.SerializeObject(new { error = "unknown command: " + e.Data }));
            return;
        }
Esempio n. 2
0
        public BmsDisplayValues ConvertToDisplayData()
        {
            BmsDisplayValues display = new BmsDisplayValues()
            {
                CellTemp       = new double[CELL_COUNT],
                CellVoltage    = new double[CELL_COUNT],
                ChargeCurrent  = GetChargeCurrent(),
                Humidity       = GetMasterHumidity(),
                PackVoltage    = GetPackVoltage(),
                PrimaryCurrent = GetMasterCurrent(),
                Temperture     = GetMasterTemperature(),
                PackAmpHours   = GetAmpHours()
            };

            for (int i = 0; i < CELL_COUNT; ++i)
            {
                display.CellTemp[i]    = GetCellTemperature(i);
                display.CellVoltage[i] = GetCellVoltage(i);
            }

            return(display);
        }