lasertransform.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "lasertransform.h"
00024
00026
00027 LaserTransform::LaserTransform( ConfigFile* cf, int section)
00028 : Driver(cf, section, true, PLAYER_MSGQUEUE_DEFAULT_MAXLEN, PLAYER_LASER_CODE)
00029 {
00030
00031 if (cf->ReadDeviceAddr(&this->laser_addr, section, "requires",
00032 PLAYER_LASER_CODE, -1, NULL) != 0)
00033 {
00034 this->SetError(-1);
00035 return;
00036 }
00037 this->laser_device = NULL;
00038 this->laser_timestamp.tv_sec = 0;
00039 this->laser_timestamp.tv_usec = 0;
00040
00041
00042 this->time.tv_sec = 0;
00043 this->time.tv_usec = 0;
00044 memset(&this->data, 0, sizeof(this->data));
00045
00046 return;
00047 }
00048
00049
00051
00052 int LaserTransform::Setup()
00053 {
00054
00055 if(Device::MatchDeviceAddress(this->laser_addr, this->device_addr))
00056 {
00057 PLAYER_ERROR("attempt to subscribe to self");
00058 return(-1);
00059 }
00060 if(!(this->laser_device = deviceTable->GetDevice(this->laser_addr)))
00061 {
00062 PLAYER_ERROR("unable to locate suitable laser device");
00063 return(-1);
00064 }
00065 if(this->laser_device->Subscribe(this->InQueue) != 0)
00066 {
00067 PLAYER_ERROR("unable to subscribe to laser device");
00068 return(-1);
00069 }
00070 return 0;
00071 }
00072
00073
00075
00076 int LaserTransform::Shutdown()
00077 {
00078
00079 this->laser_device->Unsubscribe(this->InQueue);
00080
00081 return 0;
00082 }
00083
00085
00086 int LaserTransform::ProcessMessage(QueuePointer & resp_queue,
00087 player_msghdr * hdr,
00088 void * data)
00089 {
00090
00091 if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_DATA, PLAYER_LASER_DATA_SCAN,
00092 this->laser_addr))
00093 {
00094 assert(hdr->size != 0);
00095 player_laser_data_t * l_data = reinterpret_cast<player_laser_data_t * > (data);
00096 this->UpdateLaser(l_data);
00097 return(0);
00098 }
00099
00100 else if(Message::MatchMessage(hdr, PLAYER_MSGTYPE_REQ, -1, this->device_addr))
00101 {
00102
00103 laser_device->PutMsg(this->InQueue, hdr, data);
00104
00105 this->ret_queue = resp_queue;
00106
00107 this->InQueue->SetFilter(this->laser_addr.host,
00108 this->laser_addr.robot,
00109 this->laser_addr.interf,
00110 this->laser_addr.index,
00111 -1,
00112 hdr->subtype);
00113
00114
00115 return(0);
00116 }
00117
00118 else if((Message::MatchMessage(hdr, PLAYER_MSGTYPE_RESP_ACK,
00119 -1, this->laser_addr)) ||
00120 (Message::MatchMessage(hdr, PLAYER_MSGTYPE_RESP_NACK,
00121 -1, this->laser_addr)))
00122 {
00123
00124 hdr->addr = this->device_addr;
00125 this->Publish(this->ret_queue, hdr, data);
00126
00127 this->InQueue->ClearFilter();
00128
00129 return(0);
00130 }
00131
00132 return(-1);
00133 }
Last updated 12 September 2005 21:38:45
|