Fixed build scripts to generate resource header files.

master
Hannes Matuschek 11 years ago
parent 4d79c7e1e4
commit 23d2e122bd

@ -3,6 +3,7 @@ project(libsdr)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
include(InstallHeadersWithDirectory) include(InstallHeadersWithDirectory)
include(LinkResources)
OPTION(BUILD_EXAMPLES "Build examples" OFF) OPTION(BUILD_EXAMPLES "Build examples" OFF)
OPTION(BUILD_UNIT_TESTS "Build unit tests" OFF) OPTION(BUILD_UNIT_TESTS "Build unit tests" OFF)

@ -0,0 +1,7 @@
macro(link_resources HEADER_NAME)
#create_resources("${CMAKE_CURRENT_BINARY_DIR}/${HEADER_NAME}.hh" ${ARGN})
add_custom_target(${HEADER_NAME} ALL
COMMAND ${CMAKE_COMMAND} -DOUTPUT="${CMAKE_CURRENT_BINARY_DIR}/${HEADER_NAME}.hh" -DRESOURCE_PATH="${CMAKE_CURRENT_SOURCE_DIR}" -DFILES="${ARGN}" -P "${PROJECT_SOURCE_DIR}/cmake/create_resources.cmake"
DEPENDS ${ARGN} SOURCES ${ARGN})
endmacro(link_resources)

@ -0,0 +1,22 @@
#
# Implements the packing of resource files into a header file
#
get_filename_component(OUTPUT_FILE ${OUTPUT} NAME)
message(STATUS "Generate resource file '${OUTPUT_FILE}' from: ${FILES}")
# Create empty file
file(WRITE ${OUTPUT} "")
# For each resource file
foreach(file ${FILES})
# Normalize filename
string(REGEX MATCH "([^/]+)$" filename ${file})
string(REGEX REPLACE "\\.| " "_" filename ${filename})
# Read and convert file content
file(READ "${RESOURCE_PATH}/${file}" filedata HEX)
string(REGEX REPLACE "([0-9a-fA-F][0-9a-fA-F])" "0x\\1," filedata ${filedata})
# Update output file
file(APPEND ${OUTPUT}
"extern \"C\" {\n"
" static char ${filename}[] = {${filedata}};\n"
" static unsigned ${filename}_size = sizeof(${filename});\n"
"}\n")
endforeach()

@ -1,4 +1,8 @@
#add_subdirectory(libhttpd)
# Creates a header file including the shared resources
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
link_resources(sdr_cmd_resources shared/index.html)
add_executable(sdr_cmd main.cc) add_executable(sdr_cmd main.cc)
add_dependencies(sdr_cmd sdr_cmd_resources)
target_link_libraries(sdr_cmd ${LIBS} libsdr ) target_link_libraries(sdr_cmd ${LIBS} libsdr )

@ -1,5 +0,0 @@
#include "json.hh"
JSON::JSON()
{
}

@ -1,5 +0,0 @@
#ifndef __SDR_HTTP_JSON_HH__
#define __SDR_HTTP_JSON_HH__
#endif // __SDR_HTTP_JSON_HH__

@ -6,6 +6,7 @@
#include <iostream> #include <iostream>
#include <csignal> #include <csignal>
#include "sdr_cmd_resources.hh"
using namespace sdr; using namespace sdr;
@ -27,14 +28,6 @@ static void __sigint_handler(int signo) {
server->stop(true); server->stop(true);
} }
const char *index_html = "<html>"
"<head></head>"
"<body>"
"<b>It is alive!</b>"
"<body>"
"</html>";
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
Application app; Application app;
server = new http::Server(8080); server = new http::Server(8080);
@ -47,9 +40,8 @@ int main(int argc, char *argv[]) {
signal(SIGINT, __sigint_handler); signal(SIGINT, __sigint_handler);
// Register callbacks // Register callbacks
server->addStatic("/", index_html, "text/html"); server->addStatic("/", std::string(index_html, index_html_size), "text/html");
server->addJSON("/echo", &app, &Application::echo); server->addJSON("/echo", &app, &Application::echo);
// start server // start server
server->start(true); server->start(true);

@ -0,0 +1,71 @@
<html>
<head>
<title>sdr-aprs &mdash; An APRS receiver using libsdr.</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
var map;
var connections = {};
var qth = null;
function onSetQTH (lon, lat) {
// Center map at QTH
map.setCenter(new google.maps.LatLng(lat, lon));
// Add or update the marker at QTH
if (null == qth) {
qth = new google.maps.Marker({
position: new google.maps.LatLng(lat, lon),
title: "QTH", map: map});
} else {
qth.setPosition(new google.maps.LatLng(lat, lon));
}
}
function onAddConnection (callsign, lon, lat, snr) {
// Check if connection exists
if (callsign in connections) {
// If connection exists, update SNR
connections[callsign].line.setOptions(options={
clickable: false, draggable: false, geodesic: true,
path: [qth.getPosition(), new google.maps.LatLng(lat, lon)],
strokeColor: '#0000FF', strokeOpacity: (1.0 + Math.min(0, snr/40)), strokeWeight: 2 } );
connections[callsign].marker.setPosition(new google.maps.LatLng(lat, lon));
} else {
// otherwise, add marker at location with label callsign and line from QTH to location
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lon), title: callsign, map: map});
var line = new google.maps.Polyline({
clickable: false, draggable: false, geodesic: true,
path: [qth.getPosition(), new google.maps.LatLng(lat, lon)],
strokeColor: '#0000FF', strokeOpacity: (1.0 + Math.min(0, snr/40)), strokeWeight: 2 });
line.setMap(map);
connections[callsign] = { marker: marker, line: line };
}
}
function initialize() {
// Create Map object
map = new google.maps.Map(
document.getElementById('map-canvas'),
{zoom:2, center: new google.maps.LatLng(0,0), streetViewControl:false});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas">
<p>Can not load Google Maps view. Check your internet conenction!</p>
</div>
</body>
</html>
Loading…
Cancel
Save