Esempio n. 1
0
void clockServiceHandler (xPL_ServicePtr theService, xPL_MessagePtr theMessage, xPL_ObjectPtr userValue)
{
    printf ( "Received a Clock Message from %s-%s.%s of type %d for %s.%s\n",
    xPL_getSourceVendor (theMessage), xPL_getSourceDeviceID (theMessage), xPL_getSourceInstanceID (theMessage),
    xPL_getMessageType (theMessage), xPL_getSchemaClass (theMessage), xPL_getSchemaType (theMessage));
    
}
Esempio n. 2
0
File: xPL-hub.c Progetto: Gremio/xPL
/* Return true if this is a signoff  message */
static Bool isSignoffMessage(xPL_MessagePtr theMessage) {
  String schemaType = xPL_getSchemaType(theMessage);
  if (schemaType == NULL) {
    xPL_Debug("Message is missing schema type -- not a heartbeat message");
    return FALSE;
  }

  return (xPL_strcmpIgnoreCase(schemaType, "end") == 0);
}
Esempio n. 3
0
void internalMessageHandler(xPL_MessagePtr theMessage, xPL_ObjectPtr userValue)
{

	char *sourceVendor, *sourceDeviceID, *sourceInstanceID, *schemaClass, *schemaType;
	xPL_MessageType messgeType;	
	char *timeStr;
	int tickMonth, tickDate, tickDay, tickYear, tickTime;
	time_t epoch;




	sourceVendor = xPL_getSourceVendor (theMessage);
	sourceDeviceID = xPL_getSourceDeviceID (theMessage);
	sourceInstanceID = xPL_getSourceInstanceID (theMessage);
	messgeType = xPL_getMessageType (theMessage);
	schemaClass = xPL_getSchemaClass (theMessage);
	schemaType = xPL_getSchemaType (theMessage);

	printf ( "Received a Message from %s-%s.%s of type %d for %s.%s\n",
										sourceVendor, sourceDeviceID, sourceInstanceID, messgeType, schemaClass, schemaType);
	
	if ( strcmp(schemaClass, "internal") == 0)
	{
		if ( strcmp(schemaType, "tick") == 0 )
		{
			timeStr = xPL_getMessageNamedValue(theMessage, "time");
/*			int timeMinutes = timeStr2int( timeStr );*/
			tickDate  = atoi (xPL_getMessageNamedValue(theMessage, "date"));
			tickYear  = atoi (xPL_getMessageNamedValue(theMessage, "year"));
			tickMonth = atoi (xPL_getMessageNamedValue(theMessage, "month"));
			tickDay   = atoi (xPL_getMessageNamedValue(theMessage, "day"));
			tickTime  = timeStr2int( xPL_getMessageNamedValue(theMessage, "time") );
			
			
			epoch   = atol (xPL_getMessageNamedValue(theMessage, "epoch"));
			
			//timeEvent( &epoch);
			compute_ev_time (&epoch);
			
			printf("heure %s => %d\n", timeStr, tickTime);
			printf("tickMonth=%d tickDate=%d tickDay=%d tickYear=%d tickTime=%d epoch=%d\n", tickMonth, tickDate, tickDay, tickYear, tickTime, epoch );

		}
	}

}
Esempio n. 4
0
void webgatewayMessageHandler(xPL_ServicePtr theService, xPL_MessagePtr theMessage, xPL_ObjectPtr userValue) {
 // printf( "Received a pmax Message from %s-%s.%s of type %d for %s.%s\n", 
	//  xPL_getSourceVendor(theMessage), xPL_getSourceDeviceID(theMessage), xPL_getSourceInstanceID(theMessage),
	//  xPL_getMessageType(theMessage), xPL_getSchemaClass(theMessage), xPL_getSchemaType(theMessage));
//	  printf("%s<BR>",xPL_formatMessage(theMessage));
//	printf(".");  
	  if (strcmp("gatestat",xPL_getSchemaType(theMessage))==0 )
    {
      if (xPL_getMessageNamedValue(theMessage, "status")!=NULL)
        strcpy(pmaxSystem.status    ,xPL_getMessageNamedValue(theMessage, "status"));
      if (xPL_getMessageNamedValue(theMessage, "pmaxstatus")!=NULL)
        strcpy(pmaxSystem.pmaxstatus,xPL_getMessageNamedValue(theMessage, "pmaxstatus"));
      if (xPL_getMessageNamedValue(theMessage, "readytoarm")!=NULL)
        strcpy(pmaxSystem.readytoarm,xPL_getMessageNamedValue(theMessage, "readytoarm"));
    } 
    
    
  if (strcmp("zonelist",xPL_getSchemaType(theMessage))==0 && xPL_getMessageNamedValue(theMessage, "zone-list")!=NULL )
    {
      strcpy(zonelist,xPL_getMessageNamedValue(theMessage, "zone-list"));
//      printf("%s\n",zonelist);
      nbzone=XPLlistLength(zonelist);
   //   printf("nbzone.....  %d<BR>",nbzone);   
    }
    
    if (strcmp("zoneinfo",xPL_getSchemaType(theMessage))==0 && xPL_getMessageNamedValue(theMessage, "zone-type")!=NULL && xPL_getMessageNamedValue(theMessage, "zone")!=NULL )
    {
      int zone=0;
      int i; 
      for (i=1;i<=30;i++)
      {
        if (strcmp(pmaxSystem.sensor[i].id,xPL_getMessageNamedValue(theMessage, "zone"))==0) {
          zone=i;
          break;
        }         
      }
     //printf("zinfo1 %d ",zone);  
      if (zone==0) { 
        for (i=1;i<=30;i++)
        {
          if (strcmp(pmaxSystem.sensor[i].id,"")==0) break;         
        }
        zone=i;
        strcpy(pmaxSystem.sensor[zone].id,xPL_getMessageNamedValue(theMessage, "zone"));
      //  printf("zoneid %s ",pmaxSystem.sensor[zone].id);    
    } 
    //printf("zinfo2 %d ",zone);    
      //sscanf(xPL_getMessageNamedValue(theMessage, "zone"),"%d",&zone);
      
      
      
      strcpy( pmaxSystem.sensor[zone].type , xPL_getMessageNamedValue(theMessage, "zone-type") );
    } 
   if (strcmp("zonestat",xPL_getSchemaType(theMessage))==0 && xPL_getMessageNamedValue(theMessage, "zone")!=NULL )
    {
      int zone=0;
      int i; 
      for (i=1;i<=30;i++)
      {
        if (strcmp(pmaxSystem.sensor[i].id,xPL_getMessageNamedValue(theMessage, "zone"))==0) {
          zone=i;
          break;
        }         
      } 
   //   printf("zstat1 %d ",zone);
      if (zone==0) { 
        for (i=1;i<=30;i++)
        {
          if (strcmp(pmaxSystem.sensor[i].id,"")==0) break;         
        }
        zone=i;
        strcpy(pmaxSystem.sensor[zone].id,xPL_getMessageNamedValue(theMessage, "zone"));
      //  printf("zoneid %s ",xPL_getMessageNamedValue(theMessage, "zone"));   
    }   
  //  printf("zstat2 %d ",zone);  
      
      
      
      //sscanf(xPL_getMessageNamedValue(theMessage, "zone"),"%d",&zone);
      
      if ( xPL_getMessageNamedValue(theMessage, "alert")!=NULL )
        strcpy(pmaxSystem.sensor[zone].alert,xPL_getMessageNamedValue(theMessage, "alert")); 
      if ( xPL_getMessageNamedValue(theMessage, "armed")!=NULL ) 
        strcpy(pmaxSystem.sensor[zone].armed,xPL_getMessageNamedValue(theMessage, "armed"));
      if ( xPL_getMessageNamedValue(theMessage, "tamper")!=NULL ) 
        strcpy(pmaxSystem.sensor[zone].tampered,xPL_getMessageNamedValue(theMessage, "tamper"));      
      if ( xPL_getMessageNamedValue(theMessage, "low-battery")!=NULL )
        strcpy(pmaxSystem.sensor[zone].lowbattery,xPL_getMessageNamedValue(theMessage, "low-battery"));
      if ( xPL_getMessageNamedValue(theMessage, "alarm")!=NULL )
        strcpy(pmaxSystem.sensor[zone].alarmed,xPL_getMessageNamedValue(theMessage, "alarm"));
      strcpy(pmaxSystem.sensor[zone].enrolled,"true");     
    }   
    
}
Esempio n. 5
0
void pmaxdMessageHandler(xPL_ServicePtr theService, xPL_MessagePtr theMessage, xPL_ObjectPtr userValue) {
  DEBUG(LOG_DEBUG,"Received a pmaxd Message from %s-%s.%s of type %d for %s.%s\n", 
	xPL_getSourceVendor(theMessage), xPL_getSourceDeviceID(theMessage), xPL_getSourceInstanceID(theMessage),
	xPL_getMessageType(theMessage), xPL_getSchemaClass(theMessage), xPL_getSchemaType(theMessage));
	DEBUG(LOG_DEBUG,"xpl message received: %s",xPL_formatMessage(theMessage));    
  DEBUG(LOG_INFO,"command: %s ", xPL_getMessageNamedValue(theMessage, "command"));
        
  if (strcmp("basic",xPL_getSchemaType(theMessage))==0 && xPL_getMessageNamedValue(theMessage, "command")!=NULL )  { 
    if (strcmp("arm-away",xPL_getMessageNamedValue(theMessage, "command"))==0 ) {
      DEBUG(LOG_INFO,"arming away.........");
      sendBuffer(&PowerlinkCommand[Pmax_ARMAWAY]);
    } 
    if (strcmp("arm-home",xPL_getMessageNamedValue(theMessage, "command"))==0 ) {
      DEBUG(LOG_INFO,"arming home........");
      sendBuffer(&PowerlinkCommand[Pmax_ARMHOME]);
    } 
    if (strcmp("disarm",xPL_getMessageNamedValue(theMessage, "command"))==0  )  {
      DEBUG(LOG_INFO,"disarming.....");
      sendBuffer(&PowerlinkCommand[Pmax_DISARM]);
    }
  }
  DEBUG(LOG_INFO,"not a security basic");
  if (strcmp("request",xPL_getSchemaType(theMessage))==0 && xPL_getMessageNamedValue(theMessage, "request")!=NULL )  { 
    DEBUG(LOG_INFO,"a security request");
    if (strcmp("gatestat",xPL_getMessageNamedValue(theMessage, "request"))==0  )  {
      DEBUG(LOG_INFO,"requesting getstat.....");
    
    
      
      sendBuffer(&PowerlinkCommand[Pmax_REQSTATUS]);
      int i;
      for(i=0;i<50;i++) {      
      serialHandler();
      }
      
      if (lastValidSerialIO<(time(NULL)-10))
      { DEBUG(LOG_INFO,"lst serial command too old");}
      else  {
      DEBUG(LOG_INFO,"lst serial recent enough");
      
      /* Create a message to send */
      pmaxdMessage = xPL_createBroadcastMessage(pmaxdService, xPL_MESSAGE_STATUS); 
    
      xPL_setSchema(pmaxdMessage, "security", "gatestat");              // setschema to security.basic
  
      xPL_setMessageNamedValue(pmaxdMessage, "status", gatestat.status);
     /* if (pmaxSystem.xplalarmstatus==AlarmArmed)    
        xPL_setMessageNamedValue(pmaxdMessage, "status", "armed");
      else   
        xPL_setMessageNamedValue(pmaxdMessage, "status", "disarmed"); */
      
      xPL_setMessageNamedValue(pmaxdMessage, "pmaxstatus", gatestat.pmstatus);
      /*if (pmaxSystem.xplpmaxstatus==PmaxArmedAway)
        xPL_setMessageNamedValue(pmaxdMessage, "pmaxstatus", "armed-away");
      if (pmaxSystem.xplpmaxstatus==PmaxArmedHome)  
        xPL_setMessageNamedValue(pmaxdMessage, "pmaxstatus", "armed-home");
      if (pmaxSystem.xplpmaxstatus==PmaxDisarmed)  
        xPL_setMessageNamedValue(pmaxdMessage, "pmaxstatus", "disarmed"); */
      
      /*if (pmaxSystem.readytoarm)        
        xPL_setMessageNamedValue(pmaxdMessage, "readytoarm", "true");
      else
        xPL_setMessageNamedValue(pmaxdMessage, "readytoarm", "false");   
        */
/*           
      
      if (pmaxSystem.status==0 || pmaxSystem.status==1 || pmaxSystem.status==2) {
        xPL_setMessageNamedValue(pmaxdMessage, "status", "disarmed");
        xPL_setMessageNamedValue(pmaxdMessage, "pmaxstatus", "disarmed");
      }      
      if (pmaxSystem.status==4 ||  pmaxSystem.status==10 )  {
        xPL_setMessageNamedValue(pmaxdMessage, "status", "armed");
        xPL_setMessageNamedValue(pmaxdMessage, "pmaxstatus", "armed-home");
      }     
      if (pmaxSystem.status==3 || pmaxSystem.status==5 || pmaxSystem.status==11)  {
        xPL_setMessageNamedValue(pmaxdMessage, "status", "armed");
        xPL_setMessageNamedValue(pmaxdMessage, "pmaxstatus", "armed-away");
      }      
      if ( (pmaxSystem.flags & 0x01)==1 )  {
        xPL_setMessageNamedValue(pmaxdMessage, "readytoarm", "true");
      }
      else  {
        xPL_setMessageNamedValue(pmaxdMessage, "readytoarm", "false");
      } */
      
      /* Broadcast the message */
      DEBUG(LOG_DEBUG,"xpl message sent: %s",xPL_formatMessage(pmaxdMessage));
      xPL_sendMessage(pmaxdMessage);
      }      
    }
    if (strcmp("zonelist",xPL_getMessageNamedValue(theMessage, "request"))==0  )  {
      DEBUG(LOG_INFO,"requesting zonelist.....");
  
      pmaxdMessage = xPL_createBroadcastMessage(pmaxdService, xPL_MESSAGE_STATUS);
      xPL_setSchema(pmaxdMessage, "security", "zonelist");              // setschema to security.basic
      
      char zonelist[256];
      zonelist[0]=0;
      char id[10];
      int i;
      for (i=1;i<=30;i++) {
        if (gatestat.zone[i].enrolled)  {
        //sprintf(id,"%d,",i);
        strcat(zonelist,gatestat.zone[i].info.id);
        strcat(zonelist,","); 
        }
      }
      zonelist[strlen(zonelist)-1]=0;
      DEBUG(LOG_INFO,"zonelist: %s",zonelist);
      xPL_setMessageNamedValue(pmaxdMessage, "zone-list", zonelist);
      DEBUG(LOG_DEBUG,"xpl message sent: %s",xPL_formatMessage(pmaxdMessage)); 
      xPL_sendMessage(pmaxdMessage);   
    }
     
     if (strcmp("zoneinfo",xPL_getMessageNamedValue(theMessage, "request"))==0  )  {
      int zone;
      zone=0;
      char * zonebuffer;
      zonebuffer= xPL_getMessageNamedValue(theMessage, "zone");
  //    sscanf(zonebuffer,"%d",&zone);
     int i; 
      for (i=1;i<=30;i++)
  {
//      pmaxSystem.sensor[i].type=perimeter;
      if (strcmp(gatestat.zone[i].info.id,zonebuffer)==0) break;         
  }
     zone=i; 
      
      
     DEBUG(LOG_INFO,"requesting zoneinfo for zone %s,%d.....",zonebuffer,zone);
          
      pmaxdMessage = xPL_createBroadcastMessage(pmaxdService, xPL_MESSAGE_STATUS);
      xPL_setSchema(pmaxdMessage, "security", "zoneinfo");              // setschema to security.basic
      xPL_setMessageNamedValue(pmaxdMessage, "zone", zonebuffer);
      xPL_setMessageNamedValue(pmaxdMessage, "zone-type", gatestat.zone[zone].info.zonetype);
      
     // if (pmaxSystem.sensor[zone].type==interior  )  xPL_setMessageNamedValue(pmaxdMessage, "zone-type", "interior");
     // if (pmaxSystem.sensor[zone].type==perimeter  )  xPL_setMessageNamedValue(pmaxdMessage, "zone-type", "perimeter");      
      DEBUG(LOG_DEBUG,"xpl message sent: %s",xPL_formatMessage(pmaxdMessage));
      xPL_sendMessage(pmaxdMessage);   
    }
    if (strcmp("zonestat",xPL_getMessageNamedValue(theMessage, "request"))==0  )  {
      int zone;
      zone=0;
      char * zonebuffer;
      zonebuffer=xPL_getMessageNamedValue(theMessage, "zone");
      //sscanf(zonebuffer,"%d",&zone);
       int i; 
      for (i=1;i<=30;i++)
  {
      if (strcmp(gatestat.zone[i].info.id,zonebuffer)==0) break;         
  }
     zone=i; 
      DEBUG(LOG_INFO,"requesting zonestat for zone %s,%d.....",zonebuffer,zone);
          
      pmaxdMessage = xPL_createBroadcastMessage(pmaxdService, xPL_MESSAGE_STATUS);
      xPL_setSchema(pmaxdMessage, "security", "zonestat");              // setschema to security.basic
      xPL_setMessageNamedValue(pmaxdMessage, "zone", zonebuffer);
      
      xPL_setMessageNamedValue(pmaxdMessage, "alert", gatestat.zone[zone].stat.alert); 
      //if (pmaxSystem.sensor[zone].state==SensorClose  )  xPL_setMessageNamedValue(pmaxdMessage, "alert", "false");
      //if (pmaxSystem.sensor[zone].state==SensorOpen  )  xPL_setMessageNamedValue(pmaxdMessage, "alert", "true");

      xPL_setMessageNamedValue(pmaxdMessage, "armed", gatestat.zone[zone].stat.armed);   
      //if (pmaxSystem.sensor[zone].armed  )  xPL_setMessageNamedValue(pmaxdMessage, "armed", "true");
      //else  xPL_setMessageNamedValue(pmaxdMessage, "armed", "false"); 
      
   
     
      xPL_setMessageNamedValue(pmaxdMessage, "alarm", gatestat.zone[zone].stat.alarm);
      xPL_setMessageNamedValue(pmaxdMessage, "state", gatestat.zone[zone].stat.state);
      
      xPL_setMessageNamedValue(pmaxdMessage, "tamper", gatestat.zone[zone].stat.tamper);
      //if (pmaxSystem.sensor[zone].tampered  )  xPL_setMessageNamedValue(pmaxdMessage, "tamper", "true");
      //else  xPL_setMessageNamedValue(pmaxdMessage, "tamper", "false");
      
      xPL_setMessageNamedValue(pmaxdMessage, "low-battery", gatestat.zone[zone].stat.lowbattery); 
      //if (pmaxSystem.sensor[zone].lowbattery  )  xPL_setMessageNamedValue(pmaxdMessage, "low-battery", "true");
      //else  xPL_setMessageNamedValue(pmaxdMessage, "low-battery", "false");  
      DEBUG(LOG_DEBUG,"xpl message sent: %s",xPL_formatMessage(pmaxdMessage));
      xPL_sendMessage(pmaxdMessage);
      
         
    }
  }
  DEBUG(LOG_INFO,"end message handling");
}
Esempio n. 6
0
static void xPLListener(xPL_MessagePtr theMessage, xPL_ObjectPtr userValue)
{

	if(!xPL_isBroadcastMessage(theMessage)){ /* If not a broadcast message */
		if(xPL_MESSAGE_COMMAND == xPL_getMessageType(theMessage)){ /* If the message is a command */
			const String iID = xPL_getTargetInstanceID(theMessage);
			const String type = xPL_getSchemaType(theMessage);
			const String class = xPL_getSchemaClass(theMessage);
			const String command =  xPL_getMessageNamedValue(theMessage, "command");
			const String request =  xPL_getMessageNamedValue(theMessage, "request");
		
				
			debug(DEBUG_EXPECTED,"Non-broadcast message received: type=%s, class=%s", type, class);
			
			/* Allocate a working string */


			if((!strcmp(instanceID, iID)) && (!strcmp(class, "security"))){
				
				if(!strcmp(type, "basic")){ /* Basic command schema */
					if(command){
						int index;
						switch((index = matchCommand(basicCommandList, command))){
							
							case 0: /* arm-away */
							case 1: /* arm-home */
							case 2: /* disarm */
								doArmDisarm(theMessage, index);
								break;
							
							default:
								break;
						}
					}
				}
				else if(!strcmp(type, "request")){ /* Request command schema */
					if(request){
						switch(matchCommand(requestCommandList, request)){

							case 0: /* gateinfo */
								doGateInfo();
								break;

							case 1: /* zonelist */
								doZoneList();
								break;

							case 2: /* zoneinfo */
								doZoneInfo(theMessage);
								break;

							case 3: /* gatestat */
								doGateStat();
								break;

							default:
								break;
						}
								
					}
				}
			}
		}

	}
}