Esempio n. 1
0
void Bridge::onStatusByte(uint8_t byte) {
  if(byte == MSG_SYSEX_END && bufferStartsWith(MSG_SYSEX_START)) {
    this->msg_data.append(byte); // bookends of a complete SysEx message
    sendMidiMessage();
    return;
  }

  if(this->data_expected > 0) {
    emit displayMessage(applyTimeStamp(QString("Warning: got a status byte when we were expecting %1 more data bytes, sending possibly incomplete MIDI message 0x%2").arg(this->data_expected).arg((uint8_t)this->msg_data[0], 0, 16)));
    sendMidiMessage();
  }

  if(is_voice_msg(byte))
    this->running_status = byte;
  if(is_syscommon_msg(byte))
    this->running_status = 0;

  this->data_expected = get_data_length(byte);
  if(this->data_expected == UNKNOWN_MIDI) {
      emit displayMessage(applyTimeStamp(QString("Warning: got unexpected status byte %1").arg((uint8_t)byte,0,16)));
      this->data_expected = 0;
  }
  this->msg_data.clear();
  this->msg_data.append(byte);
}
Esempio n. 2
0
File: cli.c Progetto: hyrant/fulcrum
bool CLI_process(CLIContext *context)
{
    while (true) {
        char *end = strpbrk(context->buffer, "\r\n");
        if (end == NULL)
            return true;            
        *end = 0;
        
        if (bufferStartsWith(context, "quit")) {
            addToOutput(context, "EXIT");
            return false;
        }
        
        const char *ptr;
        if (bufferStartsWith(context, "set uart mode") ||
                bufferStartsWith(context, "set uart tx") ||
                bufferStartsWith(context, "set sys iofunc")) {
            /* Ignored */
            addToOutput(context, "AOK\r\n");
        } else if ((ptr=bufferStartsWith(context, 
                "set uart instant ")) != NULL) {
            uint32_t baud = parseDecimal(ptr);
            if (baud > 0) {
                Serial_setBaud(baud);
                addToOutput(context, "AOK\r\n");
            } else {
                addToOutput(context, "ERROR\r\n");
            }
        } else if ((ptr=bufferStartsWith(context, "set sys mask ")) != NULL) {
            uint32_t mask = parseHex(ptr, &ptr);
            if (!(*ptr)) {
                addToOutput(context, "ERROR\r\n");
            } else if (*ptr == '0') {
                GPIO_setMode(mask, false);
                addToOutput(context, "AOK\r\n");
            } else {
                GPIO_setMode(mask, true);
                addToOutput(context, "AOK\r\n");
            }
        } else if ((ptr=bufferStartsWith(context, "set sys output ")) != NULL) {
            uint32_t output = parseHex(ptr, &ptr);
            if (!(*ptr)) {
                addToOutput(context, "ERROR\r\n");
            } else {
                uint32_t mask = parseHex(ptr, &ptr);
                GPIO_setOutput(mask, output);
                addToOutput(context, "AOK\r\n");
            }
        } else if (end != &context->buffer[0]) {
            addToOutput(context, "ERROR\r\n");
        }
        
        memmove(context->buffer, end+1, strlen(end+1)+1);
    }
}
Esempio n. 3
0
void Bridge::sendMidiMessage() {
  if(msg_data.length() == 0)
    return;
  if(bufferStartsWith(MSG_DEBUG)) {
      QString debug_msg = QString::fromAscii(msg_data.mid(4, msg_data[3]).data());
      emit displayMessage(applyTimeStamp(QString("Serial Says: %1").arg(debug_msg)));
  } else {
      emit debugMessage(applyTimeStamp(QString("Serial In: %1").arg(describeMIDI(msg_data))));
      if(midiOut) {
        std::vector<uint8_t> message = std::vector<uint8_t>(msg_data.begin(), msg_data.end());
        midiOut->sendMessage(&message);
        emit midiSent();
      }
  }
  msg_data.clear();
  data_expected = 0;
}
Esempio n. 4
0
void Bridge::onDataByte(uint8_t byte)
{
  if(this->data_expected == 0 && this->running_status != 0) {
    onStatusByte(this->running_status);
  }
  if(this->data_expected == 0) { // checking again just in in case running status failed to update us to expect data
    emit displayMessage(applyTimeStamp(QString("Error: got unexpected data byte 0x%1.").arg((uint8_t)byte,0,16)));
    return;
  }

  this->msg_data.append(byte);
  this->data_expected--;

  if( bufferStartsWith(MSG_DEBUG)
      && this->data_expected == 0
      && this->msg_data.length() == 4) { // we've read the length of the debug message
    this->data_expected += this->msg_data[3]; // add the message length
  }
}