Merge pull request #47 from TitanMKD/master

libhackrf fix and cleanup
This commit is contained in:
Michael Ossmann
2013-05-08 08:43:22 -07:00
3 changed files with 454 additions and 285 deletions

View File

@ -67,15 +67,15 @@
/* WAVE or RIFF WAVE file format containing IQ 2x8bits data for HackRF compatible with SDR# Wav IQ file */ /* WAVE or RIFF WAVE file format containing IQ 2x8bits data for HackRF compatible with SDR# Wav IQ file */
typedef struct typedef struct
{ {
char groupID[4]; /* "RIFF" */ char groupID[4]; /* 'RIFF' */
uint32_t size; /* File size + 8bytes */ uint32_t size; /* File size + 8bytes */
char riffType[4]; /* WAVE */ char riffType[4]; /* 'WAVE'*/
} t_WAVRIFF_hdr; } t_WAVRIFF_hdr;
#define FormatID "fmt " /* chunkID for Format Chunk. NOTE: There is a space at the end of this ID. */ #define FormatID "fmt " /* chunkID for Format Chunk. NOTE: There is a space at the end of this ID. */
typedef struct { typedef struct {
char chunkID[4]; /* "fmt " */ char chunkID[4]; /* 'fmt ' */
uint32_t chunkSize; /* 16 fixed */ uint32_t chunkSize; /* 16 fixed */
uint16_t wFormatTag; /* 1 fixed */ uint16_t wFormatTag; /* 1 fixed */
@ -88,7 +88,7 @@ typedef struct {
typedef struct typedef struct
{ {
char chunkID[4]; /* "data" */ char chunkID[4]; /* 'data' */
uint32_t chunkSize; /* Size of data in bytes */ uint32_t chunkSize; /* Size of data in bytes */
/* Samples I(8bits) then Q(8bits), I, Q ... */ /* Samples I(8bits) then Q(8bits), I, Q ... */
} t_DataChunk; } t_DataChunk;
@ -104,13 +104,13 @@ t_wav_file_hdr wave_file_hdr =
{ {
/* t_WAVRIFF_hdr */ /* t_WAVRIFF_hdr */
{ {
"RIFF", /* groupID */ { 'R', 'I', 'F', 'F' }, /* groupID */
0, /* size to update later */ 0, /* size to update later */
"WAVE" { 'W', 'A', 'V', 'E' }
}, },
/* t_FormatChunk */ /* t_FormatChunk */
{ {
"fmt ", /* char chunkID[4]; */ { 'f', 'm', 't', ' ' }, /* char chunkID[4]; */
16, /* uint32_t chunkSize; */ 16, /* uint32_t chunkSize; */
1, /* uint16_t wFormatTag; 1 fixed */ 1, /* uint16_t wFormatTag; 1 fixed */
2, /* uint16_t wChannels; 2 fixed */ 2, /* uint16_t wChannels; 2 fixed */
@ -121,7 +121,7 @@ t_wav_file_hdr wave_file_hdr =
}, },
/* t_DataChunk */ /* t_DataChunk */
{ {
"data", /* char chunkID[4]; */ { 'd', 'a', 't', 'a' }, /* char chunkID[4]; */
0, /* uint32_t chunkSize; to update later */ 0, /* uint32_t chunkSize; to update later */
} }
}; };
@ -572,8 +572,8 @@ int main(int argc, char** argv) {
gettimeofday(&time_start, NULL); gettimeofday(&time_start, NULL);
printf("Stop with Ctrl-C\n"); printf("Stop with Ctrl-C\n");
while( (hackrf_is_streaming(device)) && while( (hackrf_is_streaming(device) == HACKRF_TRUE) &&
(do_exit == false) ) (do_exit == false) )
{ {
sleep(1); sleep(1);
@ -596,11 +596,14 @@ int main(int argc, char** argv) {
break; break;
} }
} }
if (do_exit) result = hackrf_is_streaming(device);
printf("\nUser cancel, exiting...\n"); if (do_exit)
else {
printf("\nExiting...\n"); printf("\nUser cancel, exiting...\n");
} else {
printf("\nExiting... hackrf_is_streaming() result: %s (%d)\n", hackrf_error_name(result), result);
}
struct timeval t_end; struct timeval t_end;
gettimeofday(&t_end, NULL); gettimeofday(&t_end, NULL);

File diff suppressed because it is too large Load Diff

View File

@ -49,12 +49,16 @@
enum hackrf_error { enum hackrf_error {
HACKRF_SUCCESS = 0, HACKRF_SUCCESS = 0,
HACKRF_TRUE = 1,
HACKRF_ERROR_INVALID_PARAM = -2, HACKRF_ERROR_INVALID_PARAM = -2,
HACKRF_ERROR_NOT_FOUND = -5, HACKRF_ERROR_NOT_FOUND = -5,
HACKRF_ERROR_BUSY = -6, HACKRF_ERROR_BUSY = -6,
HACKRF_ERROR_NO_MEM = -11, HACKRF_ERROR_NO_MEM = -11,
HACKRF_ERROR_LIBUSB = -1000, HACKRF_ERROR_LIBUSB = -1000,
HACKRF_ERROR_THREAD = -1001, HACKRF_ERROR_THREAD = -1001,
HACKRF_ERROR_STREAMING_THREAD_ERR = -1002,
HACKRF_ERROR_STREAMING_STOPPED = -1003,
HACKRF_ERROR_STREAMING_EXIT_CALLED = -1004,
HACKRF_ERROR_OTHER = -9999, HACKRF_ERROR_OTHER = -9999,
}; };
@ -98,8 +102,9 @@ extern ADDAPI int ADDCALL hackrf_stop_rx(hackrf_device* device);
extern ADDAPI int ADDCALL hackrf_start_tx(hackrf_device* device, hackrf_sample_block_cb_fn callback, void* tx_ctx); extern ADDAPI int ADDCALL hackrf_start_tx(hackrf_device* device, hackrf_sample_block_cb_fn callback, void* tx_ctx);
extern ADDAPI int ADDCALL hackrf_stop_tx(hackrf_device* device); extern ADDAPI int ADDCALL hackrf_stop_tx(hackrf_device* device);
extern ADDAPI bool ADDCALL hackrf_is_streaming(hackrf_device* device); /* return HACKRF_TRUE if success */
extern ADDAPI int ADDCALL hackrf_is_streaming(hackrf_device* device);
extern ADDAPI int ADDCALL hackrf_max2837_read(hackrf_device* device, uint8_t register_number, uint16_t* value); extern ADDAPI int ADDCALL hackrf_max2837_read(hackrf_device* device, uint8_t register_number, uint16_t* value);
extern ADDAPI int ADDCALL hackrf_max2837_write(hackrf_device* device, uint8_t register_number, uint16_t value); extern ADDAPI int ADDCALL hackrf_max2837_write(hackrf_device* device, uint8_t register_number, uint16_t value);