Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 1 | /** |
| 2 | * \file |
| 3 | * \brief Utility functions |
| 4 | */ |
| 5 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 6 | #ifndef _DVR_UTILS_H_ |
| 7 | #define _DVR_UTILS_H_ |
| 8 | |
| 9 | #ifdef __cplusplus |
| 10 | extern "C" { |
| 11 | #endif |
| 12 | |
wentao ma | 98707a3 | 2022-10-20 04:53:46 -0700 | [diff] [blame^] | 13 | |
| 14 | /**\brief read sysfs node |
| 15 | * name file name |
| 16 | * buf store sysfs value buf |
| 17 | * len buf len |
| 18 | */ |
| 19 | typedef void (*DVR_Read_Sysfs_Cb)(const char *name, char *buf, int len); |
| 20 | |
| 21 | /**\brief write sysfs |
| 22 | * name file name |
| 23 | * cmd write to sysfs node cmd |
| 24 | */ |
| 25 | typedef void (*DVR_Write_Sysfs_Cb)(const char *name, const char *cmd); |
| 26 | |
| 27 | /**\brief read prop |
| 28 | * name prop name |
| 29 | * buf store prop value buf |
| 30 | * len buf len |
| 31 | */ |
| 32 | typedef void (*DVR_Read_Prop_Cb)(const char *name, char *buf, int len); |
| 33 | |
| 34 | /**\brief write prop |
| 35 | * name prop name |
| 36 | * cmd write to prop node cmd |
| 37 | */ |
| 38 | typedef void (*DVR_Write_Prop_Cb)(const char *name, const char *cmd); |
| 39 | |
| 40 | |
| 41 | /**\brief regist rw sysfs cb |
| 42 | * \param[in] fun callback |
| 43 | * \return |
| 44 | * - DVR_SUCCESS |
| 45 | * - error |
| 46 | */ |
| 47 | int dvr_register_rw_sys(DVR_Read_Sysfs_Cb RCb, DVR_Write_Sysfs_Cb WCb); |
| 48 | |
| 49 | /**\brief unregist rw sys cb |
| 50 | */ |
| 51 | int dvr_unregister_rw_sys(void); |
| 52 | |
| 53 | |
| 54 | /**\brief regist rw prop cb |
| 55 | * \param[in] fun callback |
| 56 | * \return |
| 57 | * - DVR_SUCCESS |
| 58 | * - error |
| 59 | */ |
| 60 | |
| 61 | int dvr_register_rw_prop(DVR_Read_Prop_Cb RCb, DVR_Write_Prop_Cb WCb); |
| 62 | |
| 63 | /**\brief unregist rw prop cb */ |
| 64 | int dvr_unregister_rw_prop(void); |
| 65 | |
| 66 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 67 | /**\brief Write a string cmd to a file |
Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 68 | * \param[in] name File name |
| 69 | * \param[in] cmd String command |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 70 | * \return DVR_SUCCESS On success |
| 71 | * \return Error code On failure |
| 72 | */ |
wentao ma | 98707a3 | 2022-10-20 04:53:46 -0700 | [diff] [blame^] | 73 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 74 | int dvr_file_echo(const char *name, const char *cmd); |
| 75 | |
wentao ma | 98707a3 | 2022-10-20 04:53:46 -0700 | [diff] [blame^] | 76 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 77 | /**\brief read sysfs file |
| 78 | * \param[in] name, File name |
| 79 | * \param[out] buf, store sysfs node value |
| 80 | * \return DVR_SUCCESS On success |
| 81 | * \return Error code On failure |
| 82 | */ |
wentao ma | 98707a3 | 2022-10-20 04:53:46 -0700 | [diff] [blame^] | 83 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 84 | int dvr_file_read(const char *name, char *buf, int len); |
| 85 | |
wentao ma | 98707a3 | 2022-10-20 04:53:46 -0700 | [diff] [blame^] | 86 | |
| 87 | /**\brief Write a string cmd to a prop |
| 88 | * \param[in] name, prop name |
| 89 | * \param[in] cmd, String command |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 90 | * \return DVR_SUCCESS On success |
wentao ma | 98707a3 | 2022-10-20 04:53:46 -0700 | [diff] [blame^] | 91 | * \return Error code On failure |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 92 | */ |
wentao ma | 98707a3 | 2022-10-20 04:53:46 -0700 | [diff] [blame^] | 93 | |
| 94 | int dvr_prop_echo(const char *name, const char *cmd); |
| 95 | |
| 96 | |
| 97 | /**\brief read prop value |
| 98 | * \param[in] name, prop name |
| 99 | * \param[out] buf, store prop node value |
| 100 | * \return DVR_SUCCESS On success |
| 101 | * \return Error code On failure |
| 102 | */ |
| 103 | |
hualing chen | a540a7e | 2020-03-27 16:44:05 +0800 | [diff] [blame] | 104 | int dvr_prop_read(const char *name, char *buf, int len); |
Gong Ke | 497c4c2 | 2020-03-20 10:15:42 +0800 | [diff] [blame] | 105 | |
Wentao MA | 907b643 | 2022-08-01 06:23:08 +0000 | [diff] [blame] | 106 | /**\brief calculates the difference between ts1 and ts2 |
| 107 | * \param[in] ts1, higher bound of the timespec* whose length is calculated |
| 108 | * \param[in] ts2, lower bound of the timespec* whose length is calculated |
| 109 | * \param[out] ts3, The result timespec* of (ts1-ts2) |
| 110 | * \return void |
| 111 | */ |
| 112 | void clock_timespec_subtract(struct timespec *ts1, struct timespec *ts2, struct timespec *ts3); |
| 113 | |
Pengfei Liu | b473423 | 2020-01-17 18:25:10 +0800 | [diff] [blame] | 114 | #ifdef __cplusplus |
| 115 | } |
| 116 | #endif |
| 117 | |
| 118 | #endif /*END _DVR_UTILS_H_*/ |