80 lines
2.5 KiB
C
80 lines
2.5 KiB
C
/*
|
||||
|
|
* Copyright (c) 2020 by UNISOC Technology(Shanghai), Inc. ALL RIGHTS RESERVED.
|
|||
|
|
*
|
|||
|
|
* These coded instructions, statements, and computer programs are the
|
|||
|
|
* copyrighted works and confidential proprietary information of
|
|||
|
|
* UNISOC Technology(Shanghai), Inc. They may not be modified, copied, reproduced,
|
|||
|
|
* distributed, or disclosed to third parties in any manner, medium, or form,
|
|||
|
|
* in whole or in part, without the prior written consent of UNISOC Technology(Shanghai), Inc.
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#define _GNU_SOURCE
|
|||
|
|
#include <pthread.h>
|
|||
|
|
#include <signal.h>
|
|||
|
|
#include <stdbool.h>
|
|||
|
|
#include <stdio.h>
|
|||
|
|
#include <stdlib.h>
|
|||
|
|
#include <unistd.h>
|
|||
|
|
|
|||
|
|
#include "gnss-ota.h"
|
|||
|
|
#include "pc_request.h"
|
|||
|
|
#include "gpsd_report.h"
|
|||
|
|
|
|||
|
|
bool loop = true;
|
|||
|
|
|
|||
|
|
//set loop false to stop thread while abnormal signal arrived
|
|||
|
|
void sig_handler(int sig_number)
|
|||
|
|
{
|
|||
|
|
if((SIGTERM == sig_number) || (SIGKILL == sig_number) || (SIGINT == sig_number))
|
|||
|
|
{
|
|||
|
|
loop = false;
|
|||
|
|
LOGD("%s received signal %d, loop be set false.", __func__, sig_number);
|
|||
|
|
}else{
|
|||
|
|
LOGD("%s received signal %d.", __func__, sig_number);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int main()
|
|||
|
|
{
|
|||
|
|
LOGD("gnss-ota booting...");
|
|||
|
|
if (signal(SIGINT, sig_handler) == SIG_ERR) {
|
|||
|
|
LOGE("%s can not catch signal", __func__);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//use for main thread holding there
|
|||
|
|
pthread_mutex_t main_mutex;
|
|||
|
|
pthread_cond_t main_cond;
|
|||
|
|
pthread_mutex_init(&main_mutex, NULL);
|
|||
|
|
pthread_cond_init(&main_cond, NULL);
|
|||
|
|
|
|||
|
|
//thread wait for pc request
|
|||
|
|
pthread_t pc_request_handler_tid;
|
|||
|
|
if ((pthread_create(&pc_request_handler_tid, NULL, pc_request_handler, NULL)) != 0) {
|
|||
|
|
LOGE("create pc_request_handler thread fail");
|
|||
|
|
return -1;
|
|||
|
|
} else {
|
|||
|
|
LOGD("create pc_request_handler thread ok, tid=%d", pc_request_handler_tid);
|
|||
|
|
}
|
|||
|
|
pthread_detach(pc_request_handler_tid); //auto recyle
|
|||
|
|
|
|||
|
|
//thread wait for pc request
|
|||
|
|
pthread_t gpsd_report_handler_tid;
|
|||
|
|
if ((pthread_create(&gpsd_report_handler_tid, NULL, gpsd_report_handler, NULL)) != 0) {
|
|||
|
|
LOGE("create gpsd_report_handler thread fail");
|
|||
|
|
return -1;
|
|||
|
|
} else {
|
|||
|
|
LOGD("create gpsd_report_handler thread ok, tid=%d", gpsd_report_handler_tid);
|
|||
|
|
}
|
|||
|
|
pthread_detach(gpsd_report_handler_tid); //auto recyle
|
|||
|
|
|
|||
|
|
while(loop){
|
|||
|
|
pthread_mutex_lock(&main_mutex);
|
|||
|
|
LOGD("unisoc-gnss-ota pthread_cond_wait here");
|
|||
|
|
pthread_cond_wait(&main_cond, &main_mutex);
|
|||
|
|
pthread_mutex_unlock(&main_mutex);
|
|||
|
|
}
|
|||
|
|
LOGE("gnss-ota exiting...");
|
|||
|
|
|
|||
|
|
return 0;
|
|||
|
|
}
|