Пример #1
0
        public static byte[] getBytes(EPS.eps_config_t str)
        {
            byte[] ans   = new byte[133]; //TODO: determine size
            int    index = 0;

            copyToByteArr(ans, str.commandReply, ref index);

            ans[index] = str.ppt_mode;
            index     += 1;

            ans[index] = str.battheater_mode;
            index     += 1;

            ans[index] = str.battheater_low;
            index     += 1;

            ans[index] = str.battheater_high;
            index     += 1;

            copyToByteArr(ans, str.output_normal_value, ref index);
            copyToByteArr(ans, str.output_safe_value, ref index);
            copyToByteArr(ans, str.output_initial_on_delay, ref index);
            copyToByteArr(ans, str.output_initial_off_delay, ref index);
            copyToByteArr(ans, str.vboost, ref index);

            return(ans);
        }
Пример #2
0
        public void GomEpsConfigSet_no_error_Test()
        {
            GomEPS gom = new GomEPS();

            gom.GomEpsInitialize(add, 1);
            EPS.eps_config_t conf = new EPS.eps_config_t();
            //conf.output = new EPS.eps_config_t();
            EPS eps = gom.eps_table[0];

            conf.ppt_mode                 = (byte)eps.CurrentConfig.PptMode;
            conf.battheater_mode          = (byte)eps.CurrentConfig.BattheaterMode;
            conf.battheater_low           = eps.CurrentConfig.BattheaterLow;
            conf.battheater_high          = eps.CurrentConfig.BattheaterHigh;
            conf.output_initial_off_delay = new ushort[8];
            conf.output_initial_on_delay  = new ushort[8];
            conf.output_normal_value      = new byte[8];
            conf.output_safe_value        = new byte[8];
            for (int i = 0; i < 8; i++)
            {
                conf.output_initial_off_delay[i] = eps.CurrentConfig.OutputInitialOffDelay[i];
                conf.output_initial_on_delay[i]  = eps.CurrentConfig.OutputInitialOnDelay[i];
                conf.output_normal_value[i]      = eps.CurrentConfig.OutputNormalValue[i];
                conf.output_safe_value[i]        = eps.CurrentConfig.OutputSafeValue[i];
            }
            conf.vboost = new ushort[3];
            for (int i = 0; i < 3; i++)
            {
                conf.vboost[i] = eps.CurrentConfig.Vboost[i];
            }
            Assert.AreEqual(Constants.E_NO_SS_ERR, gom.GomEpsConfigSet(0, conf));
        }
Пример #3
0
        public static EPS.eps_config_t convertToSturcteps_config_t(string str)
        {
            IntPtr pBuf = Marshal.StringToBSTR(str);

            EPS.eps_config_t strct = (EPS.eps_config_t)Marshal.PtrToStructure(pBuf, typeof(EPS.eps_config_t));
            return(strct);
        }
Пример #4
0
        public void GomEpsConfigSet_not_an_index_Test()
        {
            GomEPS gom = new GomEPS();

            gom.GomEpsInitialize(add, 1);
            EPS.eps_config_t conf = new EPS.eps_config_t();
            Assert.AreEqual(Constants.E_INDEX_ERROR, gom.GomEpsConfigSet(1, conf));
        }
Пример #5
0
        public void CONFIG_SETTest()
        {
            EPS eps = new EPS();

            EPS.eps_config_t config = new EPS.eps_config_t();
            config.ppt_mode                 = 8;
            config.battheater_mode          = 8;
            config.battheater_low           = 8;
            config.battheater_high          = 8;
            config.battheater_mode          = 8;
            config.output_initial_off_delay = new ushort[8];
            config.output_initial_on_delay  = new ushort[8];
            config.output_normal_value      = new byte[8];
            config.output_safe_value        = new byte[8];
            config.vboost = new ushort[3];
            for (int i = 0; i < 8; i++)
            {
                config.output_initial_off_delay[i] = 8;
                config.output_initial_on_delay[i]  = 8;
                config.output_normal_value[i]      = 8;
                config.output_safe_value[i]        = 8;
            }
            for (int i = 0; i < 3; i++)
            {
                config.vboost[i] = 8;
            }

            eps.CONFIG_SET(config);
            Assert.AreEqual((byte)eps.CurrentConfig.PptMode, config.ppt_mode);
            Assert.AreEqual((byte)eps.CurrentConfig.BattheaterMode, config.battheater_mode);
            Assert.AreEqual(eps.CurrentConfig.BattheaterLow, config.battheater_low);
            Assert.AreEqual(eps.CurrentConfig.BattheaterHigh, config.battheater_high);
            Assert.AreEqual((byte)eps.CurrentConfig.BattheaterMode, config.battheater_mode);

            for (int i = 0; i < 8; i++)
            {
                Assert.AreEqual(config.output_initial_off_delay[i], eps.CurrentConfig.OutputInitialOffDelay[i]);
                Assert.AreEqual(config.output_initial_on_delay[i], eps.CurrentConfig.OutputInitialOnDelay[i]);
                Assert.AreEqual(config.output_normal_value[i], eps.CurrentConfig.OutputNormalValue[i]);
                Assert.AreEqual(config.output_safe_value[i], eps.CurrentConfig.OutputSafeValue[i]);
            }
            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(config.vboost[i], eps.CurrentConfig.Vboost[i]);
            }
        }
