ERIS CORE

◆ streamTransmitHandler()

void FLASHMEM SvcSerialCommandInterface::streamTransmitHandler ( )
protected

Definition at line 256 of file svcSerialCommandInterface.cpp.

256  {
257  char bufferChr; //only need one char - 512 size is due to a potential bug in the teensy library identified by covintry static analysis
258  char hexBuffer[8];
259  uint16_t payload_len;
260  //if(Serial.availableForWrite() < 6000) return;
261  if(throttle()) return;
262  p_SD->chdir(p_stream_path);
263  if (p_SD->exists(p_stream_file)){
264  payload_len = 0;
265  if(!file.open(p_stream_file, O_READ)){
266  Serial.println(F("M GET_ERR FILE OPEN ERROR"));
267  is_streaming_file = false;
269  stream_pos = 0;
270  return;
271  }
272  startLZ4Message();
273  print("FS ");
274  file.seek(stream_pos);
275  //send the next chunked message until eof
276  uint64_t i;
277  i = file.available();
278  if(i>0){
279  //if i is zero then last chunk was eof
280  if(i > SERIAL_FILESTREAM_PAYLOAD_SIZE) i = SERIAL_FILESTREAM_PAYLOAD_SIZE;
281  for(;i > 0; i--){
282  payload_len += 1;
283  if (file.read(&bufferChr,1) < 0){
284  Serial.println(F("\nM GET_ERR FILE READ ERROR"));
285  is_streaming_file = false;
287  stream_pos = 0;
288  file.close();
289  return;
290  }
291  sprintf(hexBuffer,"%02X,",(unsigned int)bufferChr);
292  print(hexBuffer);
293  }
294  if(index_tx_buffer > 0) p_tx_Buffer[--index_tx_buffer] = '\0'; //remove last comma
295  stream_pos = file.position();
296  println("");
297  }
298  file.close();
299  if (payload_len == 0){
300  //no data to tx; @ eof
301  sendLZ4Message();
302  Serial.println("FS_END");
303  is_streaming_file = false;
305  stream_pos = 0;
306  delayMicroseconds(3000);
307  return;
308  }
309  else if (payload_len < SERIAL_FILESTREAM_PAYLOAD_SIZE) {
310  sendLZ4Message();
311  Serial.println("FS_END");
312  empty();
313  is_streaming_file = false;
315  stream_pos = 0;
316  delayMicroseconds(3000);
317  return;
318  } else{
319  //send file chunk
320  sendLZ4Message();
321  return;
322  }
323  }
324  else{
325  Serial.print(F("M GET_ERR FILE NOT FOUND "));
326  Serial.println(p_stream_file);
327  is_streaming_file = false;
328  stream_pos = 0;
329  return;
330  }
331 };
bool throttle()
returns true if the available serial buffer falls below SERIAL_THROTTLE_BUFFER_REMAINING_THRESHOLD if...
void empty()
zero out the transmit buffer and reset the write index
void sendLZ4Message()
Calling this function signals the end of a compressed message. The txBuffer contents are lz4 compres...

References empty(), file, index_tx_buffer, is_periodic_messages_enabled, is_streaming_file, p_SD, p_stream_file, p_stream_path, p_tx_Buffer, sendLZ4Message(), startLZ4Message(), stream_pos, and throttle().

Referenced by update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: