Flexwire 1500 necessary code changes

  • 2
  • Idea
  • Updated 3 years ago
  • (Edited)

Necessary software changes for using the Flex 1500 Flexwire CAT commands...  and a few problems still exist.    Prepare for code changes in the PowerSDR software:

In console.cs I added the following functions:


        public void WriteFlexwire2Data(byte addr, byte d1, byte d2)
        {
            switch (CurrentModel)
            {
                case Model.FLEX5000:
                case Model.FLEX3000:
                    if (fwc_init)
                        FWC.FlexWire_Write2Value(addr, d1, d2);
                    break;
                case Model.FLEX1500:
                    if (hid_init)
                        USBHID.FlexWire_Write2Value(addr, d1, d2);
                    break;
            }
        }

        public void WriteFlexwireData(byte addr, byte d1)
        {
            switch (CurrentModel)
            {
                case Model.FLEX5000:
                case Model.FLEX3000:
                    if (fwc_init)
                        FWC.FlexWire_WriteValue(addr, d1);
                    break;
                case Model.FLEX1500:
                    if (hid_init)
                        USBHID.FlexWire_WriteValue(addr, d1);
                    break;
            }
        }


        public void ReadFlexwireData(byte devaddr, byte addr, out byte d1)
        {
            uint val = 0;
            d1 = 0;
            switch (CurrentModel)
            {
                case Model.FLEX5000:
                case Model.FLEX3000:
                    if (fwc_init)
                        FWC.FlexWire_ReadValue(devaddr, addr, out val);
                    d1 = (byte)val;
                    break;
                case Model.FLEX1500:
                    if (hid_init)
                        USBHID.FlexWire_ReadValue(devaddr, addr, out d1);
                    break;
            }
        }

        public void ReadFlexwire2Data(ushort devaddr, ushort addr, out byte d1, out byte d2)
        {
            uint val = 0;
            d1 = 0;
            d2 = 0;
            switch (CurrentModel)
            {
                case Model.FLEX5000:
                case Model.FLEX3000:
                    if (fwc_init)
                        FWC.FlexWire_Read2Value(devaddr, addr, out val);
                    d1 = (byte)((val >> 8) & 0x00FF);
                    d2 = (byte)(val & 0x00FF);
                    break;
                case Model.FLEX1500:
                    if (hid_init)
                        USBHID.FlexWire_Read2Value((byte) devaddr, (byte) addr, out d1, out d2);
                    break;
            }
        }

This was because there's no generalized handling of the FlexWire calls except in the Heros/Preselector window, which is in PreSelForm.cs, which I changed to use the new console code:


            /*
            switch (console.CurrentModel)
            {
                case Model.FLEX5000:
                case Model.FLEX3000:
                    if(console.fwc_init)
                        FWC.FlexWire_Write2Value(0x40, reg0, reg1);
                    break;
                case Model.FLEX1500:
                    if(console.hid_init)
                        USBHID.FlexWire_Write2Value(0x40, reg0, reg1);
                    break;
            }
             */
            console.WriteFlexwire2Data(0x40, reg0, reg1);


And I had to change fwc.cs to accept a more correct I2C register read command, which used to be:


  public static int FlexWire_ReadValue(ushort addr, out uint val)
  {
   return Pal.ReadOp(Opcode.RDAL_OP_FLEXWIRE_READ_VALUE, (uint)addr, 0, out val);
  }

  public static int FlexWire_Read2Value(ushort addr, out uint val)
  {
   return Pal.ReadOp(Opcode.RDAL_OP_FLEXWIRE_READ_2_VALUE, (uint)addr, 0, out val);
  }

But I now changed to this:


  public static int FlexWire_ReadValue(ushort devaddr, ushort addr, out uint val)
  {
   return Pal.ReadOp(Opcode.RDAL_OP_FLEXWIRE_READ_VALUE, (uint)devaddr, addr, out val);
  }

  public static int FlexWire_Read2Value(ushort devaddr, ushort addr, out uint val)
  {
   return Pal.ReadOp(Opcode.RDAL_OP_FLEXWIRE_READ_2_VALUE, (uint)devaddr, addr, out val);
  }

But had to change FLEX5000LLHWForm.cs to conform with this changed call...


  private void btnFlexWireReadVal_Click(object sender, System.EventArgs e)
  {
   try
   {
    byte addr = byte.Parse(txtFlexWireAddr.Text, NumberStyles.HexNumber); 
    uint val;

    FWC.FlexWire_ReadValue(addr, 0, out val);
    txtFlexWireVal2.Text = String.Format("{0:X2}", val);
   }
   catch(Exception ex)
   {
    MessageBox.Show(ex.Message+"\n\n"+ex.StackTrace);
   }
  }

  private void btnFlexWireRead2Val_Click(object sender, System.EventArgs e)
  {
   try
   {
    byte addr = byte.Parse(txtFlexWireAddr.Text, NumberStyles.HexNumber); 
    uint val;

    FWC.FlexWire_Read2Value(addr, 0, out val);
    txtFlexWireVal1.Text = String.Format("{0:X2}", val>>8);
    txtFlexWireVal2.Text = String.Format("{0:X2}", (byte)val);
   }
   catch(Exception ex)
   {
    MessageBox.Show(ex.Message+"\n\n"+ex.StackTrace);
   }
  }

