diff --git a/Librador_API/___librador/librador_shared_library/librador.cpp b/Librador_API/___librador/librador_shared_library/librador.cpp index 25dc2931..c01a93e2 100644 --- a/Librador_API/___librador/librador_shared_library/librador.cpp +++ b/Librador_API/___librador/librador_shared_library/librador.cpp @@ -119,6 +119,26 @@ std::vector * librador_get_analog_data_sincelast(int channel, double tim } +std::vector * librador_get_digital_data_sincelast(int channel, double timeWindow_max_seconds, double sample_rate_hz, double delay_seconds){ + VECTOR_API_INIT_CHECK + VECTOR_USB_INIT_CHECK + + double subsamples_per_second = internal_librador_object->usb_driver->get_samples_per_second() * 8; + + if(subsamples_per_second == 0){ + return NULL; + } + + + int interval_subsamples = round(subsamples_per_second / sample_rate_hz); + int feasible_window_end = round(delay_seconds * subsamples_per_second); + int feasible_window_begin = round((delay_seconds + timeWindow_max_seconds) * subsamples_per_second); + + printf("interval_subsamples = %d\nfeasible_window_end = %d\nfeasible_window_begin = %d\n", interval_subsamples, feasible_window_end, feasible_window_begin); + + return internal_librador_object->usb_driver->getMany_singleBit_sincelast(channel, feasible_window_begin, feasible_window_end, interval_subsamples); +} + int librador_reset_usb(){ CHECK_API_INITIALISED diff --git a/Librador_API/___librador/librador_shared_library/librador.h b/Librador_API/___librador/librador_shared_library/librador.h index 657eb645..4780d88d 100644 --- a/Librador_API/___librador/librador_shared_library/librador.h +++ b/Librador_API/___librador/librador_shared_library/librador.h @@ -42,6 +42,7 @@ uint8_t LIBRADORSHARED_EXPORT librador_get_device_firmware_variant(); std::vector * LIBRADORSHARED_EXPORT librador_get_analog_data(int channel, double timeWindow_seconds, double sample_rate_hz, double delay_seconds, int filter_mode); std::vector * LIBRADORSHARED_EXPORT librador_get_analog_data_sincelast(int channel, double timeWindow_max_seconds, double sample_rate_hz, double delay_seconds, int filter_mode); std::vector * LIBRADORSHARED_EXPORT librador_get_digital_data(int channel, double timeWindow_seconds, double sample_rate_hz, double delay_seconds); +std::vector * LIBRADORSHARED_EXPORT librador_get_digital_data_sincelast(int channel, double timeWindow_seconds, double sample_rate_hz, double delay_seconds); //TODO: flashFirmware(); diff --git a/Librador_API/___librador/librador_shared_library/o1buffer.cpp b/Librador_API/___librador/librador_shared_library/o1buffer.cpp index 92e80f7b..e4dc748f 100644 --- a/Librador_API/___librador/librador_shared_library/o1buffer.cpp +++ b/Librador_API/___librador/librador_shared_library/o1buffer.cpp @@ -143,6 +143,54 @@ std::vector *o1buffer::getMany_singleBit(int numToGet, int interval_sub return &convertedStream_digital; } +std::vector *o1buffer::getSinceLast_singleBit(int feasible_window_begin, int feasible_window_end, int interval_subsamples) { + //Calculate what sample the feasible window begins at + //printf_debugging("o1buffer::getSinceLast()\n") + int feasible_start_point = mostRecentAddress * 8 - feasible_window_begin; + if(feasible_start_point < 0){ + feasible_start_point += NUM_SAMPLES_PER_CHANNEL * 8; + } + + //Work out whether or not we're starting from the feasible window or the last point + int actual_start_point; + if(distanceFromMostRecentAddress(feasible_start_point / 8) > distanceFromMostRecentAddress(stream_index_at_last_call + interval_subsamples / 8)){ + actual_start_point = stream_index_at_last_call * 8 + interval_subsamples; + } else { + actual_start_point = feasible_start_point; + } + + //Work out how much we're copying + int actual_sample_distance = distanceFromMostRecentAddress(actual_start_point / 8) - distanceFromMostRecentAddress(mostRecentAddress - feasible_window_end / 8); + int numToGet = actual_sample_distance / interval_subsamples; + //printf_debugging("Fetching %d samples, starting at index %d with interval %d\n", numToGet, actual_start_point, interval_samples); + + //Resize the vector + convertedStream_digital.resize(numToGet); + + //Copy raw samples out. + int tempAddress; + int subsample_current_delay; + uint8_t mask; + uint8_t *data = convertedStream_digital.data(); + int tempInt; + + for(int i=0;i *o1buffer::getSinceLast(int feasible_window_begin, int feasible_window_end, int interval_samples, int filter_mode, double scope_gain, bool AC, bool twelve_bit_multimeter){ //Calculate what sample the feasible window begins at diff --git a/Librador_API/___librador/librador_shared_library/o1buffer.h b/Librador_API/___librador/librador_shared_library/o1buffer.h index 5bbbeed8..0bf0469a 100644 --- a/Librador_API/___librador/librador_shared_library/o1buffer.h +++ b/Librador_API/___librador/librador_shared_library/o1buffer.h @@ -25,6 +25,7 @@ public: std::vector *getMany_double(int numToGet, int interval_samples, int delay_sample, int filter_mode, double scope_gain, bool AC, bool twelve_bit_multimeter); std::vector *getMany_singleBit(int numToGet, int interval_subsamples, int delay_subsamples); std::vector *getSinceLast(int feasible_window_begin, int feasible_window_end, int interval_samples, int filter_mode, double scope_gain, bool AC, bool twelve_bit_multimeter); + std::vector *getSinceLast_singleBit(int feasible_window_begin, int feasible_window_end, int interval_subsamples); double vcc = 3.3; double frontendGain = (75.0/1075.0); double voltage_ref = 1.65; diff --git a/Librador_API/___librador/librador_shared_library/usbcallhandler.cpp b/Librador_API/___librador/librador_shared_library/usbcallhandler.cpp index 965ceb7c..40531cbf 100644 --- a/Librador_API/___librador/librador_shared_library/usbcallhandler.cpp +++ b/Librador_API/___librador/librador_shared_library/usbcallhandler.cpp @@ -370,6 +370,26 @@ std::vector *usbCallHandler::getMany_sincelast(int channel, int feasible } +std::vector * usbCallHandler::getMany_singleBit_sincelast(int channel, int feasible_window_begin, int feasible_window_end, int interval_subsamples){ + std::vector* temp_to_return = NULL; + + buffer_read_write_mutex.lock(); + switch(deviceMode){ + case 1: + if(channel == 1) temp_to_return = internal_o1_buffer_375_CH2->getSinceLast_singleBit(feasible_window_begin, feasible_window_end, interval_subsamples); + break; + case 3: + if(channel == 1) temp_to_return = internal_o1_buffer_375_CH1->getSinceLast_singleBit(feasible_window_begin, feasible_window_end, interval_subsamples); + break; + case 4: + if(channel == 1) temp_to_return = internal_o1_buffer_375_CH1->getSinceLast_singleBit(feasible_window_begin, feasible_window_end, interval_subsamples); + else if (channel == 2) temp_to_return = internal_o1_buffer_375_CH2->getSinceLast_singleBit(feasible_window_begin, feasible_window_end, interval_subsamples); + break; + } + buffer_read_write_mutex.unlock(); + return temp_to_return; +} + int usbCallHandler::send_device_reset(){ libusb_reset_device(handle); return 0; diff --git a/Librador_API/___librador/librador_shared_library/usbcallhandler.h b/Librador_API/___librador/librador_shared_library/usbcallhandler.h index f9f2cbe1..d5179542 100644 --- a/Librador_API/___librador/librador_shared_library/usbcallhandler.h +++ b/Librador_API/___librador/librador_shared_library/usbcallhandler.h @@ -68,6 +68,7 @@ public: std::vector *getMany_double(int channel, int numToGet, int interval_samples, int delay_sample, int filter_mode); std::vector * getMany_singleBit(int channel, int numToGet, int interval_subsamples, int delay_subsamples); std::vector *getMany_sincelast(int channel, int feasible_window_begin, int feasible_window_end, int interval_samples, int filter_mode); + std::vector * getMany_singleBit_sincelast(int channel, int feasible_window_begin, int feasible_window_end, int interval_subsamples); bool connected = false; //Control Commands int set_device_mode(int mode);