Beispiel #1
0
        public static void ReadTXImage(float[] gain_table, float[] phase_table)
        {
            Band[] bands = { Band.B160M, Band.B80M, Band.B60M, Band.B40M, Band.B30M, Band.B20M,
                             Band.B17M,  Band.B15M, Band.B12M, Band.B10M, Band.B6M };

            ushort addr = 0x30B0;

            byte[] buf1 = new byte[32];
            byte[] buf2 = new byte[32];
            USBHID.ReadEEPROM(addr, 32, out buf1);
            addr += 32;
            USBHID.ReadEEPROM(addr, 32, out buf2);
            int index = 0;

            for (int i = 0; i < 8; i++)
            {
                if (buf1[i] != 0xFF)
                {
                    break;
                }

                if (i == 7)
                {
                    return;         // data is all defaults -- nothing to read
                }
            }

            for (int i = 0; i < bands.Length; i++)
            {
                float val = 0.0f;
                if (index < 32)
                {
                    val = BitConverter.ToSingle(buf1, index);
                }
                else
                {
                    val = BitConverter.ToSingle(buf2, index - 32);
                }
                index += 4;

                if (val > 500.0f || val < -500.0f)
                {
                    TextWriter writer = new StreamWriter(app_data_path + "\\eeprom_error.log", true);
                    writer.WriteLine(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " " +
                                     "Error reading TX Image Gain value from EEPROM -- sn: " + SerialToString(serial_number) + " > " +
                                     bands[i].ToString() + " - Value out of range [-400.0, 400.0] (" + val.ToString("f4") + ").");
                    writer.Close();
                    val = 0.0f;
                }

                gain_table[(int)bands[i]] = val;
            }

            addr = 0x30E0;
            USBHID.ReadEEPROM(addr, 32, out buf1);
            addr += 32;
            USBHID.ReadEEPROM(addr, 32, out buf2);
            index = 0;

            for (int i = 0; i < 8; i++)
            {
                if (buf1[i] != 0xFF)
                {
                    break;
                }

                if (i == 7)
                {
                    return;         // data is all defaults -- nothing to read
                }
            }

            for (int i = 0; i < bands.Length; i++)
            {
                float val = 0.0f;
                if (index < 32)
                {
                    val = BitConverter.ToSingle(buf1, index);
                }
                else
                {
                    val = BitConverter.ToSingle(buf2, index - 32);
                }
                index += 4;

                if (val > 400.0f || val < -400.0f)
                {
                    TextWriter writer = new StreamWriter(app_data_path + "\\eeprom_error.log", true);
                    writer.WriteLine(DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + " " +
                                     "Error reading TX Image Phase value from EEPROM -- " + serial_number + " -- " +
                                     bands[i].ToString() + " - Value out of range [-400.0, 400.0] (" + val.ToString("f4") + ").");
                    writer.Close();
                    val = 0.0f;
                }

                phase_table[(int)bands[i]] = val;
            }
        }
Beispiel #2
0
        private static void Dump()
        {
            if (File.Exists(Application.StartupPath + "\\nobackup"))
            {
                return;                                                                // for production
            }
            uint data;

            StringBuilder s = new StringBuilder("F1.5K_");

            USBHID.GetSerialNum(out data);
            s.Append(SerialToString(data));
            if (!Directory.Exists(app_data_path + "\\Backup\\"))
            {
                Directory.CreateDirectory(app_data_path + "\\Backup\\");
            }
            if (File.Exists(app_data_path + "\\Backup\\" + s + " backup.csv"))
            {
                return;
            }
            StreamWriter writer = new StreamWriter(app_data_path + "\\Backup\\" + s + " backup.csv");

            s = new StringBuilder(",");
            for (int i = 0; i < 16; i++)
            {
                s.Append(i.ToString("X") + ",");
            }
            writer.WriteLine(s);

            byte[] buf = new byte[32];

            USBHID.ReadEEPROM(0x1800, 32, out buf);
            s = new StringBuilder("1800,");

            for (int j = 0; j < 16; j++)
            {
                s.Append(buf[j].ToString("X") + ",");
            }

            writer.WriteLine(s);
            Application.DoEvents();

            s = new StringBuilder("1810,");

            for (int j = 0; j < 16; j++)
            {
                s.Append(buf[j + 16].ToString("X") + ",");
            }

            writer.WriteLine(s);

            USBHID.ReadEEPROM(0x1820, 16, out buf);
            s = new StringBuilder("1820,");

            for (int j = 0; j < 16; j++)
            {
                s.Append(buf[j].ToString("X") + ",");
            }

            writer.WriteLine(s);
            Application.DoEvents();

            for (int i = 0; i < 9; i++) // 32*9 = 288
            {
                USBHID.ReadEEPROM((ushort)(0x3000 + i * 32), 32, out buf);

                s = new StringBuilder((0x300 + i * 2).ToString("X") + "0,");

                for (int j = 0; j < 16; j++)
                {
                    s.Append(buf[j].ToString("X") + ",");
                }

                writer.WriteLine(s);
                Application.DoEvents();

                s = new StringBuilder((0x300 + i * 2 + 1).ToString("X") + "0,");

                for (int j = 0; j < 16; j++)
                {
                    s.Append(buf[j + 16].ToString("X") + ",");
                }

                writer.WriteLine(s);
            }

            writer.Close();
        }
