| 468 | } |
| 469 | |
| 470 | void StreamingModule::sendBytes(Array<uint8> bytes, var params) |
| 471 | { |
| 472 | if (!enabled->boolValue()) return; |
| 473 | if (!isReadyToSend()) |
| 474 | { |
| 475 | if (logOutgoingData->boolValue()) NLOGWARNING(niceName, "Can't send data, output is not connected."); |
| 476 | return; |
| 477 | } |
| 478 | |
| 479 | if (streamingType->getValueDataAsEnum<StreamingType>() == COBS) |
| 480 | { |
| 481 | if (bytes.size() > 255) |
| 482 | { |
| 483 | NLOGWARNING(niceName, "Packet length cannot be more than 255 bytes with COBS encoding"); |
| 484 | return; |
| 485 | } |
| 486 | |
| 487 | int numBytes = bytes.size(); |
| 488 | uint8_t data[255]; |
| 489 | cobs_encode(bytes.getRawDataPointer(), numBytes, data); |
| 490 | bytes.clear(); |
| 491 | |
| 492 | for (int i = 0; i < numBytes + 1; ++i) bytes.add(data[i]); |
| 493 | bytes.add(0); |
| 494 | } |
| 495 | |
| 496 | sendBytesInternal(bytes, params); |
| 497 | outActivityTrigger->trigger(); |
| 498 | |
| 499 | if (logOutgoingData->boolValue()) |
| 500 | { |
| 501 | String s = "Sending " + String(bytes.size()) + " bytes :"; |
| 502 | for (auto& b : bytes) s += "\n0x" + String::toHexString(b); |
| 503 | NLOG(niceName, s); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | void StreamingModule::showMenuAndCreateValue(ControllableContainer* container) |
| 508 | { |
no test coverage detected