364 lines
15 KiB
C
364 lines
15 KiB
C
/* *****************************************************************************
|
|
* libp7.h -- libp7 main public header.
|
|
* 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/>.
|
|
*
|
|
* WARNING: Do NOT include this header using <libp7-(version)/libp7.h>!
|
|
* Compile with either `libp7-config --cflags` or `pkg-config libp7 --cflags`,
|
|
* and include using <libp7.h>.
|
|
* ************************************************************************** */
|
|
#ifndef LIBP7_H
|
|
# define LIBP7_H
|
|
# include <libp7/types.h>
|
|
# include <libp7/stream.h>
|
|
# ifdef __cplusplus
|
|
extern "C" {
|
|
# endif
|
|
|
|
/* ************************************************************************** */
|
|
/* libp7 errors */
|
|
/* ************************************************************************** */
|
|
/* WARNING: Whenever you add/remove errors, think about updating core/strerror!
|
|
* ---
|
|
* First, the none error. */
|
|
# define p7_noerror 0x00
|
|
# define p7_error_none 0x00
|
|
# define p7_error_success 0x00
|
|
|
|
/* Other errors */
|
|
# define p7_error_unknown 0x01
|
|
# define p7_error_unsupported 0x02
|
|
# define p7_error_unsupported_device 0x03
|
|
# define p7_error_alloc 0x04
|
|
# define p7_error_invalid 0x05
|
|
# define p7_error_invalid_argument 0x05
|
|
# define p7_error_op 0x06
|
|
|
|
/* Stream errors */
|
|
# define p7_error_nostream 0x10
|
|
# define p7_error_nobuffer 0x10
|
|
# define p7_error_nobuf 0x10
|
|
# define p7_error_noread 0x11
|
|
# define p7_error_nowrite 0x12
|
|
# define p7_error_noseek 0x13
|
|
|
|
/* Communication errors */
|
|
# define p7_error_uninitialized 0x20
|
|
# define p7_error_nocalc 0x21
|
|
# define p7_error_noaccess 0x22
|
|
# define p7_error_nochar 0x23
|
|
# define p7_error_timeout 0x24
|
|
# define p7_error_checksum 0x25
|
|
# define p7_error_irrecoverable 0x26
|
|
# define p7_error_interrupted 0x27
|
|
# define p7_error_terminated 0x28
|
|
# define p7_error_active 0x29
|
|
# define p7_error_doubleshift 0x2A
|
|
# define p7_error_empty 0x2B
|
|
# define p7_error_fullmem 0x2C
|
|
# define p7_error_notfound 0x2D
|
|
# define p7_error_denied_overwrite 0x2E
|
|
|
|
/* Error type -- for compatibility with old programs using enum */
|
|
typedef int p7_error_t;
|
|
|
|
/* Message getting macro */
|
|
extern const char *p7_error_strings[];
|
|
# define p7_strerror(P7_ARG_N) p7_error_strings[P7_ARG_N]
|
|
# define p7_geterror(P7_ARG_N) p7_error_strings[P7_ARG_N]
|
|
/* ************************************************************************** */
|
|
/* Random stuff */
|
|
/* ************************************************************************** */
|
|
/* Filename and dirname */
|
|
extern int p7_validate_filename(const char *p7_arg_filename)
|
|
p7_attribute_THROW p7_attribute_wur p7_attribute_nonnull(1);
|
|
extern int p7_validate_dirname(const char *p7_arg_dirname)
|
|
p7_attribute_THROW p7_attribute_wur p7_attribute_nonnull(1);
|
|
|
|
/* Make settings out of a string */
|
|
# define p7_attrs_makesettings \
|
|
p7_attribute_THROW p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_makesettings, p7_attrs_makesettings,
|
|
p7_streamsettings_t *p7_arg_settings, const char *p7_arg_string)
|
|
/* ************************************************************************** */
|
|
/* Core functions */
|
|
/* ************************************************************************** */
|
|
/* Initialization flags */
|
|
# define p7_flag_active 0x00000001
|
|
# define p7_flag_check 0x00000002
|
|
# define p7_flag_term 0x00000004
|
|
|
|
/* Protocol */
|
|
# define p7_mask_protocol 0x00030000
|
|
# define p7_protocol_cas40 0x00010000
|
|
# define p7_protocol_cas50 0x00020000
|
|
# define p7_protocol_seven 0x00000000
|
|
|
|
/* Old flags (for some sort of compatibility) */
|
|
# define P7_ACTIVE p7_flag_active
|
|
# define P7_CHECK p7_flag_check
|
|
# define P7_TERM p7_flag_term
|
|
|
|
/* "Normal" initialization */
|
|
# define p7_attrs_init p7_attribute_THROW
|
|
p7_declare_func(p7_init, int, p7_attrs_init,
|
|
p7_handle_t **p7_arg_handle, unsigned int p7_arg_flags)
|
|
# define p7_attrs_cominit p7_attribute_THROW p7_attribute_nonnull(3)
|
|
p7_declare_func(p7_cominit, int, p7_attrs_cominit,
|
|
p7_handle_t **p7_arg_handle, unsigned int p7_arg_flags,
|
|
const char *p7_arg_path, const p7_streamsettings_t *p7_arg_settings)
|
|
|
|
/* Deinitialization */
|
|
# define p7_attrs_exit p7_attribute_nonnull(1)
|
|
p7_declare_func(p7_exit, void, p7_attrs_exit,
|
|
p7_handle_t *p7_arg_handle)
|
|
|
|
/* List serial devices */
|
|
# define p7_attrs_comlist p7_attribute_nonnull(1)
|
|
p7_declare_func(p7_comlist, int, p7_attrs_comlist,
|
|
p7_liststr_t *p7_arg_callback, void *p7_arg_cookie)
|
|
/* ************************************************************************** */
|
|
/* Interact with the login */
|
|
/* ************************************************************************** */
|
|
/* Log levels -- prefer the functions to these values, that can change! */
|
|
typedef int p7_loglevel_t; /* uint_fast8_t? */
|
|
# define p7_loglevel_info 0
|
|
# define p7_loglevel_warn 10
|
|
# define p7_loglevel_error 20
|
|
# define p7_loglevel_fatal 30
|
|
# define p7_loglevel_none 40
|
|
|
|
/* Get and set the log level at runtime */
|
|
# define p7_attrs_setlog p7_attribute_THROW
|
|
p7_declare_func(p7_setlog, void, p7_attrs_setlog,
|
|
p7_loglevel_t p7_arg_level)
|
|
# define p7_attrs_getlog p7_attribute_THROW
|
|
p7_declare_func(p7_getlog, p7_loglevel_t, p7_attrs_getlog, void)
|
|
|
|
/* Get, set and list log level strings */
|
|
# define p7_attrs_loglevel_tostring p7_attribute_THROW
|
|
p7_declare_func(p7_loglevel_tostring, const char*,
|
|
p7_attrs_loglevel_tostring,
|
|
p7_loglevel_t p7_arg_level)
|
|
# define p7_attrs_loglevel_fromstring p7_attribute_THROW
|
|
p7_declare_func(p7_loglevel_fromstring, p7_loglevel_t,
|
|
p7_attrs_loglevel_fromstring,
|
|
const char *p7_arg_string)
|
|
# define p7_attrs_loglevel_list
|
|
p7_declare_func(p7_loglevel_list, void,
|
|
p7_attrs_loglevel_list,
|
|
p7_liststr_t *p7_arg_callback, void *p7_arg_cookie)
|
|
/* ************************************************************************** */
|
|
/* MCS interaction */
|
|
/* ************************************************************************** */
|
|
/* List files */
|
|
# define p7_attrs_mcs_list p7_attribute_nonnull(1)
|
|
p7_declare_ufunc(p7_mcs_list, p7_attrs_mcs_list,
|
|
p7_handle_t *p7_arg_handle,
|
|
p7_mcslist_t *p7_arg_callback, void *p7_arg_cookie)
|
|
|
|
/* Send a file */
|
|
# define p7_attrs_mcs_send p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_mcs_send, p7_attrs_mcs_send,
|
|
p7_handle_t *p7_arg_handle, g1m_mcsfile_t *p7_arg_file,
|
|
int p7_arg_overwrite, p7_confirm_t *p7_arg_confirm,
|
|
p7_disp_t *p7_arg_disp)
|
|
|
|
/* Request a file */
|
|
# define p7_attrs_mcs_request \
|
|
p7_attribute_nonnull(1) p7_attribute_nonnull(2) p7_attribute_nonnull(3)
|
|
p7_declare_ufunc(p7_mcs_request, p7_attrs_mcs_request,
|
|
p7_handle_t *p7_arg_handle, g1m_mcsfile_t **p7_arg_file,
|
|
g1m_mcshead_t *p7_arg_head, p7_disp_t *p7_arg_disp)
|
|
/* ************************************************************************** */
|
|
/* Storage memory interaction */
|
|
/* ************************************************************************** */
|
|
/* Send a file using buffer */
|
|
# define p7_attrs_send \
|
|
p7_attribute_nonnull(1) p7_attribute_nonnull(2) \
|
|
p7_attribute_nonnull(4) p7_attribute_nonnull(5)
|
|
p7_declare_ufunc(p7_send, p7_attrs_send,
|
|
p7_handle_t *p7_arg_handle, const p7_buffer_t *p7_arg_buffer,
|
|
const char *p7_arg_dirname, const char *p7_arg_filename,
|
|
const char *p7_arg_devname, int p7_arg_overwrite,
|
|
p7_confirm_t *p7_arg_confirm, p7_disp_t *p7_arg_disp)
|
|
|
|
/* Receive a file using buffer */
|
|
# define p7_attrs_request \
|
|
p7_attribute_nonnull(1) p7_attribute_nonnull(2) \
|
|
p7_attribute_nonnull(4) p7_attribute_nonnull(5)
|
|
p7_declare_ufunc(p7_request, p7_attrs_request,
|
|
p7_handle_t *p7_arg_handle, const p7_buffer_t *p7_arg_buffer,
|
|
const char *p7_arg_dirname, const char *p7_arg_filename,
|
|
const char *p7_arg_devname, p7_disp_t *p7_arg_disp)
|
|
|
|
/* FILE version of the two previous functions */
|
|
# ifndef P7_DISABLED_FILE
|
|
# define p7_attrs_sendfile \
|
|
p7_attribute_nonnull(1) p7_attribute_nonnull(2) \
|
|
p7_attribute_nonnull(4) p7_attribute_nonnull(5)
|
|
p7_declare_ufunc(p7_sendfile, p7_attrs_sendfile,
|
|
p7_handle_t *p7_arg_handle, FILE *p7_arg_file,
|
|
const char *p7_arg_dirname, const char *p7_arg_filename,
|
|
const char *p7_arg_devname, int p7_arg_overwrite,
|
|
p7_confirm_t *p7_arg_confirm, p7_disp_t *p7_arg_disp)
|
|
|
|
# define p7_attrs_reqfile \
|
|
p7_attribute_nonnull(1) p7_attribute_nonnull(2) \
|
|
p7_attribute_nonnull(4) p7_attribute_nonnull(5)
|
|
p7_declare_ufunc(p7_reqfile, p7_attrs_reqfile,
|
|
p7_handle_t *p7_arg_handle, FILE *p7_arg_file,
|
|
const char *p7_arg_dirname, const char *p7_arg_filename,
|
|
const char *p7_arg_devname, p7_disp_t *p7_arg_disp)
|
|
# endif
|
|
|
|
/* Memory version of the send function */
|
|
# define p7_attrs_sendmem \
|
|
p7_attribute_nonnull(1) p7_attribute_nonnull(2) \
|
|
p7_attribute_nonnull(5) p7_attribute_nonnull(6)
|
|
p7_declare_ufunc(p7_sendmem, p7_attrs_sendmem,
|
|
p7_handle_t *p7_arg_handle, const void *p7_arg_mem, size_t p7_arg_size,
|
|
const char *p7_arg_dirname, const char *p7_arg_filename,
|
|
const char *p7_arg_devname,
|
|
int p7_arg_overwrite, p7_confirm_t *p7_arg_confirm,
|
|
p7_disp_t *p7_arg_disp)
|
|
|
|
/* Create a directory */
|
|
# define p7_attrs_createdir p7_attribute_nonnull(1) p7_attribute_nonnull(3)
|
|
p7_declare_ufunc(p7_createdir, p7_attrs_createdir,
|
|
p7_handle_t *p7_arg_handle,
|
|
const char *p7_arg_dirname, const char *p7_arg_devname)
|
|
|
|
/* Delete distant file */
|
|
# define p7_attrs_delete \
|
|
p7_attribute_nonnull(1) p7_attribute_nonnull(3) p7_attribute_nonnull(4)
|
|
p7_declare_ufunc(p7_delete, p7_attrs_delete,
|
|
p7_handle_t *p7_arg_handle, const char *p7_arg_dirname,
|
|
const char *p7_arg_filename, const char *p7_arg_devname)
|
|
|
|
/* Copy file on distant device */
|
|
# define p7_attrs_copy \
|
|
p7_attribute_nonnull(1) p7_attribute_nonnull(3) \
|
|
p7_attribute_nonnull(5) p7_attribute_nonnull(6)
|
|
p7_declare_ufunc(p7_copy, p7_attrs_copy,
|
|
p7_handle_t *p7_arg_handle,
|
|
const char *p7_arg_dirname, const char *p7_arg_filename,
|
|
const char *p7_arg_newdir, const char *p7_arg_newname,
|
|
const char *p7_arg_devname)
|
|
|
|
/* List files */
|
|
# define p7_attrs_list p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_list, p7_attrs_list,
|
|
p7_handle_t *p7_arg_handle, const char *p7_arg_devname,
|
|
p7_list_t *p7_arg_callback, void *p7_arg_cookie)
|
|
|
|
/* Get the free memory amount */
|
|
# define p7_attrs_getfreemem p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_getfreemem, p7_attrs_getfreemem,
|
|
p7_handle_t *p7_arg_handle, const char *p7_arg_devname,
|
|
p7uint_t *p7_arg_capacity)
|
|
|
|
/* Reset filesystem on a distant device */
|
|
# define p7_attrs_reset p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_reset, p7_attrs_reset,
|
|
p7_handle_t *p7_arg_handle, const char *p7_arg_devname)
|
|
|
|
/* Optimize distant device */
|
|
# define p7_attrs_optimize p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_optimize, p7_attrs_optimize,
|
|
p7_handle_t *p7_arg_handle, const char *p7_arg_devname)
|
|
/* ************************************************************************** */
|
|
/* Miscallenous interactions */
|
|
/* ************************************************************************** */
|
|
/* Poke the calculator in order to keep it happy */
|
|
# define p7_attrs_poke p7_attribute_nonnull(1)
|
|
p7_declare_ufunc(p7_poke, p7_attrs_poke,
|
|
p7_handle_t *p7_arg_handle)
|
|
|
|
/* Send an update.exe */
|
|
# define p7_attrs_sendexe p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_sendexe, p7_attrs_sendexe,
|
|
p7_handle_t *p7_arg_handle, const p7_buffer_t *p7_arg_buffer,
|
|
p7uint_t p7_arg_loadaddr, p7uint_t p7_arg_straddr, p7_disp_t *p7_arg_disp)
|
|
|
|
/* Backup the flash ROM, bootcode and CASIOWIN entry */
|
|
# define p7_attrs_backup_rom p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_backup_rom, p7_attrs_backup_rom,
|
|
p7_handle_t *p7_arg_handle, const p7_buffer_t *p7_arg_buffer,
|
|
p7_disp_t *p7_arg_disp)
|
|
# define p7_attrs_backup_ram p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_backup_ram, p7_attrs_backup_ram,
|
|
p7_handle_t *p7_arg_handle, const p7_buffer_t *p7_arg_buffer,
|
|
p7_disp_t *p7_arg_disp)
|
|
# define p7_attrs_backup_boot p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_backup_boot, p7_attrs_backup_boot,
|
|
p7_handle_t *p7_arg_handle, const p7_buffer_t *p7_arg_buffer,
|
|
p7_disp_t *p7_arg_disp)
|
|
# define p7_attrs_backup_casiowin_entry \
|
|
p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_backup_casiowin_entry, p7_attrs_backup_casiowin_entry,
|
|
p7_handle_t *p7_arg_handle, p7_casiowin_entry_t *p7_arg_entry)
|
|
|
|
/* set link settings */
|
|
# define p7_attrs_setlink p7_attribute_nonnull(1)
|
|
p7_declare_ufunc(p7_setlink, p7_attrs_setlink,
|
|
p7_handle_t *p7_arg_handle, const p7_streamsettings_t *p7_arg_settings)
|
|
|
|
/* FILE version of the previous functions */
|
|
# ifndef P7_DISABLED_FILE
|
|
/* Send an update.exe */
|
|
# define p7_attrs_sendexe_file p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_sendexe_file, p7_attrs_sendexe_file,
|
|
p7_handle_t *p7_arg_handle, FILE *p7_arg_exe,
|
|
p7uint_t p7_arg_loadaddr, p7uint_t p7_arg_straddr,
|
|
p7_disp_t *p7_arg_disp)
|
|
|
|
/* Backup things */
|
|
# define p7_attrs_backup_romfile \
|
|
p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_backup_romfile, p7_attrs_backup_romfile,
|
|
p7_handle_t *p7_arg_handle, FILE *p7_arg_file,
|
|
p7_disp_t *p7_arg_disp)
|
|
# define p7_attrs_backup_ramfile \
|
|
p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_backup_ramfile, p7_attrs_backup_ramfile,
|
|
p7_handle_t *p7_arg_handle, FILE *p7_arg_file,
|
|
p7_disp_t *p7_arg_disp)
|
|
# define p7_attrs_backup_bootfile \
|
|
p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_backup_bootfile, p7_attrs_backup_bootfile,
|
|
p7_handle_t *p7_arg_handle, FILE *p7_arg_file,
|
|
p7_disp_t *p7_arg_disp)
|
|
# endif
|
|
|
|
/* Memory version of the previous functions */
|
|
# define p7_attrs_sendexe_mem p7_attribute_nonnull(1) p7_attribute_nonnull(2)
|
|
p7_declare_ufunc(p7_sendexe_mem, p7_attrs_sendexe_mem,
|
|
p7_handle_t *p7_arg_handle, const void *p7_arg_mem, size_t p7_arg_size,
|
|
p7uint_t p7_arg_loadaddr, p7uint_t p7_arg_straddr,
|
|
p7_disp_t *p7_arg_disp)
|
|
|
|
/* Display streamed screen */
|
|
# define p7_attrs_getscreen p7_attribute_nonnull(1)
|
|
p7_declare_ufunc(p7_getscreen, p7_attrs_getscreen,
|
|
p7_handle_t *p7_arg_handle, p7_screenfunc_t *p7_arg_callback)
|
|
|
|
# ifdef __cplusplus
|
|
}
|
|
# endif
|
|
# include <libp7/server.h>
|
|
#endif /* LIBP7_H */
|