Exemple #1
0
// Process device properties into a JSON string.
int processDeviceJSON(int32_t deviceOffset, char* result, int resultLength) {
	char* currentPos = result;
	char* endPos = result + resultLength;
	uint32_t i;
	int32_t* device = _devices + deviceOffset;

	// If no properties return empty JSON.
	if (_requiredPropertiesCount == 0) {
        currentPos += snprintf(currentPos, endPos - currentPos, "{ }");
		return (int)(currentPos - result);
	}

	currentPos += snprintf(currentPos, endPos - currentPos, "{\n");

	// Process each line of data using the relevant value separator. In this case, a pipe.
	for(i = 0; i < _requiredPropertiesCount; i++) {
		// Add the next property to the buffer.
		currentPos += snprintf(
			currentPos,
			(int)(endPos - currentPos),
			"\"%s\": \"%s\"",
			*(_requiredPropertiesNames + i),
			getValueFromDevice(device, *(_requiredProperties + i)));

		if(i + 1 != _requiredPropertiesCount) {
			currentPos += snprintf(currentPos, endPos - currentPos, ",\n");
		}
		// Check to see if buffer is filled in which case return -1.
		if (currentPos >= endPos)
			return -1;
	}
	currentPos += snprintf(currentPos, endPos - currentPos, "\n}");
	return (int)(currentPos - result);
}
Exemple #2
0
// Process device properties into a CSV string.
int processDeviceCSV(int32_t deviceOffset, char* result, int resultLength) {
	char* currentPos = result;
	char* endPos = result + resultLength;
	uint32_t i;
	int32_t* device = _devices + deviceOffset;

	// If no properties return nothing.
	if (_requiredPropertiesCount == 0) {
        *currentPos = 0;
		return 0;
	}

	// Process each line of data using the relevant value separator. In this case, a pipe.
	for(i = 0; i < _requiredPropertiesCount; i++) {
		// Add the next property to the buffer.
		currentPos += snprintf(
			currentPos,
			(int)(endPos - currentPos),
			"%s,%s\n",
			*(_requiredPropertiesNames + i),
			getValueFromDevice(device, *(_requiredProperties + i)));

		// Check to see if buffer is filled in which case return -1.
		if (currentPos >= endPos)
			return -1;
	}

	// Return the length of the string buffer used.
	return (int)(currentPos - result);
}
Exemple #3
0
// Process device properties into a JSON string.
int fiftyoneDegreesProcessDeviceJSON(int32_t deviceOffset, char* result, int resultLength) {
	const char* deviceValue;
	int32_t deviceValueLength, deviceValueIndex;
	char* currentPos = result;
	char* endPos = result + resultLength;
	uint32_t i;
	int32_t* device = _devices + deviceOffset;

	// If no properties return empty JSON.
	if (_requiredPropertiesCount == 0) {
        currentPos += snprintf(currentPos, endPos - currentPos, "{ }");
		return (int)(currentPos - result);
	}

	currentPos += snprintf(currentPos, endPos - currentPos, "{\n");

	// Process each line of data using the relevant value separator. In this case, a pipe.
	for(i = 0; i < _requiredPropertiesCount; i++) {
		
	
		// Add the next property to the buffer.
		currentPos += snprintf(
			currentPos,
			(int)(endPos - currentPos),
			"\"%s\": \"",
			*(_requiredPropertiesNames + i));
			
			deviceValue = getValueFromDevice(device, *(_requiredProperties + i));
			deviceValueLength = strlen(deviceValue);
			for(deviceValueIndex = 0; deviceValueIndex < deviceValueLength; deviceValueIndex++) {
				if(deviceValue[deviceValueIndex] == 0){
					break;
				}
				else if(deviceValue[deviceValueIndex] == '"'){
					currentPos += snprintf(
						currentPos,
						(int)(endPos - currentPos),
						"\\");
				}
				currentPos += snprintf(
					currentPos,
					(int)(endPos - currentPos),
					"%c",
					deviceValue[deviceValueIndex]);
			}
			currentPos += snprintf(
				currentPos,
				(int)(endPos - currentPos),
				"\"");
		if(i + 1 != _requiredPropertiesCount) {
			currentPos += snprintf(currentPos, endPos - currentPos, ",\n");
		}
		// Check to see if buffer is filled in which case return -1.
		if (currentPos >= endPos)
			return -1;
	}
	currentPos += snprintf(currentPos, endPos - currentPos, "\n}");
	return (int)(currentPos - result);
}
Exemple #4
0
// Takes the results of getDeviceOffset and getPropertyIndex to return a value.
char* getValue(int deviceOffset, int propertyIndex) {
    return getValueFromDevice(_devices + deviceOffset, propertyIndex);
}
Exemple #5
0
// Takes the results of getDeviceOffset and getPropertyIndex to return a value.
char* fiftyoneDegreesGetValue(int deviceOffset, int propertyIndex) {
    return getValueFromDevice(_devices + deviceOffset, propertyIndex);
}