mirror of
https://github.com/steve-m/hsdaoh.git
synced 2025-12-10 07:44:41 +01:00
switch to struct for callback
This commit is contained in:
parent
1fbd15eedc
commit
83342ad691
5 changed files with 31 additions and 6 deletions
|
|
@ -34,6 +34,14 @@ extern "C" {
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <hsdaoh_export.h>
|
#include <hsdaoh_export.h>
|
||||||
|
|
||||||
|
typedef struct hsdaoh_data_info {
|
||||||
|
void *ctx;
|
||||||
|
unsigned char *buf;
|
||||||
|
uint32_t len; /* buffer length */
|
||||||
|
uint16_t stream_id;
|
||||||
|
bool device_error; /* device error happened, terminate application */
|
||||||
|
} hsdaoh_data_info_t;
|
||||||
|
|
||||||
typedef struct hsdaoh_dev hsdaoh_dev_t;
|
typedef struct hsdaoh_dev hsdaoh_dev_t;
|
||||||
|
|
||||||
HSDAOH_API uint32_t hsdaoh_get_device_count(void);
|
HSDAOH_API uint32_t hsdaoh_get_device_count(void);
|
||||||
|
|
@ -89,7 +97,7 @@ HSDAOH_API int hsdaoh_get_usb_strings(hsdaoh_dev_t *dev, char *manufact,
|
||||||
|
|
||||||
/* streaming functions */
|
/* streaming functions */
|
||||||
|
|
||||||
typedef void(*hsdaoh_read_cb_t)(unsigned char *buf, uint32_t len, void *ctx);
|
typedef void(*hsdaoh_read_cb_t)(hsdaoh_data_info_t *data_info);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Start streaming data from the device.
|
* Start streaming data from the device.
|
||||||
|
|
|
||||||
|
|
@ -75,8 +75,11 @@ static void sighandler(int signum)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void hsdaoh_callback(unsigned char *buf, uint32_t len, void *ctx)
|
void hsdaoh_callback(hsdaoh_data_info_t *data_info)
|
||||||
{
|
{
|
||||||
|
unsigned char *buf = data_info->buf;
|
||||||
|
uint32_t len = data_info->len;
|
||||||
|
void *ctx = data_info->ctx;
|
||||||
size_t nbytes = 0;
|
size_t nbytes = 0;
|
||||||
|
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
|
|
|
||||||
|
|
@ -147,8 +147,12 @@ static void sighandler(int signum)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void hsdaoh_callback(unsigned char *buf, uint32_t len, void *ctx)
|
void hsdaoh_callback(hsdaoh_data_info_t *data_info)
|
||||||
{
|
{
|
||||||
|
unsigned char *buf = data_info->buf;
|
||||||
|
uint32_t len = data_info->len;
|
||||||
|
void *ctx = data_info->ctx;
|
||||||
|
|
||||||
if(!do_exit) {
|
if(!do_exit) {
|
||||||
struct llist *rpt = (struct llist*)malloc(sizeof(struct llist));
|
struct llist *rpt = (struct llist*)malloc(sizeof(struct llist));
|
||||||
rpt->data = (char*)malloc(len);
|
rpt->data = (char*)malloc(len);
|
||||||
|
|
|
||||||
|
|
@ -222,8 +222,12 @@ static void ppm_test(uint32_t len)
|
||||||
|
|
||||||
uint16_t last_value = 0;
|
uint16_t last_value = 0;
|
||||||
|
|
||||||
static void hsdaoh_callback(unsigned char *buf, uint32_t len, void *ctx)
|
static void hsdaoh_callback(hsdaoh_data_info_t *data_info)
|
||||||
{
|
{
|
||||||
|
unsigned char *buf = data_info->buf;
|
||||||
|
uint32_t len = data_info->len;
|
||||||
|
void *ctx = data_info->ctx;
|
||||||
|
|
||||||
/* verify the counter value */
|
/* verify the counter value */
|
||||||
uint16_t *cnt = (uint16_t *)buf;
|
uint16_t *cnt = (uint16_t *)buf;
|
||||||
int n = len / sizeof(uint16_t);
|
int n = len / sizeof(uint16_t);
|
||||||
|
|
|
||||||
|
|
@ -601,7 +601,6 @@ void hsdaoh_process_frame(hsdaoh_dev_t *dev, uint8_t *data, int size)
|
||||||
dev->in_order_cnt++;
|
dev->in_order_cnt++;
|
||||||
|
|
||||||
dev->last_frame_cnt = meta.framecounter;
|
dev->last_frame_cnt = meta.framecounter;
|
||||||
|
|
||||||
int frame_errors = 0;
|
int frame_errors = 0;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < dev->height; i++) {
|
for (unsigned int i = 0; i < dev->height; i++) {
|
||||||
|
|
@ -610,6 +609,7 @@ void hsdaoh_process_frame(hsdaoh_dev_t *dev, uint8_t *data, int size)
|
||||||
/* extract number of payload words from reserved field at end of line */
|
/* extract number of payload words from reserved field at end of line */
|
||||||
uint16_t payload_len = le16toh(((uint16_t *)line_dat)[dev->width - 1]);
|
uint16_t payload_len = le16toh(((uint16_t *)line_dat)[dev->width - 1]);
|
||||||
uint16_t crc = le16toh(((uint16_t *)line_dat)[dev->width - 2]);
|
uint16_t crc = le16toh(((uint16_t *)line_dat)[dev->width - 2]);
|
||||||
|
uint16_t stream_id = le16toh(((uint16_t *)line_dat)[dev->width - 3]);
|
||||||
|
|
||||||
/* we only use 12 bits, the upper 4 bits are reserved for the metadata */
|
/* we only use 12 bits, the upper 4 bits are reserved for the metadata */
|
||||||
payload_len &= 0x0fff;
|
payload_len &= 0x0fff;
|
||||||
|
|
@ -641,8 +641,14 @@ void hsdaoh_process_frame(hsdaoh_dev_t *dev, uint8_t *data, int size)
|
||||||
frame_payload_bytes += payload_len * sizeof(uint16_t);
|
frame_payload_bytes += payload_len * sizeof(uint16_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hsdaoh_data_info_t data_info;
|
||||||
|
data_info.stream_id = 0;
|
||||||
|
data_info.buf = (uint8_t *)data;
|
||||||
|
data_info.len = frame_payload_bytes;
|
||||||
|
data_info.ctx = dev->cb_ctx;
|
||||||
|
|
||||||
if (dev->cb && dev->stream_synced)
|
if (dev->cb && dev->stream_synced)
|
||||||
dev->cb(data, frame_payload_bytes, dev->cb_ctx);
|
dev->cb(&data_info);
|
||||||
|
|
||||||
if (frame_errors && dev->stream_synced) {
|
if (frame_errors && dev->stream_synced) {
|
||||||
fprintf(stderr,"%d frame errors, %d frames since last error\n", frame_errors, dev->frames_since_error);
|
fprintf(stderr,"%d frame errors, %d frames since last error\n", frame_errors, dev->frames_since_error);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue