Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
robotastic committed Mar 5, 2024
1 parent bcb35d6 commit 4d433e8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion occlusion-mapper/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM node:16.17.1-alpine3.16 as build
COPY client /
WORKDIR /client
RUN ls
RUN npm install
RUN npm install --force
RUN npm run build


Expand Down
1 change: 1 addition & 0 deletions occlusion-mapper/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@testing-library/user-event": "^13.5.0",
"bootstrap": "^5.3.3",
"luxon": "^3.4.4",
"media-stream-library": "^13.1.1",
"media-stream-player": "^13.1.1",
"react": "^18.2.0",
"react-bootstrap": "^2.10.1",
Expand Down
40 changes: 26 additions & 14 deletions occlusion-mapper/occlusion_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,21 @@ def __init__(

self.app = Flask(__name__)
CORS(self.app) # Add this line to enable CORS
self.app.add_url_rule("/camera-point", "camera-point", self._camera_callback) # Add this line
self.app.add_url_rule("/save-mapping", "save-mapping", self._save_mapping_callback, methods=["POST"]) # Add this line
@self.app.route('/camera.js')
self.app.add_url_rule(
"/camera-point", "camera-point", self._camera_callback
) # Add this line
self.app.add_url_rule(
"/save-mapping",
"save-mapping",
self._save_mapping_callback,
methods=["POST"],
) # Add this line

@self.app.route("/camera.js")
def hello_world():
return f'var camera_ip = "{self.camera_ip}";'
#self.app.run(host="0.0.0.0", debug=True, port=5000)

# self.app.run(host="0.0.0.0", debug=True, port=5000)

# Connect client in constructor
self.connect_client()
Expand All @@ -51,36 +60,36 @@ def _log_config(self) -> None:
"mapping_filepath": self.mapping_filepath,
"camera_ip": self.camera_ip,
}
logging.info(
f"Occlusion Mapper configuration:\n{json.dumps(config, indent=4)}"
)

logging.info(f"Occlusion Mapper configuration:\n{json.dumps(config, indent=4)}")

def _save_mapping_callback(self: Any) -> Tuple[str, int]:
# Do something with the data
data = request.get_json()
logging.info(f"Save Mapping request: {data}")
# Serializing json
json_object = json.dumps(data, indent=4)

# Writing to sample.json
with open(self.mapping_filepath, "w") as outfile:
outfile.write(json_object)
return jsonify({"status": "success"})


def _camera_callback(self: Any) -> Tuple[str, int]:
azimuth = request.args.get("azimuth")
elevation = request.args.get("elevation")
zoom = request.args.get("zoom")
logging.info(f"Camera Point request elevation: {elevation}, azimuth: {azimuth}, zoom: {zoom}")
logging.info(
f"Camera Point request elevation: {elevation}, azimuth: {azimuth}, zoom: {zoom}"
)
if azimuth is None or elevation is None or zoom is None:
return jsonify({"error": "Pan, elevation, and zoom parameters required"}), 400
return (
jsonify({"error": "Pan, elevation, and zoom parameters required"}),
400,
)
azimuth = float(azimuth)
elevation = float(elevation)
zoom = float(zoom)


data = {"azimuth": azimuth, "elevation": elevation, "zoom": zoom}

payload_json = self.generate_payload_json(
Expand Down Expand Up @@ -110,7 +119,10 @@ def main(self: Any) -> None:
self.publish_heartbeat, payload="Occlusion Mapper Module Heartbeat"
)

frontend_thread = Thread(target=self.app.run, kwargs={"host":"0.0.0.0", "port":5000, "debug":False})
frontend_thread = Thread(
target=self.app.run,
kwargs={"host": "0.0.0.0", "port": 5000, "debug": False},
)
frontend_thread.start()

while True:
Expand Down

0 comments on commit 4d433e8

Please sign in to comment.