Mock out mgos_i2c.h to work with Linux.

This commit is contained in:
Pim van Pelt
2018-04-02 13:30:45 +02:00
commit cef7c5107d
8 changed files with 491 additions and 0 deletions

44
src/mgos_mock.c Normal file
View File

@ -0,0 +1,44 @@
/* Some functions mocked from MGOS, so we can run unit tests standalone.
*/
#include "mgos_mock.h"
int _mgos_timers = 0;
int log_print_prefix(enum cs_log_level l, const char *func, const char *file) {
char ll_str[6];
switch(l) {
case LL_ERROR:
strncpy(ll_str, "ERROR", sizeof(ll_str));
break;
case LL_WARN:
strncpy(ll_str, "WARN", sizeof(ll_str));
break;
case LL_INFO:
strncpy(ll_str, "INFO", sizeof(ll_str));
break;
case LL_DEBUG:
strncpy(ll_str, "DEBUG", sizeof(ll_str));
break;
case LL_VERBOSE_DEBUG:
strncpy(ll_str, "VERB", sizeof(ll_str));
break;
default: // LL_NONE
return 0;
}
printf ("%-5s %-20s %-40s| ", ll_str, file, func);
return 1;
}
float mg_time() {
struct timeval tod;
float time;
gettimeofday(&tod, NULL);
time = tod.tv_sec;
time += tod.tv_usec/1000000;
return time;
}