hexaguin / keePebble

A Google Keep client for Pebble smartwatches
6 stars 2 forks source link

Rewrite of protocol between watch and phone #15

Open hexaguin opened 8 years ago

hexaguin commented 8 years ago

The main limitation right now is a lack of flexibility in terms of watch-phone communication. Here is a draft of a new protocol:

Constants: MenuBuffer: 50. Number of notes for the pebble to store at once. Will need experimentation to determine how big this can safely be. Maybe make this platform-specific later? (e.g. Aplite has a smaller buffer, Basalt and Chalk larger, and when the Time 2 and Pebble 2 come out, they could have even larger buffers).

pebble -> phone:
    Module 0: System. Used to check for matching versions, and automatically causes the phone to send a list of reminders.
        uint16 1: Protocol version. Note that both the watch and phone should check that the received version matches the internal version.
    Module 1: Request
        uint8 1: Request packet type/ID
            ID 0: Menu begining. Asks the phone to send the first (MenuBuffer) notes. Has no extra data.
            ID 1: Specific list item
                uint16 2: Item position in list
            ID 2: Full note
                uint16 2: Item position in list
            ID 3: Total number of notes

phone -> pebble:
    Module 0: System
        uint16 1: Protocol version. Hard-coded (watchapp will have it in globals.h for example) for each version, changed every time the protocol itself is updated.
        uint8 2: Error status. 0 is normal. 1 is protocol mismatch (watchapp out of date). 2 is out of date phone app.
    Module 1: Note list item
        uint16 1: Note position in list
        cstring 2: Note title. Probably doesn't need to be truncated.
        cstring 3: Note body. Truncated, since this is just the second line of the menu item, not a full view of the note.
    Module 2: Full note
        uint 1: End of note. 0 if this is not the end of the note, 1 if it is.
        cstring 2: Note title if this is the first part of the note. Single null character if it is a continuation.
        cstring 3: Note body
    Module 3: Number of notes total. Will be replaced with a "General info" module with packet IDs if more info is needed in later versions.
        uint16 1: Number of notes

Basic startup behavior:

  1. Watchapp opens, sends system packet to phone
  2. Phone app checks for version mismatch, displays error if mismatched (and sends error packet to pebble)
  3. Phone app checks if it has a Timeline token (or if the last Timeline action failed), and requests a new token if it needs one.
  4. Phone responds with system packet to watch
  5. If there is no error, the watchapp requests a list of notes
  6. Phone sends the first list of notes, pebble adds them to a circular buffer

Other behavior:

Edit: replaced "packet type" with "packet ID"

hexaguin commented 8 years ago

Updated to use packet IDs for everything.

value 0 is always module, 1 is always packet ID
pebble -> phone:
    Module 0: System. Used to check for matching versions, and automatically causes the phone to send a list of reminders.
        ID 0: Protocol version
            uint16 2: Protocol version
    Module 1: Request
        ID 0: Menu begining. Asks the phone to send the first (MenuBuffer) notes. Has no extra data.
        ID 1: Specific list item
            uint16 2: Item position in list
        ID 2: Full note
            uint16 2: Item position in list
        ID 3: Total number of notes. Has no extra data.

phone -> pebble:
    Module 0: System
        ID 0: Protocol version
            uint16 2: Protocol version
        ID 1: Error
            uint16 2: Error type. 0 is protocol mismatch.
    Module 1: Note list
        ID 0: Note list item
            uint16 2: Note position in list
            cstring 3: Note title. Probably doesn't need to be truncated.
            cstring 4: Note body. Truncated, since this is just the second line of the menu item, not a full view of the note.
        ID 1: Total number of notes
            uint16 2: Number of notes
    Module 2: Full note
        ID 0: Note contents
            uint 2: End of note. 0 if this is not the end of the note, 1 if it is.
            cstring 3: Note title if this is the first part of the note. Single null character if it is a continuation.
            cstring 4: Note body