From 6ce59a947742d7e2fcd251dc09a4427d53c81e30 Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Sat, 17 Oct 2015 23:18:32 -0400 Subject: [PATCH] Implement getVersion --- tool/gcn64lib.c | 23 +++++++++++++++++++++++ tool/gcn64lib.h | 1 + tool/main.c | 13 +++++++++++++ 3 files changed, 37 insertions(+) diff --git a/tool/gcn64lib.c b/tool/gcn64lib.c index b0c785c..c429511 100644 --- a/tool/gcn64lib.c +++ b/tool/gcn64lib.c @@ -56,6 +56,29 @@ int gcn64lib_suspendPolling(gcn64_hdl_t hdl, unsigned char suspend) return 0; } +int gcn64lib_getVersion(gcn64_hdl_t hdl, char *dst, int dstmax) +{ + unsigned char cmd[64]; + int n; + + if (dstmax <= 0) + return -1; + + cmd[0] = RQ_GCN64_GET_VERSION; + + n = gcn64_exchange(hdl, cmd, 2, cmd, sizeof(cmd)); + if (n<0) + return n; + + dst[0] = 0; + if (n > 1) { + strncpy(dst, (char*)cmd+1, n); + } + dst[dstmax-1] = 0; + + return 0; +} + int gcn64lib_rawSiCommand(gcn64_hdl_t hdl, unsigned char channel, unsigned char *tx, unsigned char tx_len, unsigned char *rx, unsigned char max_rx) { unsigned char cmd[3 + tx_len]; diff --git a/tool/gcn64lib.h b/tool/gcn64lib.h index 7e76699..18b33f2 100644 --- a/tool/gcn64lib.h +++ b/tool/gcn64lib.h @@ -7,6 +7,7 @@ int gcn64lib_suspendPolling(gcn64_hdl_t hdl, unsigned char suspend); int gcn64lib_setConfig(gcn64_hdl_t hdl, unsigned char param, unsigned char *data, unsigned char len); int gcn64lib_getConfig(gcn64_hdl_t hdl, unsigned char param, unsigned char *rx, unsigned char rx_max); int gcn64lib_rawSiCommand(gcn64_hdl_t hdl, unsigned char channel, unsigned char *tx, unsigned char tx_len, unsigned char *rx, unsigned char max_rx); +int gcn64lib_getVersion(gcn64_hdl_t hdl, char *dst, int dstmax); int gcn64lib_8bit_scan(gcn64_hdl_t hdl, unsigned char min, unsigned char max); int gcn64lib_16bit_scan(gcn64_hdl_t hdl, unsigned short min, unsigned short max); diff --git a/tool/main.c b/tool/main.c index 5dadbc3..ff9a47b 100644 --- a/tool/main.c +++ b/tool/main.c @@ -48,6 +48,7 @@ static void printUsage(void) printf(" --nonstop Continue testing forever or until an error occurs.\n"); printf("\n"); printf("Configuration commands:\n"); + printf(" --get_version Read adapter firmware version\n"); printf(" --set_serial serial Assign a new device serial number\n"); printf(" --get_serial Read serial from eeprom\n"); printf(" --set_poll_rate ms Set time between controller polls in milliseconds\n"); @@ -112,6 +113,7 @@ static void printUsage(void) #define OPT_GC_TO_N64_READ_MAPPING 320 #define OPT_GC_TO_N64_LOAD_MAPPING 321 #define OPT_GC_TO_N64_STORE_CURRENT_MAPPING 322 +#define OPT_GET_VERSION 323 struct option longopts[] = { { "help", 0, NULL, 'h' }, @@ -144,6 +146,7 @@ struct option longopts[] = { { "gc_to_n64_load_mapping", 1, NULL, OPT_GC_TO_N64_LOAD_MAPPING }, { "gc_to_n64_store_current_mapping", 1, NULL, OPT_GC_TO_N64_STORE_CURRENT_MAPPING }, { "nonstop", 0, NULL, OPT_NONSTOP }, + { "get_version", 0, NULL, OPT_GET_VERSION }, { }, }; @@ -487,6 +490,16 @@ int main(int argc, char **argv) } } break; + + case OPT_GET_VERSION: + { + char version[64]; + + if (0 == gcn64lib_getVersion(hdl, version, sizeof(version))) { + printf("Firmware version: %s\n", version); + } + } + break; } if (do_exchange) {