예제 #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));
    
}
예제 #2
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 );

		}
	}

}
예제 #3
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");
}
예제 #4
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;
						}
								
					}
				}
			}
		}

	}
}