Example #1
0
void sendDevList(xPL_MessagePtr msg) {
	int deviceCount = 0, i;
	char deviceList[128];
	xPL_MessagePtr message = NULL;

	message = xPL_createBroadcastMessage(telldusService, xPL_MESSAGE_STATUS);
	xPL_setSchema(message, "lighting", "devlist");

	xPL_setMessageNamedValue(message, "network", xPL_getMessageNamedValue(msg, "network"));

	if (xPL_strcmpIgnoreCase(xPL_getMessageNamedValue(msg, "network"), "1") == 0) {
		xPL_setMessageNamedValue(message, "status", "ok");
		deviceCount = tdGetNumberOfDevices();
		for( i = 0; i < deviceCount; ++i ) {
			if (i == 0) { /* First */
				strcpy(deviceList, xPL_intToStr(tdGetDeviceId(i)));
			} else {
				strcat(deviceList, ",");
				strcat(deviceList, xPL_intToStr(tdGetDeviceId(i)));
			}
		}

		xPL_setMessageNamedValue(message, "device-count", xPL_intToStr(deviceCount) );
		xPL_setMessageNamedValue(message, "device", deviceList );
	} else {
		xPL_setMessageNamedValue(message, "status", "not-found");
	}

	xPL_sendMessage(message);

	xPL_releaseMessage(message);
}
Example #2
0
void sendDevInfo(xPL_MessagePtr msg) {
	xPL_MessagePtr message = NULL;
	Bool found = FALSE, deviceCount = tdGetNumberOfDevices();
	int deviceId = 0, methods = 0, i = 0, lastSentCommand, level = 0;
	char *name, buffer[12], *value;

	xPL_strToInt(xPL_getMessageNamedValue(msg, "device"), &deviceId);
	for( i = 0; i < deviceCount; ++i ) {
		if (tdGetDeviceId(i) == deviceId) {
			found = TRUE;
			break;
		}
	}

	message = xPL_createBroadcastMessage(telldusService, xPL_MESSAGE_STATUS);
	xPL_setSchema(message, "lighting", "devinfo");

	xPL_setMessageNamedValue(message, "network", xPL_getMessageNamedValue(msg, "network"));
	xPL_setMessageNamedValue(message, "device", xPL_getMessageNamedValue(msg, "device"));

	if (xPL_strcmpIgnoreCase(xPL_getMessageNamedValue(msg, "network"), "1") == 0 && found == TRUE) {
		lastSentCommand = tdLastSentCommand(deviceId, TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_DIM);
		if (lastSentCommand == TELLSTICK_TURNON) {
			level = 100;
		} else if (lastSentCommand == TELLSTICK_DIM) {
			value = tdLastSentValue(deviceId);
			level = atoi(value);
			free(value);
 			level = round((float)level / 255.0 * 100.0);
			if (level > 100) {
				level = 100;
			} else if (level < 0) {
				level = 0;
			}
		} else {
			level = 0;
		}
		methods = tdMethods(deviceId, TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_DIM);
		name = tdGetName(deviceId);
		sprintf(buffer, "1,%s,0,%i", (methods & TELLSTICK_DIM ? "true" : "false"), level);
		xPL_setMessageNamedValue(message, "status", "ok");
		xPL_setMessageNamedValue(message, "name", name );
		xPL_setMessageNamedValue(message, "report-on-manual", "false" );
		xPL_setMessageNamedValue(message, "channel-count", "1" );
		xPL_setMessageNamedValue(message, "primary-channel", "1" );
		xPL_setMessageNamedValue(message, "channel", buffer );
		xPL_setMessageNamedValue(message, "scene-count", "0" );

		free(name);
	} else {
		xPL_setMessageNamedValue(message, "status", "not-found");
	}

	xPL_sendMessage(message);

	xPL_releaseMessage(message);
}
Example #3
0
void sendGatewayReadyMessage() {
	xPL_MessagePtr gatewayReadyMessage = NULL;
	/* Create a message to send */
	gatewayReadyMessage = xPL_createBroadcastMessage(telldusService, xPL_MESSAGE_TRIGGER);
	xPL_setSchema(gatewayReadyMessage, "lighting", "gateway");

	/* Install the value and send the message */
	xPL_setMessageNamedValue(gatewayReadyMessage, "report", "gateway-ready");

	/* Broadcast the message */
	xPL_sendMessage(gatewayReadyMessage);

	xPL_releaseMessage(gatewayReadyMessage);
}
Example #4
0
void sendNetList() {
	xPL_MessagePtr message = NULL;

	message = xPL_createBroadcastMessage(telldusService, xPL_MESSAGE_STATUS);
	xPL_setSchema(message, "lighting", "netlist");

	xPL_setMessageNamedValue(message, "status", "ok");
	xPL_setMessageNamedValue(message, "network", "1");

	/* Broadcast the message */
	xPL_sendMessage(message);

	xPL_releaseMessage(message);
}
Example #5
0
/* Release an xPL service */
void xPL_releaseService(xPL_ServicePtr theService) {
  int ctxIndex;

  for (ctxIndex = 0; ctxIndex < serviceCount; ctxIndex++) {
    if (theService != serviceList[ctxIndex]) continue;

    /* Disable any heartbeats */
    xPL_setServiceEnabled(theService, FALSE);

    /* Release heartbeat message, if any */
    if (theService->heartbeatMessage != NULL) {
      xPL_releaseMessage(theService->heartbeatMessage);
    }

    /* Release service resources */
    STR_FREE(theService->serviceVendor);
    STR_FREE(theService->serviceDeviceID);
    STR_FREE(theService->serviceInstanceID);
    
    /* Release group info */
    if (theService->groupList != NULL) {
      xPL_clearServiceGroups(theService);
      free(theService->groupList);
    }

    /* Release filters */
    if (theService->messageFilterList != NULL) {
      /* Release filter resources */
      xPL_clearServiceFilters(theService);

      /* Release block of filters */
      free(theService->messageFilterList);
    }

    /* Release any listeners */
    if (theService->serviceListenerList != NULL) free(theService->serviceListenerList);

    /* Release configuration data */
    xPL_releaseServiceConfigurables(theService);

    /* Free the service */
    serviceCount--;
    if (ctxIndex < serviceCount) 
      memcpy(&serviceList[ctxIndex], &serviceList[ctxIndex + 1], sizeof(xPL_ServicePtr) * (serviceCount - ctxIndex));
    xPL_FreeService(theService);
    return;
  }
}
Example #6
0
/* Send an Goodbye XPL Heartbeat immediatly */
Bool xPL_sendGoodbyeHeartbeat(xPL_ServicePtr theService) {
  xPL_MessagePtr theHeartbeat;
  
  /* Create a shutdown message */
  if (theService->configurableService && !theService->serviceConfigured)
    theHeartbeat = createHeartbeatMessage(theService, HBEAT_CONFIG_END);
  else
    theHeartbeat = createHeartbeatMessage(theService, HBEAT_NORMAL_END);
    
  /* Send the message */
  if (!xPL_sendMessage(theHeartbeat)) return FALSE;

  /* Release message */
  xPL_releaseMessage(theHeartbeat);

  xPL_Debug("Sent Goodbye Heatbeat");
  return TRUE;
}
Example #7
0
void sendNetInfo(xPL_MessagePtr msg) {
	xPL_MessagePtr message = NULL;

	message = xPL_createBroadcastMessage(telldusService, xPL_MESSAGE_STATUS);
	xPL_setSchema(message, "lighting", "netinfo");

	xPL_setMessageNamedValue(message, "network", xPL_getMessageNamedValue(msg, "network"));

	if (xPL_strcmpIgnoreCase(xPL_getMessageNamedValue(msg, "network"), "1") == 0) {
		xPL_setMessageNamedValue(message, "status", "ok");
		xPL_setMessageNamedValue(message, "name", hostname );
		xPL_setMessageNamedValue(message, "device-count", xPL_intToStr(tdGetNumberOfDevices()) );
		xPL_setMessageNamedValue(message, "scene-count", "0" );
	} else {
		xPL_setMessageNamedValue(message, "status", "not-found");
	}

	xPL_sendMessage(message);

	xPL_releaseMessage(message);
}
Example #8
0
void xPL_setServiceEnabled(xPL_ServicePtr theService, Bool isEnabled) {
  /* Skip if already enabled */
  if (theService->serviceEnabled == isEnabled) return;

  /* Mark the service */
  theService->serviceEnabled = isEnabled;

  /* Handle enabling a disabled service */
  if (theService->serviceEnabled) {
    /* If there is an existing heartbeat, release it and rebuild it */
    if (theService->heartbeatMessage != NULL) {
      xPL_releaseMessage(theService->heartbeatMessage);
      theService->heartbeatMessage = NULL;
    }

    /* Start sending heartbeats */
    xPL_sendHeartbeat(theService);
  } else {
    /* Send goodby heartbeat */
    xPL_sendGoodbyeHeartbeat(theService);
  }
}
Example #9
0
void sendGatewayInfo() {
	xPL_MessagePtr message = NULL;

	message = xPL_createBroadcastMessage(telldusService, xPL_MESSAGE_STATUS);
	xPL_setSchema(message, "lighting", "gateinfo");

	xPL_setMessageNamedValue(message, "status", "ok");
	xPL_setMessageNamedValue(message, "protocol", "TELLDUS");
	xPL_setMessageNamedValue(message, "description", "xPL to Telldus TellStick gateway");
	xPL_setMessageNamedValue(message, "version", TELLDUS_VERSION);
	xPL_setMessageNamedValue(message, "author", "Telldus Technologies AB");
	xPL_setMessageNamedValue(message, "info-url", "http://www.telldus.se");
	xPL_setMessageNamedValue(message, "net-count", "1");
	xPL_setMessageNamedValue(message, "preferred-net", "1");
	xPL_setMessageNamedValue(message, "scenes-ok", "false");
	xPL_setMessageNamedValue(message, "channels-ok", "false");
	xPL_setMessageNamedValue(message, "fade-rate-ok", "false");

	/* Broadcast the message */
	xPL_sendMessage(message);

	xPL_releaseMessage(message);
}