Case statement not recognized

I'm having a strange issue. all of the case statements in this group work except for case'j': why is case 'j' not recognized ??

void oneLineReceived(const char * buffer) {
  bool success = false;
  byte oldTarget = 0;
  switch (*buffer) {
    case 0: //empty line
      Serial.println();
      return;
    case 's':
        success = writeTo(buffer[2], buffer + 1, strlen(buffer + 1) + 1, false);
        Serial.print(F(" s>   "));
        ((Command*)(buffer + 1))->disp();
        if (!success) {
          Serial.println(F("*failed"));
        }
      break;
    case 'S':
        success = writeTo(buffer[1], &cmd, cmd.setData(buffer[1], buffer + 2), false);
        Serial.print(F(" S>   "));
        cmd.disp();
        if (success) {
          cmd.incId();
        } else {
          Serial.println(F("*failed"));
        }
      break;
    case 'T':
      oldTarget = seq.to;
      seq.to = buffer[1];
      success = writeTo(buffer[1], &seq, sizeof(TimerInfos), false);
      Serial.print(F(" T>   "));
      seq.disp();
      seq.to = oldTarget;
      if (success) {
        seq.incId();
      } else {
        Serial.println(F("*failed"));
      }
      break;
    case 't':
      if (!seq.handleCommand(buffer + 1)) {
        Serial.print(F("could not understand '"));
        Serial.print(buffer);
        Serial.println(F("'"));
      }
      break;
      case 'q':
      Serial.print(F("Stopped Timer  '"));
      int newStates = atoi(&buffer[1]);
      seq.StopTimer();
        Serial.print(F("Stopped Timer  '"));
        Serial.print(newStates);
        Serial.println(F("'"));
      break;
      
      case 'j':
       newStates = atoi(&buffer[1]);
      seq.jumpToTimer(newStates);
        Serial.print(F("Jumping To Timer '"));
        Serial.print(newStates);
        Serial.println(F("'"));
      break;
      
    case 'D':
        oldTarget = dos.to;
        dos.to = buffer[1];
        success = writeTo(buffer[1], &dos, sizeof(Doses), false);
        Serial.print(F(" D>   "));
        dos.disp();
        dos.to = oldTarget;
        if (success) {
          dos.incId();
        } else {
          Serial.println(F("*failed"));
        }
      break;
    case 'd':
      if (!dos.handleCommand(buffer + 1)) {
        Serial.print(F("could not understand '"));
        Serial.print(buffer);
        Serial.println(F("'"));
      }
      break;
    case 'n':
      EEPROM.update(NodeIdInEEPROM, buffer[1] ? buffer[1] : 255);
      radio.stopListening();
      setFromAdr(buffer[1]);
      radio.openReadingPipe(1, personalAddress);
      radio.startListening();     
      break;
    case 'A':
      switch (buffer[1]) {
      case 't':
        oneUL(buffer + 2, &seq.announce.interval, F("announce timer"));
        break;
      case 'd':
        oneUL(buffer + 2, &dos.announce.interval, F("announce doser"));
        break;
      case 'w':
        oneUL(buffer + 2, &cmd.announce.interval, F("whine"));
        break;
      }
      break;
    case 'O':
      switch (buffer[1]) {
        case 'C':
          Hdr::compressed = !Hdr::compressed;
          printBool(F("compressed"), Hdr::compressed);
          break;
        case 'P':
          wishPrintPipe = !wishPrintPipe;
          printBool(F("printPipe"), wishPrintPipe);
          break;
        case 'M':
          showMulticast = !showMulticast;
          printBool(F("showMulticast"), showMulticast);
          break;
        case 'S':
          seq.runTimer = !seq.runTimer;
          printBool(F("runSequencer"), seq.runTimer);
          break;
        case 'L':
          seq.showStateTransitions = !seq.showStateTransitions;
          printBool(F("show timer transitions"), seq.showStateTransitions);
          break;
        case 'D':
          dos.runOk = !dos.runOk;
          printBool(F("run Doser"), dos.runOk);
          break;
        case 'l':
          dos.showStateTransitions = !dos.showStateTransitions;
          printBool(F("show doser transitions"), dos.showStateTransitions);
          break;
      }
      break;
    case '?':
      signOn();
      Serial.println((const __FlashStringHelper *)bigHelpString);
      printBool(F("compressed"), Hdr::compressed);
      printBool(F("printPipe"), wishPrintPipe);
      printBool(F("showMulticast"), showMulticast);
      printBool(F("run Sequencer"), seq.runTimer);
      printBool(F("run Doser"), dos.runOk);
      printBool(F("show timer transitions"), seq.showStateTransitions);
      printBool(F("show doser transitions"), dos.showStateTransitions);
      Serial.print(F("whine interval = "));
      Serial.println(cmd.announce.interval);
      Serial.print(F("announce timer interval = "));
      Serial.println(seq.announce.interval);
      Serial.print(F("announce doser interval = "));
      Serial.println(dos.announce.interval);
      break;

    default:
      Serial.print(F("unknown command '"));
      Serial.write(*buffer);
      Serial.println(F("' try one of '?sStTdDA[tdw}O[CPMS]'."));
  }
}

