2 Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "compose.hpp"
23 #include <dcp/raw_convert.h>
24 #include <libxml++/libxml++.h>
25 #include <boost/filesystem.hpp>
26 #include <boost/algorithm/string.hpp>
29 #define EDID_SYS_PATH "/sys/class/drm"
30 static uint8_t const edid_header[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 };
39 using namespace boost::filesystem;
40 using namespace boost::algorithm;
42 vector<Monitor> monitors;
46 path card_dir = String::compose("%1/card%2", EDID_SYS_PATH, card);
47 if (!is_directory(card_dir)) {
51 for (directory_iterator i = directory_iterator(card_dir); i != directory_iterator(); ++i) {
52 if (!starts_with(i->path().filename().string(), String::compose("card%1", card))) {
56 FILE* edid_file = fopen(path(i->path() / "edid").string().c_str(), "r");
62 int const N = fread(edid, 1, sizeof(edid), edid_file);
68 if (memcmp(edid, edid_header, 8) != 0) {
74 uint16_t mid = (edid[8] << 8) | edid[9];
75 mon.manufacturer_id += char(((mid >> 10) & 0x1f) + 'A' - 1);
76 mon.manufacturer_id += char(((mid >> 5) & 0x1f) + 'A' - 1);
77 mon.manufacturer_id += char(((mid >> 0) & 0x1f) + 'A' - 1);
79 mon.manufacturer_product_code = (edid[11] << 8) | edid[10];
81 mon.serial_number = (edid[15] << 24) | (edid[14] << 16) | (edid[13] << 8) | edid[12];
82 mon.week_of_manufacture = edid[16];
83 mon.year_of_manufacture = edid[17];
84 monitors.push_back (mon);
94 : manufacturer_product_code (0)
96 , week_of_manufacture (0)
97 , year_of_manufacture (0)
102 Monitor::Monitor (cxml::ConstNodePtr node)
103 : manufacturer_id(node->string_child("ManufacturerId"))
104 , manufacturer_product_code(node->number_child<uint32_t>("ManufacturerProductCode"))
105 , serial_number(node->number_child<uint32_t>("SerialNumber"))
106 , week_of_manufacture(node->number_child<int>("WeekOfManufacture"))
107 , year_of_manufacture(node->number_child<int>("YearOfManufacture"))
114 Monitor::as_xml (xmlpp::Node* parent) const
116 parent->add_child("ManufacturerId")->add_child_text(manufacturer_id);
117 parent->add_child("ManufacturerProductCode")->add_child_text(dcp::raw_convert<string>(manufacturer_product_code));
118 parent->add_child("SerialNumber")->add_child_text(dcp::raw_convert<string>(serial_number));
119 parent->add_child("WeekOfManufacture")->add_child_text(dcp::raw_convert<string>(week_of_manufacture));
120 parent->add_child("YearOfManufacture")->add_child_text(dcp::raw_convert<string>(year_of_manufacture));
124 operator== (Monitor const & a, Monitor const & b)
126 return a.manufacturer_id == b.manufacturer_id &&
127 a.manufacturer_product_code == b.manufacturer_product_code &&
128 a.serial_number == b.serial_number &&
129 a.week_of_manufacture == b.week_of_manufacture &&
130 a.year_of_manufacture == b.year_of_manufacture;