CAN library containing a CAN controller object handling a FIFO, and CAN peripherals attached to it.
Diff: ControllerCAN.cpp
- Revision:
- 1:b69d05604535
- Parent:
- 0:ebe6f5e97160
- Child:
- 2:c81dff9c8a93
diff -r ebe6f5e97160 -r b69d05604535 ControllerCAN.cpp --- a/ControllerCAN.cpp Sat Feb 06 14:10:54 2016 +0000 +++ b/ControllerCAN.cpp Sat Feb 06 14:18:08 2016 +0000 @@ -3,7 +3,7 @@ ControllerCAN::ControllerCAN() : can(p30, p29) { can.frequency(250000); // Baud rate : kbits/s - can.attach(this, &ControllerCAN::can_ISR_Reader); // Fonction d'interruption CAN + can.attach(this, &ControllerCAN::can_ISR_Reader); // CAN ISR FIFO_ecriture = 0; FIFO_lecture = 0; FIFO_occupation = 0; @@ -13,8 +13,8 @@ ControllerCAN::~ControllerCAN(){ } -void ControllerCAN::attach(PeripherialCAN* peripherial){ - peripherials.push_back(peripherial); +void ControllerCAN::attach(PeripheralCAN* peripheral){ + peripherals.push_back(peripheral); } long ControllerCAN::writeData(long Id, const char *data, char len){ @@ -34,23 +34,15 @@ if(FIFO_max_occupation<FIFO_occupation) FIFO_max_occupation=FIFO_occupation; if(FIFO_occupation>SIZE_FIFO) - {}//while(!can.write(CANMessage(LCD_OVERFLOW,CANStandard))); + {} if(FIFO_occupation!=0) { - /*if(can_MsgRx[FIFO_lecture].id == Id) - { - //data = can_MsgRx[FIFO_lecture].data; - msg = can_MsgRx[FIFO_lecture]; - FIFO_lecture=(FIFO_lecture+1)%SIZE_FIFO; - return 1; - } - return 0;*/ char res = 0; - for (int i = 0; i < peripherials.size(); i++){ - vector<unsigned short*> IdsRead = peripherials[i]->getIdsRead(); + for (int i = 0; i < peripherals.size(); i++){ + vector<unsigned short*> IdsRead = peripherals[i]->getIdsRead(); for (int j = 0; j < IdsRead.size() ; j++){ if (can_MsgRx[FIFO_lecture].id == *(IdsRead[j])){ - peripherials[i]->update(*(IdsRead[j]), can_MsgRx[FIFO_lecture]); + peripherals[i]->update(*(IdsRead[j]), can_MsgRx[FIFO_lecture]); res = 1; break; } @@ -63,55 +55,10 @@ return -1; } -/*void ControllerCAN::FIFO_remove_msg(void){ - FIFO_lecture=(FIFO_lecture+1)%SIZE_FIFO; -}*/ - void ControllerCAN::can_ISR_Reader(void){ if (can.read(can_MsgRx[FIFO_ecriture])) { // FIFO gestion FIFO_ecriture=(FIFO_ecriture+1)%SIZE_FIFO; } -} - -/**void ControllerCAN::CAN_automate_reception(void){ - - static signed char FIFO_lecture=0,FIFO_occupation=0,FIFO_max_occupation=0; - FIFO_occupation=FIFO_ecriture-FIFO_lecture; - if(FIFO_occupation<0) - FIFO_occupation=FIFO_occupation+SIZE_FIFO; - if(FIFO_max_occupation<FIFO_occupation) - FIFO_max_occupation=FIFO_occupation; - if(FIFO_occupation>SIZE_FIFO) - //while(!can.write(CANMessage(LCD_OVERFLOW,CANStandard))); - if(FIFO_occupation!=0) - { - switch(can_MsgRx[FIFO_lecture].id) - { - case MOT_G_DAT_1 : - MOT_G_vit=(short)(can_MsgRx[FIFO_lecture].data[1]*256)+can_MsgRx[FIFO_lecture].data[0]; - MOT_G_i=(short)(can_MsgRx[FIFO_lecture].data[3]*256)+can_MsgRx[FIFO_lecture].data[2]; - MOT_G_pos=( short)(can_MsgRx[FIFO_lecture].data[5]*256)+can_MsgRx[FIFO_lecture].data[4]; - break; - case MOT_G_DAT_2 : - MOT_G_voltage=(unsigned short)(can_MsgRx[FIFO_lecture].data[3]*256)+can_MsgRx[FIFO_lecture].data[2]; - MOT_G_temp1=( short)(can_MsgRx[FIFO_lecture].data[5]*256)+can_MsgRx[FIFO_lecture].data[4]; - MOT_G_temp2=( short)(can_MsgRx[FIFO_lecture].data[7]*256)+can_MsgRx[FIFO_lecture].data[6]; - break; - case MOT_D_DAT_1 : - MOT_D_vit=(short)(can_MsgRx[FIFO_lecture].data[1]*256)+can_MsgRx[FIFO_lecture].data[0]; - MOT_D_i=(short)(can_MsgRx[FIFO_lecture].data[3]*256)+can_MsgRx[FIFO_lecture].data[2]; - MOT_D_pos=( short)(can_MsgRx[FIFO_lecture].data[5]*256)+can_MsgRx[FIFO_lecture].data[4]; - break; - case MOT_D_DAT_2 : - MOT_D_voltage=(unsigned short)(can_MsgRx[FIFO_lecture].data[3]*256)+can_MsgRx[FIFO_lecture].data[2]; - MOT_D_temp1=( short)(can_MsgRx[FIFO_lecture].data[5]*256)+can_MsgRx[FIFO_lecture].data[4]; - MOT_D_temp2=( short)(can_MsgRx[FIFO_lecture].data[7]*256)+can_MsgRx[FIFO_lecture].data[6]; - break; - default: - break; - } - FIFO_lecture=(FIFO_lecture+1)%SIZE_FIFO; - } -}**/ \ No newline at end of file +} \ No newline at end of file