Skip to content

Commit

Permalink
Init location client implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
pasuder committed Dec 2, 2014
1 parent f4097df commit 9a47d91
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 1 deletion.
2 changes: 1 addition & 1 deletion protoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export AMBER_DIR=${ROOT_DIR}/src/amber
export COMMON_DIR=${AMBER_DIR}/common

protoc -I ${COMMON_DIR} --python_out=${COMMON_DIR} ${COMMON_DIR}/drivermsg.proto
for pp in hokuyo ninedof roboclaw dummy; do
for pp in hokuyo location ninedof roboclaw dummy; do
protoc -I ${COMMON_DIR} -I ${AMBER_DIR}/${pp} --python_out=${AMBER_DIR}/${pp} ${AMBER_DIR}/${pp}/${pp}.proto
done
1 change: 1 addition & 0 deletions src/amber/location/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'paoolo'
18 changes: 18 additions & 0 deletions src/amber/location/location.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package amber.location_proto;
option java_package = "pl.edu.agh.amber.location.proto";
option java_outer_classname = "LocationProto";

import "drivermsg.proto";

extend amber.DriverMsg {
optional bool get_location = 60;
optional Location currentLocation = 61;
}

message Location {
optional double x = 1;
optional double y = 2;
optional double p = 3;
optional double alfa = 4;
optional double timeStamp = 5;
}
60 changes: 60 additions & 0 deletions src/amber/location/location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import logging
import logging.config
import os

from amber.common import amber_proxy, future_object
from amber.common import amber_proxy

__author__ = 'paoolo'

DEVICE_TYPE = 6

LOGGER_NAME = 'LocationProxy'
pwd = os.path.dirname(os.path.abspath(__file__))
try:
logging.config.fileConfig('%s/location.ini' % pwd)
except BaseException:
print 'Logging not set.'


class LocationProxy(amber_proxy.AmberProxy):
def __init__(self, amber_client, device_id):
super(LocationProxy, self).__init__(DEVICE_TYPE, device_id, amber_client)
self.__amber_client, self.__syn_num, self.__future_objs, self.__listener = amber_client, 0, {}, None

self.__logger = logging.getLogger(LOGGER_NAME)
self.__logger.setLevel(logging.WARNING)

self.__logger.info('Starting and registering LocationProxy.')

def __get_next_syn_num(self):
self.__syn_num += 1
return self.__syn_num

def handle_data_msg(self, header, message):
pass

def get_location(self):
self.__logger.debug('Get location')

syn_num = self.__get_next_syn_num()

driver_msg = self.__build_get_location_req_msg(syn_num)

location = Location()
self.__future_objs[syn_num] = location

self.__amber_client.send_message(self.build_header(), driver_msg)

return location


class Location(future_object.FutureObject):
def __init__(self):
super(Location, self).__init__()
self.__x, self.__y, self.__p, self.__alfa, self.__timestamp = None, None, None, None, None

def __str__(self):
if not self.is_available():
self.wait_available()
return "location:"
120 changes: 120 additions & 0 deletions src/amber/location/location_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9a47d91

Please sign in to comment.