ROME 2 Lab5
Embed:
(wiki syntax)
Show/hide line numbers
HTTPScriptLIDAR.cpp
00001 /* 00002 * HTTPScriptLIDAR.cpp 00003 * Copyright (c) 2020, ZHAW 00004 * All rights reserved. 00005 */ 00006 00007 #include <deque> 00008 #include "HTTPScriptLIDAR.h" 00009 00010 using namespace std; 00011 00012 inline string int2String(int i) { 00013 00014 char buffer[32]; 00015 sprintf(buffer, "%d", i); 00016 00017 return string(buffer); 00018 } 00019 00020 inline string float2String(float f) { 00021 00022 char buffer[32]; 00023 sprintf(buffer, "%.3f", f); 00024 00025 return string(buffer); 00026 } 00027 00028 /** 00029 * Create and initialize this http script. 00030 * @param lidar a reference to the lidar to read scans from. 00031 */ 00032 HTTPScriptLIDAR::HTTPScriptLIDAR(LIDAR& lidar) : lidar(lidar) {} 00033 00034 HTTPScriptLIDAR::~HTTPScriptLIDAR() {} 00035 00036 /** 00037 * This method gets called by the http server, when an object of this class is 00038 * registered with the server, and the corresponding script is called 00039 * by an http client. 00040 */ 00041 string HTTPScriptLIDAR::call(vector<string> names, vector<string> values) { 00042 00043 string response; 00044 00045 deque<Point> scan = lidar.getScan(); 00046 deque<Point> beacons = lidar.getBeacons(); 00047 00048 response += " <lidar>\r\n"; 00049 response += " <scan>\r\n"; 00050 response += " <size><int>"+int2String(scan.size())+"</int></size>\r\n"; 00051 for (unsigned short i = 0; i < scan.size(); i++) { 00052 response += " <point><x><float>"+float2String(scan[i].x)+"</float></x><y><float>"+float2String(scan[i].y)+"</float></y></point>\r\n"; 00053 } 00054 response += " </scan>\r\n"; 00055 response += " <beacons>\r\n"; 00056 response += " <size><int>"+int2String(beacons.size())+"</int></size>\r\n"; 00057 for (unsigned short i = 0; i < beacons.size(); i++) { 00058 response += " <point><x><float>"+float2String(beacons[i].x)+"</float></x><y><float>"+float2String(beacons[i].y)+"</float></y></point>\r\n"; 00059 } 00060 response += " </beacons>\r\n"; 00061 response += " </lidar>\r\n"; 00062 00063 return response; 00064 } 00065
Generated on Thu Jul 14 2022 18:53:11 by
1.7.2