X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=src%2Flibsigrok-internal.h;h=98d1631e2f4a4a5d3b209f3e85446e464799ccc6;hp=b614c93d0bdc039407a345cdc0db0d844103abcf;hb=efce57da322cbe3d8c65332122ab3fb76e02089a;hpb=3ad30b4e19211eda2f4e00f78c76feeea3323b49 diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index b614c93d..98d1631e 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -475,6 +475,23 @@ static inline void write_u32le(uint8_t *p, uint32_t x) } #define WL32(p, x) write_u32le((uint8_t *)(p), (uint32_t)(x)) +/** + * Write a 64 bits unsigned integer to memory stored as big endian. + * @param p a pointer to the output memory + * @param x the input unsigned integer + */ +static inline void write_u64be(uint8_t *p, uint64_t x) +{ + p[7] = x & 0xff; x >>= 8; + p[6] = x & 0xff; x >>= 8; + p[5] = x & 0xff; x >>= 8; + p[4] = x & 0xff; x >>= 8; + p[3] = x & 0xff; x >>= 8; + p[2] = x & 0xff; x >>= 8; + p[1] = x & 0xff; x >>= 8; + p[0] = x & 0xff; x >>= 8; +} + /** * Write a 64 bits unsigned integer to memory stored as little endian. * @param p a pointer to the output memory @@ -1786,6 +1803,7 @@ SR_PRIV int sr_atoi(const char *str, int *ret); SR_PRIV int sr_atod(const char *str, double *ret); SR_PRIV int sr_atof(const char *str, float *ret); SR_PRIV int sr_atod_ascii(const char *str, double *ret); +SR_PRIV int sr_atod_ascii_digits(const char *str, double *ret, int *digits); SR_PRIV int sr_atof_ascii(const char *str, float *ret); SR_PRIV GString *sr_hexdump_new(const uint8_t *data, const size_t len); @@ -1823,6 +1841,8 @@ enum { }; typedef gboolean (*packet_valid_callback)(const uint8_t *buf); +typedef int (*packet_valid_len_callback)(void *st, + const uint8_t *p, size_t l, size_t *pl); typedef GSList *(*sr_ser_list_append_t)(GSList *devs, const char *name, const char *desc); @@ -1852,10 +1872,10 @@ SR_PRIV int serial_set_paramstr(struct sr_serial_dev_inst *serial, SR_PRIV int serial_readline(struct sr_serial_dev_inst *serial, char **buf, int *buflen, gint64 timeout_ms); SR_PRIV int serial_stream_detect(struct sr_serial_dev_inst *serial, - uint8_t *buf, size_t *buflen, - size_t packet_size, - packet_valid_callback is_valid, - uint64_t timeout_ms); + uint8_t *buf, size_t *buflen, + size_t packet_size, packet_valid_callback is_valid, + packet_valid_len_callback is_valid_len, size_t *return_size, + uint64_t timeout_ms); SR_PRIV int sr_serial_extract_options(GSList *options, const char **serial_device, const char **serial_options); SR_PRIV int serial_source_add(struct sr_session *session, @@ -2341,11 +2361,43 @@ struct brymen_bm52x_info { size_t ch_idx; }; #ifdef HAVE_SERIAL_COMM SR_PRIV int sr_brymen_bm52x_packet_request(struct sr_serial_dev_inst *serial); +SR_PRIV int sr_brymen_bm82x_packet_request(struct sr_serial_dev_inst *serial); #endif SR_PRIV gboolean sr_brymen_bm52x_packet_valid(const uint8_t *buf); +SR_PRIV gboolean sr_brymen_bm82x_packet_valid(const uint8_t *buf); +/* BM520s and BM820s protocols are similar, the parse routine is shared. */ SR_PRIV int sr_brymen_bm52x_parse(const uint8_t *buf, float *floatval, struct sr_datafeed_analog *analog, void *info); +struct brymen_bm52x_state; + +SR_PRIV void *brymen_bm52x_state_init(void); +SR_PRIV void brymen_bm52x_state_free(void *state); +SR_PRIV int brymen_bm52x_config_get(void *state, uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg); +SR_PRIV int brymen_bm52x_config_set(void *state, uint32_t key, GVariant *data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg); +SR_PRIV int brymen_bm52x_config_list(void *state, uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg); +SR_PRIV int brymen_bm52x_acquire_start(void *state, + const struct sr_dev_inst *sdi, + sr_receive_data_callback *cb, void **cb_data); + +/*--- dmm/bm85x.c -----------------------------------------------------------*/ + +#define BRYMEN_BM85x_PACKET_SIZE_MIN 4 + +struct brymen_bm85x_info { int dummy; }; + +#ifdef HAVE_SERIAL_COMM +SR_PRIV int brymen_bm85x_after_open(struct sr_serial_dev_inst *serial); +SR_PRIV int brymen_bm85x_packet_request(struct sr_serial_dev_inst *serial); +#endif +SR_PRIV gboolean brymen_bm85x_packet_valid(void *state, + const uint8_t *buf, size_t len, size_t *pkt_len); +SR_PRIV int brymen_bm85x_parse(void *state, const uint8_t *buf, size_t len, + double *floatval, struct sr_datafeed_analog *analog, void *info); + /*--- dmm/bm86x.c -----------------------------------------------------------*/ #define BRYMEN_BM86X_PACKET_SIZE 24