Пример #6
0
 /**
  *	Set configuration data for the GOMSpace EPS version
  *
  *	@param[in] index index of GOMSpace EPS I2C bus address
  *	@param[in] config_data configuration 1 data.
  *  @return Error code according to <hal/errors.h>
  */
 public int GomEpsConfigSet(byte index, EPS.eps_config_t config_data)
 {
     logs.Add(DateTime.Now + " GomEpsConfigSet");
     logs.Add("index: " + index);
     if (eps_table == null)
     {
         logs.Add(DateTime.Now + "Exit Status: " + Constants.MapIdToError[Constants.E_NOT_INITIALIZED]);
         return(Constants.E_NOT_INITIALIZED);
     }
     if (index < eps_num && index >= 0)
     {
         eps_table[index].CONFIG_SET(config_data);
         logs.Add(DateTime.Now + "Exit Status: " + Constants.MapIdToError[Constants.E_NO_SS_ERR]);
         return(Constants.E_NO_SS_ERR);
     }
     else
     {
         logs.Add(DateTime.Now + "Exit Status: " + Constants.MapIdToError[Constants.E_INDEX_ERROR]);
         return(Constants.E_INDEX_ERROR);
     }
 }
Пример #7
0
        public static byte[] analyzeGomEps(string request)
        {
            byte[]   response   = { 0 };
            string[] args       = request.Split('&');
            string   methodName = args[0];
            byte     index      = Encoding.ASCII.GetBytes(args[1])[0];

            switch (methodName)
            {
            case "GomEpsInitialize":
            {
                byte i2c_address = Encoding.ASCII.GetBytes(args[1])[0];
                byte number      = Encoding.ASCII.GetBytes(args[2])[0];
                response = convertErrorToByteArr(eps.GomEpsInitialize(i2c_address, number));
                break;
            }

            case "GomEpsPing":
            {
                byte          pingByte = Encoding.ASCII.GetBytes(args[2])[0];
                Output <Byte> byteOut  = new Output <byte>();      // How to use it??
                byte[]        err      = convertErrorToByteArr(eps.GomEpsPing(index, pingByte, byteOut));
                byte[]        output   = new byte[] { byteOut.output };
                response = concatBytesArr(err, output);
                break;
            }

            case "GomEpsSoftReset":
            {
                response = convertErrorToByteArr(eps.GomEpsSoftReset(index));
                break;
            }

            case "GomEpsHardReset":
            {
                response = convertErrorToByteArr(eps.GomEpsHardReset(index));
                break;
            }

            case "GomEpsGetHkData_param":
            {
                //TODO: Take care when mor implement function
                break;
            }

            case "GomEpsGetHkData_general":
            {
                Output <EPS.eps_hk_t> dataOut = new Output <EPS.eps_hk_t>();
                byte[] err    = convertErrorToByteArr(eps.GomEpsGetHkData_general(index, dataOut));
                byte[] output = getBytes(dataOut.output);
                response = concatBytesArr(err, output);
                break;
            }

            case "GomEpsGetHkData_vi":
            {
                Output <EPS.eps_hk_vi_t> dataOut = new Output <EPS.eps_hk_vi_t>();
                byte[] err    = convertErrorToByteArr(eps.GomEpsGetHkData_vi(index, dataOut));
                byte[] output = getBytes(dataOut.output);
                response = concatBytesArr(err, output);
                break;
            }

            case "GomEpsGetHkData_out":
            {
                Output <EPS.eps_hk_out_t> dataOut = new Output <EPS.eps_hk_out_t>();
                byte[] err    = convertErrorToByteArr(eps.GomEpsGetHkData_out(index, dataOut));
                byte[] output = getBytes(dataOut.output);
                response = concatBytesArr(err, output);
                break;
            }

            case "GomEpsGetHkData_wdt":
            {
                Output <EPS.eps_hk_wdt_t> dataOut = new Output <EPS.eps_hk_wdt_t>();
                byte[] err    = convertErrorToByteArr(eps.GomEpsGetHkData_wdt(index, dataOut));
                byte[] output = getBytes(dataOut.output);
                response = concatBytesArr(err, output);
                break;
            }

            case "GomEpsGetHkData_basic":
            {
                Output <EPS.eps_hk_basic_t> dataOut = new Output <EPS.eps_hk_basic_t>();
                byte[] err    = convertErrorToByteArr(eps.GomEpsGetHkData_basic(index, dataOut));
                byte[] output = getBytes(dataOut.output);
                response = concatBytesArr(err, output);
                break;
            }

            case "GomEpsSetOutput":
            {
                byte output = Encoding.ASCII.GetBytes(args[2])[0];
                response = convertErrorToByteArr(eps.GomEpsSetOutput(index, output));
                break;
            }

            case "GomEpsSetSingleOutput":
            {
                byte   channel_id = Encoding.ASCII.GetBytes(args[2])[0];
                byte   value      = Encoding.ASCII.GetBytes(args[3])[0];
                ushort delay      = BitConverter.ToUInt16(Encoding.ASCII.GetBytes(args[4]), 0);
                response = convertErrorToByteArr(eps.GomEpsSetSingleOutput(index, channel_id, value, delay));
                break;
            }

            case "GomEpsSetPhotovoltaicInputs":
            {
                ushort voltage1 = BitConverter.ToUInt16(Encoding.ASCII.GetBytes(args[2]), 0);
                ushort voltage2 = BitConverter.ToUInt16(Encoding.ASCII.GetBytes(args[3]), 0);
                ushort voltage3 = BitConverter.ToUInt16(Encoding.ASCII.GetBytes(args[4]), 0);
                response = convertErrorToByteArr(eps.GomEpsSetPhotovoltaicInputs(index, voltage1, voltage2, voltage3));
                break;
            }

            case "GomEpsSetPptMode":
            {
                byte mode = Encoding.ASCII.GetBytes(args[2])[0];
                response = convertErrorToByteArr(eps.GomEpsSetPptMode(index, mode));
                break;
            }

            case "GomEpsSetHeaterAutoMode":     //TODO: need to check after mor will fix the function
            {
                byte            auto_mode        = Encoding.ASCII.GetBytes(args[2])[0];
                Output <ushort> auto_mode_return = new Output <ushort>();
                //response = String.Concat(convertErrorToByteArr(eps.GomEpsSetHeaterAutoMode(index, auto_mode, auto_mode_return)), Encoding.UTF8.GetString(getBytes(auto_mode_return.output))); //Maybe need to be different
                byte[] err    = convertErrorToByteArr(eps.GomEpsSetHeaterAutoMode(index, auto_mode, auto_mode_return));
                byte[] output = BitConverter.GetBytes(Convert.ToInt32(auto_mode_return.output));
                response = concatBytesArr(err, output);
                break;
            }

            case "GomEpsResetCounters":
            {
                response = convertErrorToByteArr(eps.GomEpsResetCounters(index));
                break;
            }

            case "GomEpsResetWDT":
            {
                response = convertErrorToByteArr(eps.GomEpsResetWDT(index));
                break;
            }

            case "GomEpsConfigCMD":
            {
                byte cmd = Encoding.ASCII.GetBytes(args[2])[0];
                response = convertErrorToByteArr(eps.GomEpsConfigCMD(index, cmd));
                break;
            }

            case "GomEpsConfigGet":
            {
                Output <EPS.eps_config_t> config_data = new Output <EPS.eps_config_t>();
                byte[] err    = convertErrorToByteArr(eps.GomEpsConfigGet(index, config_data));
                byte[] output = getBytes(config_data.output);
                response = concatBytesArr(err, output);
                break;
            }

            case "GomEpsConfigSet":
            {
                EPS.eps_config_t config_data = new EPS.eps_config_t();
                config_data = convertToSturcteps_config_t(args[2]);
                response    = convertErrorToByteArr(eps.GomEpsConfigSet(index, config_data));
                break;
            }

            case "GomEpsConfig2CMD":
            {
                byte cmd = Encoding.ASCII.GetBytes(args[2])[0];
                response = convertErrorToByteArr(eps.GomEpsConfig2CMD(index, cmd));
                break;
            }

            case "GomEpsConfig2Get":     //TODO: check after mor fix the function
            {
                Output <EPS.eps_config2_t> config_data = new Output <EPS.eps_config2_t>();
                //response = String.Concat(convertErrorToByteArr(eps.GomEpsConfig2Get(index, config_data)), Encoding.UTF8.GetString(getBytes(config_data.output))); //Maybe need to be different
                byte[] err    = convertErrorToByteArr(eps.GomEpsConfig2Get(index, config_data));
                byte[] output = getBytes(config_data.output);
                response = concatBytesArr(err, output);
                break;
            }

            case "GomEpsConfig2Set":
            {
                EPS.eps_config2_t config_data = new EPS.eps_config2_t();
                config_data = convertToSturcteps_config2_t(args[2]);
                response    = convertErrorToByteArr(eps.GomEpsConfig2Set(index, config_data));
                break;
            }
            }
            return(response);
        }