forked from nkolban/esp32-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kolban
committed
Jan 20, 2017
1 parent
a4db3b1
commit 848587e
Showing
74 changed files
with
9,268 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* c_timeutils.c | ||
* | ||
* Created on: Nov 26, 2016 | ||
* Author: kolban | ||
*/ | ||
#include <sys/time.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
|
||
/** | ||
* Add a number of milliseconds to a timeval and replace the | ||
* existing timeval with the new value. | ||
*/ | ||
void timeval_addMsecs(struct timeval *a, uint32_t msecs) { | ||
int uSecs = (msecs%1000) * 1000 + a->tv_usec; | ||
a->tv_usec = uSecs % 1000000; | ||
a->tv_sec += msecs/1000 + uSecs/1000000; | ||
} // addMsecs | ||
|
||
/** | ||
* Convert a timeval into the number of msecs. | ||
*/ | ||
uint32_t timeval_toMsecs(struct timeval *a) { | ||
return a->tv_sec * 1000 + a->tv_usec/1000; | ||
} // timeval_toMsecs | ||
|
||
|
||
/** | ||
* Subtract one timeval from another. | ||
*/ | ||
struct timeval timeval_sub(struct timeval *a, struct timeval *b) { | ||
struct timeval result; | ||
result.tv_sec = a->tv_sec - b->tv_sec; | ||
result.tv_usec = a->tv_usec - b->tv_usec; | ||
if (a->tv_usec < b->tv_usec) { | ||
result.tv_sec -= 1; | ||
result.tv_usec += 1000000; | ||
} | ||
return result; | ||
} // timeval_sub | ||
|
||
|
||
/* | ||
* Add one timeval to another. | ||
*/ | ||
struct timeval timeval_add(struct timeval *a, struct timeval *b) { | ||
struct timeval result; | ||
result.tv_sec = a->tv_sec + b->tv_sec; | ||
result.tv_usec = a->tv_usec + b->tv_usec; | ||
if (result.tv_usec >= 1000000) { | ||
result.tv_sec += 1; | ||
result.tv_usec -= 1000000; | ||
} | ||
return result; | ||
} // timeval_add | ||
|
||
/** | ||
* Return the number of milliseconds until future time value. | ||
*/ | ||
uint32_t timeval_durationFromNow(struct timeval *a) { | ||
struct timeval b; | ||
gettimeofday(&b, NULL); | ||
struct timeval delta = timeval_sub(a, &b); | ||
if (delta.tv_sec < 0) { | ||
return 0; | ||
} | ||
return timeval_toMsecs(&delta); | ||
// assuming that a is later than b, then the result is a-b | ||
} // timeval_durationFromNow | ||
|
||
/** | ||
* Return the number of milliseconds the historic time value was before now. | ||
*/ | ||
uint32_t timeval_durationBeforeNow(struct timeval *a) { | ||
struct timeval b; | ||
gettimeofday(&b, NULL); | ||
struct timeval delta = timeval_sub(&b, a); | ||
if (delta.tv_sec < 0) { | ||
return 0; | ||
} | ||
return timeval_toMsecs(&delta); | ||
} // timeval_durationBeforeNow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* c_timeutils.h | ||
* | ||
* Created on: Nov 26, 2016 | ||
* Author: kolban | ||
*/ | ||
|
||
#if !defined(_C_TIMEUTILS_H_) | ||
#define _C_TIMEUTILS_H_ | ||
#include <sys/time.h> | ||
#include <stdint.h> | ||
|
||
struct timeval timeval_add(struct timeval *a, struct timeval *b); | ||
void timeval_addMsecs(struct timeval *a, uint32_t msecs); | ||
uint32_t timeval_durationBeforeNow(struct timeval *a); | ||
uint32_t timeval_durationFromNow(struct timeval *a); | ||
struct timeval timeval_sub(struct timeval *a, struct timeval *b); | ||
uint32_t timeval_toMsecs(struct timeval *a); | ||
|
||
#endif /* _C_TIMEUTILS_H_ */ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>embedded-C</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name> | ||
<triggers>clean,full,incremental,</triggers> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name> | ||
<triggers>full,incremental,</triggers> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.cdt.core.cnature</nature> | ||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature> | ||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> | ||
</natures> | ||
</projectDescription> |
163 changes: 163 additions & 0 deletions
163
networking/mqtt/paho_mqtt_embedded_c/.settings/org.eclipse.cdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.cdt.core.formatter.alignment_for_arguments_in_method_invocation=16 | ||
org.eclipse.cdt.core.formatter.alignment_for_assignment=16 | ||
org.eclipse.cdt.core.formatter.alignment_for_base_clause_in_type_declaration=80 | ||
org.eclipse.cdt.core.formatter.alignment_for_binary_expression=16 | ||
org.eclipse.cdt.core.formatter.alignment_for_compact_if=16 | ||
org.eclipse.cdt.core.formatter.alignment_for_conditional_expression=34 | ||
org.eclipse.cdt.core.formatter.alignment_for_conditional_expression_chain=18 | ||
org.eclipse.cdt.core.formatter.alignment_for_constructor_initializer_list=0 | ||
org.eclipse.cdt.core.formatter.alignment_for_declarator_list=16 | ||
org.eclipse.cdt.core.formatter.alignment_for_enumerator_list=48 | ||
org.eclipse.cdt.core.formatter.alignment_for_expression_list=0 | ||
org.eclipse.cdt.core.formatter.alignment_for_expressions_in_array_initializer=16 | ||
org.eclipse.cdt.core.formatter.alignment_for_member_access=0 | ||
org.eclipse.cdt.core.formatter.alignment_for_overloaded_left_shift_chain=16 | ||
org.eclipse.cdt.core.formatter.alignment_for_parameters_in_method_declaration=16 | ||
org.eclipse.cdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 | ||
org.eclipse.cdt.core.formatter.brace_position_for_array_initializer=next_line | ||
org.eclipse.cdt.core.formatter.brace_position_for_block=next_line | ||
org.eclipse.cdt.core.formatter.brace_position_for_block_in_case=next_line | ||
org.eclipse.cdt.core.formatter.brace_position_for_method_declaration=next_line | ||
org.eclipse.cdt.core.formatter.brace_position_for_namespace_declaration=next_line | ||
org.eclipse.cdt.core.formatter.brace_position_for_switch=next_line | ||
org.eclipse.cdt.core.formatter.brace_position_for_type_declaration=next_line | ||
org.eclipse.cdt.core.formatter.comment.min_distance_between_code_and_line_comment=1 | ||
org.eclipse.cdt.core.formatter.comment.never_indent_line_comments_on_first_column=true | ||
org.eclipse.cdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true | ||
org.eclipse.cdt.core.formatter.compact_else_if=true | ||
org.eclipse.cdt.core.formatter.continuation_indentation=2 | ||
org.eclipse.cdt.core.formatter.continuation_indentation_for_array_initializer=2 | ||
org.eclipse.cdt.core.formatter.format_guardian_clause_on_one_line=false | ||
org.eclipse.cdt.core.formatter.indent_access_specifier_compare_to_type_header=false | ||
org.eclipse.cdt.core.formatter.indent_access_specifier_extra_spaces=0 | ||
org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_access_specifier=true | ||
org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_namespace_header=false | ||
org.eclipse.cdt.core.formatter.indent_breaks_compare_to_cases=true | ||
org.eclipse.cdt.core.formatter.indent_declaration_compare_to_template_header=false | ||
org.eclipse.cdt.core.formatter.indent_empty_lines=false | ||
org.eclipse.cdt.core.formatter.indent_statements_compare_to_block=true | ||
org.eclipse.cdt.core.formatter.indent_statements_compare_to_body=true | ||
org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_cases=true | ||
org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_switch=false | ||
org.eclipse.cdt.core.formatter.indentation.size=4 | ||
org.eclipse.cdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert | ||
org.eclipse.cdt.core.formatter.insert_new_line_after_template_declaration=do not insert | ||
org.eclipse.cdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert | ||
org.eclipse.cdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert | ||
org.eclipse.cdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert | ||
org.eclipse.cdt.core.formatter.insert_new_line_before_colon_in_constructor_initializer_list=do not insert | ||
org.eclipse.cdt.core.formatter.insert_new_line_before_else_in_if_statement=insert | ||
org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration=do not insert | ||
org.eclipse.cdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert | ||
org.eclipse.cdt.core.formatter.insert_new_line_in_empty_block=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_assignment_operator=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_binary_operator=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_arguments=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_parameters=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_closing_brace_in_block=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_closing_paren_in_cast=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_colon_in_base_clause=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_colon_in_case=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_colon_in_conditional=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_comma_in_array_initializer=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_comma_in_base_types=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_comma_in_declarator_list=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_comma_in_expression_list=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_arguments=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_parameters=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_arguments=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_parameters=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_bracket=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_exception_specification=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_postfix_operator=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_prefix_operator=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_question_in_conditional=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_semicolon_in_for=insert | ||
org.eclipse.cdt.core.formatter.insert_space_after_unary_operator=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_assignment_operator=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_binary_operator=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_arguments=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_parameters=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_bracket=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_exception_specification=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_colon_in_base_clause=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_colon_in_case=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_colon_in_conditional=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_colon_in_default=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_comma_in_base_types=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_comma_in_declarator_list=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_comma_in_expression_list=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_arguments=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_parameters=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_arguments=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_parameters=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_block=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_namespace_declaration=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_switch=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_bracket=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_catch=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_exception_specification=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_for=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_if=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_switch=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_while=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_postfix_operator=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_prefix_operator=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_question_in_conditional=insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_semicolon=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_semicolon_in_for=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_before_unary_operator=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_between_empty_brackets=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_exception_specification=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert | ||
org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert | ||
org.eclipse.cdt.core.formatter.join_wrapped_lines=true | ||
org.eclipse.cdt.core.formatter.keep_else_statement_on_same_line=false | ||
org.eclipse.cdt.core.formatter.keep_empty_array_initializer_on_one_line=false | ||
org.eclipse.cdt.core.formatter.keep_imple_if_on_one_line=false | ||
org.eclipse.cdt.core.formatter.keep_then_statement_on_same_line=false | ||
org.eclipse.cdt.core.formatter.lineSplit=80 | ||
org.eclipse.cdt.core.formatter.number_of_empty_lines_to_preserve=1 | ||
org.eclipse.cdt.core.formatter.put_empty_statement_on_new_line=true | ||
org.eclipse.cdt.core.formatter.tabulation.char=tab | ||
org.eclipse.cdt.core.formatter.tabulation.size=4 | ||
org.eclipse.cdt.core.formatter.use_tabs_only_for_leading_indentations=false |
3 changes: 3 additions & 0 deletions
3
networking/mqtt/paho_mqtt_embedded_c/.settings/org.eclipse.cdt.ui.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
eclipse.preferences.version=1 | ||
formatter_profile=org.eclipse.cdt.ui.default.allman_profile | ||
formatter_settings_version=1 |
Oops, something went wrong.