And added the FlexWire_WriteValue, FlexWire_ReadValue and FlexWire_Read2Value functions in usbhid.cs...  but these still don't work...


        public static int FlexWire_WriteValue(byte addr, byte b1)
        {
            return Flex1500.WriteOp(Opcode.USB_OP_FLEXWIRE_WRITE_VALUE, addr, (uint)(b1));
        }

        public static int FlexWire_ReadValue(byte devaddr, byte addr, out byte b1)
        {
            int rv;
            uint outval;
            rv = Flex1500.ReadOp(Opcode.USB_OP_FLEXWIRE_READ_VALUE, (uint) devaddr, (uint) addr, out outval);
            b1 = (byte)(outval);
            return rv;
        }

        public static int FlexWire_Read2Value(byte devaddr, byte addr, out byte b1, out byte b2)
        {
            int rv;
            uint outval;
            rv = Flex1500.ReadOp(Opcode.USB_OP_FLEXWIRE_READ_2_VALUE, devaddr, addr, out outval);

            b1 = (byte) ((outval >> 8) & 0x00FF);
            b2 = (byte) (outval & 0x00FF);
            return rv;
        }



And finally, I corrected the bug that was causing the PowerSDR software to crash when using a Flex 1500 with the ZZFV - ZZFY commands, of which only ZZFY works properly, found in CATCommands.cs...


  //Reads FlexWire single byte value commands
  public string ZZFV(string s)
  {
   if(s.Length == parser.nGet)
   {
    String pattern = "^[a-fA-F0-9][a-fA-F0-9]$";
    Regex sfxpattern = new Regex(pattern);
    if(!sfxpattern.IsMatch(s))
     return parser.Error1;

    byte addr = byte.Parse(s, NumberStyles.HexNumber);
    byte val;

                /// \bug  CRASH!!!!   If this is a 1500, it crashes here.
//    FWC.FlexWire_ReadValue(addr,  out val);
                console.ReadFlexwireData(addr, 0, out val);


    string ans = String.Format("{0:X2}", val);
    return ans;
   }
   else
    return parser.Error1;
  }

  //Reds FlexWire double byte value commands
  public string ZZFW(String s)
  {
   if(s.Length == parser.nGet)
   {
    String pattern = "^[a-fA-F0-9][a-fA-F0-9]$";
    Regex sfxpattern = new Regex(pattern);
    if(!sfxpattern.IsMatch(s))
     return parser.Error1;

    byte addr = byte.Parse(s, NumberStyles.HexNumber);
    byte val1;
                byte val2;


                /// \bug  CRASH!!!!   If this is a 1500, it crashes here.
//    FWC.FlexWire_Read2Value(addr, out val);
                console.ReadFlexwire2Data(addr, 0, out val1, out val2);


    string ans1 = String.Format("{0:X2}", val1);
    string ans2 = String.Format("{0:X2}", val2);
    string ans = String.Concat(ans1,ans2);
    return ans;
   
   }
   else
    return parser.Error1;
  }

  //Sends FlexWire single byte value commands
  public string ZZFX(string s)
  {
   if(s.Length == parser.nSet)
   {
    String pattern = "^[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]$";
    Regex sfxpattern = new Regex(pattern);
    if(!sfxpattern.IsMatch(s))
     return parser.Error1;

    byte addr = byte.Parse(s.Substring(0,2),NumberStyles.HexNumber);
    byte val = byte.Parse(s.Substring(2,2),NumberStyles.HexNumber);


                /// \bug  CRASH!!!!   If this is a 1500, it crashes here.
//    FWC.FlexWire_WriteValue(addr, val);
                console.WriteFlexwireData(addr, val);


    return "";
   }
   else
    return parser.Error1;
  }

  //Sends FlexWire double byte value commands
  public string ZZFY(String s)
  {
   if(s.Length == parser.nSet)
   {
    String pattern = "^[a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]$";
    Regex sfxpattern = new Regex(pattern);
    if(!sfxpattern.IsMatch(s))
     return parser.Error1;

    byte addr = byte.Parse(s.Substring(0,2), NumberStyles.HexNumber);
    byte val1 = byte.Parse(s.Substring(2,2), NumberStyles.HexNumber);
    byte val2 = byte.Parse(s.Substring(4,2), NumberStyles.HexNumber);



                /// \bug  CRASH!!!!   If this is a 1500, it crashes here.
                //    FWC.FlexWire_Write2Value(addr, val1, val2);
                console.WriteFlexwire2Data(addr, val1, val2);



    return "";
   
   }
   else
    return parser.Error1;
  }


If you refer to these functions and my change in the PreSelForm.cs, you will see that the necessary switch and checks that happen in PreSelForm.cs are ignored in the CATCommands.cs...  and the FWC call is used without regard for type of radio or initialization status.

At current, I cannot get the ZZFV,  ZZFW,  ZZFX commands to work, but at least they don't crash the whole program now.   ZZFY works fine now.


Thank you,

Rob
KF5QDT

Photo of Robert Stoddard

Robert Stoddard

  • 3 Posts
  • 1 Reply Like
  • Frustrated that I had to fix this stuff and most of it still isn't working.

Posted 3 years ago

  • 2
Photo of Robert Stoddard

Robert Stoddard

  • 3 Posts
  • 1 Reply Like
I posted this as a problem for two reasons:

1) These are code changes that are necessary to prevent PowerSDR from crashing.
2) There are still unimplemented or otherwise not working commands, both read and the single-byte write command in the Flex1500.   I'd like somebody to look into that.

Is it possible to get some feedback regarding the three commands that seem to not work?