code refactoring 2

This commit is contained in:
dreamsourcelabTAI 2022-07-14 17:09:02 +08:00
parent b63cc00d9e
commit b424accfd5
5 changed files with 81 additions and 18 deletions

View File

@ -49,7 +49,7 @@ void usage()
"Help Options:\n"
" -l, --loglevel Set log level, value between 0 to 5\n"
" -v, -V, --version Show release version\n"
" -s, --storelog save log to locale file\n"
" -s, --storelog Save log to locale file\n"
" -h, -?, --help Show help option\n"
"\n", DS_BIN_NAME, DS_DESCRIPTION);
}

61
libsigrok4DSL/help.txt Normal file
View File

@ -0,0 +1,61 @@
/*
How to use libsigrok4DSL
*/
1.Complie
cd libsigrok4DSL
cmake .
make
make install
2.Example
#include <libsigrok.h>
#include <stdio.h>
void event_cb(int ev)
{
}
void data_cb(pack p){
}
void main()
{
sr_init();
const char *res_path = "c:\DSView\res"
sr_set_firmware_resource_dir(res_path);
sr_disable_data_cache(flag); // don't manager data
sr_set_datafeed_callback(data_cb); //only transfers data
sr_set_event_callback(event_cb);
while(true){
if (getche() == 'x'){
//exit app
break;
}
}
sr_exit();
}
/* api
sr_init();
sr_exit();
sr_set_firmware_resource_dir();
sr_set_datafeed_callback(data_cb);
sr_set_event_callback(event_cb);
*/

View File

@ -142,6 +142,16 @@ SR_PRIV int sr_session_stop_sync(void);
SR_PRIV int usb_hotplug_callback(struct libusb_context *ctx, struct libusb_device *dev,
libusb_hotplug_event event, void *user_data);
SR_PRIV int sr_session_source_add(int fd, int events, int timeout,
sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi);
SR_PRIV int sr_session_source_add_pollfd(GPollFD *pollfd, int timeout,
sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi);
SR_PRIV int sr_session_source_add_channel(GIOChannel *channel, int events,
int timeout, sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi);
SR_PRIV int sr_session_source_remove(int fd);
SR_PRIV int sr_session_source_remove_pollfd(GPollFD *pollfd);
SR_PRIV int sr_session_source_remove_channel(GIOChannel *channel);
/*--- std.c -----------------------------------------------------------------*/
typedef int (*dev_close_t)(struct sr_dev_inst *sdi);

View File

@ -1342,7 +1342,9 @@ SR_API void sr_config_free(struct sr_config *src);
typedef void (*sr_datafeed_callback_t)(const struct sr_dev_inst *sdi,
const struct sr_datafeed_packet *packet, void *cb_data);
/**
* firmware binary file directory
*/
SR_API void sr_set_firmware_resource_dir(const char *dir);
@ -1364,16 +1366,6 @@ SR_API int sr_session_start(void);
SR_API int sr_session_run(void);
SR_API int sr_session_stop(void);
SR_API int sr_session_source_add(int fd, int events, int timeout,
sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi);
SR_API int sr_session_source_add_pollfd(GPollFD *pollfd, int timeout,
sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi);
SR_API int sr_session_source_add_channel(GIOChannel *channel, int events,
int timeout, sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi);
SR_API int sr_session_source_remove(int fd);
SR_API int sr_session_source_remove_pollfd(GPollFD *pollfd);
SR_API int sr_session_source_remove_channel(GIOChannel *channel);
//0:ok, 1:error
SR_API int sr_check_session_start_before();

View File

@ -660,7 +660,7 @@ static int _sr_session_source_add(GPollFD *pollfd, int timeout,
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or
* SR_ERR_MALLOC upon memory allocation errors.
*/
SR_API int sr_session_source_add(int fd, int events, int timeout,
SR_PRIV int sr_session_source_add(int fd, int events, int timeout,
sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi)
{
GPollFD p;
@ -682,7 +682,7 @@ SR_API int sr_session_source_add(int fd, int events, int timeout,
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or
* SR_ERR_MALLOC upon memory allocation errors.
*/
SR_API int sr_session_source_add_pollfd(GPollFD *pollfd, int timeout,
SR_PRIV int sr_session_source_add_pollfd(GPollFD *pollfd, int timeout,
sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi)
{
return _sr_session_source_add(pollfd, timeout, cb,
@ -701,7 +701,7 @@ SR_API int sr_session_source_add_pollfd(GPollFD *pollfd, int timeout,
* @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or
* SR_ERR_MALLOC upon memory allocation errors.
*/
SR_API int sr_session_source_add_channel(GIOChannel *channel, int events,
SR_PRIV int sr_session_source_add_channel(GIOChannel *channel, int events,
int timeout, sr_receive_data_callback_t cb, const struct sr_dev_inst *sdi)
{
GPollFD p;
@ -791,7 +791,7 @@ static int _sr_session_source_remove(gintptr poll_object)
* SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon
* internal errors.
*/
SR_API int sr_session_source_remove(int fd)
SR_PRIV int sr_session_source_remove(int fd)
{
return _sr_session_source_remove((gintptr)fd);
}
@ -805,7 +805,7 @@ SR_API int sr_session_source_remove(int fd)
* SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon
* internal errors.
*/
SR_API int sr_session_source_remove_pollfd(GPollFD *pollfd)
SR_PRIV int sr_session_source_remove_pollfd(GPollFD *pollfd)
{
return _sr_session_source_remove((gintptr)pollfd);
}
@ -819,7 +819,7 @@ SR_API int sr_session_source_remove_pollfd(GPollFD *pollfd)
* SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon
* internal errors.
*/
SR_API int sr_session_source_remove_channel(GIOChannel *channel)
SR_PRIV int sr_session_source_remove_channel(GIOChannel *channel)
{
return _sr_session_source_remove((gintptr)channel);
}