Skip to content
Rhodri James edited this page Dec 3, 2015 · 9 revisions

UPC2 Core

Core Structures

The primary system structure is the system context, defined in include/upc2/up.h:

typedef struct up_context_struct {
    up_bio_t      *bio;
    int            grouchfsm;
    int            cur_arg;
    int            ttyfd;
    int            ttyflags;
    struct termios tc;
    int            logfd;
    int            control_mode;
} up_context_t;

The bio field is a pointer to the back-end structure. All communications with the target device should go through this structure.

The grouchfsm field is a variable used by the grouch protocol. Other protocols may re-use it for their own purposes, and may similarly define extra fields in the context. (RMJ: really we could do with a union of protocol-specific storage, but with only grouch needing any it's not currently worth it.)

cur_arg is used by the core logic as an index into the array of parsed arguments it is given. Nothing outside the core should fiddle with it.

The fields ttyfd, ttyflags and tc are all associated with the console. ttyfd is the file descriptor that should be used for console communications; it has been appropriately doctored to avoid translational problems. The other fields should be left alone; they contain the original state of the console which is restored when upc2 exits.

logfd is the file descriptor of the log file for output, or -1 if there is no log file. Logging is for serial output, and generally only needs to be done by the core code.

Finally, control_mode is a flag used to catch console escape sequences. The flag is set if the last character read from the console was C-a. (RMJ: escape handling, and console input in general, is a bit of a mess at the moment.)

Core Logic

The core logic can be found in src/up.c. It is about to get a major overhaul, so this description is being left for the moment.

TODO:

  • Sort out upload/console state, and the passing of keyboard input to the serial output
  • Protocol handling is clumsy, needs to be more easily extensible. This also affects the front-end argument parsing.
  • The split C-a handling makes me (RMJ) nervous.
  • It's currently the core logic that decides the console will be stdin/stdout, despite being able to support any file descriptor-based connection. This should be the application's decision in the front-end.
Clone this wiki locally