0

I am currently sending CAN Messages from my RaspberryPi to my Android Smartphone per Bluetooth. I should get between 200-1300 messages per second. Unfortunately I only average around 80 messages per second. I hope you can help me to achieve a greater number.

The steps I took on the Raspberry to achieve the connection are:

sudo hciconfig hci0 piscan
sudo sdptool add sp
sudo ./rfcomm listen hci0

This establishes the Bluetooth connection between the smartphone and the Raspberry. I write all CAN messages I receive on can0 to rfcomm0.

sudo candump -c can0 > /dev/rfcomm0 &

Now i am uncertain how I can make this process more efficient. I am not sure where I am losing my messages.

I know that all messages arrive on the Raspberry. I checked that with candump -n.

The messages I receive on the Smartphone are ASCII coded. Every second message I receive on the Android Smartphone is ASCII CR and LF. I imagine if I could get rid of that, than I would get double the messages to the Smartphone. Each Can Message contains 35 HEX chars it would be most efficient to send them as 2 Bytes per Char via Bluetooth to the Smartphone. How can I achieve this?

Thank you for your help.

Edit:

Corrected Question

Edit2:

On the Raspberry I receive through candump messages like this (40 Characters):

  can0  10C [8]  F4 4D B0 94 A7 08 EA 00

the 290 is the ID, the 8 are the Bytes of the content. The ID and the content are in Hex.

