Use the result codes in the test application.
This commit is contained in:
parent
8b6db75873
commit
7747a6d4bd
@ -11,43 +11,43 @@ int test_dump_sdm16 (const char* name, const char* filename)
|
||||
|
||||
printf ("suunto_vyper_open\n");
|
||||
int rc = suunto_vyper_open (&device, name);
|
||||
if (rc != 0) {
|
||||
if (rc != SUUNTO_VYPER_SUCCESS) {
|
||||
fprintf (stderr, "%s:%d: Error opening serial port.\n",__FILE__,__LINE__);
|
||||
return 1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
printf ("suunto_vyper_detect_interface\n");
|
||||
rc = suunto_vyper_detect_interface (device);
|
||||
if (rc != 0) {
|
||||
if (rc != SUUNTO_VYPER_SUCCESS) {
|
||||
fprintf (stderr, "%s:%d: Interface not found.\n",__FILE__,__LINE__);
|
||||
suunto_vyper_close (device);
|
||||
return 1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
printf ("suunto_vyper_read_memory\n");
|
||||
rc = suunto_vyper_read_memory (device, 0x24, data + 0x24, 1);
|
||||
if (rc != 0) {
|
||||
if (rc != SUUNTO_VYPER_SUCCESS) {
|
||||
fprintf (stderr, "%s:%d: Cannot identify computer.\n",__FILE__,__LINE__);
|
||||
suunto_vyper_close (device);
|
||||
return 1;
|
||||
return rc;
|
||||
}
|
||||
rc = suunto_vyper_read_memory (device, 0x1E, data + 0x1E, 14);
|
||||
if (rc != 0) {
|
||||
if (rc != SUUNTO_VYPER_SUCCESS) {
|
||||
fprintf (stderr, "Cannot read memory.\n");
|
||||
suunto_vyper_close (device);
|
||||
return 1;
|
||||
return rc;
|
||||
}
|
||||
rc = suunto_vyper_read_memory (device, 0x2C, data + 0x2C, 32);
|
||||
if (rc != 0) {
|
||||
if (rc != SUUNTO_VYPER_SUCCESS) {
|
||||
fprintf (stderr, "Cannot read memory.\n");
|
||||
suunto_vyper_close (device);
|
||||
return 1;
|
||||
return rc;
|
||||
}
|
||||
rc = suunto_vyper_read_memory (device, 0x53, data + 0x53, 30);
|
||||
if (rc != 0) {
|
||||
if (rc != SUUNTO_VYPER_SUCCESS) {
|
||||
fprintf (stderr, "Cannot read memory.\n");
|
||||
suunto_vyper_close (device);
|
||||
return 1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
printf ("suunto_vyper_read_dive\n");
|
||||
@ -56,10 +56,10 @@ int test_dump_sdm16 (const char* name, const char* filename)
|
||||
do {
|
||||
fprintf (stderr, "Reading dive #%d.\n", ndives + 1);
|
||||
rc = suunto_vyper_read_dive (device, data + offset, sizeof (data) - offset, (ndives == 0));
|
||||
if (rc == -1) {
|
||||
if (rc < 0) {
|
||||
fprintf (stderr, "Cannot read dive.\n");
|
||||
suunto_vyper_close (device);
|
||||
return 1;
|
||||
return rc;
|
||||
}
|
||||
fprintf (stderr, "Returned %i bytes at offset 0x%04x.\n", rc, offset);
|
||||
ndives++;
|
||||
@ -75,12 +75,12 @@ int test_dump_sdm16 (const char* name, const char* filename)
|
||||
|
||||
printf ("suunto_vyper_close\n");
|
||||
rc = suunto_vyper_close (device);
|
||||
if (rc != 0) {
|
||||
if (rc != SUUNTO_VYPER_SUCCESS) {
|
||||
fprintf (stderr, "Cannot close device.");
|
||||
return 1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return SUUNTO_VYPER_SUCCESS;
|
||||
}
|
||||
|
||||
int test_dump_memory (const char* name, const char* filename)
|
||||
@ -90,25 +90,25 @@ int test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
printf ("suunto_vyper_open\n");
|
||||
int rc = suunto_vyper_open (&device, name);
|
||||
if (rc != 0) {
|
||||
if (rc != SUUNTO_VYPER_SUCCESS) {
|
||||
fprintf (stderr, "%s:%d: Error opening serial port.\n",__FILE__,__LINE__);
|
||||
return 1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
printf ("suunto_vyper_detect_interface\n");
|
||||
rc = suunto_vyper_detect_interface (device);
|
||||
if (rc != 0) {
|
||||
if (rc != SUUNTO_VYPER_SUCCESS) {
|
||||
fprintf (stderr, "%s:%d: Interface not found.\n",__FILE__,__LINE__);
|
||||
suunto_vyper_close (device);
|
||||
return 1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
printf ("suunto_vyper_read_memory\n");
|
||||
rc = suunto_vyper_read_memory (device, 0x00, data, sizeof (data));
|
||||
if (rc != 0) {
|
||||
if (rc != SUUNTO_VYPER_SUCCESS) {
|
||||
fprintf (stderr, "Cannot read memory.\n");
|
||||
suunto_vyper_close (device);
|
||||
return 1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
printf ("Dumping data\n");
|
||||
@ -120,14 +120,33 @@ int test_dump_memory (const char* name, const char* filename)
|
||||
|
||||
printf ("suunto_vyper_close\n");
|
||||
rc = suunto_vyper_close (device);
|
||||
if (rc != 0) {
|
||||
if (rc != SUUNTO_VYPER_SUCCESS) {
|
||||
fprintf (stderr, "Cannot close device.");
|
||||
return 1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return SUUNTO_VYPER_SUCCESS;
|
||||
}
|
||||
|
||||
const char* errmsg (int rc)
|
||||
{
|
||||
switch (rc) {
|
||||
case SUUNTO_VYPER_SUCCESS:
|
||||
return "Success";
|
||||
case SUUNTO_VYPER_ERROR:
|
||||
return "Generic error";
|
||||
case SUUNTO_VYPER_ERROR_IO:
|
||||
return "Input/output error";
|
||||
case SUUNTO_VYPER_ERROR_MEMORY:
|
||||
return "Memory error";
|
||||
case SUUNTO_VYPER_ERROR_PROTOCOL:
|
||||
return "Protocol error";
|
||||
case SUUNTO_VYPER_ERROR_TIMEOUT:
|
||||
return "Timeout";
|
||||
default:
|
||||
return "Unknown error";
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -146,8 +165,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
printf ("\nSUMMARY\n");
|
||||
printf ("-------\n");
|
||||
printf ("test_dump_sdm16: %s\n", a == 0 ? "SUCCESS" : "FAILED");
|
||||
printf ("test_dump_memory: %s\n", b == 0 ? "SUCCESS" : "FAILED");
|
||||
printf ("test_dump_sdm16: %s\n", errmsg (a));
|
||||
printf ("test_dump_memory: %s\n", errmsg (b));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user