Files
MoHadiShibli--Control4Free/include/c4f_net.h
T
MoHadiShibli 243f5efa68 Keep the page on a home screen, say the address out loud, and say what went wrong
Three bits of polish for people who did not write this.

The payload serves /manifest.webmanifest and /icon-192.png, and the page points
at both, so a phone can keep the controller on its home screen instead of typing
an IP address again. The icon is the app's own icon, rendered by the launcher's
drawing code and committed, so the payload build needs no renderer; a test
re-renders it and fails if the two drift apart. One size only: the gradient does
not compress, and a 512 copy would add 150 KB for a splash screen that a plain
HTTP shortcut never shows. write_png now picks the best filter per row, which
also shrinks the package icon.

When the service starts it works out which address the console is actually
reachable on, from the route to the outside world without sending anything, and
puts it in the start-up notification on the TV.

Every error the page can show now says what happened and what to do about it,
rather than "Invalid axis", and the README has a troubleshooting section covering
the ones people will actually hit.
2026-10-05 02:31:50 +03:00

52 lines
1.7 KiB
C

#ifndef C4F_NET_H
#define C4F_NET_H
#include <stddef.h>
#include <stdint.h>
#define C4F_NET_CLIENTS 8
#define C4F_NET_MESSAGE 4096
typedef struct C4fNetClient {
int fd, websocket, closing, fragmented;
uint64_t openedMs;
unsigned char rx[8192], tx[8192];
size_t rxUsed, txUsed, txSent, messageUsed;
char message[C4F_NET_MESSAGE + 1];
const unsigned char *body;
size_t bodySize, bodySent;
void *user;
} C4fNetClient;
enum { C4F_NET_OPEN, C4F_NET_MESSAGE_EVENT, C4F_NET_CLOSE,
C4F_NET_HTTP_STATUS, C4F_NET_HTTP_STOP };
typedef void (*C4fNetHandler)(C4fNetClient *, int, const char *, size_t, void *);
typedef struct {
int fd;
uint64_t checkedMs;
C4fNetClient clients[C4F_NET_CLIENTS];
C4fNetHandler handler;
void *context;
} C4fNet;
uint64_t c4fTimeMs(void);
int c4fNetOpen(C4fNet *, int port, C4fNetHandler, void *);
/* -1: listener/select failure; -2: long pause inside select. Reopen transport. */
int c4fNetPoll(C4fNet *, int timeoutMs);
void c4fNetClose(C4fNet *);
int c4fNetText(C4fNetClient *, const char *);
void c4fNetHttpJson(C4fNetClient *, const char *);
void c4fWebSocketAccept(const char *key, char out[29]);
extern const unsigned char c4fPage[];
extern const size_t c4fPageSize;
/* The console's own address on the network it reaches the internet through, as
* "192.168.1.20", or an empty string if it cannot be worked out. Nothing is sent. */
void c4fNetLocalAddress(char *out, size_t size);
/* Served so the page can be kept on a phone's home screen (tools/embed_file.py). */
extern const unsigned char c4fManifest[];
extern const size_t c4fManifestSize;
extern const unsigned char c4fIcon[];
extern const size_t c4fIconSize;
#endif