how do you know it does not work?

you are calling atoi(&buffer[1]);. Are you sure buffer is properly terminated cString?

J-M-L:
how do you know it does not work?

you are calling atoi(&buffer[1]);. Are you sure buffer is properly terminated cString?

Sorry im bad at explaining things. WWhat i mean by not work is if i type j in the serial console and i get nothing. however every other case works. i can type q and get serial print. if i place the case 'j' above the case 'q' then j works and q wont?

you are messing around with pointers et doing weird stuff.. without full code it's hard to say what's going on... you might have a rogue pointer and corrupt memory

would suggest you remove all codes in the switch / case and just print the character you recognize. if that works then your issue is either in what you do there or elsewhere in the code

void oneLineReceived(const char* buffer) {
  Serial.print(F("command: ["));Serial.print(buffer);Serial.println(F("]"));
  switch (*buffer) {
    case 0: //empty line
      Serial.println(0);
      break;
    case 's':
      Serial.println('s');
      break;
    case 'S':
      Serial.println('S');
      break;
    case 'T':
      Serial.println('T');
      break;
    case 't':
      Serial.println('t');
      break;
    case 'q':
      Serial.println('q');
      break;
    case 'j':
      Serial.println('j');
      break;
    case 'D':
      Serial.println('D');
      break;
    case 'd':
      Serial.println('d');
      break;
    case 'n':
      Serial.println('n');
      break;
    case 'A':
      Serial.println('A');
      break;
    case 'O':
      Serial.println('O');
      break;
    case '?':
      Serial.println('?');
      break;
    default:
      Serial.print(F("unknown command '"));
      Serial.write(*buffer);
      Serial.println(F("' try one of '?sStTdDA[tdw}O[CPMS]'."));
  }
}

J-M-L:
you are messing around with pointers et doing weird stuff… without full code it’s hard to say what’s going on… you might have a rogue pointer and corrupt memory

would suggest you remove all codes in the switch / case and just print the character you recognize. if that works then your issue is either in what you do there or elsewhere in the code

