Vrekrer / Vrekrer_scpi_parser

Simple SCPI parser for Arduino
MIT License
86 stars 26 forks source link

Hash crashes #33

Closed palmerr23 closed 11 months ago

palmerr23 commented 11 months ago

I have a largish project with 42 tokens and 52 commands, and PrintDebugInfo() is showing "Hash Crashes" is that because I have wrong settings of SCPI_HASH_TYPE , hash_magic_number and hash_magic_offset or is it simply that a lot of the commands still point to &doNothing()?

Richard


#define SCPI_MAX_TOKENS 60 //Default value = 15
#define SCPI_ARRAY_SYZE 6 //Default value = 6
#define SCPI_MAX_COMMANDS 70 //Default value = 20
#define SCPI_MAX_SPECIAL_COMMANDS 0 //Default value = 0
#define SCPI_BUFFER_LENGTH 128 //Default value = 64
#define SCPI_HASH_TYPE uint16_t //Default value = uint8_t
#include "Vrekrer_scpi_parser.h"

SCPI_Parser ddSCPI;
#include "SCPIcmds.h"

void SCPIstart()
{
  ddSCPI.hash_magic_number = 137; //Default value = 37
  ddSCPI.hash_magic_offset = 123;  //Default value = 7
  ddSCPI.timeout = 10; //value in miliseconds. Default value = 10
  regCmds();
  ddSCPI.PrintDebugInfo(Serial);
}

void regCmds()
{
    ddSCPI.SetCommandTreeBase(F(""));
      ddSCPI.RegisterCommand(F("*IDN?"), &Identify);
    ddSCPI.SetCommandTreeBase(F("INST"));
      ddSCPI.RegisterCommand(F(":SEL"), &setChanSel);
      ddSCPI.RegisterCommand(F(":SEL?"), &getChanSel);
      //ddSCPI.RegisterCommand(F(":SWEEP"), &setSweep);
      ddSCPI.RegisterCommand(F(":SWEEP:ENA"), &setSweepEnable);
      ddSCPI.RegisterCommand(F(":SWEEP:ENA?"), &getSweepEnable);
      ddSCPI.RegisterCommand(F(":SWEEP:STA"), &setSweepStart);
      ddSCPI.RegisterCommand(F(":SWEEP:STOP"), &setSweepStop);
      ddSCPI.RegisterCommand(F(":SWEEP:TYPE"), &DoNothing);
      ddSCPI.RegisterCommand(F(":SWEEP:INIT"), &DoNothing);
      ddSCPI.RegisterCommand(F(":SWEEP:FINAL"), &DoNothing);
      ddSCPI.RegisterCommand(F(":SWEEP:STEPS"), &DoNothing);
      ddSCPI.RegisterCommand(F(":SWEEP:LIN"), &DoNothing);
      ddSCPI.RegisterCommand(F(":SWEEP:REPEAT"), &DoNothing);

      ddSCPI.RegisterCommand(F(":BURST:ENA"), &setSweepEnable);
      ddSCPI.RegisterCommand(F(":BURST:ENA?"), &getSweepEnable);
      ddSCPI.RegisterCommand(F(":BURST:STA"), &setSweepStart);
      ddSCPI.RegisterCommand(F(":BURST:STOP"), &setSweepStop);
      ddSCPI.RegisterCommand(F(":BURST:STEPS"), &DoNothing);
      ddSCPI.RegisterCommand(F(":BURST:BALTA"), &DoNothing);
      ddSCPI.RegisterCommand(F(":BURST:REPEAT"), &DoNothing);

      ddSCPI.RegisterCommand(F(":CONT:COUPLE"), &DoNothing);
      ddSCPI.RegisterCommand(F(":CONT:BPHASE"), &DoNothing);
      ddSCPI.RegisterCommand(F(":CONT:EXT"), &DoNothing);
      ddSCPI.RegisterCommand(F(":CONT:BPHASE"), &DoNothing); // removed this one too
      ddSCPI.RegisterCommand(F(":CONT:INPOL"), &DoNothing);
      ddSCPI.RegisterCommand(F(":CONT:OUTPOL"), &DoNothing);

    ddSCPI.SetCommandTreeBase(F("SOURCE"));
      ddSCPI.RegisterCommand(F(":START"), &setChanStart);
      ddSCPI.RegisterCommand(F(":STOP"), &setChanStop);
      ddSCPI.RegisterCommand(F(":ENA"), &setChanEnable);
      ddSCPI.RegisterCommand(F(":ENA?"), &getChanEnable);
      ddSCPI.RegisterCommand(F(":WAVE"), &setWave);
      ddSCPI.RegisterCommand(F(":WAVE?"), &getWave);

      ddSCPI.RegisterCommand(F(":SINE:FREQ"), &DoNothing);
      ddSCPI.RegisterCommand(F(":SINE:AMP"), &DoNothing);
      ddSCPI.RegisterCommand(F(":SINE:DCOFF"), &DoNothing);
      ddSCPI.RegisterCommand(F(":IMD:FREQ"), &DoNothing); // removed this one

      ddSCPI.RegisterCommand(F(":SQR:FREQ"), &DoNothing);
      ddSCPI.RegisterCommand(F(":SQR:V#"), &DoNothing);
      ddSCPI.RegisterCommand(F(":SQR:DUTY"), &DoNothing);

      ddSCPI.RegisterCommand(F(":TRI:FREQ"), &DoNothing);
      ddSCPI.RegisterCommand(F(":TRI:V#"), &DoNothing);
      ddSCPI.RegisterCommand(F(":TRI:DUTY"), &DoNothing);

      ddSCPI.RegisterCommand(F(":IMD:AMP#"), &DoNothing);
      ddSCPI.RegisterCommand(F(":IMD:FREQ#"), &DoNothing);

      ddSCPI.RegisterCommand(F(":WHITE:AMP"), &DoNothing);
      ddSCPI.RegisterCommand(F(":WHITE:DCOFF"), &DoNothing);

      ddSCPI.RegisterCommand(F(":PULSE:V#"), &DoNothing);
      ddSCPI.RegisterCommand(F(":PULSE:SUP"), &DoNothing);
      ddSCPI.RegisterCommand(F(":PULSE:SDN"), &DoNothing);
      ddSCPI.RegisterCommand(F(":PULSE:TUP"), &DoNothing);
      ddSCPI.RegisterCommand(F(":PULSE:TDN"), &DoNothing);
      ddSCPI.RegisterCommand(F(":PULSE:REPT"), &DoNothing);

}

