sync uiot bugfix

This commit is contained in:
ethan.du 2021-04-25 13:57:06 +08:00
parent 11f1b46432
commit 09c3690ac3
7 changed files with 30 additions and 29 deletions

4
deps/deps.mk vendored
View File

@ -21,5 +21,5 @@ all :
cp $(LIB_CJSON_TAR)/cJSON.h $(LIB_CJSON_DIR)
clean :
cd $(LIB_NATS_TAR) && $(MAKE) clean
cd $(LIB_CJSON_TAR) && $(MAKE) clean
rm -rf $(LIB_NATS_TAR)
rm -rf $(LIB_CJSON_TAR)

View File

@ -479,7 +479,7 @@ void log_print(const char *format,...)
va_list args;
va_start(args, format);
printf(format, args);
vprintf(format, args);
va_end(args);
fflush(stdout);
@ -491,7 +491,7 @@ void log_write(log_level level, const char *format,...)
{
return;
}
const char *log_lev[5] = {"debug", "info", "warn", "error"};
const char *log_lev[4] = {"debug", "info", "warn", "error"};
struct timeval stamp;
char *msg_str_rep = (char *)EDGE_MALLOC(NATS_MSG_MAX_LEN);
if(NULL == msg_str_rep)

View File

@ -266,19 +266,4 @@ void natsMutex_Destroy(natsMutex *m)
EDGE_FREE(m);
}
void natsTimer_Init(nats_timer *pst_nats_timer, timer_handle timer_handle_func)
{
struct itimerval timer;
timer.it_interval.tv_sec = pst_nats_timer->interval_sec;
timer.it_interval.tv_usec = pst_nats_timer->interval_usec;
timer.it_value.tv_sec = pst_nats_timer->effect_sec;
timer.it_value.tv_usec = pst_nats_timer->effect_usec;
setitimer(ITIMER_REAL, &timer, NULL);//让它产生SIGVTALRM信号
//为SIGALRM注册信号处理函数
signal(SIGALRM, timer_handle_func);
return;
}

View File

@ -81,8 +81,7 @@ natsStatus natsMutex_Create(natsMutex **newMutex);
void natsMutex_Lock(natsMutex *m);
void natsMutex_Unlock(natsMutex *m);
void natsMutex_Destroy(natsMutex *m);
typedef void (* timer_handle)(int signo);
void natsTimer_Init(nats_timer *pst_nats_timer, timer_handle timer_handle_func);
#endif

View File

@ -460,7 +460,7 @@ static int _subdev_client_match(void *a, void *b)
return false;
}
static void _handle_status_sync(int signo)
static void _handle_status_sync(union sigval v)
{
edge_status status;
char *device_list_msg = (char *)EDGE_MALLOC(NATS_MSG_MAX_LEN);
@ -549,17 +549,33 @@ static void _handle_status_sync(int signo)
static void _fetch_online_status(void)
{
nats_timer nats_timer;
nats_timer.interval_sec = 15;
nats_timer.interval_usec = 0;
nats_timer.effect_sec = 15;
nats_timer.effect_usec = 0;
struct sigevent evp;
struct itimerspec ts;
timer_t timer;
int ret;
natsTimer_Init(&nats_timer, _handle_status_sync);
memset(&evp, 0, sizeof(evp));
evp.sigev_value.sival_ptr = &timer;
evp.sigev_notify = SIGEV_THREAD;
evp.sigev_notify_function = _handle_status_sync;
evp.sigev_value.sival_int = 0;
ret = timer_create(CLOCK_REALTIME, &evp, &timer);
if(ret)
perror("timer_create");
ts.it_interval.tv_sec = 15;
ts.it_interval.tv_nsec = 0;
ts.it_value.tv_sec = 15;
ts.it_value.tv_nsec = 0;
ret = timer_settime(timer, 0, &ts, NULL);
if( ret )
perror("timer_settime");
return;
}
edge_status edge_common_init(void)
{
edge_status status;

View File

@ -188,6 +188,7 @@ int main(int argc, char **argv)
log_write(LOG_DEBUG, "send message[%s]", time_stamp);
status = edge_publishString(topic_str, time_stamp);
//spuuprt publish binary message
status |= edge_publish(topic_str, "0D0A2131", 8);
if(EDGE_OK != status)
{

View File

@ -10,7 +10,7 @@ target = iotstack_driver_test
all : $(target)
$(target) :
$(CC) -o $(target) $(src) $(LIBS) $(INCLUDE) $(CFLAGS)
$(CC) -o $(target) $(src) $(LIBS) $(INCLUDE) $(CFLAGS) -lrt
clean:
-$(RM) $(target) $(target).o