If write the Data to rfcomm0 like mentioned above than I receive on my Android Smartphone this Message:

  [1m[34mcan0[0m  10C  [8] F4 4D B0 94 A7 08 EA 00

the 53 Bytes I receive are:

32 32 27 91 49 109 27 91 51 52 109 99 97 110 48 27 91 48 109 32 32 49 48 67 32 32 91 56 93 32 70 52 32 52 68 32 66 48 32 57 52 32 65 55 32 48 56 32 69 65 32 48 48

Why do I receive additional informations on the Smartphone? If I modify the message so that I only have the context and the ID, than I would theoretically only need 10 Bytes to store the information. Is this correct?

MalusDarkb
  • 153
  • 1
  • 10
  • Related: http://stackoverflow.com/questions/14524866/android-bluetooth-serial-rfcomm-low-baud-rate-slow-transmission – Morrison Chang Nov 20 '16 at 21:35
  • `written in HEX it would be most efficient to send them as such`. No. Of course not. Hex representation is very inefficient. Better send bytes. One byte for two hex chars. – greenapps Nov 20 '16 at 22:19
  • And it is up to you to get rid of cr and nl. Its you who defines the communication. – greenapps Nov 20 '16 at 22:21
  • `I would get double the messages`. As you did not tell how many bytes or hex chars you receive before a \r\n we cannot confirm or deny that. – greenapps Nov 20 '16 at 22:23
  • @greenapps OK, that sound right. How would I get rid of cr and nl? I am not sure how to define the communication. Do I need to modify candump? I need to send 35 Bytes per message. 3 Bytes are the ID and 32 Bytes are the informations. And what is the best baud rate for this and why? – MalusDarkb Nov 20 '16 at 23:06
  • I do not understand your questions. Baud rate with bluetooth? What do you mean with modifying candump? You get rid of a cr or nl by not sending them further. Defining a communication is that sender and receiver agree about what is transferred. So for instance that messages of length 35 bytes separated by a crlf. Or what ever. – greenapps Nov 21 '16 at 08:11
  • @greenapps , right changing the Baud rate should not make a difference since it is not a real serial port but an emulation. I am receiving 200 messages per second on can0. I don't know how I can define it, so that a part of each messages is not sent. The only possibility which comes to my mind is to write the CAN Data to a file and to read each line of the file and to define what I want to send. This seems kinda dirty to me. Is there another way? – MalusDarkb Nov 21 '16 at 10:22
  • ` right changing the Baud rate` ????? Of what? Of a bluetooth connection??? Where are you talking about? – greenapps Nov 21 '16 at 10:26
  • `I don't know how I can define it, so that a part of each messages is not sent`. And i really do not understand which problems you have with that. If you receive 85 bytes then you can transfer 6 or 10 or 12. Tht's up to you. – greenapps Nov 21 '16 at 10:27
  • Well i supposed its your executable `candump`. Otherwise there is not much you can do except writing your own candump. Sorry but i assumed you already did. – greenapps Nov 21 '16 at 10:30
  • `it would be most efficient to send them as 2 Bytes per Char ` No. you make it even worse. That would double the amount of data to be transported. Efficient would be to send two hex chars in one byte. – greenapps Nov 21 '16 at 10:33
  • `The messages I receive on the Smartphone are ASCII coded.`. You should start telling how the Raspi receives the messages from the ODB device. – greenapps Nov 21 '16 at 10:35
  • cr and nl are sent after every Message I am sending from the Raspberry to the Smartphone. E.g 'echo "test" >/dev/rfcomm0' – MalusDarkb Nov 21 '16 at 11:05
  • `I receive the messages on the RaspPi as Hex`. Are you shure? I doubt it! To me it seems that you are talking in the wrong way about hex. (As so many others). `How do I make sure the RaspPi sends the messages as HEX chars?`. That would not be clever as you wanted to transfer less data. And we were talking the whole time about sending one byte for two hex chars. So you are pretty confusing at the moment. – greenapps Nov 21 '16 at 11:56
  • Each can frame can only transfer eigth bytes according to https://en.wikipedia.org/wiki/CAN_bus . So if you would print the values of eigth bytes in hexadecimal notation it would be sixteen hex chars. Now please explain why you are talking about 35. – greenapps Nov 21 '16 at 12:12
  • OK I edited the Question. Sorry that I didn't write it like that from the beginning. What I meant with the 35 is, that it is the length of the Message that I am currently sending to the Smartphone (40 Characters not 35). – MalusDarkb Nov 21 '16 at 12:29
  • You still make a mesh out of it. If the Rasspi receives eight bytes which in hexadecimal notation are `F4 4D B0 94 A7 08 EA 00` and you forward those eigth bytes to the Android phone and the Android phone receives eigth bytes with values `F4 4D B0 94 A7 08 EA 00` then you did it ok. Then why is it that you talk about receiving 53 chars. Completely wrong. Maybe you forwarded 16 hex chars insted of 8 bytes. – greenapps Nov 21 '16 at 13:10
  • Do you see? Can sends 8 bytes and you are talking about 53! Something goes terrible wrong. – greenapps Nov 21 '16 at 13:15
  • `the 8 are the Bytes of the content. The ID and the content are in Hex`. No. No. No. The content is not in hex. The content are eight bytes. Each byte has a value of 0-255. You can write down the value in decimal, binary or hexadecimal notation. That is up to you. Alll notations are equally valid. – greenapps Nov 21 '16 at 13:18
  • ok. So would it be correct to say that the 8 Bytes of the content are displayed as 16 Hex chars. I guess I was should be more precise. So I need to extract the 8 Bytes out of 40 Characters I am receiving. When I am only sending 8 Bytes I will get back to you. Thanks for the help. – MalusDarkb Nov 21 '16 at 13:37
  • Now I am sending Messages like '0B2#FA002455DC1A8A26' to the RaspberryPi. I am receiving 20 Bytes on the Smartphone. So the Raspberry is sending each Char of the Message as one Byte. How is it possible to make the Raspberry send the Chars representing Hex values as 4 Bits instead of a byte? – MalusDarkb Nov 22 '16 at 13:29
  • An easier example would be this command: 'sudo echo "11111111" > /dev/rfcomm0'. How can I achieve that the Raspberry is sending one Byte and not eight Byte to the Smartphone? – MalusDarkb Nov 22 '16 at 13:42

0 Answers0