Marco Oehler
/
Lab5
ROME 2 Lab5
HTTPScriptLIDAR.cpp@1:5201940a41c1, 2020-06-12 (annotated)
- Committer:
- oehlemar
- Date:
- Fri Jun 12 08:19:42 2020 +0000
- Revision:
- 1:5201940a41c1
- Parent:
- 0:893a1e710078
asdf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oehlemar | 0:893a1e710078 | 1 | /* |
oehlemar | 0:893a1e710078 | 2 | * HTTPScriptLIDAR.cpp |
oehlemar | 0:893a1e710078 | 3 | * Copyright (c) 2020, ZHAW |
oehlemar | 0:893a1e710078 | 4 | * All rights reserved. |
oehlemar | 0:893a1e710078 | 5 | */ |
oehlemar | 0:893a1e710078 | 6 | |
oehlemar | 0:893a1e710078 | 7 | #include <deque> |
oehlemar | 0:893a1e710078 | 8 | #include "HTTPScriptLIDAR.h" |
oehlemar | 0:893a1e710078 | 9 | |
oehlemar | 0:893a1e710078 | 10 | using namespace std; |
oehlemar | 0:893a1e710078 | 11 | |
oehlemar | 0:893a1e710078 | 12 | inline string int2String(int i) { |
oehlemar | 0:893a1e710078 | 13 | |
oehlemar | 0:893a1e710078 | 14 | char buffer[32]; |
oehlemar | 0:893a1e710078 | 15 | sprintf(buffer, "%d", i); |
oehlemar | 0:893a1e710078 | 16 | |
oehlemar | 0:893a1e710078 | 17 | return string(buffer); |
oehlemar | 0:893a1e710078 | 18 | } |
oehlemar | 0:893a1e710078 | 19 | |
oehlemar | 0:893a1e710078 | 20 | inline string float2String(float f) { |
oehlemar | 0:893a1e710078 | 21 | |
oehlemar | 0:893a1e710078 | 22 | char buffer[32]; |
oehlemar | 0:893a1e710078 | 23 | sprintf(buffer, "%.3f", f); |
oehlemar | 0:893a1e710078 | 24 | |
oehlemar | 0:893a1e710078 | 25 | return string(buffer); |
oehlemar | 0:893a1e710078 | 26 | } |
oehlemar | 0:893a1e710078 | 27 | |
oehlemar | 0:893a1e710078 | 28 | /** |
oehlemar | 0:893a1e710078 | 29 | * Create and initialize this http script. |
oehlemar | 0:893a1e710078 | 30 | * @param lidar a reference to the lidar to read scans from. |
oehlemar | 0:893a1e710078 | 31 | */ |
oehlemar | 0:893a1e710078 | 32 | HTTPScriptLIDAR::HTTPScriptLIDAR(LIDAR& lidar) : lidar(lidar) {} |
oehlemar | 0:893a1e710078 | 33 | |
oehlemar | 0:893a1e710078 | 34 | HTTPScriptLIDAR::~HTTPScriptLIDAR() {} |
oehlemar | 0:893a1e710078 | 35 | |
oehlemar | 0:893a1e710078 | 36 | /** |
oehlemar | 0:893a1e710078 | 37 | * This method gets called by the http server, when an object of this class is |
oehlemar | 0:893a1e710078 | 38 | * registered with the server, and the corresponding script is called |
oehlemar | 0:893a1e710078 | 39 | * by an http client. |
oehlemar | 0:893a1e710078 | 40 | */ |
oehlemar | 0:893a1e710078 | 41 | string HTTPScriptLIDAR::call(vector<string> names, vector<string> values) { |
oehlemar | 0:893a1e710078 | 42 | |
oehlemar | 0:893a1e710078 | 43 | string response; |
oehlemar | 0:893a1e710078 | 44 | |
oehlemar | 0:893a1e710078 | 45 | deque<Point> scan = lidar.getScan(); |
oehlemar | 0:893a1e710078 | 46 | deque<Point> beacons = lidar.getBeacons(); |
oehlemar | 0:893a1e710078 | 47 | |
oehlemar | 0:893a1e710078 | 48 | response += " <lidar>\r\n"; |
oehlemar | 0:893a1e710078 | 49 | response += " <scan>\r\n"; |
oehlemar | 0:893a1e710078 | 50 | response += " <size><int>"+int2String(scan.size())+"</int></size>\r\n"; |
oehlemar | 0:893a1e710078 | 51 | for (unsigned short i = 0; i < scan.size(); i++) { |
oehlemar | 0:893a1e710078 | 52 | response += " <point><x><float>"+float2String(scan[i].x)+"</float></x><y><float>"+float2String(scan[i].y)+"</float></y></point>\r\n"; |
oehlemar | 0:893a1e710078 | 53 | } |
oehlemar | 0:893a1e710078 | 54 | response += " </scan>\r\n"; |
oehlemar | 0:893a1e710078 | 55 | response += " <beacons>\r\n"; |
oehlemar | 0:893a1e710078 | 56 | response += " <size><int>"+int2String(beacons.size())+"</int></size>\r\n"; |
oehlemar | 0:893a1e710078 | 57 | for (unsigned short i = 0; i < beacons.size(); i++) { |
oehlemar | 0:893a1e710078 | 58 | response += " <point><x><float>"+float2String(beacons[i].x)+"</float></x><y><float>"+float2String(beacons[i].y)+"</float></y></point>\r\n"; |
oehlemar | 0:893a1e710078 | 59 | } |
oehlemar | 0:893a1e710078 | 60 | response += " </beacons>\r\n"; |
oehlemar | 0:893a1e710078 | 61 | response += " </lidar>\r\n"; |
oehlemar | 0:893a1e710078 | 62 | |
oehlemar | 0:893a1e710078 | 63 | return response; |
oehlemar | 0:893a1e710078 | 64 | } |
oehlemar | 0:893a1e710078 | 65 |