Beispiel #3
0
        public static void ReadPAPower(float[][] table)
        {
            Band[] bands = { Band.B160M, Band.B80M, Band.B60M, Band.B40M, Band.B30M, Band.B20M,
                             Band.B17M,  Band.B15M, Band.B12M, Band.B10M, Band.B6M };

            ushort addr = 0x3030;

            byte[] buf = new byte[32];
            USBHID.ReadEEPROM(addr, 32, out buf);
            int index = 0;

            if (buf[0] == 0xFF && buf[1] == 0xFF)
            {
                return;
            }

            // check for shifted data

            /*bool bad_early_data = false;
             * for (int i = 0; i < 8; i++)
             * {
             *  short val = BitConverter.ToInt16(buf, i * 2);
             *  float f = (float)(val / 10000.0);
             *  if (f > 10.0 || f < 0.0)
             *  {
             *      bad_early_data = true;
             *      break;
             *  }
             * }
             *
             * bool bad_late_data = false;
             * if (bad_early_data)
             * {
             *  byte[] buf1 = new byte[6];
             *  USBHID.ReadEEPROM(0x3050, 6, out buf1);
             *
             *  for (int i = 0; i < 3; i++)
             *  {
             *      short val = BitConverter.ToInt16(buf1, i * 2);
             *      float f = (float)(val / 10000.0);
             *      if (f > 10.0 || f < 0.0)
             *      {
             *          bad_late_data = true;
             *          break;
             *      }
             *  }
             * }
             *
             * // verifies that the middle of the RX Image Gain table is unwritten
             * bool blank_image_data = true;
             * if (bad_early_data)
             * {
             *  byte[] buf2 = new byte[16];
             *  USBHID.ReadEEPROM(0x3060, 16, out buf2);
             *
             *  for (int i = 0; i < 16; i++)
             *  {
             *      if (buf2[i] != 0xFF)
             *      {
             *          blank_image_data = false;
             *          break;
             *      }
             *  }
             * }
             *
             * if (bad_early_data && bad_late_data) // data is invalid -- how to handle this??
             * {
             *  MessageBox.Show("Error E8390: Please contact technical support with this number.\n"+
             *  "You may experience low output power until this is corrected.",
             *      "Error E8390",
             *      MessageBoxButtons.OK,
             *      MessageBoxIcon.Error);
             *  for (int i = 0; i < bands.Length; i++)
             *      table[(int)bands[i]][0] = 0.1f;
             *  return;
             * }
             * else if (bad_early_data && !bad_late_data && blank_image_data) // data is shifted -- move it to the appropriate place
             * {
             *  StreamWriter sw = new StreamWriter(app_data_path + "error.log", true);
             *  sw.WriteLine(DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + ": " +
             *      "FLEX-1500 Power Cal Data shifted -- corrective measures taken.");
             *  sw.WriteLine("Before:");
             *  sw.Write("\t0x3030: ");
             *  for(int i=0; i<16; i++)
             *      sw.Write(buf[i].ToString("X").PadLeft(2, '0')+" ");
             *  sw.WriteLine("");
             *  sw.Write("\t0x3040: ");
             *  for (int i = 0; i < 16; i++)
             *      sw.Write(buf[i + 16].ToString("X").PadLeft(2, '0') + " ");
             *  sw.WriteLine("");
             *
             *  byte[] buf1 = new byte[6];
             *  USBHID.ReadEEPROM(0x3050, 6, out buf1);
             *
             *  sw.Write("\t0x3050: ");
             *  for (int i = 0; i < 6; i++)
             *      sw.Write(buf1[i].ToString("X").PadLeft(2, '0') + " ");
             *  sw.WriteLine("");
             *
             *  // shift data back 16 bytes
             *  Array.Copy(buf, 16, buf, 0, 16);
             *  Array.Copy(buf1, 0, buf, 16, 6);
             *
             *  // reset remaining bytes to the default 0xFF
             *  byte[] buf2 = new byte[10];
             *  for(int i=0; i<10; i++)
             *      buf2[i] = 0xFF;
             *  Array.Copy(buf2, 0, buf, 22, 10);
             *
             *  // handle 15m getting overwritten by the checksum
             *  Array.Copy(buf, 12, buf, 14, 2); // copy 15m from 17m
             *
             *  // write data back to EEPROM
             *  USBHID.WriteEEPROM(0x3030, buf);
             *
             *  // read corrected data back into buffer for following work
             *  USBHID.ReadEEPROM(addr, 32, out buf);
             *
             *  // write 0xFF to 0x3050 row
             *  buf1 = new byte[16];
             *  for (int i = 0; i < 16; i++)
             *      buf1[i] = 0xFF;
             *  USBHID.WriteEEPROM(0x3050, buf1);
             *
             *  sw.WriteLine("After:");
             *  sw.Write("\t0x3030: ");
             *  for (int i = 0; i < 16; i++)
             *      sw.Write(buf[i].ToString("X").PadLeft(2, '0') + " ");
             *  sw.WriteLine("");
             *  sw.Write("\t0x3040: ");
             *  for (int i = 0; i < 16; i++)
             *      sw.Write(buf[i + 16].ToString("X").PadLeft(2, '0') + " ");
             *  sw.WriteLine("");
             *  sw.Write("\t0x3050: ");
             *  for (int i = 0; i < 6; i++)
             *      sw.Write(buf1[i].ToString("X").PadLeft(2, '0') + " ");
             *  sw.WriteLine("");
             *  sw.Close();
             * }*/

            // read the data from the EEPROM into the table
            for (int i = 0; i < bands.Length; i++)
            {
                short val = 0;
                val    = BitConverter.ToInt16(buf, index);
                index += 2;

                table[(int)bands[i]][0] = (float)(val / 10000.0);
            }

            /*if(bad_early_data && !bad_late_data)
             * {
             *  // recalculate and write checksum
             *  WritePAPowerChecksum(Checksum.Calc(table));
             * }*/
        }