Beispiel #1
0
static void doEXPTrigger(String line)
{
	String plist[4];
	int i;
	expMapPtr_t e;
	
	plist[0] = NULL;
	
	/* Do not send zone state changes if armed */
	if(stateBits.armed)
		return;
		
	/* Split the message */
	if(3 == splitString(line, plist, ',', 3)){
		for(e = expMapHead; e ; e = e->next){
			/* debug(DEBUG_EXPECTED,"plist[0]: %s, plist[1]: %s, e->addr: %d, e->channel: %d", plist[0], plist[1], e->addr, e->channel); */
			if((atoi(plist[0]) == e->addr)&&(atoi(plist[1]) == e->channel))
				break;
		}
		if(e){ /* If match */
			i = atoi(plist[2]);
			xPL_clearMessageNamedValues(xplEventTriggerMessage);
			xPL_addMessageNamedValue(xplEventTriggerMessage, "event", i ? "alert" : "normal");
			xPL_addMessageNamedValue(xplEventTriggerMessage, "zone", e->zone);
			xPL_sendMessage(xplEventTriggerMessage);
		}
	}
	if(plist[0])
		free(plist[0]);

}
Beispiel #2
0
static void tickHandler(int userVal, xPL_ObjectPtr obj)
{
	static Bool firstTime = TRUE;

	/* Process clock tick update checking */
	if(firstTime){
		firstTime = FALSE;
		xPL_clearMessageNamedValues(xplEventTriggerMessage);
		xPL_addMessageNamedValue(xplEventTriggerMessage, "event", "ready");
		xPL_sendMessage(xplEventTriggerMessage);
	}
	
	if(serialRetryTimer){ /* If this is non-zero, we lost the serial connection, wait retry time and try again */
		serialRetryTimer--;
		if(!serialRetryTimer){
			if(!(serioStuff = serio_open(comPort, COM_BAUD_RATE))){
				debug(DEBUG_UNEXPECTED,"Serial reconnect failed, trying later...");
				serialRetryTimer = SERIAL_RETRY_TIME;
				return;
			}
			else{
				debug(DEBUG_EXPECTED,"Serial reconnect successful");
				if(!xPL_addIODevice(serioHandler, 1234, serio_fd(serioStuff), TRUE, FALSE, FALSE))
					fatal("Could not register serial I/O fd with xPL");
			}
		}
	}

}
Beispiel #3
0
static void doLRRTrigger(String line)
{
	String plist[4];
	int i;

	plist[0] = NULL;

	/* Split the message */


	if(3 == splitString(line, plist, ',', 3)){
		
		/* If OPEN or CANCEL, clear the alarmLRR flag */
		if((!strcmp(plist[2], "OPEN")) || (!strcmp(plist[2], "CANCEL")))
			alarmLRR = FALSE;
			
		/* Try to find a match to an xPL equivalent reporting state */
		for(i = 0; lrrNameMap[i].ademco; i++){
			if(!strcmp(lrrNameMap[i].ademco, plist[2]))
				break;
		}
		if(lrrNameMap[i].ademco){ /* If match */
			xPL_clearMessageNamedValues(xplEventTriggerMessage);
			xPL_addMessageNamedValue(xplEventTriggerMessage, "event", lrrNameMap[i].xpl);
			xPL_sendMessage(xplEventTriggerMessage);
		
			/* Update the alarmLRR bit which reflects the status of all the alarms */
			if(!strcmp(lrrNameMap[i].xpl, "alarm"))
					alarmLRR = TRUE;
		}
	}
	if(plist[0])
		free(plist[0]);
}
Beispiel #4
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;  
}       
Beispiel #5
0
static void doZoneInfo(xPL_MessagePtr theMessage)
{
		const String zone = xPL_getMessageNamedValue(theMessage, "zone");
		zoneMapPtr_t zm;
		if(zone && (zm = zoneLookup(zone))){
			xPL_setSchema(xplStatusMessage, "security", "zoneinfo");
			
			/* Clear the message */
			xPL_clearMessageNamedValues(xplStatusMessage);
			
			/* Fill in the data */
			xPL_addMessageNamedValue(xplStatusMessage, "id", zone);
			xPL_addMessageNamedValue(xplStatusMessage, "zone-type", zm->zone_type);
			xPL_addMessageNamedValue(xplStatusMessage, "alarm-type", zm->alarm_type);
			xPL_addMessageNamedValue(xplStatusMessage, "area-count","0");
			/* Send the message */
			if(!xPL_sendMessage(xplStatusMessage))
				debug(DEBUG_UNEXPECTED, "request.zoneinfo transmission failed");
		}
}
Beispiel #6
0
static void doGateStat()
{
		String status = "disarmed";
		
		xPL_setSchema(xplStatusMessage, "security", "gatestat");
		
		/* Clear the message */
		xPL_clearMessageNamedValues(xplStatusMessage);
		
		/* Fill in the data */
		xPL_addMessageNamedValue(xplStatusMessage, "ac-fail", stateBits.acfail ? "true" : "false");
		xPL_addMessageNamedValue(xplStatusMessage, "low-battery", stateBits.lowbatt ? "true" : "false");
		if(stateBits.alarm)
			status = "alarm";
		else if(stateBits.armed)
			status = "armed";
		xPL_addMessageNamedValue(xplStatusMessage, "status", status);		
		
		/* Send the message */
		if(!xPL_sendMessage(xplStatusMessage))
			debug(DEBUG_UNEXPECTED, "request.gatestat transmission failed");
}
Beispiel #7
0
static void doZoneList()
{
	zoneMapPtr_t zm;

	xPL_setSchema(xplStatusMessage, "security", "zonelist");

	xPL_clearMessageNamedValues(xplStatusMessage);

	for(zm = zoneMapHead; zm; zm = zm->next){
		xPL_addMessageNamedValue(xplStatusMessage, "zone-list", zm->zone_name);
	}
	if(!xPL_sendMessage(xplStatusMessage))
		debug(DEBUG_UNEXPECTED, "request.zonelist transmission failed");
}
Beispiel #8
0
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;
}
Beispiel #9
0
static xPL_MessagePtr createHeartbeatMessage(xPL_ServicePtr theService, HeartbeatType heartbeatType) {
  xPL_MessagePtr theHeartbeat;

  /* Create the Heartbeat message */
  theHeartbeat = xPL_createBroadcastMessage(theService, xPL_MESSAGE_STATUS);
    
  /* Configure the heartbeat */
  switch (heartbeatType) {
  case HBEAT_NORMAL:
    xPL_setSchemaClass(theHeartbeat, "hbeat");
    xPL_setSchemaType(theHeartbeat, "app");
    xPL_addMessageNamedValue(theHeartbeat, "interval", xPL_intToStr(theService->heartbeatInterval / 60));
    break;

  case HBEAT_NORMAL_END:
    xPL_setSchemaClass(theHeartbeat, "hbeat");
    xPL_setSchemaType(theHeartbeat, "end");
    xPL_addMessageNamedValue(theHeartbeat, "interval", xPL_intToStr(theService->heartbeatInterval / 60));
    break;

  case HBEAT_CONFIG:
    xPL_setSchemaClass(theHeartbeat, "config");
    xPL_setSchemaType(theHeartbeat, "app");
    xPL_addMessageNamedValue(theHeartbeat, "interval", xPL_intToStr(CONFIG_HEARTBEAT_INTERVAL / 60));
    break;

  case HBEAT_CONFIG_END:
    xPL_setSchemaClass(theHeartbeat, "config");
    xPL_setSchemaType(theHeartbeat, "end");
    xPL_addMessageNamedValue(theHeartbeat, "interval", xPL_intToStr(CONFIG_HEARTBEAT_INTERVAL / 60));
    break;

  default: 
    return NULL;
  }

  /* Add standard heartbeat data */
  xPL_addMessageNamedValue(theHeartbeat, "port", xPL_intToStr(xPL_getPort()));
  xPL_addMessageNamedValue(theHeartbeat, "remote-ip", xPL_getListenerIPAddr());
  if (theService->serviceVersion) {
    xPL_addMessageNamedValue(theHeartbeat, "version", theService->serviceVersion);
  }    
  return theHeartbeat;
}
Beispiel #10
0
void doArmDisarm(xPL_MessagePtr theMessage, int cmd)
{
	const String code = xPL_getMessageNamedValue(theMessage, "id");
	
	if(!code) /* If no code, then bail */
		return;
	
	if(cmd < 2){
		if(stateBits.ready){
			serio_printf(serioStuff, "%s%c", code, (cmd == 0) ? '3' : '2');
		}
		else{ /* arming failed, send error trigger message */
			xPL_clearMessageNamedValues(xplEventTriggerMessage);
			xPL_addMessageNamedValue(xplEventTriggerMessage, "event", "error");
			xPL_sendMessage(xplEventTriggerMessage);
		}
	}
	else{ /* disarm */
		serio_printf(serioStuff, "%s1", code);
	}
}