Adapting to libcasio
This commit is contained in:
parent
bce40172e1
commit
dc97d65696
|
@ -1,3 +0,0 @@
|
|||
[submodule "src/p7os/cake.exe"]
|
||||
path = src/p7os/cake.exe
|
||||
url = https://github.com/cakeisalie5/cake.exe.git
|
29
Makefile
29
Makefile
|
@ -117,30 +117,19 @@ endif
|
|||
all-bins: $(CHECKCFG) $(DEFAULT_BINARIES:%=all-%)
|
||||
|
||||
# Make a binary object directory.
|
||||
$(BINARIES:%=$(OBJDIR)/%):
|
||||
$(DIRS):
|
||||
$(call bcmd,mkdir,$@,$(MD) $@)
|
||||
|
||||
# Make an object out of a source file/directory.
|
||||
define make-binaryobj-rule
|
||||
ifeq ($(shell test -f $(SRCDIR)/$1/$2.c && echo y),y)
|
||||
# - Out of a C source file
|
||||
$(OBJDIR)/$1/$2.o: $(SRCDIR)/$1/$2.c | $(OBJDIR)/$1
|
||||
$(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(CFLAGS_$1))
|
||||
else
|
||||
# - Out of an update.exe project
|
||||
$(SRCDIR)/$1/$2.exe/$2.exe.bin:| $(SRCDIR)/$1/$2.exe
|
||||
$(call check-gitmodule,$(SRCDIR)/$1/$2.exe)
|
||||
$(if $(shell test -f $(SRCDIR)/$1/$2.exe/configure \
|
||||
&& test -x $(SRCDIR)/$1/$2.exe/configure && echo y), \
|
||||
$(call qcmd,cd $(SRCDIR)/$1/$2.exe && ./configure 1>/dev/null))
|
||||
$(call bcmd,make,$2.exe,$(MAKE) -C $(SRCDIR)/$1/$2.exe $2.exe.bin \
|
||||
| sed -e 's/^/ /')
|
||||
|
||||
$(OBJDIR)/$1/$2.o: $(SRCDIR)/$1/$2.exe/$2.exe.bin | $(OBJDIR)/$1
|
||||
$(call bcmd,ld -r,$$@,cd $(SRCDIR)/$1/$2.exe && \
|
||||
$(LDR) -o ../../../$$@ -b binary $2.exe.bin)
|
||||
endif
|
||||
define make-binaryobj-rules
|
||||
# Out of a C source file
|
||||
$(OBJDIR)/$1%.c.o: $(SRCDIR)/$1%.c | $(OBJDIR)/$1
|
||||
$(call bcmd,cc,$$@,$(CC) -c -o $$@ $$< $(CFLAGS_$2))
|
||||
endef
|
||||
$(foreach bin,$(BINARIES),\
|
||||
$(foreach d,$(sort $(dir $(SRC_$(bin):%=$(bin)/%))),\
|
||||
$(eval $(call make-binaryobj-rules,$(d),$(bin)))))
|
||||
|
||||
$(foreach bin,$(BINARIES),\
|
||||
$(foreach obj,$(SRC_$(bin)),\
|
||||
$(eval $(call make-binaryobj-rule,$(bin),$(obj)))))
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
#!/usr/bin/make -f
|
||||
#******************************************************************************#
|
||||
# Include configuration #
|
||||
#******************************************************************************#
|
||||
#*****************************************************************************#
|
||||
# Include configuration #
|
||||
#*****************************************************************************#
|
||||
-include Makefile.cfg
|
||||
|
||||
# Correct target
|
||||
TARGET := $(if $(TARGET),$(TARGET)-)
|
||||
|
||||
#******************************************************************************#
|
||||
# Project main information #
|
||||
#******************************************************************************#
|
||||
#*****************************************************************************#
|
||||
# Project main information #
|
||||
#*****************************************************************************#
|
||||
# Project name.
|
||||
NAME := p7utils
|
||||
|
||||
|
@ -28,9 +28,9 @@
|
|||
# Project version string.
|
||||
VERSION := $(MAJOR).$(MINOR)$(if $(INDEV),-indev)
|
||||
|
||||
#******************************************************************************#
|
||||
# Project directories #
|
||||
#******************************************************************************#
|
||||
#*****************************************************************************#
|
||||
# Project directories #
|
||||
#*****************************************************************************#
|
||||
# Sources directory
|
||||
SRCDIR := ./src
|
||||
|
||||
|
@ -43,9 +43,9 @@
|
|||
# Manpages directory
|
||||
MANDIR := ./man
|
||||
|
||||
#******************************************************************************#
|
||||
# Binary utilities #
|
||||
#******************************************************************************#
|
||||
#*****************************************************************************#
|
||||
# Binary utilities #
|
||||
#*****************************************************************************#
|
||||
# Package configuration
|
||||
PKGCONFIG := $(TARGET)pkg-config
|
||||
|
||||
|
@ -92,9 +92,9 @@ endif
|
|||
# Gzipper
|
||||
GZIP := gzip -f
|
||||
|
||||
#******************************************************************************#
|
||||
# Binaries and sources #
|
||||
#******************************************************************************#
|
||||
#*****************************************************************************#
|
||||
# Binaries and sources #
|
||||
#*****************************************************************************#
|
||||
# Look for binaries
|
||||
BINARIES := $(notdir $(shell find $(SRCDIR) -mindepth 1 -maxdepth 1 \
|
||||
-type d | sort))
|
||||
|
@ -114,10 +114,9 @@ $(eval $(call get-binary-libs,$(bin))))
|
|||
|
||||
# Look for their sources
|
||||
define get-binary-sources
|
||||
SRC_$1 := $(basename $(shell find $(SRCDIR)/$1 \
|
||||
-maxdepth 1 -mindepth 1 \
|
||||
\( -name "*.c" -or -name "*.exe" \) \
|
||||
-printf "%P\n" | sort))
|
||||
SRC_$1 := $(shell find $(SRCDIR)/$1 \
|
||||
-mindepth 1 -name "*.c" \
|
||||
-printf "%P\n" | sort)
|
||||
|
||||
# - get the flags
|
||||
CFLAGS_$1 := $(CFLAGS) $(shell $(PKGCONFIG) $(LIBS_$1) --cflags 2>/dev/null) \
|
||||
|
@ -127,9 +126,12 @@ endef
|
|||
$(foreach bin,$(BINARIES), \
|
||||
$(eval $(call get-binary-sources,$(bin))))
|
||||
|
||||
#******************************************************************************#
|
||||
# Look for manpages #
|
||||
#******************************************************************************#
|
||||
# Get the directories
|
||||
DIRS := $(sort $(dir \
|
||||
$(foreach bin,$(BINARIES),$(SRC_$(bin):%=$(OBJDIR)/$(bin)/%))))
|
||||
#*****************************************************************************#
|
||||
# Look for manpages #
|
||||
#*****************************************************************************#
|
||||
# Get the manpages sections and contents
|
||||
MAN_SECTIONS :=
|
||||
define check-man
|
||||
|
@ -143,9 +145,9 @@ $(eval $(call check-man,$(patsubst .%,%,$(suffix $(doc))),$(basename $(doc)))))
|
|||
# Remove duplicate sections.
|
||||
MAN_SECTIONS := $(sort $(MAN_SECTIONS))
|
||||
|
||||
#******************************************************************************#
|
||||
# Check for DESTDIR (add as prefix to installation root) #
|
||||
#******************************************************************************#
|
||||
#*****************************************************************************#
|
||||
# Check for DESTDIR (add as prefix to installation root) #
|
||||
#*****************************************************************************#
|
||||
define add-dest-dir
|
||||
$1 = $(DESTDIR)$($1)
|
||||
endef
|
||||
|
|
|
@ -20,7 +20,7 @@ default_storage=fls0
|
|||
|
||||
# Installation directories
|
||||
root=''
|
||||
prefix='${root}/usr'
|
||||
prefix='${root}/opt/p7-project'
|
||||
bindir='${prefix}/bin'
|
||||
mandir='${prefix}/share/man'
|
||||
|
||||
|
|
|
@ -166,7 +166,7 @@ static const char help_main_part0[] =
|
|||
" The string has the same format than for `--use`.\n";
|
||||
|
||||
static const char help_main_loglevel_init[] =
|
||||
" --log <level> The library log levels (default: %s).\n"
|
||||
" --log <level> The library log level (default: %s).\n"
|
||||
" One of: %s";
|
||||
|
||||
static const char help_main_part1[] =
|
||||
|
@ -183,15 +183,22 @@ static const char help_main_part1[] =
|
|||
* @arg level the level string.
|
||||
*/
|
||||
|
||||
static void put_loglevel(int *initialized, const char *level)
|
||||
static void put_loglevel(char **first, const char *level)
|
||||
{
|
||||
/* initialize */
|
||||
if (!(*initialized)) {
|
||||
printf(help_main_loglevel_init, p7_loglevel_tostring(p7_getlog()),
|
||||
level);
|
||||
*initialized = 1;
|
||||
} else
|
||||
printf(", %s", level);
|
||||
if (!*first) {
|
||||
*first = malloc(strlen(level) + 2);
|
||||
if (!*first) return ;
|
||||
strcpy(*first + 1, level);
|
||||
**first = 'F';
|
||||
return ;
|
||||
}
|
||||
|
||||
if (**first == 'F') {
|
||||
printf(help_main_loglevel_init, casio_getlog(), *first + 1);
|
||||
**first = 'N';
|
||||
}
|
||||
|
||||
printf(", %s", level);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -201,15 +208,16 @@ static void put_loglevel(int *initialized, const char *level)
|
|||
|
||||
static void put_main_help(void)
|
||||
{
|
||||
int initialized;
|
||||
char *first;
|
||||
|
||||
/* first big part */
|
||||
fputs(help_main_part0, stdout);
|
||||
|
||||
/* loglevels */
|
||||
initialized = 0;
|
||||
p7_loglevel_list((p7_liststr_t*)&put_loglevel, (void*)&initialized);
|
||||
if (initialized) fputc('\n', stdout);
|
||||
first = NULL;
|
||||
casio_listlog((casio_log_list_t*)&put_loglevel, (void*)&first);
|
||||
if (first && *first == 'N') fputc('\n', stdout);
|
||||
free(first);
|
||||
|
||||
/* second big part */
|
||||
fputs(help_main_part1, stdout);
|
||||
|
@ -240,18 +248,9 @@ static void put_main_help(void)
|
|||
|
||||
int parse_args(int ac, char **av, args_t *args)
|
||||
{
|
||||
/* initialize args */
|
||||
*args = (args_t){
|
||||
.menu = 0,
|
||||
.nicedisp = 0,
|
||||
.dirname = NULL, .filename = NULL,
|
||||
.newdir = NULL, .newname = NULL,
|
||||
.local = NULL, .force = 0,
|
||||
.com = 0,
|
||||
.storage = QUOTE(DEFAULT_STORAGE),
|
||||
.initflags = P7_ACTIVE | P7_CHECK | P7_TERM};
|
||||
|
||||
/* define options */
|
||||
int c, help = 0, rst = 0;
|
||||
const char *s_out = NULL, *s_dir = NULL, *s_todir = NULL;
|
||||
const char *s_use = NULL, *s_set = NULL, *s_log = NULL;
|
||||
char short_options[] = "hvfo:d:t:#";
|
||||
struct option long_options[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
|
@ -275,11 +274,24 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
/* initialize args */
|
||||
args->menu = 0;
|
||||
args->nicedisp = 0;
|
||||
args->dirname = NULL;
|
||||
args->filename = NULL;
|
||||
args->newdir = NULL;
|
||||
args->newname = NULL;
|
||||
args->local = NULL;
|
||||
args->force = 0;
|
||||
args->com = 0;
|
||||
args->storage = QUOTE(DEFAULT_STORAGE);
|
||||
args->initflags = CASIO_LINKFLAG_ACTIVE | CASIO_LINKFLAG_CHECK
|
||||
| CASIO_LINKFLAG_TERM;
|
||||
args->use = NULL;
|
||||
args->set = NULL;
|
||||
|
||||
/* get all options */
|
||||
int c; opterr = 0;
|
||||
int help = 0, rst = 0;
|
||||
const char *s_out = NULL, *s_dir = NULL, *s_todir = NULL;
|
||||
const char *s_use = NULL, *s_set = NULL, *s_log = NULL;
|
||||
opterr = 0;
|
||||
while ((c = getopt_long(ac, av, short_options, long_options, NULL)) != -1) {
|
||||
switch (c) {
|
||||
/* help */
|
||||
|
@ -305,9 +317,9 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
/* storage */
|
||||
case 's': args->storage = optarg; break;
|
||||
/* force no initialization */
|
||||
case 'i': args->initflags &= ~P7_CHECK; break;
|
||||
case 'i': args->initflags &= ~CASIO_LINKFLAG_CHECK; break;
|
||||
/* force no exit */
|
||||
case 'e': args->initflags &= ~P7_TERM; break;
|
||||
case 'e': args->initflags &= ~CASIO_LINKFLAG_TERM; break;
|
||||
|
||||
/* use and set settings */
|
||||
case 'U': s_use = optarg; break;
|
||||
|
@ -420,7 +432,7 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
/* use serial settings */
|
||||
if (s_use) {
|
||||
if (args->com) args->use = &args->_use;
|
||||
if (p7_makesettings(&args->_use, s_use)) {
|
||||
if (casio_make_attrs(&args->_use, s_use)) {
|
||||
log("--use: invalid format!\n");
|
||||
log("--use: expected <speed><parity><stopbits>, "
|
||||
"e.g. 9600N2 or 115200E1!\n");
|
||||
|
@ -434,7 +446,7 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
else if (s_set) {
|
||||
args->do_the_set = 1;
|
||||
if (args->com) args->set = &args->_set;
|
||||
if (p7_makesettings(&args->_set, s_set)) {
|
||||
if (casio_make_attrs(&args->_set, s_set)) {
|
||||
log("--set: invalid format!\n");
|
||||
log("--set: expected <speed><parity><stopbits>, "
|
||||
"e.g. 9600N2 or 115200E1!\n");
|
||||
|
@ -455,8 +467,7 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
}
|
||||
|
||||
/* set the log level */
|
||||
if (s_log)
|
||||
p7_setlog(p7_loglevel_fromstring(s_log));
|
||||
if (s_log) casio_setlog(s_log);
|
||||
|
||||
/* everything went well */
|
||||
return (1);
|
||||
|
|
|
@ -18,9 +18,8 @@
|
|||
* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <inttypes.h>
|
||||
#include <libp7/packetio.h>
|
||||
#define numformat "%" PRIuP7INT
|
||||
#define addrformat "0x%08" PRIxP7INT
|
||||
#define numformat "%lu"
|
||||
#define addrformat "0x%08lX"
|
||||
|
||||
/**
|
||||
* dump:
|
||||
|
@ -30,64 +29,66 @@
|
|||
* @return the error code (0 if ok).
|
||||
*/
|
||||
|
||||
int dump(p7_handle_t *handle)
|
||||
int dump(casio_link_t *handle)
|
||||
{
|
||||
/* get server info */
|
||||
const p7_server_t *info = p7_get_info(handle);
|
||||
const casio_link_info_t *info = casio_get_link_info(handle);
|
||||
|
||||
/* Wiped out things */
|
||||
if (info->p7_server_preprog_rom_wiped)
|
||||
if (info->casio_link_info_wiped & casio_link_info_wiped_preprog)
|
||||
log("Warning: Preprogrammed ROM information looks wiped out!\n");
|
||||
if (info->p7_server_bootcode_wiped)
|
||||
if (info->casio_link_info_wiped & casio_link_info_wiped_bootcode)
|
||||
log("Warning: Bootcode information looks wiped out!\n");
|
||||
if (info->p7_server_os_wiped)
|
||||
if (info->casio_link_info_wiped & casio_link_info_wiped_os)
|
||||
log("Warning: OS information looks wiped out!\n");
|
||||
if (!info->p7_server_username[0])
|
||||
if (!info->casio_link_info_username[0])
|
||||
log("Warning: Username is not set.\n");
|
||||
|
||||
/* main information */
|
||||
printf("CPU ID (probably out of date): %s\n", info->p7_server_cpuid);
|
||||
printf("Environnement ID: %s\n", info->p7_server_hwid);
|
||||
printf("Product ID: %s\n", info->p7_server_product_id);
|
||||
printf("CPU ID (probably out of date): %s\n", info->casio_link_info_cpuid);
|
||||
printf("Environnement ID: %s\n", info->casio_link_info_hwid);
|
||||
printf("Product ID: %s\n", info->casio_link_info_product_id);
|
||||
|
||||
/* Preprogrammed ROM */
|
||||
if (!info->p7_server_preprog_rom_wiped) {
|
||||
if (~info->casio_link_info_wiped & casio_link_info_wiped_preprog) {
|
||||
printf("Preprogrammed ROM version: %02u.%02u",
|
||||
info->p7_server_preprog_rom_version.major,
|
||||
info->p7_server_preprog_rom_version.minor);
|
||||
info->casio_link_info_rom_version.casio_version_major,
|
||||
info->casio_link_info_rom_version.casio_version_minor);
|
||||
printf("\nPreprogrammed ROM capacity: " numformat "o\n",
|
||||
info->p7_server_preprog_rom_capacity);
|
||||
info->casio_link_info_rom_capacity);
|
||||
}
|
||||
|
||||
/* ROM and RAM */
|
||||
printf("ROM capacity: " numformat "KiB\n",
|
||||
info->p7_server_flash_rom_capacity / 1024);
|
||||
info->casio_link_info_flash_rom_capacity / 1024);
|
||||
printf("RAM capacity: " numformat "KiB\n",
|
||||
info->p7_server_ram_capacity / 1024);
|
||||
info->casio_link_info_ram_capacity / 1024);
|
||||
|
||||
/* Bootcode */
|
||||
if (!info->p7_server_bootcode_wiped) {
|
||||
if (~info->casio_link_info_wiped & casio_link_info_wiped_bootcode) {
|
||||
printf("Bootcode version: %02u.%02u",
|
||||
info->p7_server_bootcode_version.major,
|
||||
info->p7_server_bootcode_version.minor);
|
||||
info->casio_link_info_bootcode_version.casio_version_major,
|
||||
info->casio_link_info_bootcode_version.casio_version_minor);
|
||||
printf("\nBootcode offset: " addrformat "\n",
|
||||
info->p7_server_bootcode_offset);
|
||||
info->casio_link_info_bootcode_offset);
|
||||
printf("Bootcode size: " numformat "KiB\n",
|
||||
info->p7_server_bootcode_size / 1024);
|
||||
info->casio_link_info_bootcode_size / 1024);
|
||||
}
|
||||
|
||||
/* OS */
|
||||
if (!info->p7_server_os_wiped) {
|
||||
if (~info->casio_link_info_wiped & casio_link_info_wiped_os) {
|
||||
printf("OS version: %02u.%02u",
|
||||
info->p7_server_os_version.major,
|
||||
info->p7_server_os_version.minor);
|
||||
printf("\nOS offset: " addrformat "\n", info->p7_server_os_offset);
|
||||
printf("OS size: " numformat "KiB\n", info->p7_server_os_size / 1024);
|
||||
info->casio_link_info_os_version.casio_version_major,
|
||||
info->casio_link_info_os_version.casio_version_minor);
|
||||
printf("\nOS offset: " addrformat "\n",
|
||||
info->casio_link_info_os_offset);
|
||||
printf("OS size: " numformat "KiB\n",
|
||||
info->casio_link_info_os_size / 1024);
|
||||
}
|
||||
|
||||
/* Miscallenous information */
|
||||
if (info->p7_server_username[0])
|
||||
printf("Username: %s\n", info->p7_server_username);
|
||||
if (info->casio_link_info_username[0])
|
||||
printf("Username: %s\n", info->casio_link_info_username);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ static void list_a_device(void *cookie, const char *path)
|
|||
|
||||
int list_devices(void)
|
||||
{
|
||||
p7_comlist(list_a_device, NULL);
|
||||
casio_comlist(list_a_device, NULL);
|
||||
if (!initialized)
|
||||
fprintf(stderr, "Could not find any devices.\n");
|
||||
return (0);
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "main.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <libp7/stream.h>
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Error messages */
|
||||
|
@ -109,7 +108,7 @@ static int sendfile_confirm(void)
|
|||
*/
|
||||
|
||||
static int sendfile_display_initialized = 0;
|
||||
static void sendfile_display(p7ushort_t id, p7ushort_t total)
|
||||
static void sendfile_display(unsigned int id, unsigned int total)
|
||||
{
|
||||
/* here's the buffer */
|
||||
static char buf[50] =
|
||||
|
@ -136,7 +135,7 @@ static void sendfile_display(p7ushort_t id, p7ushort_t total)
|
|||
while (pos <= current) bar[pos++] = '#';
|
||||
/* - % - */
|
||||
unsigned int percent = 10000 * id / total;
|
||||
sprintf(&buf[43], "%02u.%02u", percent / 100, percent % 100);
|
||||
sprintf(&buf[43], "%02u.%02u", (percent / 100) % 100, percent % 100);
|
||||
|
||||
/* put it */
|
||||
fputs(buf, stdout);
|
||||
|
@ -154,7 +153,7 @@ static void sendfile_display(p7ushort_t id, p7ushort_t total)
|
|||
*/
|
||||
|
||||
static void print_file_info(void *cookie, const char *dir, const char *name,
|
||||
p7uint_t size)
|
||||
unsigned long size)
|
||||
{
|
||||
(void)cookie;
|
||||
/* initialize buffer */
|
||||
|
@ -172,7 +171,6 @@ static void print_file_info(void *cookie, const char *dir, const char *name,
|
|||
/* put the string */
|
||||
puts(buf);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Main function */
|
||||
/* ************************************************************************** */
|
||||
|
@ -192,17 +190,17 @@ int main(int ac, char **av)
|
|||
if (!parse_args(ac, av, &args))
|
||||
return (0);
|
||||
|
||||
/* Initialize libp7 and communication */
|
||||
p7_handle_t *handle = NULL; int err;
|
||||
if (args.com) err = p7_cominit(&handle, args.initflags,
|
||||
/* Initialize the link */
|
||||
casio_link_t *handle = NULL; int err;
|
||||
if (args.com) err = casio_open_com(&handle, args.initflags,
|
||||
args.com, args.use);
|
||||
else err = p7_init(&handle, args.initflags);
|
||||
else err = casio_open_usb(&handle, args.initflags);
|
||||
if (err) {
|
||||
/* display error */
|
||||
switch (err) {
|
||||
case p7_error_nocalc: log(error_noconnexion); break;
|
||||
case p7_error_noaccess: log(error_noaccess); break;
|
||||
default: log(error_unplanned, p7_strerror(err)); break;
|
||||
case casio_error_nocalc: log(error_noconnexion); break;
|
||||
case casio_error_noaccess: log(error_noaccess); break;
|
||||
default: log(error_unplanned, casio_strerror(err)); break;
|
||||
}
|
||||
|
||||
/* closing, removing if necessary */
|
||||
|
@ -217,7 +215,7 @@ int main(int ac, char **av)
|
|||
|
||||
/* Change speed, and things */
|
||||
if (args.do_the_set) {
|
||||
err = p7_setlink(handle, args.set);
|
||||
err = casio_setlink(handle, args.set);
|
||||
if (err) goto fail;
|
||||
}
|
||||
|
||||
|
@ -226,48 +224,48 @@ int main(int ac, char **av)
|
|||
case mn_send:
|
||||
/* get file size */
|
||||
fseek(args.local, 0, SEEK_END);
|
||||
size_t filesize = (p7uint_t)ftell(args.local);
|
||||
casio_off_t filesize = (casio_off_t)ftell(args.local);
|
||||
rewind(args.local);
|
||||
|
||||
/* get capacity */
|
||||
p7uint_t capacity;
|
||||
err = p7_getfreemem(handle, args.storage, &capacity);
|
||||
unsigned long capacity;
|
||||
err = casio_getfreemem(handle, args.storage, &capacity);
|
||||
if (err) break;
|
||||
|
||||
/* optimize if required */
|
||||
if (filesize > (size_t)capacity) {
|
||||
if (filesize > (casio_off_t)capacity) {
|
||||
printf("Not enough space on the device. Let's optimize!\n");
|
||||
err = p7_optimize(handle, args.storage);
|
||||
err = casio_optimize(handle, args.storage);
|
||||
if (err) break;
|
||||
}
|
||||
|
||||
/* send the file */
|
||||
err = p7_sendfile(handle, args.local,
|
||||
err = casio_sendfile(handle, args.local,
|
||||
args.dirname, args.filename,
|
||||
args.storage, 1, args.force ? NULL : &sendfile_confirm,
|
||||
args.nicedisp ? &sendfile_display : NULL);
|
||||
break;
|
||||
case mn_get:
|
||||
err = p7_reqfile(handle, args.local, args.dirname, args.filename,
|
||||
err = casio_reqfile(handle, args.local, args.dirname, args.filename,
|
||||
args.storage, args.nicedisp && args.local != stdout
|
||||
? &sendfile_display : NULL);
|
||||
break;
|
||||
case mn_copy:
|
||||
err = p7_copy(handle, args.dirname, args.filename,
|
||||
err = casio_copy(handle, args.dirname, args.filename,
|
||||
args.newdir, args.newname, args.storage);
|
||||
break;
|
||||
case mn_del:
|
||||
err = p7_delete(handle, args.dirname, args.filename,
|
||||
err = casio_delete(handle, args.dirname, args.filename,
|
||||
args.storage);
|
||||
break;
|
||||
case mn_list:
|
||||
err = p7_list(handle, args.storage, &print_file_info, NULL);
|
||||
err = casio_list(handle, args.storage, &print_file_info, NULL);
|
||||
break;
|
||||
case mn_reset:
|
||||
err = p7_reset(handle, args.storage);
|
||||
err = casio_reset(handle, args.storage);
|
||||
break;
|
||||
case mn_optimize:
|
||||
err = p7_optimize(handle, args.storage);
|
||||
err = casio_optimize(handle, args.storage);
|
||||
break;
|
||||
case mn_info:
|
||||
err = dump(handle);
|
||||
|
@ -277,15 +275,15 @@ int main(int ac, char **av)
|
|||
}
|
||||
|
||||
/* put error */
|
||||
if (err && err != p7_error_denied_overwrite)
|
||||
if (err && err != casio_error_noow)
|
||||
goto fail;
|
||||
|
||||
if (sendfile_display_initialized)
|
||||
puts("\b\b\b\b\b\bTransfer complete.");
|
||||
if (args.local && args.local != stdout) fclose(args.local);
|
||||
|
||||
/* terminate communication and de-initialize libp7 */
|
||||
p7_exit(handle); handle = NULL;
|
||||
/* terminate communication and de-initialize link handle */
|
||||
casio_close_link(handle); handle = NULL;
|
||||
|
||||
/* Then we're good */
|
||||
return (0);
|
||||
|
@ -300,23 +298,25 @@ fail:
|
|||
|
||||
/* put the error string */
|
||||
switch (err) {
|
||||
case p7_error_fullmem:
|
||||
case casio_error_fullmem:
|
||||
log(error_nospace); break;
|
||||
case p7_error_empty:
|
||||
case casio_error_empty:
|
||||
log(error_empty); break;
|
||||
case p7_error_notfound:
|
||||
case casio_error_notfound:
|
||||
log(error_noexists); break;
|
||||
case p7_error_nocalc:
|
||||
case casio_error_nocalc:
|
||||
log(error_disconnected); break;
|
||||
case p7_error_unsupported:
|
||||
#if 0
|
||||
case casio_error_unsupported:
|
||||
log(error_unsupported); break;
|
||||
case p7_error_unsupported_device:
|
||||
case casio_error_unsupported_device:
|
||||
log(error_unsupported_device, args.storage); break;
|
||||
default: log(error_unplanned, p7_strerror(err));
|
||||
#endif
|
||||
default: log(error_unplanned, casio_strerror(err));
|
||||
}
|
||||
|
||||
/* that doesn't mean you shouldn't exit, heh. */
|
||||
p7_exit(handle); handle = NULL;
|
||||
casio_close_link(handle); handle = NULL;
|
||||
|
||||
/* then go away */
|
||||
return (1);
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
# define Q(x) #x
|
||||
# define QUOTE(x) Q(x)
|
||||
# include <stdio.h>
|
||||
# include <libp7.h>
|
||||
# include <libcasio.h>
|
||||
# define log(S, ...) fprintf(stderr, S, ##__VA_ARGS__)
|
||||
|
||||
/* Menus */
|
||||
|
@ -37,8 +37,8 @@ typedef struct {
|
|||
|
||||
/* libp7 settings */
|
||||
unsigned int initflags;
|
||||
p7_streamsettings_t *use, _use;
|
||||
p7_streamsettings_t *set, _set;
|
||||
casio_streamattrs_t *use, _use;
|
||||
casio_streamattrs_t *set, _set;
|
||||
int do_the_set;
|
||||
|
||||
/* for file transferring menus */
|
||||
|
@ -58,6 +58,6 @@ int parse_args(int ac, char **av, args_t *args);
|
|||
int list_devices(void);
|
||||
|
||||
/* Dumping function */
|
||||
int dump(p7_handle_t *handle);
|
||||
int dump(casio_link_t *handle);
|
||||
|
||||
#endif /* MAIN_H */
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#!/usr/bin/make -f
|
||||
libs:
|
||||
@echo libp7
|
||||
@echo libcasio
|
||||
|
|
219
src/p7os/args.c
219
src/p7os/args.c
|
@ -1,4 +1,4 @@
|
|||
/* *****************************************************************************
|
||||
/* ****************************************************************************
|
||||
* p7os/args.c -- p7os command-line arguments parsing utility.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
|
@ -15,7 +15,7 @@
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
* ************************************************************************* */
|
||||
#include "main.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -23,9 +23,9 @@
|
|||
#include <getopt.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Help and version messages */
|
||||
/* ************************************************************************** */
|
||||
/* ************************************************************************* */
|
||||
/* Help and version messages */
|
||||
/* ************************************************************************* */
|
||||
/* The version message - that's when the President comes in */
|
||||
static const char version_message[] =
|
||||
QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) " (licensed under GPLv2)\n"
|
||||
|
@ -36,25 +36,33 @@ QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) " (licensed under GPLv2)\n
|
|||
"FITNESS FOR A PARTICULAR PURPOSE.";
|
||||
|
||||
/* Main help message */
|
||||
static const char help_main[] =
|
||||
static const char help_main0[] =
|
||||
"Usage: " QUOTE(BIN) " [--version|-v] [--help|-h] [--com <device>]\n"
|
||||
" [--no-prepare] [--uexe <path>]\n"
|
||||
" <subcommand> [options...]\n"
|
||||
"\n"
|
||||
"Subcommands you can use are :\n"
|
||||
" prepare-only Set-up the update program, but leave it for other programs\n"
|
||||
" to interact with it.\n"
|
||||
" get Get the OS image.\n"
|
||||
" prepare-only Set-up the update program, but leave it for other programs\n"
|
||||
" to interact with it.\n"
|
||||
" get Get the OS image.\n"
|
||||
" flash Flash the OS image.\n"
|
||||
"\n"
|
||||
"General options:\n"
|
||||
" -h, --help Display the help page of the (sub)command and quit.\n"
|
||||
" -v, --version Display the version message and quit.\n"
|
||||
" --com <device> The serial device, if you want to communicate with a\n"
|
||||
" calculator connected using a USB-to-serial cable.\n"
|
||||
" If this option isn't used, the program will look for a\n"
|
||||
" calculator connected using direct USB.\n"
|
||||
" --no-prepare Use the current environment, instead of uploading one.\n"
|
||||
" --uexe <path> Use a custom update program.\n"
|
||||
" -h, --help Display the help page of the (sub)command and quit.\n"
|
||||
" -v, --version Display the version message and quit.\n";
|
||||
|
||||
static const char help_log[] =
|
||||
" --log <level> The library log level (default: %s).\n"
|
||||
" One of: %s";
|
||||
|
||||
static const char help_main1[] =
|
||||
" --com <device> The serial device, if you want to communicate with a\n"
|
||||
" calculator connected using a USB-to-serial cable.\n"
|
||||
" If this option isn't used, the program will look for a\n"
|
||||
" calculator connected using direct USB.\n"
|
||||
" --no-prepare Use the current environment, instead of uploading one.\n"
|
||||
" -u, --uexe <path> Use a custom update program.\n"
|
||||
" If `--no-prepare` is not given, this option is required.\n"
|
||||
"\n"
|
||||
"Type \"" QUOTE(BIN) " <subcommand> --help\" for some help about a subcommand.\n"
|
||||
"Report bugs to " QUOTE(MAINTAINER) ".";
|
||||
|
@ -74,15 +82,69 @@ FOOT;
|
|||
static const char help_get[] =
|
||||
"Usage: " QUOTE(BIN) " get [-o <os.bin>]\n"
|
||||
"Get the calculator OS image.\n"
|
||||
"You must have \"p7os prepare\"-ed before.\n"
|
||||
"\n"
|
||||
"Options are :\n"
|
||||
" -o <os.bin> Where to store the image (default is \"os.bin\")\n"
|
||||
FOOT;
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Main function */
|
||||
/* ************************************************************************** */
|
||||
/* Help message for flash subcommand. */
|
||||
static const char help_flash[] =
|
||||
"Usage: " QUOTE(BIN) " flash <rom.bin>\n"
|
||||
"Flash the calculator's OS image.\n"
|
||||
FOOT;
|
||||
/* ************************************************************************* */
|
||||
/* Main help message. */
|
||||
/* ************************************************************************* */
|
||||
/**
|
||||
* put_loglevel:
|
||||
* Put a loglevel (for listing).
|
||||
*
|
||||
* @arg first the first log level.
|
||||
* @arg level the level string.
|
||||
*/
|
||||
|
||||
static void put_loglevel(char **first, const char *level)
|
||||
{
|
||||
if (!*first) {
|
||||
*first = malloc(strlen(level) + 2);
|
||||
if (!*first) return ;
|
||||
strcpy(*first + 1, level);
|
||||
**first = 'F';
|
||||
return ;
|
||||
}
|
||||
|
||||
if (**first == 'F') {
|
||||
printf(help_log, casio_getlog(), *first + 1);
|
||||
**first = 'N';
|
||||
}
|
||||
|
||||
printf(", %s", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* put_help:
|
||||
* Put the main help message.
|
||||
*/
|
||||
|
||||
static void put_help(void)
|
||||
{
|
||||
char *first;
|
||||
|
||||
/* first big part */
|
||||
fputs(help_main0, stdout);
|
||||
|
||||
/* loglevels */
|
||||
first = NULL;
|
||||
casio_listlog((casio_log_list_t*)&put_loglevel, (void*)&first);
|
||||
if (first && *first == 'N') fputc('\n', stdout);
|
||||
free(first);
|
||||
|
||||
/* second big part */
|
||||
puts(help_main1);
|
||||
}
|
||||
/* ************************************************************************* */
|
||||
/* Main function */
|
||||
/* ************************************************************************* */
|
||||
/* Help macro */
|
||||
#define sub_init(CMD, NARGS) { \
|
||||
args->menu = mn_##CMD; \
|
||||
|
@ -91,6 +153,19 @@ FOOT;
|
|||
return (1); \
|
||||
}}
|
||||
|
||||
/* Options. */
|
||||
static const char shopts[] = "hvu:o:#";
|
||||
static const struct option longopts[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"com", required_argument, NULL, 'c'},
|
||||
{"no-prepare", no_argument, NULL, 'n'},
|
||||
{"uexe", required_argument, NULL, 'u'},
|
||||
{"output", required_argument, NULL, 'o'},
|
||||
{"log", required_argument, NULL, 'l'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
/**
|
||||
* parse_args:
|
||||
* Args parsing main function.
|
||||
|
@ -105,43 +180,30 @@ FOOT;
|
|||
|
||||
int parse_args(int ac, char **av, args_t *args)
|
||||
{
|
||||
/* initialize args */
|
||||
*args = (args_t){
|
||||
.menu = 0,
|
||||
.com = 0, .noprepare = 0,
|
||||
.uexe = NULL,
|
||||
.local = NULL, .localpath = NULL
|
||||
};
|
||||
int c, help = 0, version = 0;
|
||||
const char *s_out = "os.bin", *s_uexe = NULL, *s_log = NULL;
|
||||
|
||||
/* define options */
|
||||
const char shopts[] = "hvo:#";
|
||||
const struct option longopts[] = {
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"com", required_argument, NULL, 'c'},
|
||||
{"no-prepare", no_argument, NULL, 'n'},
|
||||
{"uexe", required_argument, NULL, 'u'},
|
||||
{"output", required_argument, NULL, 'o'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
/* Initialize the arguments. */
|
||||
memset(args, 0, sizeof(*args));
|
||||
|
||||
/* get all options */
|
||||
int c; opterr = 0;
|
||||
int help = 0, version = 0;
|
||||
const char *s_out = "os.bin", *s_uexe = NULL;
|
||||
while ((c = getopt_long(ac, av, shopts, longopts, NULL)) != -1) switch (c) {
|
||||
/* help */
|
||||
case 'h': help = 1; break;
|
||||
/* version */
|
||||
opterr = 0;
|
||||
while (1) {
|
||||
c = getopt_long(ac, av, shopts, longopts, NULL);
|
||||
if (c < 0) break;
|
||||
|
||||
switch (c) {
|
||||
case 'h': help = 1; break;
|
||||
case 'v': version = 1; break;
|
||||
/* com port */
|
||||
case 'c': args->com = optarg; break;
|
||||
/* no prepare */
|
||||
case 'n': args->noprepare = 1; break;
|
||||
/* uexe */
|
||||
|
||||
/* COM port, should prepare or not */
|
||||
case 'c': args->com = optarg; break;
|
||||
case 'n': args->noprepare = 1; break;
|
||||
|
||||
/* log level, Update.Exe, output path */
|
||||
case 'l': s_log = optarg; break;
|
||||
case 'u': s_uexe = optarg; break;
|
||||
/* output */
|
||||
case 'o': s_out = optarg; break;
|
||||
case 'o': s_out = optarg; break;
|
||||
|
||||
/* error */
|
||||
case '?':
|
||||
|
@ -150,10 +212,11 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
else if (optopt == 'c')
|
||||
log("--com: expected an argument\n");
|
||||
else if (optopt == 'u')
|
||||
log("--uexe: expected an argument\n");
|
||||
log("-u, --uexe: expected an argument\n");
|
||||
else
|
||||
break;
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* check for version */
|
||||
|
@ -169,13 +232,14 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
pc--; pv++;
|
||||
|
||||
/* subcommand. */
|
||||
char fpmode[2] = "r";
|
||||
char fpmode[3] = "r\0";
|
||||
if (!sub || !strcmp(sub, "help")) {
|
||||
puts(help_main);
|
||||
put_help();
|
||||
return (1);
|
||||
} else if (!strcmp(sub, "version")) {
|
||||
puts(version_message);
|
||||
return (1);
|
||||
|
||||
} else if (!strcmp(sub, "prepare-only")) {
|
||||
sub_init(prepare_only, 0)
|
||||
|
||||
|
@ -187,6 +251,9 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
sub_init(get, 0)
|
||||
args->localpath = s_out;
|
||||
fpmode[0] = 'w';
|
||||
} else if (!strcmp(sub, "flash")) {
|
||||
sub_init(flash, 1)
|
||||
args->localpath = pv[0];
|
||||
} else {
|
||||
log("Unknown subcommand '%s'.\n", sub);
|
||||
return (1);
|
||||
|
@ -194,23 +261,51 @@ int parse_args(int ac, char **av, args_t *args)
|
|||
|
||||
/* open destination file */
|
||||
if (args->localpath) {
|
||||
args->local = fopen(args->localpath, fpmode);
|
||||
if (!args->local) {
|
||||
FILE *localfile = fopen(args->localpath, fpmode);
|
||||
if (!localfile) {
|
||||
log("Could not open local file: %s\n", strerror(errno));
|
||||
return (1);
|
||||
}
|
||||
|
||||
int err = casio_open_stream_file(&args->local,
|
||||
fpmode[0] == 'r' ? localfile : NULL,
|
||||
fpmode[0] == 'w' || fpmode[1] == '+' ? localfile : NULL,
|
||||
1, 1);
|
||||
if (err) {
|
||||
log("Could not make a stream out of local file: %s\n",
|
||||
casio_strerror(err));
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* open update.exe file */
|
||||
if (s_uexe) {
|
||||
args->uexe = fopen(s_uexe, "r");
|
||||
if (!args->uexe) {
|
||||
if (!args->noprepare) {
|
||||
if (!s_uexe) {
|
||||
log("One of `-u <file>` or `--no-prepare` is expected!\n");
|
||||
if (args->local) casio_close(args->local);
|
||||
return (1);
|
||||
}
|
||||
|
||||
FILE *uexe = fopen(s_uexe, "r");
|
||||
if (!uexe) {
|
||||
log("Could not open update program: %s\n", strerror(errno));
|
||||
if (args->local) fclose(args->local);
|
||||
if (args->local) casio_close(args->local);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int err = casio_open_stream_file(&args->uexe,
|
||||
uexe, NULL, 1, 0);
|
||||
if (err) {
|
||||
log("Could not make a stream out of the update.exe: %s\n",
|
||||
casio_strerror(err));
|
||||
if (args->local) casio_close(args->local);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* set the log level */
|
||||
if (s_log) casio_setlog(s_log);
|
||||
|
||||
/* everything went well :) */
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Subproject commit 0afc6c675dfc44411ef9571b3af7571dfbc6f503
|
160
src/p7os/main.c
160
src/p7os/main.c
|
@ -1,4 +1,4 @@
|
|||
/* *****************************************************************************
|
||||
/* ****************************************************************************
|
||||
* p7os/main.c -- p7os main source.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
|
@ -15,13 +15,9 @@
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
* ************************************************************************* */
|
||||
#include "main.h"
|
||||
#include <unistd.h>
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Error messages */
|
||||
/* ************************************************************************** */
|
||||
/* Couldn't initialize connexion to calculator. */
|
||||
static const char error_noconnexion[] =
|
||||
"Could not connect to the calculator.\n"
|
||||
|
@ -44,66 +40,6 @@ static const char error_unsupported[] =
|
|||
"Required operation was unsupported by the calculator.\n"
|
||||
"If you did not prepare, perhaps you should prepare?\n";
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Auxiliary functions */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* osdisp:
|
||||
* Nice little loading bar.
|
||||
*
|
||||
* Taken from `src/p7/main.c`.
|
||||
* "Initialization" is when id > total (called in main).
|
||||
*
|
||||
* @arg id data packet ID.
|
||||
* @arg total total number of packets.
|
||||
*/
|
||||
|
||||
static int osdisp_init = 0;
|
||||
static const char *osdisp_msg;
|
||||
static void osdisp(p7ushort_t id, p7ushort_t total)
|
||||
{
|
||||
/* here's the buffer */
|
||||
static char buf[50] =
|
||||
"\r|---------------------------------------| 00.00%";
|
||||
static char *bar = &buf[2];
|
||||
|
||||
/* initialize */
|
||||
static int pos;
|
||||
|
||||
/* if is initialize, fill */
|
||||
if (id > total) {
|
||||
pos = 0;
|
||||
puts(osdisp_msg);
|
||||
/* indicate that is has been initialized */
|
||||
osdisp_init = 1;
|
||||
/* put initial buffer */
|
||||
fputs(buf, stdout);
|
||||
/* save cursor position */
|
||||
fputs("\x1B[s", stdout);
|
||||
/* we're done */
|
||||
return ;
|
||||
}
|
||||
|
||||
/* id and total start from 1, let them start from zero */
|
||||
id--; total--;
|
||||
|
||||
/* modify buffer */
|
||||
/* - # - */
|
||||
int current = 38 * id / total;
|
||||
while (pos <= current) bar[pos++] = '#';
|
||||
/* - % - */
|
||||
unsigned int percent = 10000 * id / total;
|
||||
sprintf(&buf[43], "%02u.%02u", percent / 100, percent % 100);
|
||||
|
||||
/* put it */
|
||||
fputs(buf, stdout);
|
||||
/* force cursor position */
|
||||
fputs("\x1B""8", stdout);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Main function */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* main:
|
||||
* User entry point of the program.
|
||||
|
@ -113,89 +49,53 @@ static void osdisp(p7ushort_t id, p7ushort_t total)
|
|||
* @return return code (0 if OK)
|
||||
*/
|
||||
|
||||
#define initflags (P7_ACTIVE | P7_CHECK | P7_TERM)
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int err; args_t args;
|
||||
|
||||
/* parse args */
|
||||
args_t args;
|
||||
if (parse_args(ac, av, &args))
|
||||
return (0);
|
||||
|
||||
/* Initialize libp7 and communication */
|
||||
p7_handle_t *handle = NULL; int err;
|
||||
if (args.com) err = p7_cominit(&handle, initflags, args.com,
|
||||
&p7_default_settings);
|
||||
else err = p7_init(&handle, initflags);
|
||||
if (err) goto fail;
|
||||
|
||||
/* prepare */
|
||||
if (!args.noprepare) {
|
||||
/* make the preparation thing */
|
||||
osdisp_msg = "Uploading the Update.Exe.";
|
||||
if ((err = prepare_ops(handle, args.uexe, osdisp)))
|
||||
goto fail;
|
||||
if (osdisp_init) {
|
||||
osdisp_init = 0;
|
||||
puts("\b\b\b\b\b\bTransfer complete.");
|
||||
}
|
||||
handle = NULL;
|
||||
|
||||
/* was only about preparing? */
|
||||
if (args.menu == mn_prepare_only)
|
||||
return (0);
|
||||
|
||||
/* sleep a little, in case */
|
||||
printf("Waiting for the Update.Exe to be setup...\n");
|
||||
sleep(1);
|
||||
|
||||
/* re-open the handle */
|
||||
if (args.com) err = p7_cominit(&handle, initflags, args.com,
|
||||
&p7_default_settings);
|
||||
else err = p7_init(&handle, initflags);
|
||||
if (err) {
|
||||
p7_exit(handle);
|
||||
goto fail;
|
||||
}
|
||||
err = prepare(&args);
|
||||
if (err) goto fail;
|
||||
}
|
||||
|
||||
/* check according to menu */
|
||||
switch (args.menu) {
|
||||
/* backup the thing menu */
|
||||
case mn_prepare_only: break;
|
||||
case mn_get:
|
||||
/* get the os */
|
||||
osdisp_msg = "Gathering the OS...";
|
||||
err = p7_backup_romfile(handle, args.local, osdisp);
|
||||
if (err) goto fail;
|
||||
fclose(args.local);
|
||||
break;
|
||||
err = backup_rom(&args); break;
|
||||
case mn_flash:
|
||||
#if 0
|
||||
err = fxremote_flash(&args); break;
|
||||
#endif
|
||||
fprintf(stderr,
|
||||
"fxRemote-like flashing has been removed.\n"
|
||||
"Sorry for the inconvenience.\n");
|
||||
err = 0; break;
|
||||
}
|
||||
|
||||
/* exit libp7 */
|
||||
p7_exit(handle);
|
||||
|
||||
/* then we're good */
|
||||
return (0);
|
||||
|
||||
fail:
|
||||
/* interrupt loading bar */
|
||||
if (osdisp_init)
|
||||
puts("\b\b\b\b\b\bError !");
|
||||
/* close the file, remove if necessary */
|
||||
if (args.localpath) {
|
||||
casio_close(args.local);
|
||||
if (err && casio_iswritable(args.local))
|
||||
remove(args.localpath);
|
||||
}
|
||||
|
||||
/* displaying error */
|
||||
if (err > 0) switch (err) {
|
||||
case p7_error_nocalc: log(error_noconnexion); break;
|
||||
case p7_error_noaccess: log(error_noaccess); break;
|
||||
case p7_error_unsupported: log(error_unsupported); break;
|
||||
default: log(error_unplanned, p7_strerror(err));
|
||||
if (err) switch (err) {
|
||||
case casio_error_nocalc:
|
||||
log(error_noconnexion); break;
|
||||
case casio_error_noaccess:
|
||||
log(error_noaccess); break;
|
||||
case casio_error_command:
|
||||
log(error_unsupported); break;
|
||||
default: log(error_unplanned, casio_strerror(err));
|
||||
}
|
||||
|
||||
/* closing the handle */
|
||||
p7_exit(handle);
|
||||
|
||||
/* closing the file, removing if necessary */
|
||||
if (args.localpath) {
|
||||
fclose(args.local);
|
||||
remove(args.localpath);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#ifndef MAIN_H
|
||||
# define MAIN_H
|
||||
# include <stdio.h>
|
||||
# include <libp7.h>
|
||||
# include <libcasio.h>
|
||||
# define Q(x) #x
|
||||
# define QUOTE(x) Q(x)
|
||||
# define log(S, ...) fprintf(stderr, S, ##__VA_ARGS__)
|
||||
|
@ -28,31 +28,52 @@
|
|||
/* CLI options */
|
||||
/* ************************************************************************** */
|
||||
/* Menu */
|
||||
# define mn_prepare_only 1
|
||||
# define mn_get 2
|
||||
enum menu_e {
|
||||
mn_prepare_only = 1,
|
||||
mn_get = 2,
|
||||
mn_flash = 3
|
||||
};
|
||||
|
||||
/* Arguments */
|
||||
typedef struct {
|
||||
/* basic things */
|
||||
int menu;
|
||||
enum menu_e menu;
|
||||
int noprepare;
|
||||
|
||||
/* communication and tweaks */
|
||||
const char *com;
|
||||
int noprepare;
|
||||
FILE *uexe;
|
||||
|
||||
/* others */
|
||||
FILE *local; const char *localpath;
|
||||
casio_stream_t *local;
|
||||
const char *localpath;
|
||||
casio_stream_t *uexe;
|
||||
} args_t;
|
||||
/* ************************************************************************* */
|
||||
/* Progress displayer */
|
||||
/* ************************************************************************* */
|
||||
typedef struct {
|
||||
const char *msg, *success;
|
||||
|
||||
/* Parsing function */
|
||||
int parse_args(int ac, char **av, args_t *args);
|
||||
char buf[50], *bar;
|
||||
int init, pos;
|
||||
} osdisp_t;
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Actual things */
|
||||
/* ************************************************************************** */
|
||||
/* Main functions */
|
||||
int prepare_ops(p7_handle_t *handle, FILE *uexe, p7_disp_t disp);
|
||||
int get_os(p7_handle_t *handle, FILE *dest);
|
||||
extern void osdisp_init(osdisp_t *cookie, const char *init,
|
||||
const char *success);
|
||||
extern void osdisp(void *cookie, unsigned int id, unsigned int total);
|
||||
|
||||
extern void osdisp_interrupt(osdisp_t *cookie);
|
||||
extern void osdisp_success(osdisp_t *cookie);
|
||||
/* ************************************************************************* */
|
||||
/* Central functions */
|
||||
/* ************************************************************************* */
|
||||
/* Utilities. */
|
||||
extern int parse_args(int ac, char **av, args_t *args);
|
||||
extern int open_link(casio_link_t **link, args_t *args,
|
||||
unsigned long flags, casio_streamattrs_t *attrs);
|
||||
|
||||
/* Main functions. */
|
||||
extern int prepare(args_t *args);
|
||||
extern int backup_rom(args_t *args);
|
||||
extern int fxremote_flash(args_t *args);
|
||||
|
||||
#endif /* MAIN_H */
|
||||
|
|
|
@ -1,57 +0,0 @@
|
|||
/* *****************************************************************************
|
||||
* p7os/prepare.c -- p7os update.exe uploading utility.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of p7utils.
|
||||
* p7utils is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* p7utils 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#include "main.h"
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Embedded update.exe */
|
||||
/* ************************************************************************** */
|
||||
#define cake_exe_str ((char*)&_binary_cake_exe_bin_start)
|
||||
#define cake_exe_end ((char*)&_binary_cake_exe_bin_end)
|
||||
extern char _binary_cake_exe_bin_start[];
|
||||
extern char _binary_cake_exe_bin_end[];
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Main function */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* prepare_ops:
|
||||
* Prepare the operation, by uploading the update.exe.
|
||||
*
|
||||
* @arg handle the libp7 handle.
|
||||
* @arg uexe the update.exe to use (NULL if use the embedded one).
|
||||
* @return the error (-1 if not a libp7 error, 0 if ok)
|
||||
*/
|
||||
|
||||
int prepare_ops(p7_handle_t *handle, FILE *uexe, p7_disp_t disp)
|
||||
{
|
||||
int err;
|
||||
|
||||
/* send the update.exe */
|
||||
if (uexe)
|
||||
err = p7_sendexe_file(handle, uexe, 0x88030000, 0x88030000, disp);
|
||||
else {
|
||||
err = p7_sendexe_mem(handle, cake_exe_str,
|
||||
(size_t)(cake_exe_end - cake_exe_str),
|
||||
0x88030000, 0x88030000, disp);
|
||||
fclose(uexe);
|
||||
}
|
||||
|
||||
/* done! */
|
||||
return (err);
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/* ****************************************************************************
|
||||
* p7os/procs/std_backup.c -- backup the ROM.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of p7utils.
|
||||
* p7utils is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* p7utils 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************* */
|
||||
#include "../main.h"
|
||||
|
||||
/**
|
||||
* backup_rom:
|
||||
* Backup the ROM.
|
||||
*
|
||||
* @arg args the CLI args.
|
||||
* @return the error code (0 if ok).
|
||||
*/
|
||||
|
||||
int backup_rom(args_t *args)
|
||||
{
|
||||
int err; casio_link_t *link = NULL;
|
||||
osdisp_t osdisp_cookie;
|
||||
|
||||
/* Open the link. */
|
||||
err = open_link(&link, args,
|
||||
CASIO_LINKFLAG_ACTIVE | CASIO_LINKFLAG_CHECK | CASIO_LINKFLAG_TERM,
|
||||
NULL);
|
||||
if (err) return (err);
|
||||
|
||||
/* Use the "standard" way. */
|
||||
osdisp_init(&osdisp_cookie, "Gathering the OS...", "Backed up!");
|
||||
err = casio_backup_rom(link, args->local, osdisp, &osdisp_cookie);
|
||||
if (err) { osdisp_interrupt(&osdisp_cookie); goto fail; }
|
||||
osdisp_success(&osdisp_cookie);
|
||||
|
||||
err = 0;
|
||||
fail:
|
||||
casio_close_link(link);
|
||||
return (err);
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/* ****************************************************************************
|
||||
* p7os/procs/std_prepare.c -- upload and run the update.exe.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of p7utils.
|
||||
* p7utils is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* p7utils 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************* */
|
||||
#include "../main.h"
|
||||
|
||||
/**
|
||||
* prepare:
|
||||
* Upload and run the given update.exe.
|
||||
*
|
||||
* @arg args the command-line arguments.
|
||||
* @return the error code (0 if ok).
|
||||
*/
|
||||
|
||||
int prepare(args_t *args)
|
||||
{
|
||||
int err; casio_link_t *link = NULL;
|
||||
osdisp_t osdisp_cookie;
|
||||
casio_off_t usize;
|
||||
|
||||
/* Get the update.exe size. */
|
||||
err = casio_getsize(args->uexe, &usize);
|
||||
if (err) return (err);
|
||||
|
||||
/* Open the link. */
|
||||
err = open_link(&link, args,
|
||||
CASIO_LINKFLAG_ACTIVE | CASIO_LINKFLAG_CHECK, NULL);
|
||||
if (err) goto fail;
|
||||
|
||||
/* Upload and run. */
|
||||
osdisp_init(&osdisp_cookie, "Uploading the Update.Exe...", "Uploaded!");
|
||||
err = casio_upload_and_run(link, args->uexe, usize,
|
||||
0x88024000, 0x88024000, osdisp, &osdisp_cookie);
|
||||
if (err) {
|
||||
/* interrupt loading bar */
|
||||
osdisp_interrupt(&osdisp_cookie);
|
||||
goto fail;
|
||||
}
|
||||
osdisp_success(&osdisp_cookie);
|
||||
|
||||
/* Sleep while the software on the calculator sets up the
|
||||
* communication interface. */
|
||||
printf("Waiting for the Update.Exe to set up the communication...\n");
|
||||
casio_sleep(1000);
|
||||
|
||||
err = 0;
|
||||
fail:
|
||||
if (link) casio_close_link(link);
|
||||
casio_close(args->uexe);
|
||||
return (err);
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/* ****************************************************************************
|
||||
* p7os/utils/open_link.c -- open the link based on cli arguments and other stuff.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of p7utils.
|
||||
* p7utils is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* p7utils 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************* */
|
||||
#include "../main.h"
|
||||
|
||||
/**
|
||||
* open_link:
|
||||
* Open the link using the arguments.
|
||||
*
|
||||
* @arg link the link to open.
|
||||
* @arg args the command-line arguments.
|
||||
* @arg flags the required flags.
|
||||
* @arg attrs the serial attributes.
|
||||
* @return the error code (0 if ok).
|
||||
*/
|
||||
|
||||
int open_link(casio_link_t **link, args_t *args,
|
||||
unsigned long flags, casio_streamattrs_t *attrs)
|
||||
{
|
||||
int err;
|
||||
|
||||
/* Open the link. */
|
||||
if (args->com) err = casio_open_com(link, flags, args->com, attrs);
|
||||
else err = casio_open_usb(link, flags);
|
||||
if (err) return (err);
|
||||
|
||||
/* XXX: `--set`, `--use`? */
|
||||
return (0);
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
/* ****************************************************************************
|
||||
* p7os/utils/osdisp.c -- progress displayer.
|
||||
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
* This file is part of p7utils.
|
||||
* p7utils is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2.0 of the License,
|
||||
* or (at your option) any later version.
|
||||
*
|
||||
* p7utils 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 General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************* */
|
||||
#include "../main.h"
|
||||
#include <string.h>
|
||||
|
||||
/* ************************************************************************* */
|
||||
/* Main function */
|
||||
/* ************************************************************************* */
|
||||
/**
|
||||
* osdisp:
|
||||
* Nice little loading bar.
|
||||
*
|
||||
* Taken from `src/p7/main.c`.
|
||||
* "Initialization" is when id > total (called in main).
|
||||
*
|
||||
* @arg id data packet ID.
|
||||
* @arg total total number of packets.
|
||||
*/
|
||||
|
||||
void osdisp(void *vcookie, unsigned int id, unsigned int total)
|
||||
{
|
||||
osdisp_t *cookie = (void*)vcookie;
|
||||
int current; unsigned int percent;
|
||||
|
||||
/* if is initialize, fill */
|
||||
if (id > total) {
|
||||
/* initialize */
|
||||
strcpy(cookie->buf,
|
||||
"\r|---------------------------------------| 00.00%");
|
||||
cookie->bar = &cookie->buf[2];
|
||||
cookie->pos = 0;
|
||||
cookie->init = 1;
|
||||
|
||||
/* put message and initial buffer. */
|
||||
printf("%s\n%s", cookie->msg, cookie->buf);
|
||||
|
||||
/* save cursor position and we're done */
|
||||
fputs("\x1B[s", stdout);
|
||||
return ;
|
||||
}
|
||||
|
||||
/* id and total start from 1, let them start from zero */
|
||||
id--; total--;
|
||||
|
||||
/* modify buffer */
|
||||
/* - # - */
|
||||
current = 38 * id / total;
|
||||
while (cookie->pos <= current) cookie->bar[cookie->pos++] = '#';
|
||||
/* - % - */
|
||||
percent = 10000 * id / total;
|
||||
sprintf(&cookie->buf[43], "%02u.%02u",
|
||||
percent / 100 % 100, percent % 100);
|
||||
|
||||
/* put it */
|
||||
printf("%s", cookie->buf);
|
||||
/* force cursor position */
|
||||
fputs("\x1B""8", stdout);
|
||||
fflush(stdout);
|
||||
}
|
||||
/* ************************************************************************* */
|
||||
/* Initialization, miscallaneous actions */
|
||||
/* ************************************************************************* */
|
||||
/**
|
||||
* osdisp_init:
|
||||
* Initialize a display cookie.
|
||||
*
|
||||
* @arg cookie the display cookie to initialize.
|
||||
* @arg init the initial message.
|
||||
* @arg success the success message.
|
||||
*/
|
||||
|
||||
void osdisp_init(osdisp_t *cookie, const char *init, const char *success)
|
||||
{
|
||||
cookie->msg = init;
|
||||
cookie->success = success;
|
||||
cookie->init = 0;
|
||||
cookie->pos = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* osdisp_interrupt:
|
||||
* End with an error.
|
||||
*
|
||||
* @arg cookie the display cookie.
|
||||
*/
|
||||
|
||||
void osdisp_interrupt(osdisp_t *cookie)
|
||||
{
|
||||
/* interrupt loading bar */
|
||||
if (cookie->init)
|
||||
printf("\b\b\b\b\b\bError!\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* osdisp_success:
|
||||
* End with a success.
|
||||
*
|
||||
* @arg cookie the display cookie.
|
||||
*/
|
||||
|
||||
void osdisp_success(osdisp_t *cookie)
|
||||
{
|
||||
printf("\b\b\b\b\b\b%s\n", cookie->success);
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/make -f
|
||||
disable:
|
||||
libs:
|
||||
@echo libp7
|
||||
@echo libcasio
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* *****************************************************************************
|
||||
/* ****************************************************************************
|
||||
* p7screen/args.c -- p7screen argument parsing.
|
||||
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
||||
*
|
||||
|
@ -15,15 +15,15 @@
|
|||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
* ************************************************************************* */
|
||||
#include "main.h"
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <getopt.h>
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Help and version messages */
|
||||
/* ************************************************************************** */
|
||||
/* ************************************************************************* */
|
||||
/* Help and version messages */
|
||||
/* ************************************************************************* */
|
||||
/* Version message */
|
||||
static const char version_message[] =
|
||||
QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) " (licensed under GPLv2)\n"
|
||||
|
@ -34,22 +34,75 @@ QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION) " (licensed under GPLv2)\n
|
|||
"FITNESS FOR A PARTICULAR PURPOSE.";
|
||||
|
||||
/* Help message */
|
||||
static const char help_main[] =
|
||||
static const char help_main0[] =
|
||||
"Usage: " QUOTE(BIN) " [--help|-h] [--version|-v]\n"
|
||||
"\n"
|
||||
"Displays the streamed screen from a CASIO fx calculator.\n"
|
||||
"\n"
|
||||
"Options are:\n"
|
||||
" -h, --help Display this help page\n"
|
||||
" -v, --version Displays the version\n"
|
||||
" -v, --version Displays the version\n";
|
||||
|
||||
static const char help_log[] =
|
||||
" --log <level> The library log level (default: %s).\n"
|
||||
" One of: %s";
|
||||
|
||||
static const char help_main1[] =
|
||||
" -z ZOOM Change the zoom (1 to 16)\n"
|
||||
" By default, the zoom will be " QUOTE(DEFAULT_ZOOM) ".\n"
|
||||
"\n"
|
||||
"Report bugs to " QUOTE(MAINTAINER) ".";
|
||||
"Report bugs to " QUOTE(MAINTAINER) ".\n";
|
||||
/* ************************************************************************* */
|
||||
/* Main function */
|
||||
/* ************************************************************************* */
|
||||
/**
|
||||
* put_loglevel:
|
||||
* Put a loglevel (for listing).
|
||||
*
|
||||
* @arg first the first log level.
|
||||
* @arg level the level string.
|
||||
*/
|
||||
|
||||
static void put_loglevel(char **first, const char *level)
|
||||
{
|
||||
if (!*first) {
|
||||
*first = malloc(strlen(level) + 2);
|
||||
if (!*first) return ;
|
||||
strcpy(*first + 1, level);
|
||||
**first = 'F';
|
||||
return ;
|
||||
}
|
||||
|
||||
if (**first == 'F') {
|
||||
printf(help_log, casio_getlog(), *first + 1);
|
||||
**first = 'N';
|
||||
}
|
||||
|
||||
printf(", %s", level);
|
||||
}
|
||||
|
||||
/**
|
||||
* put_help:
|
||||
* Put the help message.
|
||||
*/
|
||||
|
||||
static void put_help(void)
|
||||
{
|
||||
char *first;
|
||||
|
||||
/* first big part */
|
||||
fputs(help_main0, stdout);
|
||||
|
||||
/* loglevels */
|
||||
first = NULL;
|
||||
casio_listlog((casio_log_list_t*)&put_loglevel, (void*)&first);
|
||||
if (first && *first == 'N') fputc('\n', stdout);
|
||||
free(first);
|
||||
|
||||
/* second big part */
|
||||
fputs(help_main1, stdout);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Main function */
|
||||
/* ************************************************************************** */
|
||||
/**
|
||||
* parse_args:
|
||||
* Args parsing main function.
|
||||
|
@ -74,14 +127,16 @@ int parse_args(int ac, char **av, int *zoom)
|
|||
{"help", no_argument, NULL, 'h'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"zoom", required_argument, NULL, 'z'},
|
||||
{"log", required_argument, NULL, 'l'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
/* get all options */
|
||||
int c; opterr = 0;
|
||||
int help = 0, version = 0;
|
||||
while ((c = getopt_long(ac, av, short_options, long_options, NULL)) != -1) {
|
||||
switch (c) {
|
||||
const char *s_log = NULL;
|
||||
while ((c = getopt_long(ac, av, short_options, long_options, NULL)) != -1)
|
||||
switch (c) {
|
||||
/* help */
|
||||
case 'h': help = 1; break;
|
||||
/* version */
|
||||
|
@ -95,6 +150,10 @@ int parse_args(int ac, char **av, int *zoom)
|
|||
}
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
s_log = optarg;
|
||||
break;
|
||||
|
||||
/* error (ignore) */
|
||||
case '?':
|
||||
if (optopt == 'z')
|
||||
|
@ -102,16 +161,18 @@ int parse_args(int ac, char **av, int *zoom)
|
|||
else
|
||||
break;
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* check if there is any parameter */
|
||||
if (ac - optind)
|
||||
help = 1;
|
||||
if (ac - optind) help = 1;
|
||||
|
||||
/* set the log level */
|
||||
if (s_log)
|
||||
casio_setlog(s_log);
|
||||
|
||||
/* print help or version if required, and return */
|
||||
if (version) puts(version_message);
|
||||
else if (help) puts(help_main);
|
||||
else if (help) put_help();
|
||||
else return (0);
|
||||
return (1);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <string.h>
|
||||
#include <libp7.h>
|
||||
#include <SDL.h>
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
@ -56,35 +55,38 @@ static int zoom;
|
|||
* display_callback:
|
||||
* The main callback for screen streaming.
|
||||
*
|
||||
* @arg w the width of the received image
|
||||
* @arg h the height of the received image
|
||||
* @arg pixels the image data
|
||||
* @return if reception should continue
|
||||
* @arg vcookie the cookie (unused).
|
||||
* @arg w the width of the received image
|
||||
* @arg h the height of the received image
|
||||
* @arg pixels the image data
|
||||
*/
|
||||
|
||||
static int display_callback(int w, int h, uint32_t **pixels)
|
||||
static void display_callback(void *vcookie,
|
||||
int w, int h, casio_uint32_t **pixels)
|
||||
{
|
||||
/* create screen if there isn't one */
|
||||
static SDL_Surface *screen = NULL;
|
||||
static int saved_w = 0, saved_h = 0;
|
||||
|
||||
(void)vcookie;
|
||||
/* Create screen if there isn't one. */
|
||||
if (!screen || saved_w != w || saved_h != h) {
|
||||
/* create the window */
|
||||
/* Create the window. */
|
||||
if (!(screen = SDL_SetVideoMode(w * zoom, h * zoom, 32,
|
||||
SDL_SWSURFACE | SDL_DOUBLEBUF))) {
|
||||
SDL_SWSURFACE | SDL_DOUBLEBUF))) {
|
||||
log("Couldn't set video mode: %s\n", SDL_GetError());
|
||||
return (0);
|
||||
return ;
|
||||
}
|
||||
SDL_WM_SetCaption("P7screen", NULL);
|
||||
|
||||
/* save data and display message */
|
||||
/* Save data and display message. */
|
||||
saved_w = w; saved_h = h;
|
||||
puts("Turn off your calculator (SHIFT+AC) when you have finished.");
|
||||
}
|
||||
|
||||
/* edit screen */
|
||||
/* - lock it - */
|
||||
/* Lock the screen. */
|
||||
SDL_LockSurface(screen);
|
||||
/* - copy - */
|
||||
|
||||
/* Copy the data. */
|
||||
uint32_t *px = (uint32_t*)screen->pixels;
|
||||
int linesize = w * zoom;
|
||||
for (int y = 0; y < h; y++) {
|
||||
|
@ -99,16 +101,11 @@ static int display_callback(int w, int h, uint32_t **pixels)
|
|||
px += linesize;
|
||||
}
|
||||
}
|
||||
/* - unlock it - */
|
||||
|
||||
/* Unlock the screen, and flippin' flip it. */
|
||||
SDL_UnlockSurface(screen);
|
||||
|
||||
/* update screen */
|
||||
SDL_Flip(screen);
|
||||
|
||||
/* continue! */
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Main function */
|
||||
/* ************************************************************************** */
|
||||
|
@ -123,19 +120,19 @@ static int display_callback(int w, int h, uint32_t **pixels)
|
|||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int err; casio_link_t *handle = NULL;
|
||||
|
||||
/* parse args */
|
||||
if (parse_args(ac, av, &zoom))
|
||||
return (0);
|
||||
|
||||
/* Initialize libp7 */
|
||||
p7_handle_t *handle = NULL; int err;
|
||||
err = p7_init(&handle, 0);
|
||||
if (err) {
|
||||
/* Make the libcasio link handle. */
|
||||
if ((err = casio_open_usb(&handle, 0))) {
|
||||
/* display error */
|
||||
switch (err) {
|
||||
case p7_error_nocalc: log(error_noconnexion); break;
|
||||
case p7_error_noaccess: log(error_noaccess); break;
|
||||
default: log(error_unplanned, p7_strerror(err)); break;
|
||||
case casio_error_nocalc: log(error_noconnexion); break;
|
||||
case casio_error_noaccess: log(error_noaccess); break;
|
||||
default: log(error_unplanned, casio_strerror(err)); break;
|
||||
}
|
||||
|
||||
/* return */
|
||||
|
@ -150,17 +147,17 @@ int main(int ac, char **av)
|
|||
atexit(SDL_Quit);
|
||||
|
||||
/* receive screen */
|
||||
if ((err = p7_getscreen(handle, &display_callback))
|
||||
&& err != p7_error_nocalc) {
|
||||
if ((err = casio_getscreen(handle, &display_callback, NULL))
|
||||
&& err != casio_error_nocalc) {
|
||||
switch (err) {
|
||||
case p7_error_timeout: log(error_noconnexion); break;
|
||||
default: log(error_unplanned, p7_strerror(err)); break;
|
||||
case casio_error_timeout: log(error_noconnexion); break;
|
||||
default: log(error_unplanned, casio_strerror(err)); break;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* close */
|
||||
p7_exit(handle);
|
||||
casio_close_link(handle);
|
||||
|
||||
/* everything went well */
|
||||
return (0);
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
#ifndef MAIN_H
|
||||
# define MAIN_H
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <libcasio.h>
|
||||
# define Q(x) #x
|
||||
# define QUOTE(x) Q(x)
|
||||
# define log(S, ...) fprintf(stderr, S, ##__VA_ARGS__)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
#!/usr/bin/make -f
|
||||
libs:
|
||||
@echo libp7 sdl
|
||||
@echo libcasio sdl
|
||||
|
|
|
@ -38,7 +38,7 @@ QUOTE(BIN) " - from " QUOTE(NAME) " v" QUOTE(VERSION)
|
|||
static const char help_main[] =
|
||||
"Usage: " QUOTE(BIN) " [--help] [--version]\n"
|
||||
"\n"
|
||||
"This utility is only there to test the libp7 server feature.\n"
|
||||
"This utility is only there to test the libcasio server feature.\n"
|
||||
"It should not be used in production for anything else.\n"
|
||||
"\n"
|
||||
"General options:\n"
|
||||
|
|
|
@ -17,36 +17,35 @@
|
|||
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
||||
* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <libp7.h>
|
||||
#include <libp7/packetio.h>
|
||||
#include <libp7/stream.h>
|
||||
|
||||
int run_client(int in, int out)
|
||||
{
|
||||
int err; casio_link_t *link = NULL;
|
||||
casio_stream_t *stream = NULL;
|
||||
|
||||
/* make the stream */
|
||||
p7_stream_t stream;
|
||||
int err = p7_sopen_streams(&stream, NULL, in, out);
|
||||
err = casio_open_stream_fd(&stream, in, out, 1, 1);
|
||||
if (err) {
|
||||
fprintf(stderr, "Client stream initialization has encountered "
|
||||
"an error: %s\n", p7_strerror(err));
|
||||
"an error: %s\n", casio_strerror(err));
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* make the handle */
|
||||
p7_handle_t *handle = NULL;
|
||||
err = p7_sinit(&handle, p7_flag_active | p7_flag_check | p7_flag_term,
|
||||
"client", &stream, NULL);
|
||||
err = casio_open_link(&link,
|
||||
CASIO_LINKFLAG_ACTIVE | CASIO_LINKFLAG_CHECK | CASIO_LINKFLAG_TERM,
|
||||
stream, NULL);
|
||||
if (err) {
|
||||
fprintf(stderr, "Client initialization has encountered an error: %s\n",
|
||||
p7_strerror(err));
|
||||
casio_strerror(err));
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* change working directory. */
|
||||
p7_seven_send_cmdfls_cwd(handle, "oui", "fls0");
|
||||
p7_seven_send_cmdfls_cwd(handle, "non", "fls0");
|
||||
casio_seven_send_cmdfls_cwd(link, "oui", "fls0");
|
||||
casio_seven_send_cmdfls_cwd(link, "non", "fls0");
|
||||
|
||||
/* we're done. */
|
||||
p7_exit(handle);
|
||||
casio_close_link(link);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <unistd.h>
|
||||
#include <libp7.h>
|
||||
|
||||
/**
|
||||
* init:
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#ifndef MAIN_H
|
||||
# define MAIN_H
|
||||
# include <stdio.h>
|
||||
# include <libp7/streams.h>
|
||||
# include <libcasio.h>
|
||||
|
||||
int parse_args(int ac, char **av);
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
* ************************************************************************** */
|
||||
#include "main.h"
|
||||
#include <string.h>
|
||||
#include <libp7.h>
|
||||
#include <libp7/stream.h>
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Server callbacks */
|
||||
|
@ -41,48 +39,49 @@ static int directory_exists(void *cookie, const char *dirname)
|
|||
/* check directory name */
|
||||
if (!strcmp(dirname, "oui"))
|
||||
return (0);
|
||||
else return (p7_error_notfound);
|
||||
else return (casio_error_notfound);
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Server configuration */
|
||||
/* ************************************************************************** */
|
||||
/* the server information */
|
||||
static p7_server_t server_information = {
|
||||
static casio_link_info_t server_information = {
|
||||
/* main calculator information */
|
||||
.cpuid = "The CPU ID, wow!",
|
||||
.hwid = "TESTSERV",
|
||||
.product_id = "OMGOMGOMGOMGOMGO",
|
||||
.casio_link_info_cpuid = "The CPU ID, wow!",
|
||||
.casio_link_info_hwid = "TESTSERV",
|
||||
.casio_link_info_product_id = "OMGOMGOMGOMGOMGO",
|
||||
|
||||
/* system configuration */
|
||||
.username = "Cow",
|
||||
.casio_link_info_username = "Cow",
|
||||
|
||||
/* preprogrammed ROM information */
|
||||
.preprog_rom_wiped = 1,
|
||||
/* wiped things */
|
||||
.casio_link_info_wiped =
|
||||
casio_link_info_wiped_preprog | casio_link_info_wiped_bootcode,
|
||||
|
||||
/* flash ROM and RAM information */
|
||||
.flash_rom_capacity = 8 * 1024 * 1024,
|
||||
.ram_capacity = 256 * 1024,
|
||||
|
||||
/* bootcode information */
|
||||
.bootcode_wiped = 1,
|
||||
.casio_link_info_flash_rom_capacity = 8 * 1024 * 1024,
|
||||
.casio_link_info_ram_capacity = 256 * 1024,
|
||||
|
||||
/* OS information */
|
||||
.os_offset = 0x80000000, .os_size = 0x100000,
|
||||
.os_version = {
|
||||
.major = 2, .minor = 9, .rev = 2201
|
||||
.casio_link_info_os_offset = 0x80000000,
|
||||
.casio_link_info_os_size = 0x100000,
|
||||
.casio_link_info_os_version = {
|
||||
.casio_version_major = 2, .casio_version_minor = 9,
|
||||
.casio_version_zone = casio_version_zone_fr,
|
||||
.casio_version_math = casio_version_math_all,
|
||||
.casio_version_status = casio_version_status_standard,
|
||||
.casio_version_platform = casio_version_platform_special
|
||||
},
|
||||
};
|
||||
|
||||
/* the server filesystems */
|
||||
static p7_filesystem_t server_filesystems[] = {
|
||||
static casio_filesystem_t server_filesystems[] = {
|
||||
/* main filesystem: the flash */ {
|
||||
.name = "fls0",
|
||||
.directory_exists = directory_exists
|
||||
.casio_filesystem_name = "fls0",
|
||||
.casio_filesystem_directory_exists = directory_exists
|
||||
},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
/* ************************************************************************** */
|
||||
/* Server functions */
|
||||
/* ************************************************************************** */
|
||||
|
@ -96,9 +95,11 @@ static p7_filesystem_t server_filesystems[] = {
|
|||
|
||||
int run_server(int in, int out)
|
||||
{
|
||||
int err; casio_link_t *handle = NULL;
|
||||
casio_stream_t *stream = NULL;
|
||||
|
||||
/* make the stream */
|
||||
p7_stream_t stream;
|
||||
int err = p7_sopen_streams(&stream, NULL, in, out);
|
||||
err = casio_open_stream_fd(stream, in, out, 1, 1);
|
||||
if (err) {
|
||||
fprintf(stderr, "Server stream initialization has encountered "
|
||||
"an error: %s\n", p7_strerror(err));
|
||||
|
@ -106,8 +107,7 @@ int run_server(int in, int out)
|
|||
}
|
||||
|
||||
/* make the handle */
|
||||
p7_handle_t *handle = NULL;
|
||||
err = p7_sinit(&handle, 0, "server", &stream, NULL);
|
||||
err = casio_open_link(&handle, 0, stream, NULL);
|
||||
if (err) {
|
||||
fprintf(stderr, "Server initialization has encountered an error: %s\n",
|
||||
p7_strerror(err));
|
||||
|
@ -115,7 +115,7 @@ int run_server(int in, int out)
|
|||
}
|
||||
|
||||
/* protect and serve */
|
||||
p7_serve(handle, &server_information, server_filesystems);
|
||||
p7_exit(handle);
|
||||
casio_serve(handle, &server_information, server_filesystems);
|
||||
casio_close_link(handle);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/make -f
|
||||
disable:
|
||||
libs:
|
||||
@echo libp7
|
||||
@echo libcasio
|
||||
|
|
Reference in New Issue