| 1 |
/* Hey EMACS -*- linux-c -*- */ |
| 2 |
/* $Id: data_log.c 1720 2006-01-20 22:34:58Z roms $ */ |
| 3 |
|
| 4 |
/* libticables2 - link cable library, a part of the TiLP project |
| 5 |
* Copyright (C) 1999-2005 Romain Lievin |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software Foundation, |
| 19 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
/* |
| 23 |
D-USB logging (taken from my TI link guide (hex2nsp program). |
| 24 |
*/ |
| 25 |
|
| 26 |
#ifdef HAVE_CONFIG_H |
| 27 |
#include <config.h> |
| 28 |
#endif |
| 29 |
|
| 30 |
#include <stdio.h> |
| 31 |
#include <string.h> |
| 32 |
#include <glib.h> |
| 33 |
#include <glib/gstdio.h> |
| 34 |
|
| 35 |
#include "logging.h" |
| 36 |
#include "data_log.h" |
| 37 |
#include "log_nsp.h" |
| 38 |
#include "internal.h" |
| 39 |
|
| 40 |
#define LOG_NSP_FILE "ticables-nsp.pkt" |
| 41 |
|
| 42 |
static char *ifn = NULL; |
| 43 |
static char *ofn = NULL; |
| 44 |
|
| 45 |
int log_nsp_start(void) |
| 46 |
{ |
| 47 |
ifn = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, LOG_DIR, G_DIR_SEPARATOR_S, HEX_FILE, NULL); |
| 48 |
ofn = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, LOG_DIR, G_DIR_SEPARATOR_S, LOG_NSP_FILE, NULL); |
| 49 |
|
| 50 |
return 0; |
| 51 |
} |
| 52 |
|
| 53 |
int log_nsp_N(int dir, const uint8_t * data, uint32_t len) |
| 54 |
{ |
| 55 |
return 0; |
| 56 |
} |
| 57 |
|
| 58 |
int log_nsp_stop(void) |
| 59 |
{ |
| 60 |
char *r; |
| 61 |
char * ifn2; |
| 62 |
|
| 63 |
if (!ifn || ! ofn) |
| 64 |
{ |
| 65 |
return 0; |
| 66 |
} |
| 67 |
|
| 68 |
r = strrchr(ifn, '.'); |
| 69 |
if (r) |
| 70 |
{ |
| 71 |
*r = '\0'; |
| 72 |
} |
| 73 |
|
| 74 |
nsp_decomp(ifn); |
| 75 |
ifn2 = g_strconcat(ifn, ".pkt", NULL); |
| 76 |
g_free(ifn); |
| 77 |
ifn = ifn2; |
| 78 |
|
| 79 |
g_unlink(ofn); |
| 80 |
if (g_rename(ifn, ofn) < 0) |
| 81 |
{ |
| 82 |
fprintf(stderr, "Failed to rename output file\n"); |
| 83 |
} |
| 84 |
|
| 85 |
g_free(ifn); |
| 86 |
ifn = NULL; |
| 87 |
g_free(ofn); |
| 88 |
ofn = NULL; |
| 89 |
|
| 90 |
return 0; |
| 91 |
} |