Here's the debug output

SSID = PalHome
MDNS: starting [DDS]
mDNS responder started. Hostname = http://DDS.local
Hostname: (DDS.local)
IP: 192.168.1.82
*** DEBUG INFO ***

Max command tree branches: 6 (SCPI_ARRAY_SYZE)
Max number of parameters: 6 (SCPI_ARRAY_SYZE)
Message buffer size: 128 (SCPI_BUFFER_LENGTH)

TOKENS : 42 / 60 (SCPI_MAX_TOKENS)
  1:    *IDN
  2:    INST
  3:    SEL
  4:    SWEEP
  5:    ENA
  6:    STA
  7:    STOP
  8:    TYPE
  9:    INIT
  10:   FINAL
  11:   STEPS
  12:   LIN
  13:   REPEAT
  14:   BURST
  15:   BALTA
  16:   CONT
  17:   COUPLE
  18:   BPHASE
  19:   EXT
  20:   INPOL
  21:   OUTPOL
  22:   SOURCE
  23:   START
  24:   WAVE
  25:   SINE
  26:   FREQ
  27:   AMP
  28:   DCOFF
  29:   IMD
  30:   SQR
  31:   V#
  32:   DUTY
  33:   TRI
  34:   AMP#
  35:   FREQ#
  36:   WHITE
  37:   PULSE
  38:   SUP
  39:   SDN
  40:   TUP
  41:   TDN
  42:   REPT

VALID CODES : 52 / 70 (SCPI_MAX_COMMANDS)
  # Hash        Handler
  1:    39EA        0x1000346D
  2:    3A76        0x100083A5
  3:    4925        0x1000348D
  4:    49B3        0x100085E1
  5:    70CA        0x10003439
  6:    49B4        0x100033D1
  7:    49B5        0x10003405
  8:    49B6        0x10007A5D
  9:    49B7        0x10007A5D
  10:   49B8        0x10007A5D
  11:   49B9        0x10007A5D
  12:   49BA        0x10007A5D
  13:   49BB        0x10007A5D
  14:   4F0D        0x100085E1
  15:   4DF4        0x10003439
  16:   4F0E        0x100033D1
  17:   4F0F        0x10003405
  18:   4F13        0x10007A5D
  19:   4F17        0x10007A5D
  20:   4F15        0x10007A5D
  21:   502B        0x10007A5D
  22:   502C        0x10007A5D
  23:   502D        0x10007A5D
  24:   502C!!      0x10007A5D
  25:   502E        0x10007A5D
  26:   502F        0x10007A5D
  27:   453E        0x10003325
  28:   452E        0x10003365
  29:   452C        0x10008511
  30:   48B     0x100033A5
  31:   453F        0x10008459
  32:   EB6     0x100032E9
  33:   F59     0x10007A5D
  34:   F5A     0x10007A5D
  35:   F5B     0x10007A5D
  36:   117D        0x10007A5D
  37:   1206        0x10007A5D
  38:   120B        0x10007A5D
  39:   120C        0x10007A5D
  40:   13A1        0x10007A5D
  41:   13A6        0x10007A5D
  42:   13A7        0x10007A5D
  43:   1185        0x10007A5D
  44:   1186        0x10007A5D
  45:   153D        0x10007A5D
  46:   153E        0x10007A5D
  47:   15CA        0x10007A5D
  48:   15D1        0x10007A5D
  49:   15D2        0x10007A5D
  50:   15D3        0x10007A5D
  51:   15D4        0x10007A5D
  52:   15D5        0x10007A5D
 **ERROR** Hash crashes found. (!!)

HASH Configuration:
  Hash size: 16bits (SCPI_HASH_TYPE)
  Hash magic number: 137
  Hash magic offset: 123

*******************
palmerr23 commented 11 months ago

I solved the problem - I had some duplicate commands. ddSCPI.RegisterCommand(F(":IMD:FREQ"), &DoNothing); // removed this one ddSCPI.RegisterCommand(F(":CONT:BPHASE"), &DoNothing); // removed this one too

removing them solved the problem.

Thanks for a very useful library.

palmerr23 commented 11 months ago

Closing the issue