NetBridgeCE Library

A bridged socket interface for the TI-84+ CE.

This library allows you to interface with a serial-tcp bridge running on a computer (ie bridged socket) while giving you the feeling of interacting with a standard socket API. The socket internally handles the configuration and maintainence of the state of the USB subsystem so that you do not need to deal with callbacks, events, or the SRL/USB drivers in your code. Simply use the provided API to send/recv data, emit directives to the bridge, and disconnect/close like you would a normal socket.

In order to use this library, the tcp bridge needs to be running on your computer with an active Internet connection. This program can be found in the tcpbridge folder and is called bridge.py.


Bridge Operation

The expectation of the bridge is that a single byte prefix the incoming data (calc=>bridge) to tell the bridge whether the data is a directive or a relay. A directive begins with the static prefix 0xFB, then an instruction byte that controls what function to run. A relay packet begins with the static prefix 0x00 and then has the data to forward to the socket.

While it is recommended to use the included bridge software, a different bridge can be used as long as it follows the same prefixing strategy. Imagine your bridge uses the prefix byte 0xC0 for directives and 0xFF for relay. To support that with this library, you will need to run the following after socket creation:

bsocket_setoption(SOCKET_SET_CONTROL_BYTE, 0xC0);
bsocket_setoption(SOCKET_SET_RELAY_BYTE, 0xFF);

It is also possible that your bridge supports directives that the included bridge doesn’t. You can still use the bsocket_emitdirective() function. Define your directive, make sure to assemble your AAD properly, and emit it to the bridge using this function. Everything should work fine.

bsocket_emitdirective(MY_NEW_DIRECTIVE, my_aad, sizeof(my_aad));

API Documentation

bool bsocket_create(void *srlbuf, size_t buflen)

Initializes the bridged socket device.

Parameters
  • srlbuf – Pointer to buffer to use with serial device.

  • buflen – Length of the buffer in bytes.

Returns

true if bridged socket created successfully, false if error

bool bsocket_connect(char *host, uint24_t port)

Attempts to open a bridged connection to the host/port specified.

Parameters
  • host – The hostname of the remote server to open a connection to.

  • port – The port number to connect to.

Returns

true if connection successful, false if error

bool bsocket_close(void)

Close the open socket, close the serial device and cleanup the USB subsystem.

bool bsocket_setoption(bsocket_option_t option, uint24_t value)

Alters socket operational parameters after initialization.

Warning

Do not use blocking sockets until further notice. USB timers not working.

Parameters
  • option – An option flag to set. See bsocket_option_t.

    • SOCKET_BLOCKING - enable/disable blocking mode

    • SOCKET_TIMEO - timeout (in MS) for blocking mode

    • SOCKET_SET_CONTROL_BYTE - change control byte

    • SOCKET_SET_RELAY_BYTE - change relay byte

  • value – A value to update parameter with. See expected data types below.

    • SOCKET_BLOCKING - [BOOL]

    • SOCKET_TIMEO - [UINT24_T]

    • SOCKET_SET_CONTROL_BYTE - [UINT8_T]

    • SOCKET_SET_RELAY_BYTE - [UINT8_T]

Returns

true if success, false if error

size_t bsocket_send(void *buffer, size_t len)

Sends a packet out the serial device for TCP relay.

Note

Sent packet format is [relayprefix][size_t][data]. [relayprefix] is stripped by the bridge.

Parameters
  • buffer – Pointer to data to write to the socket.

  • len – Length of the data at buffer.

Returns

Number of bytes written to the socket. Should be equal to len.

size_t bsocket_recv(void *buffer, size_t len)

Recieves a packet relayed from the TCP socket to the serial device.

Parameters
  • buffer – Pointer to write the data to.

  • len – Number of bytes to read.

Returns

Number of bytes read. Should be less than or equal to len depending on socket block/non-block.

bool bsocket_starttls(void)

Directs the bridge to call tls.wrap_socket on the existing socket.

Use if your connection requires encryption.

Returns

true if TLS socket creation successful, false if error or TLS not supported.

bool bsocket_emitdirective(uint8_t directive, void *aad, size_t len)

Sends a command to the bridge.

Note

Values of 0 and 1 are reserved for connect/starttls and are rejected.

Parameters
  • directive – A single-byte function code to send to the bridge

  • aad – Additional data to send to the bridge along with the directive.

  • aad_len – Length of additional data.

void bsocket_update(void)

Calls the event handlers for the USB subsystem. For asnyc use processing transfers and events in code.