btsimonh / hoverboard-firmware-hack

New Hoverboard Firmware Hack. Now written from scratch and generally much better.
GNU General Public License v3.0
22 stars 4 forks source link

machine protocol #11

Closed goktugh closed 5 years ago

goktugh commented 5 years ago

Hi,first of all you did great about the forked. I used uart2 and newprotocol branch I am bit confised about communacition , I had succesfull communication with ascii commands but on the other hand ı didn't get any result from machine protocol I dont know if there is a way to switch ascii protocol to machine protocol.

I just did simple test with arduino ide just simple code but I couldn't get result.

byte buf[2]={'R',0x0c}

serial.write(buf,2)

Could you give me information about how to use machine protocol thanks, Goktug

btsimonh commented 5 years ago

hi goktugh, the protocol requires that you construct a message of a specific structure; it has a SOM, count, data bytes, and a checksum. it also requires that you acknowledge messages.....

have a look here: https://github.com/btsimonh/hoverboard-firmware-hack/wiki/Protocol-Proposal that describes how we designed the machine protocol.... and in part why.

see line 210 of: https://github.com/btsimonh/hoverboard-firmware-hack/blob/newprotocol/nodered/snippets.js this is code which creates a message with SOM, CI & CS, etc. in javascript. If you are familiar with node-red, then there is a complete flow there too... Also take a look at https://github.com/btsimonh/hoverboard-firmware-hack/blob/newprotocol/src/machine_protocol.c this is the C source that handles the protocol in the HB.

see https://github.com/btsimonh/hoverboard-firmware-hack/issues/9 for some discussion on protocol commands. but remember everything there would be wrapped through that code at line 210 to add the SOM, length, and Checksum!.

you will find it hard to do via a terminal session - sending binary characters and you'd have to calculate the checksum :).

best regards, Simon

goktugh commented 5 years ago

hi, thank you for information but I send exactly these packet "test - 02 06 54 54 65 73 74 06" ı could't any result my concern is can I machine protocol communication via uart2 or uart2 is only for ascii communication.

btsimonh commented 5 years ago

hi goktugh,

try; SOM = 02 CI = 00 len = 05 'T' = 54 (for test message command) 'T' = 54 (for 'T') 'e' = 65 (for 'e') 's' = 73 't' = 74 Checksum (0 - (CI + len + 'T' + 'T' + 'e' + 's' + 't')) = (0 - (00+05+54+54+65+73+74)) = (0 - 1F9) = FE07 -> 07 ?

(for each msg you should increment CI - 'Continuity Indicator' - a counter which counts up for each message so we can tell if we hear a retry or not.)

expect 3 messages (or more, because it should retry if you do not ack) back: 1/ an ACK message (02 CI 01 'A' CS?) (CI will be the CI you sent). 2/ two or more (02 CI 05 't' 'T 'e' 's' 't' CS) (the test messages should be responded to by TWO test response messages, but each response will be retried if no acks are received. the two responses will have different CI! ).

use USART2 should work fine. I personally don't use it, but one of the others does :). If the ascii works, then the machine protocol will also work.

make sure you have '#define INCLUDE_PROTOCOL INCLUDE_PROTOCOL2' in config.h (and ignore old 'machine_protocol1.c' - only look at 'machine_protocol.c').

br, s

btsimonh commented 5 years ago

p.s. see note in readme - we moved the repo.