/** Handle a command specific to the specification for this device */
void handleSpecificationCommand(byte* payload, unsigned int length) {
  ArduinoCustom__Header header;
  
  memset(buffer,0,300);
  ArduinoCustom_testData testEvents;
  
  pb_istream_t stream = pb_istream_from_buffer(payload, length);
  if (pb_decode_delimited(&stream, ArduinoCustom__Header_fields, &header)) {
    baseEvents_log("Decoded header for custom command.");
    if (header.command == ArduinoCustom_Command_RGB_LED) {
      if (pb_decode_delimited(&stream, ArduinoCustom_RGB_fields, &RGB_LED)) {
        baseEvents_log("Command: RGB_LED set(h=%d, s=%d, b=%d)", 
                       RGB_LED.rgbled_h, RGB_LED.rgbled_s, RGB_LED.rgbled_b);
        hsb2rgb_led_open(RGB_LED.rgbled_h, RGB_LED.rgbled_s, RGB_LED.rgbled_b);
      }
    }
    else if (header.command == ArduinoCustom_Command_DC_MOTOR) {
      ArduinoCustom_DC_MOTOR dc_motor;
      if (pb_decode_delimited(&stream, ArduinoCustom__Header_fields, &dc_motor)) {
        baseEvents_log("Command: DC_MOTOR set: %d", dc_motor.motor_sw);
        dc_motor_set(dc_motor.motor_sw);
      }
    }
    else if (header.command == ArduinoCustom_Command_PING) {
      ArduinoCustom_ping ping;
      if (pb_decode_delimited(&stream, ArduinoCustom_ping_fields, &ping)) {
        handlePing(ping, header.originator);
      }
    } 
    else if (header.command == ArduinoCustom_Command_TESTEVENTS) {
      if (pb_decode_delimited(&stream, ArduinoCustom_testEvents_fields, &testEvents)) {
         handleTestEvents(testEvents, header.originator);
      }
    } 
    else if (header.command == ArduinoCustom_Command_SERIALPRINTLN) {
      ArduinoCustom_serialPrintln serialPrintln;
      if (pb_decode_delimited(&stream, ArduinoCustom_serialPrintln_fields, &serialPrintln)) {
        handleSerialPrintln(serialPrintln,header.originator);
      }
    }
    else {
      baseEvents_log("Unknown command.");
    }
  }
}
Пример #2
0
void ennoCommandMessageHandler(char* topic, char* payload, int length){
    ArduinoCustom__Header header;
    pb_istream_t stream = pb_istream_from_buffer(payload, length);
    if (pb_decode_delimited(&stream, ArduinoCustom__Header_fields, &header)) {
        printf("Decoded header for custom command.\n");
        if (header.command == ArduinoCustom_Command_PING) {
            ArduinoCustom_ping ping;
            if (pb_decode_delimited(&stream, ArduinoCustom_ping_fields, &ping)) {
                handlePing(ping, header.originator);
            }
        } else if (header.command == ArduinoCustom_Command_TESTEVENTS) {
            ArduinoCustom_testEvents testEvents;
            if (pb_decode_delimited(&stream, ArduinoCustom_testEvents_fields, &testEvents)) {
                handleTestEvents(testEvents, header.originator);
            }
        } else if (header.command == ArduinoCustom_Command_SERIALPRINTLN) {
            ArduinoCustom_serialPrintln serialPrintln;
            if (pb_decode_delimited(&stream, ArduinoCustom_serialPrintln_fields, &serialPrintln)) {
                handleSerialPrintln(serialPrintln, header.originator);
            }
        }
    }

}