OpenSourceEBike / TSDZ2-Smart-EBike

Flexible OpenSource firmware for TongSheng TSDZ2 mid drive ebike motor
GNU General Public License v3.0
251 stars 130 forks source link

New improved communications protocol #125

Closed casainho closed 4 years ago

casainho commented 4 years ago

We need to write the specification for a new improved communications protocol. Some needs of improvement:

Wiki page for writing the specification: https://github.com/OpenSource-EBike-firmware/TSDZ2_wiki/wiki/Improved-communications-protocol

geeksville commented 4 years ago

Misc thoughts:

geeksville commented 4 years ago

Possibly use nanopb and most of this stuff is handled for you: https://jpa.kapsi.fi/nanopb/benchmark/ & https://github.com/nanopb/nanopb

Though probably not worth the hassle given the small number of packet types and client devices.

casainho commented 4 years ago

My worries on motor controller side:

I don´t think that in future, like next 2 or 5 years, they will upgrade this motor controllers - I think they will continue to be with this memory and processing limitation.

So, I think we should stick to very basic and having only the things we strictly need.

geeksville commented 4 years ago

I haven't looked at the motor controller code, but one idea if memory is tight on the MC: Move everything out of that controller that is possible (i.e. just have the motor PID (or whatever) control loop). Anything else, calibration etc... could be done with the help of the display controller. The display controller could even send down a raw preformatted 'config packet' which is just blindly used for whatever settings the motor controller needs.

On Wed, Nov 6, 2019 at 10:04 PM casainho notifications@github.com wrote:

My worries on motor controller side:

  • the memory is VERY limited (we have free only 6K bytes from total of 32 kbytes and there are other important features as full torque sensor calibration to be done and a wish for better high cadence mode). Let´s not forget that original firmware even uses only 16 kbytes of flash memory, that should be the official microcontroller memory amount.
  • it is very slow and has no interrupts when it sends data to the display so it hangs waiting for full send. The processing power should mainly be dedicated to the motor control and so keep a good energy efficiency for FOC / battery range

I don´t think that in future, like next 2 or 5 years, they will upgrade this motor controllers - I think they will continue to be with this memory and processing limitation.

So, I think we should stick to very basic and having only the things we strictly need.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/OpenSource-EBike-firmware/TSDZ2-Smart-EBike/issues/125?email_source=notifications&email_token=AABXB2IDSG3LFBH2NGTWB7LQSOVXNA5CNFSM4JJOPYJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDKUWJA#issuecomment-550849316, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABXB2KIDS7KMVQB4YWVCWLQSOVXNANCNFSM4JJOPYJA .

casainho commented 4 years ago

Needs:

How should we number the various firmware versions??

lowPerformer commented 4 years ago

My suggestion for a more versatile and yet simple protocol: 1st Start Byte (always the same) 2nd Lenght Of Frame (all following bytes) 3rd Type Of Frame 4th and following Payload (including CRC alway at the end)

With this information it will be possible to: 1) Low Level functions can receive (and CRC check) those frames just scanning for startbyte & receiving LengthOfFrame bytes. 2) Higher Level functions can decode those frames dependent on TypeOfFrame

Version of motorcontroller/protocol f.i. can be in a special "heartbeat" frame or just put it in the current data stream.

So this seems to be more or less the same just adding two bytes (2nd and 3rd byte).

casainho commented 4 years ago

Done!! Seems to work well, I already drove some kms with it.