void oneLineReceived(const char* buffer) {

switch (*buffer) {
   case 0: //empty line
     Serial.println(0);
     break;
   case ‘s’:
     Serial.println(‘s’);
     break;
   case ‘S’:
     Serial.println(‘S’);
     break;
   case ‘T’:
     Serial.println(‘T’);
     break;
   case ‘t’:
     Serial.println(‘t’);
     break;
   case ‘q’:
     Serial.println(‘q’);
     break;
   case ‘j’:
     Serial.println(‘j’);
     break;
   case ‘D’:
     Serial.println(‘D’);
     break;
   case ‘d’:
     Serial.println(‘d’);
     break;
   case ‘n’:
     Serial.println(‘n’);
     break;
   case ‘A’:
     Serial.println(‘A’);
     break;
   case ‘O’:
     Serial.println(‘O’);
     break;
   case ‘?’:
     Serial.println(’?’);
     break;
   default:
     Serial.print(F(“unknown command '”));
     Serial.write(*buffer);
     Serial.println(F("’ try one of ‘?sStTdDA[tdw}O[CPMS]’."));
 }
}

If your willing to take a look at the code i attached it below thanks,

TimerModule_2.ino (10.5 KB)

packetDefinitions.h (23.4 KB)

what happens if you replace the function with what I've shared above?
(why don't you use classes and you seem to use byte and char interchangeably. a char is signed and a byte is not)

the above works. and also if i delete every case except case :0 starting from T up it works too?? im lost

how can this work?        ((Command*)(buffer + 1))->disp();

J-M-L:
how can this work?        ((Command*)(buffer + 1))->disp();

Im not exactly sure yet, I didnt write that part of the code but it seems like it does

I have been getting errors sometimes when compiling the code but i cant figure out whats causing it,

" language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\User\\ArduDebug\\Build\\preproc\\ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"C:\\Users\\User\\Documents\\arduino-1.8.7\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10807 -DARDUINO_AVR_DUEMILANOVE -DARDUINO_ARCH_AVR "-IC:\\Users\\User\\Documents\\arduino-1.8.7\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Users\\User\\Documents\\arduino-1.8.7\\hardware\\arduino\\avr\\variants\\standard" "-IC:\\Users\\User\\Documents\\Arduino\\libraries\\RF24-master" "-IC:\\Users\\User\\Documents\\arduino-1.8.7\\hardware\\arduino\\avr\\libraries\\SPI\\src" "-IC:\\Users\\User\\Documents\\arduino-1.8.7\\hardware\\arduino\\avr\\libraries\\EEPROM\\src" "C:\\Users\\User\\ArduDebug\\Build\\sketch\\TimerModule_2.ino.cpp" -o "C:\\Users\\User\\ArduDebug\\Build\\sketch\\TimerModule_2.ino.cpp.o"
In file included from C:\Users\User\AppData\Local\Temp\arduino_modified_sketch_276028\TimerModule_2.ino:3:0:

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h: In member function 'byte Sequencer::jumpToTimer(int)':

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h:379:3: warning: no return statement in function returning non-void [-Wreturn-type]

   }

   ^

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h: In member function 'byte Sequencer::StopTimer()':

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h:382:3: warning: no return statement in function returning non-void [-Wreturn-type]

   }

   ^

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h: In constructor 'pH::pH(byte, byte, byte)':

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h:788:22: warning: 'pH::phAnalogPins' will be initialized after [-Wreorder]

   byte phAnalogPins[2];

                      ^

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h:783:19: warning:   'float pH::pHValues [2]' [-Wreorder]

   float pHValues[2];

                   ^

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h:789:3: warning:   when initialized here [-Wreorder]

   pH(byte from, byte pin1, byte pin2) : pH1avgValue(0), pH2avgValue(0), phAnalogPins{pin1, pin2}, pHValues{5.89, 5.89}, phreadstate(1) {}

   ^

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h:783:19: warning: 'pH::pHValues' will be initialized after [-Wreorder]

   float pHValues[2];

                   ^

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h:780:7: warning:   'int pH::phreadstate' [-Wreorder]

   int phreadstate;

       ^

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h:789:3: warning:   when initialized here [-Wreorder]

   pH(byte from, byte pin1, byte pin2) : pH1avgValue(0), pH2avgValue(0), phAnalogPins{pin1, pin2}, pHValues{5.89, 5.89}, phreadstate(1) {}

   ^

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h: At global scope:

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h:789:11: warning: unused parameter 'from' [-Wunused-parameter]

   pH(byte from, byte pin1, byte pin2) : pH1avgValue(0), pH2avgValue(0), phAnalogPins{pin1, pin2}, pHValues{5.89, 5.89}, phreadstate(1) {}

           ^

Compiling libraries...
Compiling library "RF24-master"
Using previously compiled file: C:\Users\User\ArduDebug\Build\libraries\RF24-master\RF24.cpp.o
Compiling library "SPI"
Using previously compiled file: C:\Users\User\ArduDebug\Build\libraries\SPI\SPI.cpp.o
Compiling library "EEPROM"
Compiling core...
Using precompiled core: C:\Users\User\AppData\Local\Temp\arduino_cache_914529\core\core_arduino_avr_diecimila_cpu_atmega328_894a0c12f06ef970bc466e481e751540.a
Linking everything together...
"C:\\Users\\User\\Documents\\arduino-1.8.7\\hardware\\tools\\avr/bin/avr-gcc" -Wall -Wextra -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "C:\\Users\\User\\ArduDebug\\Build/TimerModule_2.ino.elf" "C:\\Users\\User\\ArduDebug\\Build\\sketch\\TimerModule_2.ino.cpp.o" "C:\\Users\\User\\ArduDebug\\Build\\libraries\\RF24-master\\RF24.cpp.o" "C:\\Users\\User\\ArduDebug\\Build\\libraries\\SPI\\SPI.cpp.o" "C:\\Users\\User\\ArduDebug\\Build/..\\..\\AppData\\Local\\Temp\\arduino_cache_914529\\core\\core_arduino_avr_diecimila_cpu_atmega328_894a0c12f06ef970bc466e481e751540.a" "-LC:\\Users\\User\\ArduDebug\\Build" -lm
C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h: In member function 'disp':

C:\Users\User\ArduDebug\Build\sketch\packetDefinitions.h:53:3: internal compiler error: Segmentation fault

   }

   ^

