/*********************************************************************************
|
* Copyright: (C) 2019 LingYun IoT System Studio
|
* All rights reserved.
|
*
|
* Filename: main.c
|
* Description: This file
|
*
|
* Version: 1.0.0(29/01/19)
|
* Author: Guo Wenxue <guowenxue@gmail.com>
|
* ChangeLog: 1, Release initial version on "29/01/19 15:34:41"
|
*
|
********************************************************************************/
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <unistd.h>
|
#include <time.h>
|
#include <getopt.h>
|
#include <libgen.h>
|
#include <string.h>
|
#include <errno.h>
|
|
#include "logger.h"
|
#include "ds18b20.h"
|
#include "proc.h"
|
|
#define PROG_VERSION "v1.0.0"
|
#define DAEMON_PIDFILE "/tmp/.socketd.pid"
|
|
static void program_usage(char *progname)
|
{
|
|
printf("Usage: %s [OPTION]...\n", progname);
|
printf(" %s is LingYun studio temperature socket client program running on RaspberryPi\n", progname);
|
|
printf("\nMandatory arguments to long options are mandatory for short options too:\n");
|
printf(" -d[debug ] Running in debug mode\n");
|
printf(" -h[help ] Display this help information\n");
|
printf(" -v[version ] Display the program version\n");
|
|
printf("\n%s version %s\n", progname, PROG_VERSION);
|
return;
|
}
|
|
int main (int argc, char **argv)
|
{
|
int daemon = 1;
|
int opt;
|
char *progname=NULL;
|
char *logfile="client.log";
|
int loglevel=LOG_LEVEL_INFO;
|
int logsize=10; /* logfile size max to 10K */
|
|
struct option long_options[] = {
|
{"debug", no_argument, NULL, 'd'},
|
{"version", no_argument, NULL, 'v'},
|
{"help", no_argument, NULL, 'h'},
|
{NULL, 0, NULL, 0}
|
};
|
|
progname = (char *)basename(argv[0]);
|
|
/* Parser the command line parameters */
|
while ((opt = getopt_long(argc, argv, "dvh", long_options, NULL)) != -1)
|
{
|
switch (opt)
|
{
|
case 'd': /* Set debug running */
|
daemon = 0;
|
logfile="console";
|
loglevel=LOG_LEVEL_DEBUG;
|
break;
|
|
case 'v': /* Get software version */
|
printf("%s version %s\n", progname, PROG_VERSION);
|
return 0;
|
|
case 'h': /* Get help information */
|
program_usage(progname);
|
return 0;
|
|
default:
|
break;
|
}
|
|
}
|
|
if( log_open(logfile, loglevel, logsize, THREAD_LOCK_NONE) < 0 )
|
{
|
fprintf(stderr, "Initial log system failed\n");
|
return 1;
|
}
|
|
install_default_signal();
|
|
if( check_set_program_running(daemon, DAEMON_PIDFILE) < 0 )
|
goto cleanup;
|
|
while( ! g_signal.stop )
|
{
|
msleep(1000);
|
}
|
|
cleanup:
|
log_close();
|
unlink(DAEMON_PIDFILE);
|
|
return 0;
|
}
|