/* * Copyright (C) 2018 Knowles Electronics * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include #include #define LOG_TAG "ia_tunneling_sensor_test" #include #include #include #include #define MAX_TUNNELS 32 #define BUF_SIZE 8192 #define OUTPUT_FILE "/data/data/tnl_op" #define UNPARSED_OUTPUT_FILE "/data/data/unparsed_output" #define TUNNEL_DEVICE "/dev/sensor_tunnel" #define SENSOR_TUNNEL_SOURCE_ID IAXXX_SYSID_CHANNEL_RX_15_EP_0 #define SENSOR_TUNNEL_MODE TNL_MODE_ASYNC #define SENSOR_TUNNEL_ENCODE TNL_ENC_Q15 #define VSYNC_SENSOR_SOURCE_ID IAXXX_SYSID_SENSOR_OUTPUT_1 #define VSYNC_SENSOR_MODE TNL_MODE_ASYNC #define VSYNC_SENSOR_ENCODE TNL_ENC_OPAQUE struct raf_format_type { uint16_t frameSizeInBytes; // Frame length in bytes uint8_t encoding; // Encoding uint8_t sampleRate; // Sample rate }; struct raf_frame_type { uint64_t timeStamp; // Timestamp of the frame uint32_t seqNo; // Optional sequence number of the frame struct raf_format_type format; // Format information for the frame uint32_t data[0]; /* Start of the variable size payload. It must start at 128 bit aligned address for all the frames */ }; volatile int capturing = 1; void sigint_handler(int sig __unused) { ALOGE("Interrupted, setting the exit condition"); capturing = 0; } int main(int argc, char *argv[]) { int err = 0; FILE *tun_dev = NULL; FILE *out_fp[MAX_TUNNELS] = { NULL }; FILE *unp_out_fp = NULL; int bytes_avail = 0, bytes_rem = 0; int bytes_read = 0; void *buf = NULL; // The magic number is ROME in ASCII reversed. // So we are looking for EMOR in the byte stream const unsigned char magic_num[4] = {0x45, 0x4D, 0x4F, 0x52}; int i = 0; bool valid_frame = true; int timer_signal = 0; int lastSeqNum[MAX_TUNNELS] = { 0 }; int notFirstFrame[MAX_TUNNELS] = { 0 }; int frameDropCount[MAX_TUNNELS] = { 0 }; uint64_t tunnel_time_stamps[MAX_TUNNELS] = { 0 }; unsigned char *frame_start, *buf_itr; // Minimum bytes required is the magic number + tunnel id + reserved and // crc + raf struct int min_bytes_req = 4 + 2 + 6 + sizeof(struct raf_frame_type); struct tunlMsg tm; if (argc < 2) { ALOGE("USAGE: %s