Please submit a full bug report,

with preprocessed source if appropriate.

See <http://gcc.gnu.org/bugs.html> for instructions.

lto-wrapper.exe: fatal error: C:\Users\User\Documents\arduino-1.8.7\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/users/user/documents/arduino-1.8.7/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

Multiple libraries were found for "RF24.h"
 Used: C:\Users\User\Documents\Arduino\libraries\RF24-master
 Not used: C:\Users\User\Documents\arduino-1.8.7\libraries\RF24-master
Using library RF24-master at version 1.3.1 in folder: C:\Users\User\Documents\Arduino\libraries\RF24-master 
Using library SPI at version 1.0 in folder: C:\Users\User\Documents\arduino-1.8.7\hardware\arduino\avr\libraries\SPI 
Using library EEPROM at version 2.0 in folder: C:\Users\User\Documents\arduino-1.8.7\hardware\arduino\avr\libraries\EEPROM 
exit status 1
Error compiling for board Arduino Duemilanove or Diecimila.

tho i have to say that error message is a lot longer than what i seen in the output of the compiler

What do you think the problem with the case statements is?

if i comment this line out of the case statement it all works again?

int newStates = atoi(&buffer[1]);

if i declare int newStates in the case statement then it breaks something. if i declare it outside the loop as a global variable then the program works? this sounds like a compiler error?

:frowning: >:( >:( -fpermissive >:( >:( >:(
strikes again.

oqibidipo:

:frowning: >:( >:( -fpermissive >:( >:( >:(
strikes again.

What does that mean?

if you want to declare a local variable inside a case, you need to create its scope with {} in the case

notsolowki:
if i declare int newStates in the case statement then it breaks something. if i declare it outside the loop as a global variable then the program works? this sounds like a compiler error?

Does seem like bad form - since the variable is local to the switch statement, does newStates get created if the case in which it is declared is not executed?

Unrelated to the problems above, the IDE autoformat seems to have a problem after using the R option when declaring a string literal. Spent a bit of time trying to determine why autoformat would not align the case statements properly.

  const char bigHelpString[] PROGMEM = R"( ?  - this help

J-M-L:
if you want to declare a local variable inside a case, you need to create its scope with {} in the case

The variable is declared in one of the cases, but used in some of the other cases, so it is not local to that particular case.

Ah yes i had missed the int newStates

Don’t define it there there -if it needs to exist for the whole switch instruction then declare it before the switch or as a local variable to your function