Skip to content

Commit 8d9bf42

Browse files
[FEAT] Add time units module in lib_ccxr (#1623)
* chore: Add cargo dependencies * feat: Make time module in `lib_ccxr` * feat: Add conversion guide in `time/mod.rs` module & Create `units` module * feat: Add time units code * feat: Make time module in `lib_ccxr/util` & Add helper function * feat: Add utils time related functions * feat: Add extern functions in `libccxr_exports` * feat: Add extern functions in C and use in proper place * docs: Mention in Changelogs
1 parent 8e4c07e commit 8d9bf42

File tree

15 files changed

+1249
-115
lines changed

15 files changed

+1249
-115
lines changed

docs/CHANGES.TXT

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
0.95 (to be released)
22
-----------------
3+
- New: Add time units module in lib_ccxr (#1623)
34
- New: Add bits and levenshtein module in lib_ccxr (#1627)
4-
- New: [FEAT] Add constants module in lib_ccxr (#1624)
5+
- New: Add constants module in lib_ccxr (#1624)
56
- New: Add log module in lib_ccxr (#1622)
67
- New: Create `lib_ccxr` and `libccxr_exports` (#1621)
78
- Fix: Unexpected behavior of get_write_interval (#1609)

src/lib_ccx/ccx_common_common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ int fdprintf(int fd, const char *fmt, ...)
2626
void millis_to_time(LLONG milli, unsigned *hours, unsigned *minutes,
2727
unsigned *seconds, unsigned *ms)
2828
{
29+
#ifndef DISABLE_RUST
30+
return ccxr_millis_to_time(milli, hours, minutes, seconds, ms);
31+
#endif /* ifndef DISABLE_RUST */
2932
// LLONG milli = (LLONG) ((ccblock*1000)/29.97);
3033
*ms = (unsigned)(milli % 1000); // milliseconds
3134
milli = (milli - *ms) / 1000; // Remainder, in seconds

src/lib_ccx/ccx_common_common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
int cc608_parity(unsigned int byte);
4444
int fdprintf(int fd, const char *fmt, ...);
4545
void millis_to_time(LLONG milli, unsigned *hours, unsigned *minutes,unsigned *seconds, unsigned *ms);
46+
47+
#ifndef DISABLE_RUST
48+
extern void ccxr_millis_to_time(LLONG milli, unsigned *hours, unsigned *minutes,unsigned *seconds, unsigned *ms);
49+
#endif // !DISABLE_RUST
50+
4651
void freep(void *arg);
4752
void dbg_print(LLONG mask, const char *fmt, ...);
4853
unsigned char *debug_608_to_ASC(unsigned char *ccdata, int channel);

src/lib_ccx/utility.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ int verify_crc32(uint8_t *buf, int len)
8989

9090
int stringztoms(const char *s, struct ccx_boundary_time *bt)
9191
{
92+
#ifndef DISABLE_RUST
93+
return ccxr_stringztoms(s, bt);
94+
#endif
9295
unsigned ss = 0, mm = 0, hh = 0;
9396
int value = -1;
9497
int colons = 0;
@@ -133,6 +136,10 @@ int stringztoms(const char *s, struct ccx_boundary_time *bt)
133136
}
134137
void timestamp_to_srttime(uint64_t timestamp, char *buffer)
135138
{
139+
#ifndef DISABLE_RUST
140+
return ccxr_timestamp_to_srttime(timestamp, buffer);
141+
#endif
142+
136143
uint64_t p = timestamp;
137144
uint8_t h = (uint8_t)(p / 3600000);
138145
uint8_t m = (uint8_t)(p / 60000 - 60 * h);
@@ -142,6 +149,10 @@ void timestamp_to_srttime(uint64_t timestamp, char *buffer)
142149
}
143150
void timestamp_to_vtttime(uint64_t timestamp, char *buffer)
144151
{
152+
#ifndef DISABLE_RUST
153+
return ccxr_timestamp_to_vtttime(timestamp, buffer);
154+
#endif
155+
145156
uint64_t p = timestamp;
146157
uint8_t h = (uint8_t)(p / 3600000);
147158
uint8_t m = (uint8_t)(p / 60000 - 60 * h);
@@ -202,6 +213,10 @@ int levenshtein_dist_char(const char *s1, const char *s2, unsigned s1len, unsign
202213

203214
void millis_to_date(uint64_t timestamp, char *buffer, enum ccx_output_date_format date_format, char millis_separator)
204215
{
216+
#ifndef DISABLE_RUST
217+
return ccxr_millis_to_date(timestamp, buffer, date_format, millis_separator);
218+
#endif
219+
205220
time_t secs;
206221
unsigned int millis;
207222
char c_temp[80];

src/lib_ccx/utility.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ volatile extern sig_atomic_t change_filename_requested;
3030
extern int ccxr_verify_crc32(uint8_t *buf, int len);
3131
extern int ccxr_levenshtein_dist(const uint64_t *s1, const uint64_t *s2, unsigned s1len, unsigned s2len);
3232
extern int ccxr_levenshtein_dist_char(const char *s1, const char *s2, unsigned s1len, unsigned s2len);
33+
extern void ccxr_timestamp_to_srttime(uint64_t timestamp, char *buffer);
34+
extern void ccxr_timestamp_to_vtttime(uint64_t timestamp, char *buffer);
35+
extern void ccxr_millis_to_date(uint64_t timestamp, char *buffer, enum ccx_output_date_format date_format, char millis_separator);
36+
extern int ccxr_stringztoms(const char *s, struct ccx_boundary_time *bt);
3337
#endif
3438

3539
int levenshtein_dist_char (const char *s1, const char *s2, unsigned s1len, unsigned s2len);

0 commit comments

Comments
 (0)