{"id":9187,"url":"https://patchwork.libcamera.org/api/1.1/patches/9187/?format=json","web_url":"https://patchwork.libcamera.org/patch/9187/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200804161358.1628962-5-niklas.soderlund@ragnatech.se>","date":"2020-08-04T16:13:53","name":"[libcamera-devel,v7,4/9] libcamera: camera_sensor: Generate a sensor ID","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"8d16bdeedab7e9e9509fb7ffc33f444c1676ff61","submitter":{"id":5,"url":"https://patchwork.libcamera.org/api/1.1/people/5/?format=json","name":"Niklas Söderlund","email":"niklas.soderlund@ragnatech.se"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/9187/mbox/","series":[{"id":1190,"url":"https://patchwork.libcamera.org/api/1.1/series/1190/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1190","date":"2020-08-04T16:13:49","name":"libcamera: Generate unique and stable camera IDs","version":7,"mbox":"https://patchwork.libcamera.org/series/1190/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9187/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9187/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 526AFBD87A\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  4 Aug 2020 16:14:26 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AFE7B6055A;\n\tTue,  4 Aug 2020 18:14:25 +0200 (CEST)","from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net\n\t[195.74.38.229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9328B60548\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  4 Aug 2020 18:14:22 +0200 (CEST)","from bismarck.berto.se (p54ac52a8.dip0.t-ipconnect.de\n\t[84.172.82.168]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA\n\tid 8e18ce9c-d66d-11ea-b48b-0050569116f7;\n\tTue, 04 Aug 2020 18:14:21 +0200 (CEST)"],"X-Halon-ID":"8e18ce9c-d66d-11ea-b48b-0050569116f7","Authorized-sender":"niklas@soderlund.pp.se","From":"=?utf-8?q?Niklas_S=C3=B6derlund?= <niklas.soderlund@ragnatech.se>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  4 Aug 2020 18:13:53 +0200","Message-Id":"<20200804161358.1628962-5-niklas.soderlund@ragnatech.se>","X-Mailer":"git-send-email 2.28.0","In-Reply-To":"<20200804161358.1628962-1-niklas.soderlund@ragnatech.se>","References":"<20200804161358.1628962-1-niklas.soderlund@ragnatech.se>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v7 4/9] libcamera: camera_sensor: Generate\n\ta sensor ID","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The ID is generated from information in the firmware description of the\nsensor if available or from module and model information if the sensor\nis virtual (for example VIMC).\n\nSigned-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>\n---\n* Changes sinve v6\n- Do not allow for subclassing\n- Add support for virtual sensors\n- Use new sysfs:: helper.\n\n* Changes since v5\n- Use new utils:: helper.\n- Allow for subclassing\n\n* Changes since v4\n- Fix spelling.\n\n* Changes since v3\n- Update commit message.\n- Add description of how ID are generated to comment.\n---\n include/libcamera/internal/camera_sensor.h |  3 ++\n src/libcamera/camera_sensor.cpp            | 38 ++++++++++++++++++++++\n 2 files changed, 41 insertions(+)","diff":"diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h\nindex 06c8292ca30129de..0f65fca46877e89a 100644\n--- a/include/libcamera/internal/camera_sensor.h\n+++ b/include/libcamera/internal/camera_sensor.h\n@@ -67,11 +67,14 @@ protected:\n \tstd::string logPrefix() const override;\n \n private:\n+\tint generateId();\n+\n \tconst MediaEntity *entity_;\n \tstd::unique_ptr<V4L2Subdevice> subdev_;\n \tunsigned int pad_;\n \n \tstd::string model_;\n+\tstd::string id_;\n \n \tV4L2Subdevice::Formats formats_;\n \tSize resolution_;\ndiff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp\nindex 350f49accad99c7b..3952d16b053ae20e 100644\n--- a/src/libcamera/camera_sensor.cpp\n+++ b/src/libcamera/camera_sensor.cpp\n@@ -9,6 +9,7 @@\n \n #include <algorithm>\n #include <float.h>\n+#include <fstream>\n #include <iomanip>\n #include <limits.h>\n #include <math.h>\n@@ -16,7 +17,9 @@\n \n #include <libcamera/property_ids.h>\n \n+#include \"libcamera/internal/file.h\"\n #include \"libcamera/internal/formats.h\"\n+#include \"libcamera/internal/sysfs.h\"\n #include \"libcamera/internal/utils.h\"\n \n /**\n@@ -204,6 +207,11 @@ int CameraSensor::init()\n \tif (ret < 0)\n \t\treturn ret;\n \n+\t/* Generate a unique ID for the sensor. */\n+\tret = generateId();\n+\tif (ret)\n+\t\treturn ret;\n+\n \t/* Retrieve and store the camera sensor properties. */\n \tconst ControlInfoMap &controls = subdev_->controls();\n \tint32_t propertyValue;\n@@ -541,4 +549,34 @@ std::string CameraSensor::logPrefix() const\n \treturn \"'\" + entity_->name() + \"'\";\n }\n \n+int CameraSensor::generateId()\n+{\n+\tconst std::string devPath = subdev_->devicePath();\n+\n+\t/* Try to get ID from firmware description. */\n+\tif (!sysfs::firmwareId(devPath, &id_))\n+\t\treturn 0;\n+\n+\t/* Virtual sensors not described in firmware, use modalias and model. */\n+\tstd::string path = devPath + \"/modalias\";\n+\tif (File::exists(path)) {\n+\t\tstd::ifstream file(path.c_str());\n+\n+\t\tif (!file.is_open()) {\n+\t\t\tLOG(CameraSensor, Error) << \"Failed to read modalias\";\n+\t\t\treturn -EINVAL;\n+\t\t}\n+\n+\t\tstd::string modalias;\n+\t\tstd::getline(file, modalias);\n+\t\tfile.close();\n+\n+\t\tid_ = modalias + \" \" + model();\n+\t\treturn 0;\n+\t}\n+\n+\tLOG(CameraSensor, Error) << \"Can't generate sensor ID\";\n+\treturn -EINVAL;\n+}\n+\n } /* namespace libcamera */\n","prefixes":["libcamera-devel","v7","4/9"]}