예제 #1
0
void startServer() {
	/* Initialze lighting service */

	/* Create  a service for us */
	if (gethostname(hostname, INSTANCE_MAX) != 0) {
		fprintf(stderr, "Unable to retrieve the hostname");
		exit(1);
	}
	telldusService = xPL_createService("telldus", "core", hostname);
	xPL_setServiceVersion(telldusService, TELLDUS_VERSION);

	/* Add a responder */
	xPL_addServiceListener(telldusService, lightingRequestHandler, xPL_MESSAGE_COMMAND, "lighting", "request", NULL);
	xPL_addServiceListener(telldusService, lightingCommandHandler, xPL_MESSAGE_COMMAND, "lighting", "basic", NULL);

	/* Install signal traps for proper shutdown */
	signal(SIGTERM, shutdownHandler);
	signal(SIGINT, shutdownHandler);

	/* Enable the service */
	xPL_setServiceEnabled(telldusService, TRUE);
	sendGatewayReadyMessage();

	for (;;) {
		/* Let XPL run */
		xPL_processMessages(-1);
	}
}
예제 #2
0
void initXpl() {
 
 if (!xPL_initialize(xPL_getParsedConnectionType())) {
    fprintf(stderr, "Unable to start xPL");
    exit(1);
  } 

  /* Initialze clock service */

  /* Create  a service for us */
  pmaxdService = xPL_createService("visonic", "powermaxplus", "default");
  xPL_setServiceVersion(pmaxdService, PMAXD_VERSION);
  
  /* Add a responder for time setting */
  xPL_addServiceListener(pmaxdService, pmaxdMessageHandler, xPL_MESSAGE_COMMAND, "security", NULL, NULL);

  

  /* Install signal traps for proper shutdown */
  signal(SIGTERM, shutdownHandler);
  signal(SIGINT, shutdownHandler);

  /* Enable the service */
    xPL_setServiceEnabled(pmaxdService, TRUE);

}
예제 #3
0
int main(void)
{
	char *data;
	long m,n;
	printf("%s%c%c\n",
	"Content-Type:text/html;charset=iso-8859-1",13,10);

//	printf("<h3>Multiplication results</h3>\n");

	data = getenv("QUERY_STRING");

  

	stripSpace(data);
	char schemaclass[500];
	char schematype[500];
	char namedvaluearray[500];
	char name[500];
	char value[500];
	char command[500];
	char varcontent[500];
  char jsoncontent[500];
  char NVelement[500];
//  printf("URL %s<BR>\n",data);
  strcpy(command,data);
  unencode(command);
  findVarInURL(varcontent,data,"xplpacket");
  unencode(varcontent); 
  stripSpace(varcontent);
	
  xPL_initialize(xPL_getParsedConnectionType());
  webgateway = xPL_createService("viknet", "webgateway", "default");  
  xPL_setServiceVersion(webgateway, "1.0");

  
  /* Add a responder for time setting */
  xPL_addServiceListener(webgateway, webgatewayMessageHandler, xPL_MESSAGE_ANY, "security", NULL, NULL);
  xPL_setServiceEnabled(webgateway, TRUE);
  /* Create a message to send */
  xplMessage = xPL_createBroadcastMessage(webgateway, xPL_MESSAGE_COMMAND);

  if (JSONfindObject(schemaclass,varcontent,"msgschemaclass")!=NULL && JSONfindObject(schematype,varcontent,"msgschematype")!=NULL)
    xPL_setSchema(xplMessage, JSONtoString(schemaclass), JSONtoString(schematype));
	else
    xPL_setSchema(xplMessage, "schemaclass", "schematype");	
	
	JSONfindObject(namedvaluearray,varcontent,"namevaluelist");
  int i;
   for (i=0;i<JSONArrayLength(namedvaluearray);i++)
   {
     JSONArrayAt(NVelement,namedvaluearray,i);
	   if ( JSONfindObject(name,NVelement,"name") && JSONfindObject(value,NVelement,"value"))
	   xPL_addMessageNamedValue(xplMessage, JSONtoString(name), JSONtoString(value));	   
   }
   xPL_sendMessage(xplMessage);
//   xPL_processMessages(0);
	return 0;  
}       
예제 #4
0
파일: xPLSend.c 프로젝트: mykeul/xPL4Linux
Bool sendMessage(int argc, String argv[]) {
  int argIndex = 0;
  xPL_ServicePtr theService = NULL;
  xPL_MessagePtr theMessage = NULL;
  String delimPtr;

  /* Create service so we can create messages */
  if ((theService = xPL_createService(srcVendor, srcDeviceID, srcInstanceID)) == NULL) {
    fprintf(stderr, "Unable to create xPL service\n");
    return FALSE;
  }

  /* Create an appropriate message */
  if (msgTarget == NULL) {
    if ((theMessage = xPL_createBroadcastMessage(theService, msgType)) == NULL) {
      fprintf(stderr, "Unable to create broadcast message\n");
      return FALSE;
    } 
  } else {
    if ((theMessage = xPL_createTargetedMessage(theService, msgType, tgtVendor, tgtDeviceID, tgtInstanceID)) == NULL) {
      fprintf(stderr, "Unable to create targetted message\n");
      return FALSE;
    }
  }

  /* Install the schema */
  xPL_setSchema(theMessage, msgSchemaClass, msgSchemaType);

  /* Install named values */
  for (argIndex = 1; argIndex < argc; argIndex++) {
    if ((delimPtr = strstr(argv[argIndex], "=")) == NULL) {
      fprintf(stderr, "Improperly formatted name/value pair %s\n", argv[argIndex]);
      return FALSE;
    }

    /* Break them up  and add it */
    *delimPtr++ = '\0';
    xPL_addMessageNamedValue(theMessage, argv[argIndex], delimPtr);
  }

  /* Send the message */
  if (!xPL_sendMessage(theMessage)) {
    fprintf(stderr, "Unable to send xPL message\n");
    return FALSE;
  }

  return TRUE;
}
예제 #5
0
int xpl4l_timer(node_t* argXmlConfig)
{
	static init = 1;
    static time_t oldClockTime, oldTickTime;
	time_t t;
    struct tm *ts;
    char       buf[80];

	Bool ret;
	
	if ( init )
	{
		t = 0;
		timer_loadConfig (argXmlConfig);
		init = 0;
		
		clockService = xPL_createService (XPLHAL4L_VENDOR, "clock", HAL4L_hostName);
		xPL_setServiceVersion (clockService, XPLHAL4L_VERSION);

		/* Add a responder for time setting */
		xPL_addServiceListener (clockService, clockServiceHandler, xPL_MESSAGE_ANY, "clock", NULL, NULL);
		
		/* Create a message to send */
		clockTickMessage = xPL_createBroadcastMessage (clockService, xPL_MESSAGE_STATUS);
		
		xPL_setSchema (clockTickMessage, "clock", "update");

		/* Internals messages */
		schedulerTickMessage = createInternalTickMessage();
		xPL_addMessageListener(internalMessageHandler, NULL);
		
		
	}
	
	t = time (NULL);
	ts = localtime(&t);

	if ( timerConfig.clock_enabled && t%timerConfig.clock_interval==0 && t!=oldClockTime)
	{

		strftime(buf, sizeof(buf), "%Y%m%d%H%M%S", ts);
		
		/* Install the value and send the message */
		xPL_setMessageNamedValue (clockTickMessage, "time", buf);
		
		/* Broadcast the message */
		xPL_sendMessage (clockTickMessage);

		oldClockTime = t;
	}

	if ( t%timerConfig.sched_interval==0 && t!=oldTickTime)
	{
		strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", ts);
		
		/* Crée le messageBody si NULL et y ajoute une seule ligne si elle n'existe pas, sinon la met à jour */
		xPL_setMessageNamedValue(schedulerTickMessage, "timestamp", buf);
		strftime(buf, sizeof(buf), "%H:%M", ts);
		xPL_setMessageNamedValue(schedulerTickMessage, "time", buf);
		strftime(buf, sizeof(buf), "%Y", ts);
		xPL_setMessageNamedValue(schedulerTickMessage, "year", buf);
		strftime(buf, sizeof(buf), "%m", ts);
		xPL_setMessageNamedValue(schedulerTickMessage, "month", buf);
		strftime(buf, sizeof(buf), "%Y%m%d", ts);
		xPL_setMessageNamedValue(schedulerTickMessage, "date", buf);
		strftime(buf, sizeof(buf), "%d", ts);
		xPL_setMessageNamedValue(schedulerTickMessage, "day", buf);

		sprintf(buf, "%d", t);
		xPL_setMessageNamedValue(schedulerTickMessage, "epoch", buf);


		
		ret = xPL_dispatchMessageEvent(schedulerTickMessage);

		printf ("Message dispatched = %s\n", ret == TRUE ? "TRUE":"FALSE");
    
		oldTickTime = t;

	}


}
예제 #6
0
int main(void)
{
  pmaxSystem.status[0]=0;
  pmaxSystem.pmaxstatus[0]=0;
  pmaxSystem.readytoarm[0]=0;
  pmaxSystem.PmaxStatus[0]=0;
  
  int k;
  for (k=0;k<31;k++)
  {
    pmaxSystem.sensor[k].type[0]=0;
    pmaxSystem.sensor[k].alert[0]=0;
    pmaxSystem.sensor[k].PmaxAlarmType[0]=0;
    pmaxSystem.sensor[k].armed[0]=0;                  
    pmaxSystem.sensor[k].alarmed[0]=0;
    pmaxSystem.sensor[k].lowbattery[0]=0;  
    pmaxSystem.sensor[k].enrolled[0]=0;
    pmaxSystem.sensor[k].tampered[0]=0;
    pmaxSystem.sensor[k].id[0]=0;
  } 
  
//	char *data;
	long m,n;
	printf("%s%c%c\n" ,
	"Content-Type:text/html;charset=iso-8859-1",13,10);

	
  xPL_initialize(xPL_getParsedConnectionType());
  webgateway = xPL_createService("viknet", "webgateway", "default");  
  xPL_setServiceVersion(webgateway, "1.0");

  /* Add a responder for time setting */
  xPL_addServiceListener(webgateway, webgatewayMessageHandler, xPL_MESSAGE_ANY, "security", NULL, NULL);
  xPL_setServiceEnabled(webgateway, TRUE);
//  int j;
  
//  for (j=0;j<10;j++)
//  {
  /* Create a message to send */
  xplMessage = xPL_createBroadcastMessage(webgateway, xPL_MESSAGE_COMMAND);
  xPL_setSchema(xplMessage, "security", "request");
  xPL_setMessageNamedValue(xplMessage, "request", "zonelist");	
  xPL_sendMessage(xplMessage);
//  printf("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n");
  int i;
  
  
  xplMessage = xPL_createBroadcastMessage(webgateway, xPL_MESSAGE_COMMAND);
  xPL_setSchema(xplMessage, "security", "request");
  xPL_setMessageNamedValue(xplMessage, "request", "gatestat");	
  xPL_sendMessage(xplMessage);
  
  
  for (i=1;i<1000;i++)
  {
    usleep(1000);
    if (nbzone!=0) break;
    xPL_processMessages(0);
  }
  
  
  strcpy(tpzonelist,zonelist);
  char * element;
//  printf("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n");
//  printf("zone: %d, %s\n",nbzone,zonelist);
//  for (i=0;i<nbzone;i++)  {
//  char * pch;
  element = strtok (tpzonelist,",");
   while (element != NULL)
  {
//    printf ("%s\n",element);
   
   // xplListAt(element,zonelist,i);
  //  sprintf(element,"%d",i);
  //  printf("element: %s\n",element);
    xplMessage = xPL_createBroadcastMessage(webgateway, xPL_MESSAGE_COMMAND);
    xPL_setSchema(xplMessage, "security", "request");
    xPL_setMessageNamedValue(xplMessage, "request", "zoneinfo");	
    xPL_setMessageNamedValue(xplMessage, "zone", element);	
    xPL_sendMessage(xplMessage);
    
    
    xplMessage = xPL_createBroadcastMessage(webgateway, xPL_MESSAGE_COMMAND);
    xPL_setSchema(xplMessage, "security", "request");
    xPL_setMessageNamedValue(xplMessage, "request", "zonestat");	
    xPL_setMessageNamedValue(xplMessage, "zone", element);	
    xPL_sendMessage(xplMessage);
    
    
    usleep(40000);
    xPL_processMessages(0);
    element = strtok (NULL, ",");  
  }
//  printf("zonelist: %s\n",zonelist);
  for (i=0;i<10;i++)
  { 
  usleep(15000);
  xPL_processMessages(0);
  }      
  printf("{ \"status\":\"%s\",\"pmaxstatus\":\"%s\",\"readytoarm\":\"%s\",\"sensor\":[",pmaxSystem.status,pmaxSystem.pmaxstatus,pmaxSystem.readytoarm);
 
// strcpy(tpzonelist,zonelist);
//  element = strtok (tpzonelist,",");
  i=0;
//  while (element != NULL)
  char tmpbuff[200];
  char buff[6000];
  buff[0]=0;
  for (i=0;i<31;i++)
  {
//    printf ("%s\n",element);
    if ( strcmp(pmaxSystem.sensor[i].id,"")!=0 ) { 
    sprintf(tmpbuff,"{\"zone\":\"%s\",\"type\":\"%s\",\"alert\":\"%s\",\"armed\":\"%s\",\"tamper\":\"%s\",\"low-battery\":\"%s\",\"alarm\":\"%s\"},",
    pmaxSystem.sensor[i].id,
    pmaxSystem.sensor[i].type,
    pmaxSystem.sensor[i].alert,
    pmaxSystem.sensor[i].armed,
    pmaxSystem.sensor[i].tampered,
    pmaxSystem.sensor[i].lowbattery,
    pmaxSystem.sensor[i].alarmed);
    strcat(buff,tmpbuff);
    //element = strtok (NULL, ",");
    //if (element!=NULL)
    
    //i++;
    }
  }
  buff[strlen(buff)-1]=0;
  printf("%s",buff);
  printf("]}"); 
  nbzone=0;
  zonelist[0]=0;

//}  
  
	return 0;  
}       
예제 #7
0
int main(int argc, char *argv[])
{
	int longindex;
	int optchar;
	String p;
	KeyEntryPtr_t e;
	zoneMapPtr_t zm;

	/* Set the program name */
	progName=argv[0];

	/* Parse the arguments. */
	while((optchar=getopt_long(argc, argv, SHORT_OPTIONS, longOptions, &longindex)) != EOF) {
		
		/* Handle each argument. */
		switch(optchar) {
			
			/* Was it a long option? */
			case 0:
				
				/* Hrmm, something we don't know about? */
				fatal("Unhandled long getopt option '%s'", longOptions[longindex].name);
			
			/* If it was an error, exit right here. */
			case '?':
				exit(1);

			/* Was it a config file path ? */
			case 'c':
				confreadStringCopy(configFile, optarg, WS_SIZE - 1);
				debug(DEBUG_ACTION,"New config file path is: %s", configFile);
				break;
		

		
			/* Was it a debug level set? */
			case 'd':

				/* Save the value. */
				debugLvl=atoi(optarg);
				if(debugLvl < 0 || debugLvl > DEBUG_MAX) {
					fatal("Invalid debug level");
				}

				break;

			/* Was it a pid file switch? */
			case 'f':
				confreadStringCopy(pidFile, optarg, WS_SIZE - 1);
				debug(DEBUG_ACTION,"New pid file path is: %s", pidFile);
				configOverride |= CO_PID_FILE;
				break;

			
			/* Was it a help request? */
			case 'h':
				showHelp();
				exit(0);

			/* Specify interface to broadcast on */
			case 'i': 
				confreadStringCopy(interface, optarg, WS_SIZE -1);
				xPL_setBroadcastInterface(interface);
				configOverride |= CO_INTERFACE;

				break;

			case 'u':
				/* Override debug path*/
				confreadStringCopy(debugFile, optarg, WS_SIZE - 1);
				debug(DEBUG_ACTION,"New debug path is: %s", debugFile);
				configOverride |= CO_DEBUG_FILE;
				break;

			/* Was it a no-backgrounding request? */
			case 'n':

				/* Mark that we shouldn't background. */
				noBackground = TRUE;

				break;
			case 'p':
				/* Override com port*/
				confreadStringCopy(comPort, optarg, WS_SIZE - 1);
				debug(DEBUG_ACTION,"New com port is: %s", comPort);
				configOverride |= CO_COM_PORT;
				break;

			/* Was it an instance ID ? */
			case 's':
				confreadStringCopy(instanceID, optarg, WS_SIZE);
				debug(DEBUG_ACTION,"New instance ID is: %s", instanceID);
				configOverride |= CO_INSTANCE_ID;
				break;


			/* Was it a version request? */
			case 'v':
				printf("Version: %s\n", VERSION);
				exit(0);
	

			
			/* It was something weird.. */
			default:
				fatal("Unhandled getopt return value %d", optchar);
		}
	}
	
	/* If there were any extra arguments, we should complain. */

	if(optind < argc) {
		fatal("Extra argument on commandline, '%s'", argv[optind]);
	}

	/* Load the config file */
	if(!(configEntry =confreadScan(configFile, NULL)))
		exit(1);

	/* Parse the general section */

	/* Com port */
	if(!(configOverride & CO_COM_PORT)){
		if((p = confreadValueBySectKey(configEntry, "general", "com-port"))){
			confreadStringCopy(comPort, p, WS_SIZE);
		}	
	}

	/* Debug file */
	if(!(configOverride & CO_DEBUG_FILE)){
		if((p = confreadValueBySectKey(configEntry, "general", "debug-file"))){
			confreadStringCopy(debugFile, p, WS_SIZE);
		}
	
	}

	/* PID file */
	if(!(configOverride & CO_PID_FILE)){
		if((p = confreadValueBySectKey(configEntry, "general", "pid-file"))){
			confreadStringCopy(pidFile, p, WS_SIZE);
		}
	
	}

	/* Instance ID */
	if(!(configOverride & CO_INSTANCE_ID)){
		if((p =  confreadValueBySectKey(configEntry, "general", "instance-id"))){
			confreadStringCopy(instanceID, p, WS_SIZE);
		}	
	}


	/* Interface */
	if(!(configOverride & CO_INTERFACE)){
		if((p = confreadValueBySectKey(configEntry, "general", "interface"))){
			confreadStringCopy(interface, p, WS_SIZE);
		}	
	}

	/* Build Zone Map */
	
	if(!(e = confreadGetFirstKeyBySection(configEntry, "zone-map")))
		fatal("A valid zone-map section and at least one entry must be defined in the config file");
	for(; e; e = confreadGetNextKey(e)){
		String plist[3];
		const String key = confreadGetKey(e);
		const String value = confreadGetValue(e);
		/* Allocate a zone struct */
		if(!(zm = mallocz(sizeof(zoneMap_t))))
			MALLOC_ERROR;
			
		/* Get the zone number */
		if(!str2uns(key, &zm->zone_num, 1, 99))
			syntax_error(e, configFile,"invalid zone number");
			
		/* Get the parameters */
		if(3 != splitString(value, plist, ',', 3))
			syntax_error(e, configFile, "3 parameters required");
		if(!(zm->zone_name = strdup(plist[0])))
			MALLOC_ERROR;
		if(!(zm->zone_type = strdup(plist[1])))
			MALLOC_ERROR;
		if(!(zm->alarm_type = strdup(plist[2])))
			MALLOC_ERROR;
			
		/* Hash the zone name */
		zm->zone_name_hash = confreadHash(zm->zone_name);
		
			
		/* Free the split string */
		free(plist[0]);
		
		/* Insert the entry into the zone list */
		if(!zoneMapHead)
			zoneMapHead = zoneMapTail = zm;
		else{
			zm->prev = zoneMapTail;
			zoneMapTail->next = zm;
			zoneMapTail = zm;
		}
		zoneCount++;
	}

	/* EXP zone mapping */

	for(e =  confreadGetFirstKeyBySection(configEntry, "exp-map"); e; e = confreadGetNextKey(e)){
		expMapPtr_t emp;
		const String keyString = confreadGetKey(e);
		const String zone = confreadGetValue(e);
		String plist[3];
		unsigned expaddr, expchannel;

		/* Check the key and zone strings */
		if(!(keyString) || (!zone))
			syntax_error(e, configFile, "key or zone missing");


		/* Split the address and channel */
		plist[0] = NULL;
		if(2 != splitString(keyString, plist, ',', 2))
			syntax_error(e, configFile, "left hand side needs 2 numbers separated by a comma");

		/* Convert and check address */
		if(!str2uns(plist[0], &expaddr, 1, 99))
			syntax_error(e, configFile,"address is limited from 1 - 99");


		/* Convert and check channel */
		if(!str2uns(plist[1], &expchannel, 1, 99))
			syntax_error(e, configFile,"channel is limited from 1 - 99");
			

		/* debug(DEBUG_ACTION, "Address: %u, channel: %u, zone: %s", expaddr, expchannel, zone); */
		
		/* Look up zone to ensure it is defined */
		
		if(!(zm = zoneLookup(zone)))
			syntax_error(e, configFile, "Zone must be defined in zone-map section");
		

		/* Get memory for entry */
		if(!(emp = mallocz(sizeof(expMap_t))))
			MALLOC_ERROR;

		/* Initialize entry */
		emp->zone_entry = zm;
		emp->addr = expaddr;
		emp->channel = expchannel;
		if(!(emp->zone = strdup(zone)))
			MALLOC_ERROR;

		/* Insert into list */
		if(!expMapHead){
			expMapHead = expMapTail = emp;
		}
		else{
			expMapTail->next = emp;
			emp->prev = expMapTail;
			expMapTail = emp;
		}

		/* Free parameter string */
		if(plist[0])
			free(plist[0]);
	}


	/* Turn on library debugging for level 5 */
	if(debugLvl >= 5)
		xPL_setDebugging(TRUE);

 	/* Make sure we are not already running (.pid file check). */
	if(pid_read(pidFile) != -1) {
		fatal("%s is already running", progName);
	}

	/* Check to see the serial device exists before we fork */
	if(!serio_check_node(comPort))
		fatal("Serial device %s does not exist or its permissions are not allowing it to be used.", comPort);

	/* Fork into the background. */

	if(!noBackground) {
		int retval;
		debug(DEBUG_STATUS, "Forking into background");

    		/* 
		* If debugging is enabled, and we are daemonized, redirect the debug output to a log file if
    		* the path to the logfile is defined
		*/

		if((debugLvl) && (debugFile[0]))                          
			notify_logpath(debugFile);

		/* Fork and exit the parent */

		if((retval = fork())){
      			if(retval > 0)
				exit(0);  /* Exit parent */
			else
				fatal_with_reason(errno, "parent fork");
    		}



		/*
		* The child creates a new session leader
		* This divorces us from the controlling TTY
		*/

		if(setsid() == -1)
			fatal_with_reason(errno, "creating session leader with setsid");


		/*
		* Fork and exit the session leader, this prohibits
		* reattachment of a controlling TTY.
		*/

		if((retval = fork())){
			if(retval > 0)
        			exit(0); /* exit session leader */
			else
				fatal_with_reason(errno, "session leader fork");
		}

		/* 
		* Change to the root of all file systems to
		* prevent mount/unmount problems.
		*/

		if(chdir("/"))
			fatal_with_reason(errno, "chdir to /");

		/* set the desired umask bits */

		umask(022);
		
		/* Close STDIN, STDOUT, and STDERR */

		close(0);
		close(1);
		close(2);
		} 

	/* Start xPL up */
	if (!xPL_initialize(xPL_getParsedConnectionType())) {
		fatal("Unable to start xPL lib");
	}

	/* Initialize xplrcs service */

	/* Create a service and set our application version */
	xplService = xPL_createService("hwstar", "xplademco", instanceID);
  	xPL_setServiceVersion(xplService, VERSION);

	/*
	* Create a status message object
	*/

  	xplStatusMessage = xPL_createBroadcastMessage(xplService, xPL_MESSAGE_STATUS);
  
	/*
	* Create trigger message objects
	*/

	/* security.gateway */
	if(!(xplEventTriggerMessage = xPL_createBroadcastMessage(xplService, xPL_MESSAGE_TRIGGER)))
		fatal("Could not initialize security.gateway trigger");
	xPL_setSchema(xplEventTriggerMessage, "security", "gateway");

	/* security.zone */
	if(!(xplZoneTriggerMessage = xPL_createBroadcastMessage(xplService, xPL_MESSAGE_TRIGGER)))
		fatal("Could not initialize security.zone trigger");
	xPL_setSchema(xplZoneTriggerMessage, "security", "zone");


  	/* Install signal traps for proper shutdown */
 	signal(SIGTERM, shutdownHandler);
 	signal(SIGINT, shutdownHandler);

	/* Initialize the COM port */
	
	if(!(serioStuff = serio_open(comPort, COM_BAUD_RATE)))
		fatal("Could not open com port: %s", comPort);


	/* Flush any partial commands */
	serio_printf(serioStuff, "\r");
	usleep(100000);
	serio_flush_input(serioStuff);

	/* Ask xPL to monitor our serial device */
	if(xPL_addIODevice(serioHandler, 1234, serio_fd(serioStuff), TRUE, FALSE, FALSE) == FALSE)
		fatal("Could not register serial I/O fd with xPL");

	/* Add 1 second tick service */
	xPL_addTimeoutHandler(tickHandler, 1, NULL);

  	/* And a listener for all xPL messages */
  	xPL_addMessageListener(xPLListener, NULL);


 	/* Enable the service */
  	xPL_setServiceEnabled(xplService, TRUE);

	/* Update pid file */
	if(pid_write(pidFile, getpid()) != 0) {
		debug(DEBUG_UNEXPECTED, "Could not write pid file '%s'.", pidFile);
	}




 	/** Main Loop **/

	for (;;) {
		/* Let XPL run forever */
		xPL_processMessages(-1);
  	}

	exit(1);
}