Merge git://github.com/libdivecomputer/libdivecomputer into Subsurface-NG

Merge with upstream from Jef.

Small trivial fixlets.

* 'master' of git://github.com/libdivecomputer/libdivecomputer:
  Fix the Cobalt 2 memory size
  Use the travis homebrew plugin to install packages
  Increase the internal log buffer
  Fix undefined behaviour in left shifts
This commit is contained in:
Linus Torvalds 2018-12-17 09:32:47 -08:00
commit e4c96e93ca
4 changed files with 38 additions and 17 deletions

View File

@ -37,11 +37,10 @@ addons:
packages: packages:
- libbluetooth-dev - libbluetooth-dev
- libusb-1.0-0-dev - libusb-1.0-0-dev
homebrew:
install: packages:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then - hidapi
brew install hidapi libusb; - libusb
fi
script: script:
- case $CC in - case $CC in

View File

@ -167,7 +167,7 @@ array_uint_be (const unsigned char data[], unsigned int n)
unsigned int value = 0; unsigned int value = 0;
for (unsigned int i = 0; i < n; ++i) { for (unsigned int i = 0; i < n; ++i) {
shift -= 8; shift -= 8;
value |= data[i] << shift; value |= (unsigned int) data[i] << shift;
} }
return value; return value;
} }
@ -178,7 +178,7 @@ array_uint_le (const unsigned char data[], unsigned int n)
unsigned int shift = 0; unsigned int shift = 0;
unsigned int value = 0; unsigned int value = 0;
for (unsigned int i = 0; i < n; ++i) { for (unsigned int i = 0; i < n; ++i) {
value |= data[i] << shift; value |= (unsigned int) data[i] << shift;
shift += 8; shift += 8;
} }
return value; return value;
@ -187,21 +187,30 @@ array_uint_le (const unsigned char data[], unsigned int n)
unsigned int unsigned int
array_uint32_be (const unsigned char data[]) array_uint32_be (const unsigned char data[])
{ {
return (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3]; return ((unsigned int) data[0] << 24) |
((unsigned int) data[1] << 16) |
((unsigned int) data[2] << 8) |
((unsigned int) data[3] << 0);
} }
unsigned int unsigned int
array_uint32_le (const unsigned char data[]) array_uint32_le (const unsigned char data[])
{ {
return data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24); return ((unsigned int) data[0] << 0) |
((unsigned int) data[1] << 8) |
((unsigned int) data[2] << 16) |
((unsigned int) data[3] << 24);
} }
unsigned int unsigned int
array_uint32_word_be (const unsigned char data[]) array_uint32_word_be (const unsigned char data[])
{ {
return data[1] + (data[0] << 8) + (data[3] << 16) + (data[2] << 24); return ((unsigned int) data[0] << 8) |
((unsigned int) data[1] << 0) |
((unsigned int) data[2] << 24) |
((unsigned int) data[3] << 16);
} }
@ -218,7 +227,9 @@ array_uint32_le_set (unsigned char data[], const unsigned int input)
unsigned int unsigned int
array_uint24_be (const unsigned char data[]) array_uint24_be (const unsigned char data[])
{ {
return (data[0] << 16) + (data[1] << 8) + data[2]; return ((unsigned int) data[0] << 16) |
((unsigned int) data[1] << 8) |
((unsigned int) data[2] << 0);
} }
@ -234,20 +245,24 @@ array_uint24_be_set (unsigned char data[], const unsigned int input)
unsigned int unsigned int
array_uint24_le (const unsigned char data[]) array_uint24_le (const unsigned char data[])
{ {
return data[0] + (data[1] << 8) + (data[2] << 16); return ((unsigned int) data[0] << 0) |
((unsigned int) data[1] << 8) |
((unsigned int) data[2] << 16);
} }
unsigned short unsigned short
array_uint16_be (const unsigned char data[]) array_uint16_be (const unsigned char data[])
{ {
return (data[0] << 8) + data[1]; return ((unsigned int) data[0] << 8) |
((unsigned int) data[1] << 0);
} }
unsigned short unsigned short
array_uint16_le (const unsigned char data[]) array_uint16_le (const unsigned char data[])
{ {
return data[0] + (data[1] << 8); return ((unsigned int) data[0] << 0) |
((unsigned int) data[1] << 8);
} }
unsigned char unsigned char

View File

@ -43,13 +43,17 @@
#define EXITCODE(rc) (rc == LIBUSB_ERROR_TIMEOUT ? DC_STATUS_TIMEOUT : DC_STATUS_IO) #define EXITCODE(rc) (rc == LIBUSB_ERROR_TIMEOUT ? DC_STATUS_TIMEOUT : DC_STATUS_IO)
#define COBALT1 0
#define COBALT2 2
#define VID 0x0471 #define VID 0x0471
#define PID 0x0888 #define PID 0x0888
#define TIMEOUT 2000 #define TIMEOUT 2000
#define FP_OFFSET 20 #define FP_OFFSET 20
#define SZ_MEMORY (29 * 64 * 1024) #define SZ_MEMORY1 (29 * 64 * 1024) // Cobalt 1
#define SZ_MEMORY2 (41 * 64 * 1024) // Cobalt 2
#define SZ_VERSION 14 #define SZ_VERSION 14
typedef struct atomics_cobalt_device_t { typedef struct atomics_cobalt_device_t {
@ -350,9 +354,12 @@ atomics_cobalt_device_foreach (dc_device_t *abstract, dc_dive_callback_t callbac
{ {
atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract; atomics_cobalt_device_t *device = (atomics_cobalt_device_t *) abstract;
// Get the model number.
unsigned int model = array_uint16_le (device->version + 12);
// Enable progress notifications. // Enable progress notifications.
dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER; dc_event_progress_t progress = EVENT_PROGRESS_INITIALIZER;
progress.maximum = SZ_MEMORY + 2; progress.maximum = (model == COBALT2 ? SZ_MEMORY2 : SZ_MEMORY1) + 2;
device_event_emit (abstract, DC_EVENT_PROGRESS, &progress); device_event_emit (abstract, DC_EVENT_PROGRESS, &progress);
// Emit a vendor event. // Emit a vendor event.

View File

@ -41,7 +41,7 @@ struct dc_context_t {
dc_logfunc_t logfunc; dc_logfunc_t logfunc;
void *userdata; void *userdata;
#ifdef ENABLE_LOGGING #ifdef ENABLE_LOGGING
char msg[8192 + 32]; char msg[16384 + 32];
dc_timer_t *timer; dc_timer_t *timer;
#endif #endif
}; };