I have a question regarding xTaskCreatePinnedToCore. It's possible to pass an array of bytes :
Code: Select all
// Save compressed in memory instead of simply: uint8_t compressed[compressedBytes.size()];
receivedLength = packet.length();
compressed = (uint8_t*)malloc(receivedLength); // I would like to pass this instead of assigning it globally
for ( int i = 0; i < packet.length(); i++ ) {
uint8_t conv = (int) packet.data()[i];
compressed[i] = conv;
// Bytes read here are OK
Serial.print(conv);Serial.print(",");
}
xTaskCreatePinnedToCore(
brTask, /* Task function. */
"uncompress", /* name of task. */
20000, /* Stack size of task */
(void*)&compressed, /* send the bytes as a parameter */
9, /* priority of the task */
&brotliTask, /* Task handle to keep track of created task */
0); /* pin task to core 1 */
// And then I would like read this array in the task
// Task sent to the core to decompress + push to Output
void brTask(void * parameter){
uint8_t * brOutBuffer = (uint8_t*)malloc(BROTLI_DECOMPRESSION_BUFFER);
Serial.print("Free heap: "+String(ESP.getFreeHeap()));
Serial.print("Brotli IN compressed bytes:"); Serial.print(receivedLength);
size_t bufferLength = BROTLI_DECOMPRESSION_BUFFER;
// Note, tried to loop here over this but I don't get the same bytes
Serial.println(*((uint8_t*)parameter));
brotli = BrotliDecoderDecompress(
receivedLength,
(const uint8_t *)compressed,
&bufferLength,
brOutBuffer);
free(compressed);
printMessage("Unbrotli result: "+String(brotli)); // Should return 1 on correct decompression
printMessage("bufferLength OUT:");printMessage(String(bufferLength));
if (brotli == 0) {
printMessage("Decompresion failed");
}
printMessage("Uncompressing:");
Serial.printf("%.*s\n", bufferLength, brOutBuffer);
}
According to an Article read in
techtutorialsx.com I could pass a parameter. But is possible to pass an array ?
I tried reading this bytes array in the other end and it's different. I'm pointing it to a wrong pointer in memory ?
And also I wanted to ask, would it be safer to do this, than to declare the compiler array at a global label ?
(NOTE: Codebox button in this BBforum needs a fix, it outputs codebox instead of code that is the right BBCODE)
Thanks in advance for your answers