123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #include <stdint.h>
- #include "../common/comm.h"
- #include "../common/iobuffer.h"
- #include "../common/sensor_socket.h"
- #include "imu_sensor.h"
- #include "message_queue.h"
-
- CImuSensor::CImuSensor(CMessageQueue* q):_message(q)
- {
-
- }
- void CImuSensor::SetSensorSocket(SensorSocket<CImuSensor>* can)
- {
- _can=can;
- }
- void CImuSensor::Notify(int8_t * buffer,int32_t size)
- {
-
-
- int32_t receivedCnt = size/CAN_MSG_LEN;
- cannet_frame* p = (cannet_frame*)buffer;
- for(int i=0; i<receivedCnt; i++)
- {
- p->canid=htonl(p->canid);
-
-
- if((p->canid&0xFF0)==0x580)
- {
- ImuProcess(*p);
- }
- p++;
- }
- if(receivedCnt>0)
- {
-
-
- _message->WriteIMUData(&_imu);
- }
-
-
- }
- int32_t CImuSensor::bcd2dec(const int8_t *data)
- {
-
- int32_t h0=(data[0]>>4)&0xF;
- int32_t l0=data[0]&0xF;
- int32_t h1=(data[1]>>4)&0xF;
- int32_t l1=data[1]&0xF;
- int32_t ret=((h0*10+l0)*10+h1)*10+l1;
- return ret;
- }
- void CImuSensor::ImuProcess(const cannet_frame& frame)
- {
- const int8_t* p=frame.data;
-
- if(p[0]==0x50&&p[1]==0x00)
- {
-
-
- }
- else if(p[0]==0x54&&p[1]==0x00)
- {
-
-
-
- }
- else
- {
-
-
- float sign=((p[0]>>4)&0xF) !=0?-1.f:1.f;
- int32_t h2=p[0]&0xF;
- int32_t h1=(p[1]>>4)&0xF;
- int32_t h0=p[1]&0xf;
- int32_t l1=((p[2]>>4)&0xF)*10+(p[2]&0xF);
-
- float dec=h2*100+h1*10+h0+(l1/100.f);
-
- _imu.rx=dec*sign;
-
- sign=((p[3]>>4)&0xF) !=0?1.f:-1.f;
- h2=p[3]&0xF;
- h1=(p[4]>>4)&0xF;
- h0=p[4]&0xf;
- l1=((p[5]>>4)&0xF)*10+(p[5]&0xF);
- dec=h2*100+h1*10+h0+(l1/100.f);
- _imu.ry=dec*sign;
-
-
- }
-
- }
-
- void CImuSensor::Start()
- {
- CIOBuffer buffer;
- cannet_frame* frame=(cannet_frame *)buffer.Buffer;
- frame->canid=htons(0x600+0x05);
- frame->dlc=8;
- frame->data[0]=0x40;
- frame->data[1]=0x53;
- frame->data[2]=0x10;
- frame->data[3]=0;
- frame->data[4]=0;
- frame->data[5]=0;
- frame->data[6]=0;
- frame->data[7]=0;
- buffer.Length=sizeof(cannet_frame);
- _can->Write(&buffer);
- _can->Read(&buffer);
- }
- void CImuSensor::Stop()
- {
- }
- void CImuSensor::PreProcess()
- {
-
- }
|