Reorganized a little, better comments in headers.
This commit is contained in:
parent
e30cc1ea97
commit
729886a7bb
16
Makefile
16
Makefile
|
@ -94,23 +94,23 @@ dist: mrproper
|
|||
all-lib: $(CHECKCFG) $(if $(STATIC),$(ANAME),$(SONAME))
|
||||
|
||||
# Make a module object directory.
|
||||
$(MODULES:%=$(OBJDIR)/%):
|
||||
$(OBJDIR)/ $(DIRS:%=$(OBJDIR)/%):
|
||||
$(call bcmd,mkdir,$@,$(MD) $@)
|
||||
|
||||
# Make a module object out of a module source file.
|
||||
define make-moduleobj-rule
|
||||
$(OBJDIR)/$1/%.o: $(SRCDIR)/$1/%.c $(INC) | $(OBJDIR)/$1
|
||||
# Make an object out of a source file.
|
||||
define make-obj-rule
|
||||
$(OBJDIR)/$1.o: $(SRCDIR)/$1.c $(INC) | $(dir $(OBJDIR)/$1)
|
||||
$(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(CFLAGS))
|
||||
endef
|
||||
$(foreach mod,$(MODULES), \
|
||||
$(eval $(call make-moduleobj-rule,$(mod))))
|
||||
$(foreach src,$(SRC),\
|
||||
$(eval $(call make-obj-rule,$(src))))
|
||||
|
||||
# Make the shared library.
|
||||
$(SONAME): $(foreach m,$(MODULES),$(SRC_$(m):%=$(OBJDIR)/$(m)/%.o))
|
||||
$(SONAME): $(SRC:%=$(OBJDIR)/%.o)
|
||||
$(call bcmd,ld,$@,$(LD) -o $@ $^ $(LDFLAGS))
|
||||
|
||||
# Make the static library.
|
||||
lib$(NAME).a: $(foreach m,$(MODULES),$(SRC_$(m):%=$(OBJDIR)/$(m)/%.o))
|
||||
lib$(NAME).a: $(SRC:%=$(OBJDIR)/%.o)
|
||||
$(call bcmd,ar rc,$@,$(AR) rcs $@ $^)
|
||||
|
||||
# Remove the objects directory.
|
||||
|
|
|
@ -128,20 +128,19 @@ endif
|
|||
GZIP := gzip -f
|
||||
|
||||
#******************************************************************************#
|
||||
# Look for modules and modules sources #
|
||||
# Look up the sources and includes #
|
||||
#******************************************************************************#
|
||||
# Look for modules first
|
||||
MODULES := $(notdir $(shell find $(SRCDIR) -mindepth 1 -maxdepth 1 \
|
||||
-type d | sort))
|
||||
# Look up the sources
|
||||
SRC := $(basename $(shell find $(SRCDIR) -mindepth 1 -type f \
|
||||
-name "*.c" -printf "%P\n"))
|
||||
DIRS := $(sort $(dir $(SRC)))
|
||||
|
||||
# Then look for their content
|
||||
define get-module-source
|
||||
SRC_$1 := $(basename $(shell find $(SRCDIR)/$1 \
|
||||
-maxdepth 1 -mindepth 1 -type f -name "*.[cs]" -printf "%P\n" | sort))
|
||||
endef
|
||||
$(foreach mod,$(MODULES), \
|
||||
$(eval $(call get-module-source,$(mod))))
|
||||
# Look up the includes
|
||||
INCPUB := $(shell find $(INCDIR) -name "*.h" -and \
|
||||
-not -path "*internals*" -printf "%P\n")
|
||||
|
||||
# Look up the includes
|
||||
INC := $(shell find $(INCDIR) -name "*.h")
|
||||
#******************************************************************************#
|
||||
# Look for public headers (not internals.h or internals/**/*.h #
|
||||
#******************************************************************************#
|
||||
|
|
|
@ -88,8 +88,8 @@ typedef struct {
|
|||
} p7_env_t;
|
||||
|
||||
/* environment functions */
|
||||
p7_env_t *p7_get_env(const char *model);
|
||||
int p7_command_is_supported(unsigned int code, const p7_env_t *env);
|
||||
extern p7_env_t *p7_get_env(const char *model);
|
||||
extern int p7_command_is_supported(unsigned int code, const p7_env_t *env);
|
||||
# define command_is_supported(N) p7_command_is_supported(N, handle->_env)
|
||||
/* ************************************************************************** */
|
||||
/* Handle-related */
|
||||
|
@ -111,14 +111,18 @@ struct p7_handle_s {
|
|||
/* flags - see above */
|
||||
unsigned int _flags;
|
||||
|
||||
/* stream, environment, response, server information */
|
||||
const p7_env_t *_env; /* see `core/devices.c` */
|
||||
/* debug name, for multi-handle logging (e.g. `p7servtest` in p7utils)
|
||||
* a space/null, 8 chars max, and imposed null char */
|
||||
char _name[10];
|
||||
|
||||
/* stream settings */
|
||||
p7_stream_t _stream;
|
||||
p7_streamsettings_t _settings;
|
||||
|
||||
/* protocol 7.00-related core things */
|
||||
const p7_env_t *_env; /* see `protocol/seven/devices.c` */
|
||||
p7_packet_t _response;
|
||||
p7_server_t _server;
|
||||
|
||||
/* last sent command, response */
|
||||
p7ushort_t _last_sent_command;
|
||||
p7_packet_t _response_data;
|
||||
|
||||
|
@ -133,33 +137,33 @@ struct p7_handle_s {
|
|||
|
||||
/* raw reception packet buffer */
|
||||
unsigned char _recv_buffer[MAX_PACKET_SIZE];
|
||||
|
||||
/* name - a space/null, 8 characters max, then imposed null char. */
|
||||
char _name[10];
|
||||
};
|
||||
|
||||
/* sub-sub-init utils */
|
||||
# ifndef P7_DISABLED_FILE
|
||||
int _p7_finit(p7_handle_t **handle, unsigned int flags,
|
||||
extern int _p7_finit(p7_handle_t **handle, unsigned int flags,
|
||||
FILE *rstream, FILE *wstream, int rstream_close);
|
||||
# endif
|
||||
/* ************************************************************************** */
|
||||
/* Packet I/O */
|
||||
/* Protocol 7.00 Packet I/O utilities */
|
||||
/* ************************************************************************** */
|
||||
/* start communication */
|
||||
extern int p7_start(p7_handle_t *handle, int check);
|
||||
|
||||
/* decode packets */
|
||||
int p7_decode_command(p7_handle_t *handle,
|
||||
extern int p7_decode_command(p7_handle_t *handle,
|
||||
const unsigned char *data, size_t data_size);
|
||||
int p7_decode_ack(p7_handle_t *handle,
|
||||
extern int p7_decode_ack(p7_handle_t *handle,
|
||||
const unsigned char *data, size_t data_size);
|
||||
int p7_decode_data(p7_handle_t *handle,
|
||||
extern int p7_decode_data(p7_handle_t *handle,
|
||||
const void *raw, p7ushort_t raw_size);
|
||||
|
||||
/* utilities */
|
||||
int p7_send_again(p7_handle_t *handle);
|
||||
int p7_recv(p7_handle_t *handle, int checksum);
|
||||
extern int p7_send_again(p7_handle_t *handle);
|
||||
extern int p7_recv(p7_handle_t *handle, int checksum);
|
||||
|
||||
/* Resend error packet (meant to be used with recv, not suited for public) */
|
||||
int p7_send_err_resend(p7_handle_t *handle);
|
||||
extern int p7_send_err_resend(p7_handle_t *handle);
|
||||
|
||||
/* active response */
|
||||
# define response (handle->_response)
|
||||
|
|
|
@ -90,7 +90,11 @@ typedef int p7_termtype_t;
|
|||
* type, there is a five-letter subtype (such as "TYP01" or "TYPZ1"), and
|
||||
* for some types, subheaders. libp7 translates this into a VRAM and a picture
|
||||
* format, which you can see in the libp7 Protocol 7.00 packet
|
||||
* representation. */
|
||||
* representation.
|
||||
*
|
||||
* Note that the screenstreaming packet flow is totally different from
|
||||
* the normal packet flow: it's just the calculator sending its screen
|
||||
* repeateadly, not expecting any answer from the other side. */
|
||||
/* ************************************************************************** */
|
||||
/* Command payload */
|
||||
/* ************************************************************************** */
|
||||
|
@ -254,7 +258,20 @@ extern int p7_send_cmd_data(p7_handle_t *handle, p7ushort_t subtype,
|
|||
* `p7_flag_active | p7_flag_check` flags takes care of that),
|
||||
* Protocol 7.00 is basically a set of packet flows.
|
||||
*
|
||||
* Command, TODO
|
||||
* A packet flow always start with a command from the active side to the
|
||||
* passive side. Then, once the command is ACK-ed, according to the command,
|
||||
* different packet flows can occur. Here are a few characteristic examples:
|
||||
*
|
||||
* - File action. For example, file removing require nothing after the command
|
||||
* confirmation;
|
||||
* - File sending. After the overwrite flow, the active side sends data
|
||||
* packets containing the file data (`p7_send_buffer`/`p7_send_data`);
|
||||
* - File receiving. The active side sends a role swap packet, then the
|
||||
* server (now active) does the file sending procedure (with command). Once
|
||||
* it has finished sending the file, it swaps roles again;
|
||||
* - File listing. The active side sends a role swap packet, then the
|
||||
* server (now active) sends file information commands for each entry.
|
||||
* Once it has finished, it swap roles again.
|
||||
*
|
||||
* If you have finished doing what you wanted to do and the communication is
|
||||
* still active, send an END packet, to which the other calculator should
|
||||
|
|
|
@ -19,15 +19,10 @@
|
|||
* The libp7 stream abstraction is there so that the core code can be more
|
||||
* platform-agnostic (althrough platform-specific helpers are built-in for
|
||||
* popular platforms like Microsoft Windows or GNU/Linux distributions).
|
||||
*
|
||||
* A stream is basically what separates libp7 from the calculator.
|
||||
* When data is read from the stream, what is expected is what the calculator
|
||||
* has sent, and when data is written to the stream, it is what the calculator
|
||||
* shall receive.
|
||||
*
|
||||
* As some streams can have buffering, there is no buffering system in this
|
||||
* superset. Also, if you don't succeed totally (all bytes read/written),
|
||||
* to the library, you have failed, and shall return an error.
|
||||
* ************************************************************************** */
|
||||
#ifndef LIBP7_STREAM_H
|
||||
# define LIBP7_STREAM_H
|
||||
|
@ -36,70 +31,33 @@
|
|||
extern "C" {
|
||||
# endif
|
||||
|
||||
/* forward structure declarations (don't mind) */
|
||||
struct p7_streamsettings_s;
|
||||
typedef struct p7_streamsettings_s p7_streamsettings_t;
|
||||
struct p7_streamtimeouts_s;
|
||||
typedef struct p7_streamtimeouts_s p7_streamtimeouts_t;
|
||||
/* ************************************************************************** */
|
||||
/* Communication settings */
|
||||
/* Stream structure */
|
||||
/* ************************************************************************** */
|
||||
/* baud speeds */
|
||||
# define P7_B9600 9600
|
||||
# define P7_B19200 19200
|
||||
# define P7_B38400 38400
|
||||
# define P7_B57600 57600
|
||||
# define P7_B115200 115200
|
||||
/* This is the main structure of a stream. It is basically only made of
|
||||
* callbacks the libp7 functions will use to interact with the other device.
|
||||
* In case of any error (buffer not fully read/written, invalid settings),
|
||||
* your callbacks will have to return one of the libp7 error codes.
|
||||
* There is no partial read or write.
|
||||
*
|
||||
* First, the basic functions: once your stream is open (and it should be
|
||||
* open before calling `p7_sinit`), it will call your `setcomm` and `settm`
|
||||
* functions using the protocol information and the information given by the
|
||||
* user to the initialization function (don't use this information directly!).
|
||||
* Then, to read data from your stream, it will use the `read` callback,
|
||||
* and to write data to your stream, it will use the `write` callback.
|
||||
* On exit, your `close` callback will be called, to free memory you have
|
||||
* allocated for your needs, and other I/O requests.
|
||||
*
|
||||
* Mind that what you will receive is the direct request from the library/user,
|
||||
* there is no buffering between your stream and the library/user! If you need
|
||||
* buffering, you'll have to implement it. */
|
||||
|
||||
/* Flags */
|
||||
# define P7_STOPBITSMASK 0x00000001
|
||||
# define P7_ONESTOPBIT 0x00000000
|
||||
# define P7_TWOSTOPBITS 0x00000001
|
||||
# define P7_PARMASK 0x00000006
|
||||
# define P7_PARDIS 0x00000000
|
||||
# define P7_PARENB 0x00000002
|
||||
# define P7_PAREVEN 0x00000000
|
||||
# define P7_PARODD 0x00000004
|
||||
# define P7_DTRMASK 0x00000018
|
||||
# define P7_DTRCTL_DISABLE 0x00000000
|
||||
# define P7_DTRCTL_ENABLE 0x00000008
|
||||
# define P7_DTRCTL_HANDSHAKE 0x00000010
|
||||
# define P7_RTSMASK 0x00000060
|
||||
# define P7_RTSCTL_DISABLE 0x00000000
|
||||
# define P7_RTSCTL_ENABLE 0x00000020
|
||||
# define P7_RTSCTL_HANDSHAKE 0x00000040
|
||||
# define P7_XONCTL_DISABLE 0x00000000
|
||||
# define P7_XONCTL_ENABLE 0x00000080
|
||||
# define P7_XOFFCTL_DISABLE 0x00000000
|
||||
# define P7_XOFFCTL_ENABLE 0x00000100
|
||||
|
||||
/* Control characters */
|
||||
# define P7_NCCS 0x02
|
||||
# define P7_XON 0x00
|
||||
# define P7_XOFF 0x01
|
||||
|
||||
/* Communication settings. */
|
||||
typedef struct p7_streamsettings_s {
|
||||
/* flags - see above */
|
||||
unsigned int flags;
|
||||
|
||||
/* speed: one of the P7_B* constants */
|
||||
unsigned int speed;
|
||||
|
||||
/* characters */
|
||||
unsigned char cc[P7_NCCS];
|
||||
} p7_streamsettings_t;
|
||||
|
||||
/* Timeout settings */
|
||||
typedef struct p7_streamtimeouts_s {
|
||||
/* read timeout in ms */
|
||||
unsigned int read;
|
||||
|
||||
/* in-between read timeout in ms */
|
||||
unsigned int read_bw;
|
||||
|
||||
/* write timeout in ms */
|
||||
unsigned int write;
|
||||
} p7_streamtimeouts_t;
|
||||
|
||||
/* The callbacks take the uncasted cookie and the required arguments for
|
||||
* the action (`timeout` being in milliseconds). They should return the libp7
|
||||
* error code, or 0 if no error has occured. Again, no partial success. */
|
||||
typedef struct p7_stream_s {
|
||||
/* main callbacks */
|
||||
int (*read)(void *cookie, unsigned char *dest, size_t size);
|
||||
|
@ -114,34 +72,134 @@ typedef struct p7_stream_s {
|
|||
void *cookie;
|
||||
} p7_stream_t;
|
||||
|
||||
/* initialize libp7 with a custom stream */
|
||||
/* ************************************************************************** */
|
||||
/* Stream settings values and flags */
|
||||
/* ************************************************************************** */
|
||||
/* Here are the different baud speeds you can encounter, in bauds.
|
||||
* Note that one speed is not supported by all models. */
|
||||
|
||||
# define P7_B1200 1200
|
||||
# define P7_B2400 2400
|
||||
# define P7_B4800 4800
|
||||
# define P7_B9600 9600
|
||||
# define P7_B19200 19200
|
||||
# define P7_B38400 38400
|
||||
# define P7_B57600 57600
|
||||
# define P7_B115200 115200
|
||||
|
||||
/* Here are the control characters and other values you have in the
|
||||
* stream settings. */
|
||||
|
||||
# define P7_NCCS 0x02 /* number of control characters */
|
||||
# define P7_XON 0x00 /* XON character: re-enable transmission */
|
||||
# define P7_XOFF 0x01 /* XOFF character: disable transmission */
|
||||
|
||||
/* From here, those are all in the stream settings flags.
|
||||
* Here are the stop bits settings: */
|
||||
|
||||
# define P7_STOPBITSMASK 0x0001
|
||||
# define P7_ONESTOPBIT 0x0000 /* one stop bit */
|
||||
# define P7_TWOSTOPBITS 0x0001 /* two stop bits */
|
||||
|
||||
/* Here are the parity settings: */
|
||||
|
||||
# define P7_PARMASK 0x0006
|
||||
# define P7_PARDIS 0x0000 /* disable parity checking */
|
||||
# define P7_PARENB 0x0002 /* enable parity checking */
|
||||
# define P7_PAREVEN 0x0000 /* even parity */
|
||||
# define P7_PARODD 0x0004 /* odd parity */
|
||||
|
||||
/* Here are the DTR/RTS settings.
|
||||
* Notice that not all platforms implement this. Just do as you can. */
|
||||
|
||||
# define P7_DTRMASK 0x0018
|
||||
# define P7_DTRCTL_DISABLE 0x0000 /* disable DTR */
|
||||
# define P7_DTRCTL_ENABLE 0x0008 /* enable DTR */
|
||||
# define P7_DTRCTL_HANDSHAKE 0x0010 /* enable DTR and handshake */
|
||||
|
||||
# define P7_RTSMASK 0x0060
|
||||
# define P7_RTSCTL_DISABLE 0x0000 /* disable RTS */
|
||||
# define P7_RTSCTL_ENABLE 0x0020 /* enable RTS */
|
||||
# define P7_RTSCTL_HANDSHAKE 0x0040 /* enable RTS and handshake */
|
||||
|
||||
/* Here are the XON/XOFF software control settings.
|
||||
* XOFF disables the transmission temporarily, usually because the device at
|
||||
* the other end can't manage too much data too quickly. */
|
||||
|
||||
# define P7_XONMASK 0x0080
|
||||
# define P7_XONCTL_DISABLE 0x0000 /* disable XON */
|
||||
# define P7_XONCTL_ENABLE 0x0080 /* enable XON */
|
||||
|
||||
/* XON re-enables the transmission, probably because the device at the end
|
||||
* has finished processing the data you sent and is ready to process more. */
|
||||
|
||||
# define P7_XOFFMASK 0x0100
|
||||
# define P7_XOFFCTL_DISABLE 0x0000 /* disable XOFF */
|
||||
# define P7_XOFFCTL_ENABLE 0x0100 /* enable XOFF */
|
||||
/* ************************************************************************** */
|
||||
/* Stream settings */
|
||||
/* ************************************************************************** */
|
||||
/* Here is the stream settings structure.
|
||||
* This structure will be sent to your `setcomm` callback to set communication
|
||||
* settings. */
|
||||
|
||||
struct p7_streamsettings_s {
|
||||
/* flags - see the above section */
|
||||
unsigned int flags;
|
||||
|
||||
/* speed: one of the P7_B* constants */
|
||||
unsigned int speed;
|
||||
|
||||
/* characters */
|
||||
unsigned char cc[P7_NCCS];
|
||||
};
|
||||
|
||||
/* And here is the stream timeouts structure.
|
||||
* This structure will be sent to your `settm` callback, usually after a state
|
||||
* change in the communication.
|
||||
* All timeouts are in milliseconds. */
|
||||
|
||||
struct p7_streamtimeouts_s {
|
||||
/* Initial read timeout */
|
||||
unsigned int read;
|
||||
|
||||
/* In-between bytes read timeout */
|
||||
unsigned int read_bw;
|
||||
|
||||
/* Total write timeout */
|
||||
unsigned int write;
|
||||
};
|
||||
/* ************************************************************************** */
|
||||
/* Stream functions */
|
||||
/* ************************************************************************** */
|
||||
/* Initialize a handle using a custom stream. */
|
||||
extern int p7_sinit(p7_handle_t **h, unsigned int flags,
|
||||
const char *name, p7_stream_t stream, const p7_streamsettings_t *settings);
|
||||
|
||||
/* get the stream from the handle */
|
||||
/* Extract the stream out of the handle. */
|
||||
extern const p7_stream_t *p7_get_stream(p7_handle_t *handle);
|
||||
|
||||
/* initialize settings */
|
||||
/* Default stream settings utilities.
|
||||
* `p7_initcomm` initializes a stream settings structure. */
|
||||
extern void p7_initcomm(p7_streamsettings_t *settings);
|
||||
extern p7_streamsettings_t p7_default_settings;
|
||||
|
||||
/* read and write data from and to stream */
|
||||
/* Read and write data from and to a stream, set stream settings and timeouts.
|
||||
* You should use these functions instead of the callbacks directly. */
|
||||
extern int p7_read(p7_stream_t *stream, void *dest, size_t size);
|
||||
extern int p7_write(p7_stream_t *stream, const void *data, size_t size);
|
||||
|
||||
/* set stream settings */
|
||||
extern int p7_setcomm(p7_stream_t *stream, const p7_streamsettings_t *settings);
|
||||
extern int p7_settm(p7_stream_t *stream, const p7_streamtimeouts_t *timeouts);
|
||||
/* ************************************************************************** */
|
||||
/* Built-in streams */
|
||||
/* ************************************************************************** */
|
||||
/* FILE stream */
|
||||
/* Make a libp7 stream using the standard FILE interface. */
|
||||
# ifndef P7_DISABLED_FILE
|
||||
extern int p7_finit(p7_handle_t **handle, unsigned int flags,
|
||||
FILE *readstream, FILE *writestream);
|
||||
# endif
|
||||
|
||||
/* STREAMS device */
|
||||
/* Make a libp7 stream using the POSIX STREAMS interface. */
|
||||
# if defined(__linux__)
|
||||
extern int p7_fdinit(p7_handle_t **handle, unsigned int flags,
|
||||
const char *name, int readfd, int writefd,
|
||||
|
@ -153,12 +211,12 @@ extern int p7_fdcominit(p7_handle_t **handle, unsigned int flags,
|
|||
# define P7_DISABLED_STREAMS
|
||||
# endif
|
||||
|
||||
/* libusb initialization */
|
||||
/* Make a libp7 stream using libusb. */
|
||||
# ifndef P7_DISABLED_LIBUSB
|
||||
extern int p7_libusbinit(p7_handle_t **handle, unsigned int flags);
|
||||
# endif
|
||||
|
||||
/* Microsoft Windows initialization */
|
||||
/* Make a libp7 stream using the Windows API. */
|
||||
# ifdef __WINDOWS__
|
||||
extern int p7_winit(p7_handle_t **handle, unsigned int flags, const char *path,
|
||||
p7_streamsettings_t *settings);
|
||||
|
@ -167,7 +225,7 @@ extern int p7_wcomlist(void (*callback)(void*, const char*), void *cookie);
|
|||
# define P7_DISABLED_WINDOWS
|
||||
# endif
|
||||
|
||||
/* Check if there is serial/usb on this platform */
|
||||
/* Using the macros, check if there is serial/usb on this platform */
|
||||
# if defined(P7_DISABLED_STREAMS) && defined(P7_DISABLED_WINDOWS)
|
||||
# define P7_NOSERIAL
|
||||
# endif
|
||||
|
|
|
@ -77,56 +77,6 @@ const p7_server_t *p7_get_info(p7_handle_t *handle)
|
|||
/* ************************************************************************** */
|
||||
/* Initialization */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* start:
|
||||
* Start the communication.
|
||||
*
|
||||
* @arg handle the handle.
|
||||
* @return the error, if any.
|
||||
*/
|
||||
|
||||
static int start(p7_handle_t *handle, int check)
|
||||
{
|
||||
int err = 0;
|
||||
log_info("so we're active? let's do what active people do then!");
|
||||
|
||||
/* send initial check */
|
||||
if (check) {
|
||||
log_info("sending initial check packet");
|
||||
if ((err = p7_send_ini_check(handle))) {
|
||||
log_fatal("couldn't send check/didn't receive answer");
|
||||
return (err);
|
||||
} else if (response.type != p7_pt_ack) {
|
||||
log_fatal("received packet wasn't ack, ask your dentist");
|
||||
return (p7_error_unknown);
|
||||
}
|
||||
#if LOGLEVEL <= ll_info
|
||||
} else {
|
||||
log_info("skipping initial check, we suppose already initialized");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* discover environment */
|
||||
log_info("checkin' up da environment");
|
||||
if ((err = p7_send_cmdsys_getinfo(handle))) {
|
||||
log_fatal("couldn't send env query/receive answer");
|
||||
return (err);
|
||||
} else if (response.type != p7_pt_ack || !response.extended) {
|
||||
log_fatal("response to env query wasn't an extended ack packet");
|
||||
return (p7_error_unknown);
|
||||
}
|
||||
|
||||
/* save server */
|
||||
handle->_server = response.info;
|
||||
|
||||
/* get environment based on sent hardware id */
|
||||
handle->_env = p7_get_env(handle->_server.hwid);
|
||||
log_info("environment is '%s'", handle->_env->name);
|
||||
|
||||
/* no error */
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* p7_sinit:
|
||||
* Initialize libp7 with a P7 stream.
|
||||
|
@ -179,7 +129,7 @@ int p7_sinit(p7_handle_t **h, unsigned int flags,
|
|||
|
||||
/* if active, start */
|
||||
if ((handle->_flags & p7_intflag_active)
|
||||
&& (err = start(handle, flags & P7_CHECK))) {
|
||||
&& (err = p7_start(handle, flags & P7_CHECK))) {
|
||||
p7_exit(*h); *h = NULL;
|
||||
return (err);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* legacy/init.c -- initialize the legacy communication.
|
||||
* protocol/legacy/init.c -- initialize the legacy communication.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
||||
|
@ -22,14 +22,14 @@
|
|||
/* Initialization */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* start:
|
||||
* p7_legacy_start:
|
||||
* Start the communication.
|
||||
*
|
||||
* @arg handle the handle.
|
||||
* @return the error, if any.
|
||||
*/
|
||||
|
||||
static int start(p7_handle_t *handle)
|
||||
int p7_legacy_start(p7_handle_t *handle)
|
||||
{
|
||||
/* receive the attention request */
|
||||
unsigned char byte;
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* packet/command.c -- the command utilities.
|
||||
* protocol/seven/command.c -- the command utilities.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* packet/data.c -- data packet and buffer sending.
|
||||
* protocol/seven/data.c -- data packet and buffer sending.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* core/devices.c -- libp7 known devices.
|
||||
* protocol/seven/devices.c -- libp7 known devices.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
||||
|
@ -198,7 +198,6 @@ static p7_env_t known_environments[] = {
|
|||
static p7_env_t default_environment =
|
||||
{NULL, "Default environment",
|
||||
MASK_ALL | MASK_MCS | MASK_LINK | MASK_FLS};
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Internal functions */
|
||||
/* ************************************************************************** */
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* packet/eack.c -- extended ACK management.
|
||||
* protocol/seven/eack.c -- extended ACK management.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -0,0 +1,69 @@
|
|||
/* *****************************************************************************
|
||||
* protocol/seven/init.c -- initialize a P7 handle.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
||||
* libp7 is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation; either version 3.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* libp7 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with libp7; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#include <libp7/internals.h>
|
||||
|
||||
/**
|
||||
* p7_start:
|
||||
* Start the communication.
|
||||
*
|
||||
* @arg handle the handle.
|
||||
* @return the error, if any.
|
||||
*/
|
||||
|
||||
int p7_start(p7_handle_t *handle, int check)
|
||||
{
|
||||
int err = 0;
|
||||
log_info("so we're active? let's do what active people do then!");
|
||||
|
||||
/* send initial check */
|
||||
if (check) {
|
||||
log_info("sending initial check packet");
|
||||
if ((err = p7_send_ini_check(handle))) {
|
||||
log_fatal("couldn't send check/didn't receive answer");
|
||||
return (err);
|
||||
} else if (response.type != p7_pt_ack) {
|
||||
log_fatal("received packet wasn't ack, ask your dentist");
|
||||
return (p7_error_unknown);
|
||||
}
|
||||
#if LOGLEVEL <= ll_info
|
||||
} else {
|
||||
log_info("skipping initial check, we suppose already initialized");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* discover environment */
|
||||
log_info("checkin' up da environment");
|
||||
if ((err = p7_send_cmdsys_getinfo(handle))) {
|
||||
log_fatal("couldn't send env query/receive answer");
|
||||
return (err);
|
||||
} else if (response.type != p7_pt_ack || !response.extended) {
|
||||
log_fatal("response to env query wasn't an extended ack packet");
|
||||
return (p7_error_unknown);
|
||||
}
|
||||
|
||||
/* save server */
|
||||
handle->_server = response.info;
|
||||
|
||||
/* get environment based on sent hardware id */
|
||||
handle->_env = p7_get_env(handle->_server.hwid);
|
||||
log_info("environment is '%s'", handle->_env->name);
|
||||
|
||||
/* no error */
|
||||
return (0);
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* packet/recv.c -- receive and decode the packet.
|
||||
* protocol/seven/recv.c -- receive and decode the packet.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* packet/send.c -- prepare and send a packet.
|
||||
* protocol/seven/send.c -- prepare and send a packet.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* misc/backup.c -- backup software elements of the calculator.
|
||||
* usage/backup.c -- backup software elements of the calculator.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* misc/getscreen.c -- receive the streamed screen from the calculator.
|
||||
* usage/getscreen.c -- receive the streamed screen from the calculator.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* mcs/list.c -- list the elements on the main memory.
|
||||
* usage/mcs/list.c -- list the elements on the main memory.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* mcs/request.c -- request a file from the main memory.
|
||||
* usage/mcs/request.c -- request a file from the main memory.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* misc/poke.c -- poke the calculator so the communication doesn't stop.
|
||||
* usage/poke.c -- poke the calculator so the communication doesn't stop.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* misc/sendexe.c -- send an update.exe to the calculator.
|
||||
* usage/sendexe.c -- send an update.exe to the calculator.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* misc/server.c -- set up a protocol 7 server.
|
||||
* usage/server.c -- set up a protocol 7 server.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* misc/setlink.c -- set link settings.
|
||||
* usage/setlink.c -- set link settings.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* storage/copy.c -- copy a file on the calculator.
|
||||
* usage/storage/copy.c -- copy a file on the calculator.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* storage/createdir.c -- create a directory on the calculator.
|
||||
* usage/storage/createdir.c -- create a directory on the calculator.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* storage/delete.c -- delete a file/directory on the calculator.
|
||||
* usage/storage/delete.c -- delete a file/directory on the calculator.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* storage/getfreemem.c -- get the amount of free memory on the calculator.
|
||||
* usage/storage/getfreemem.c -- get the amount of free memory on the calculator.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* storage/list.c -- list the elements on the calculator.
|
||||
* usage/storage/list.c -- list the elements on the calculator.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* storage/optimize.c -- optimize a filesystem on the calculator.
|
||||
* usage/storage/optimize.c -- optimize a filesystem on the calculator.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* storage/request.c -- request a file from the calculator.
|
||||
* usage/storage/request.c -- request a file from the calculator.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* storage/reset.c -- reset a filesystem on the calculator.
|
||||
* usage/storage/reset.c -- reset a filesystem on the calculator.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
|
@ -1,5 +1,5 @@
|
|||
/* *****************************************************************************
|
||||
* storage/send.c -- send a file to the calculator.
|
||||
* usage/storage/send.c -- send a file to the calculator.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of libp7.
|
Reference in New Issue