incremental
diff --git a/src/getvideo_main.cpp b/src/getvideo_main.cpp
index f73ee30..2259b8c 100644
--- a/src/getvideo_main.cpp
+++ b/src/getvideo_main.cpp
@@ -1,7 +1,14 @@
#include <video.h>
-#include <fstream>
-#include <iostream>
+
#include <iomanip>
+#include <iostream>
+#include <chrono>
+#include <thread>
+#include <vector>
+#include <fstream>
+#include <fcntl.h>
+#include <unistd.h>
+
namespace AstVideo {
class VideoPuller {
@@ -10,40 +17,91 @@
void initialize() {
std::cout << "Opening /dev/video\n";
- file.open("/dev/video", std::ios::out | std::ios::in | std::ios::binary);
- if (!file.is_open()) {
+ video_fd = open("/dev/video", O_RDWR);
+ if (!video_fd) {
std::cout << "Failed to open /dev/video\n";
+ } else {
+ std::cout << "Opened successfully\n";
}
+
+ std::vector<unsigned char> buffer(1024 * 1024, 0);
+
IMAGE_INFO image_info{};
-
- file.write(reinterpret_cast<char*>(&image_info), sizeof(image_info));
-
- file.read(reinterpret_cast<char*>(&image_info), sizeof(image_info));
+ image_info.do_image_refresh = 1; // full frame refresh
+ image_info.qc_valid = 0; // quick cursor disabled
+ image_info.parameter.features.w = 800;
+ image_info.parameter.features.h = 600;
+ image_info.parameter.features.chrom_tbl = 0; // level
+ image_info.parameter.features.lumin_tbl = 0;
+ image_info.parameter.features.jpg_fmt = 1;
+ image_info.parameter.features.buf = buffer.data();
+ image_info.crypttype = -1;
+ std::cout << "Writing\n";
- if (file){
- std::cout << "Read succeeded\n";
+ int status;
+ /*
+ status = write(video_fd, reinterpret_cast<char*>(&image_info),
+ sizeof(image_info));
+ if (status != 0) {
+ std::cout << "Write failed. Return: " << status <<"\n";
+ perror("perror output:");
}
+ */
+ std::cout << "Write done\n";
+ //std::this_thread::sleep_for(std::chrono::milliseconds(2000));
+ std::cout << "Reading\n";
+ status = read(video_fd, reinterpret_cast<char*>(&image_info), sizeof(image_info));
+ std::cout << "Reading\n";
+
+ if (status != 0) {
+ std::cout << "Read failed with status " << status << "\n";
+ }
+
auto pt = reinterpret_cast<char*>(&image_info);
- for(int i=0; i<sizeof(image_info); i++){
- std::cout << std::hex << std::setfill('0') << std::setw(2) << int(*(pt + i)) << " ";
+ for (int i = 0; i < sizeof(image_info); i++) {
+ std::cout << std::hex << std::setfill('0') << std::setw(2)
+ << int(*(pt + i)) << " ";
}
+ std::cout << "\n";
+ /*
+ for(int i = 0; i < 1024; i++){
+ if (i % 16 == 0){
+ std::cout << "\n";
+ }
+ std::cout << std::hex << std::setfill('0') << std::setw(2)
+ << int(buffer[i]) << " ";
+ }
+ */
+ buffer.resize(image_info.len);
+ std::ofstream f("/tmp/screen.jpg",std::ios::out | std::ios::binary);
+
+ f.write(reinterpret_cast<char*>(buffer.data()), buffer.size());
+
std::cout << "\n";
std::cout << "typedef struct _video_features {\n";
- std::cout << "short jpg_fmt: " << image_info.parameter.features.jpg_fmt << "\n";
- std::cout << "short lumin_tbl;" << image_info.parameter.features.lumin_tbl << "\n";
- std::cout << "short chrom_tbl;" << image_info.parameter.features.chrom_tbl << "\n";
- std::cout << "short tolerance_noise;" << image_info.parameter.features.tolerance_noise << "\n";
- std::cout << "int w;" << image_info.parameter.features.w << "\n";
- std::cout << "int h;" << image_info.parameter.features.h << "\n";
- //std::cout << "unsigned char *buf;" << image_info.parameter.features.buf << "\n";
+ std::cout << "short jpg_fmt: " << image_info.parameter.features.jpg_fmt
+ << "\n";
+ std::cout << "short lumin_tbl;" << image_info.parameter.features.lumin_tbl
+ << "\n";
+ std::cout << "short chrom_tbl;" << image_info.parameter.features.chrom_tbl
+ << "\n";
+ std::cout << "short tolerance_noise;"
+ << image_info.parameter.features.tolerance_noise << "\n";
+ std::cout << "int w; 0X" << image_info.parameter.features.w << "\n";
+ std::cout << "int h; 0X" << image_info.parameter.features.h << "\n";
+
+ std::cout << "void* buf; 0X" << static_cast<void*>(image_info.parameter.features.buf) << "\n";
+ // std::cout << "unsigned char *buf;" << image_info.parameter.features.buf
+ // << "\n";
std::cout << "} FEATURES_TAG;\n";
std::cout << "typedef struct _image_info {";
- std::cout << "short do_image_refresh;" << image_info.do_image_refresh << "\n";
+ std::cout << "short do_image_refresh;" << image_info.do_image_refresh
+ << "\n";
std::cout << "char qc_valid;" << image_info.qc_valid << "\n";
std::cout << "unsigned int len;" << image_info.len << "\n";
std::cout << "int crypttype;" << image_info.crypttype << "\n";
@@ -54,8 +112,10 @@
std::cout << "} parameter;\n";
std::cout << "} IMAGE_INFO;\n";
std::cout << std::endl;
+
+ close(video_fd);
}
- std::fstream file;
+ int video_fd;
};
}
diff --git a/src/webserver_main.cpp b/src/webserver_main.cpp
index 58483df..80354fb 100644
--- a/src/webserver_main.cpp
+++ b/src/webserver_main.cpp
@@ -1,3 +1,9 @@
+#include <webassets.hpp>
+#include <web_kvm.hpp>
+#include "ssl_key_handler.hpp"
+
+#include "app_type.hpp"
+
#include "crow/app.h"
#include "crow/ci_map.h"
#include "crow/common.h"
@@ -20,25 +26,20 @@
#include "crow/utility.h"
#include "crow/websocket.h"
-#include "app_type.hpp"
#include "color_cout_g3_sink.hpp"
#include "token_authorization_middleware.hpp"
#include "webassets.hpp"
+
+#include <boost/asio.hpp>
+#include <boost/endian/arithmetic.hpp>
+
+
#include <iostream>
#include <memory>
#include <string>
-#include "ssl_key_handler.hpp"
-
-#include <boost/endian/arithmetic.hpp>
-
-#include <boost/asio.hpp>
-
#include <unordered_set>
-#include <webassets.hpp>
-
-#include <web_kvm.hpp>
int main(int argc, char** argv) {
auto worker(g3::LogWorker::createLogWorker());
@@ -53,6 +54,7 @@
ensuressl::ensure_openssl_key_present_and_valid(ssl_pem_file);
BmcAppType app;
+
crow::webassets::request_routes(app);
crow::kvm::request_routes(app);
@@ -68,16 +70,19 @@
CROW_ROUTE(app, "/login")
.methods("POST"_method)([&](const crow::request& req) {
+ crow::json::wvalue x;
auto auth_token =
app.get_context<crow::TokenAuthorizationMiddleware>(req).auth_token;
- crow::json::wvalue x;
+
x["token"] = auth_token;
return x;
});
CROW_ROUTE(app, "/logout")
- .methods("GET"_method, "POST"_method)([]() {
+ .methods("GET"_method, "POST"_method)([&](const crow::request& req) {
+
+ app.get_context<crow::TokenAuthorizationMiddleware>(req).auth_token = "";
// Do nothing. Credentials have already been cleared by middleware.
return 200;
});