/*
 * libssc: Library to expose Qualcomm Sensor Core sensors
 * Copyright (C) 2022-2026 Dylan Van Assche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
syntax = "proto2";

/*
 * Each message has a sensor UID to specify which sensor 
 * should receive the message. UIDs are 128bit, but ProtoBuf 
 * is limited to 64bit values, thus they are split into uid_low
 * and uid_high.
 */
message SscUid {
	required fixed64 low = 1;
	required fixed64 high = 2;
}

/* 
 * Client configuration 
 * @processor: a value from the SscProcessorType enum. Default APPS (1).
 * @suspend_mode: a value from the SscSuspendType enum. Default WAKEUP (0).
 * @no_wakeup_msg_ids: list of messages that do not cause a wakeup.
 */
message SscClientConfig {
        required int32 processor = 1 [default = 1];
        required int32 suspend_mode = 2 [default = 0]; 
}

/*
 * Client request body
 * @unknown: optional
 * @msg: the actual sensor request, specific for each sensor.
 * @is_passive: request is passive or not. Active triggers sensor activation.
 */
message SscClientRequestBody {
	optional bytes unknown = 1;
	optional bytes msg = 2;
	optional bool is_passive = 3 [default = false];
}

/*
 * Client request
 * @uid: UID of the sensor.
 * @msg_id: ID of the message.
 * @config: configuration for the wakeups of the client.
 * @request: request for the sensor
 */
message SscClientRequest {
	required SscUid uid = 1;
	required fixed32 msg_id = 2;
	required SscClientConfig config = 3;
	required SscClientRequestBody request = 4;
}

/*
 * Client response body
 * @msg_id: ID of the message.
 * @timestamp: DSP internal timer, 19.2 MHz.
 * @msg: the actual response of the sensor, sensor specific.
 */
message SscClientResponseBody {
	required fixed32 msg_id = 1;
	required fixed64 timestamp = 2;
	required bytes msg = 3;
}

/*
 * Client response
 * @uid: UID of the sensor.
 * @response: list of responses.
 */
message SscClientResponse {
	required SscUid uid = 1;
	repeated SscClientResponseBody response = 2;
}

/*
 * Sensor attribute request
 * @enable_updates: setting this property to true will enable updates for attributes.
 */
message SscAttrRequest {
	optional bool enable_updates = 2;
}

/*
 * Sensor attribute value array
 * @element: element of the attribute value array.
 */
message SscAttrValueArray {
	repeated SscAttrValue element = 1;
}

/*
 * Sensor attribute value
 * Depending on the attribute one of the optional values will be included.
 * @a: attribute value array data.
 * @s: string value data.
 * @f: floating point value data.
 * @i: integer value data.
 * @b: boolean value data.
 */
message SscAttrValue {
	optional SscAttrValueArray a = 1;
	optional string s = 2;
	optional float f = 3;
	optional fixed64 i = 4;
	optional bool b = 5;
}

/*
 * Sensor attribute value array
 * @v: element of the value array
 */
message SscAttrArrayValue {
	repeated SscAttrValue v = 1;
}

/*
 * Sensor attribute
 * @id: Attribute ID.
 * @value: Attribute value.
 */
message SscAttr {
	required int32 id = 1;
	required SscAttrArrayValue value_array = 2;
}

/*
 * Sensor attribute response
 * @attr: list of attributes for a sensor.
 */
message SscAttrResponse {
	repeated SscAttr attr = 1;
}

/*
 * Sensor enable config request
 * @sample_rate: requested sample rate in Hz.
 */
message SscEnableConfigRequest {
	required float sample_rate = 1;
}

/*
 * Sensor config response
 * @sample_rate: actual sample rate in Hz.
 * @mode: the sensor's operation mode.
 */
message SscConfigResponse {
	optional float sample_rate = 1;
	optional string mode = 5;
}
