AnsweredAssumed Answered

MQX_FILE_PTR  IO stream for UART communication, mqx_file struct not accessable!

Question asked by Fabian Liebisch on Apr 6, 2017
Latest reply on Apr 25, 2017 by Daniel Chen

Hey guys, I am currently working with a Kinetis K70 processor which should communicate over UART5 with a Bluetooth Module. I use the IO serial port ittyf:  to regulate the UART. My communication works fine, i can send commands in blocking mode and the Bluetooth Module responds. Now I'm having trouble in receiving the response and buffering them since I have different commands for the Bluetooth Module and corresponding responses.

 

My code is set up as follows:

for the init:

static MQX_FILE_PTR p_bluetooth;

 

p_bluetooth = fopen(STRK_BLUETOOTH_SERIAL_PORT, (char *)(IO_SERIAL_RAW_IO));
ioctl(p_bluetooth, IO_IOCTL_SERIAL_SET_FLAGS, IO_SERIAL_RAW_IO);

 

I can send commands in blocking mode with while the RX is disabled:

 

char *command = cmd_buffer; // cmd_buffer contains the bluetooth command

fwrite(command , 1, strlen(command), p_bluetooth);

 

Afterwards RX is enabled:

 

My problem now is that the bluetooth module can respond with different strings of different length:

for the fread function I have to now how much characters exactly are in the p_bluetooth  filepointer

 

(Here an example for the first 10 characters, which works fine)

    fflush(p_bluetooth);
    char output_buffer[100];
    // read first 10 char into ouput_buffer
    fread(output_buffer, 1, 10, p_bluetooth);


For acessing the ungot_characters in the Filestream I tryed to acces the struct of MQX_FILE liike:

 

p_bluetooth->SIZE

p_bluetooth->LOCATION

p_bluetooth->UNGOT_CHARACTERS

 

Finally thoes values reamind zero all time even though I send and receive chars. I also can read and write to the file_ptr but nothing changes. I just want to now the number of chars in my p_bluetooth MQX_FILE_PTR which were not read but it seems there is no way to get that number. It seems that the mqx_file struct is not updated at all.

 

Did I miss something when I initialized it? I would be very glad for any help and advice.

 

Best regards,

 

Fabian

Outcomes