Yuta Togashi / can_network_definition_2022

Dependents:   Tourobo2022_TBCMotorDriver

Committer:
YutaTogashi
Date:
Fri Jul 29 08:11:13 2022 +0000
Revision:
5:e419661e0758
Parent:
4:11d4db00036f
Child:
6:bc2f0d4b968a
add data_type sensor_board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YutaTogashi 0:74bedeff0dc6 1 #ifndef CAN_NETWORK_DEFINITION_2022_H
YutaTogashi 0:74bedeff0dc6 2 #define CAN_NETWORK_DEFINITION_2022_H
YutaTogashi 0:74bedeff0dc6 3 /************************************************識別子(CAN_ID)****************************************************/
YutaTogashi 0:74bedeff0dc6 4 namespace can_protcol {
YutaTogashi 0:74bedeff0dc6 5 /***********デバイス型(0b000~0b111)***************/
YutaTogashi 0:74bedeff0dc6 6 namespace device_type {
YutaTogashi 0:74bedeff0dc6 7 enum DEVICE_TYPE_NUMBER {
YutaTogashi 0:74bedeff0dc6 8 ALL_MCU =0b000,
YutaTogashi 0:74bedeff0dc6 9 POWER_SUPPLY =0b001,
YutaTogashi 0:74bedeff0dc6 10 CONTROL_MCU =0b010,
YutaTogashi 0:74bedeff0dc6 11 MOTOR_DRIVER =0b011,
YutaTogashi 0:74bedeff0dc6 12 PC =0b100,
YutaTogashi 3:94ea7db4bd8c 13 SOLENOID_MCU =0b101,
YutaTogashi 0:74bedeff0dc6 14 };
YutaTogashi 0:74bedeff0dc6 15 }
YutaTogashi 0:74bedeff0dc6 16 /***********************************************/
YutaTogashi 0:74bedeff0dc6 17
YutaTogashi 0:74bedeff0dc6 18 /*********各デバイス型の番号(0b000~0b1111)*********/
YutaTogashi 0:74bedeff0dc6 19 namespace device_number {
YutaTogashi 0:74bedeff0dc6 20 enum DEVICE_NUMBER {
YutaTogashi 0:74bedeff0dc6 21 DEVICE_NUMBER =0b1111,
YutaTogashi 0:74bedeff0dc6 22 };
YutaTogashi 0:74bedeff0dc6 23 }
YutaTogashi 0:74bedeff0dc6 24 /***********************************************/
YutaTogashi 0:74bedeff0dc6 25
YutaTogashi 0:74bedeff0dc6 26 /******各デバイス型のデータタイプ(0b000~0b1111)*****/
YutaTogashi 0:74bedeff0dc6 27 namespace data_type {
YutaTogashi 0:74bedeff0dc6 28 namespace motor_driver {
YutaTogashi 0:74bedeff0dc6 29 enum DATA_TYPE_NUMBER {
YutaTogashi 0:74bedeff0dc6 30 DEBAG_MODE =0b0000,
YutaTogashi 0:74bedeff0dc6 31 PARAMETER =0b0001,
YutaTogashi 0:74bedeff0dc6 32 CONTROL_INFORMATION =0b0010,
YutaTogashi 0:74bedeff0dc6 33 STEER_CONTROL_INFORMATION =0b0011,
YutaTogashi 0:74bedeff0dc6 34 PRINTF_FORMAT =0b0100,
YutaTogashi 1:fca2417eddaa 35 DATA_TYPE_NUMBER =0b1111,
YutaTogashi 0:74bedeff0dc6 36 };
YutaTogashi 0:74bedeff0dc6 37 }
YutaTogashi 4:11d4db00036f 38
YutaTogashi 4:11d4db00036f 39 namespace solenoid_driver {
YutaTogashi 4:11d4db00036f 40 enum DATA_TYPE_NUMBER {
YutaTogashi 4:11d4db00036f 41 DEBAG_MODE =0b0000,
YutaTogashi 4:11d4db00036f 42 STATUS =0b0001,
YutaTogashi 4:11d4db00036f 43 STATUS_OR =0b0010,
YutaTogashi 4:11d4db00036f 44 STATUS_AND =0b0011,
YutaTogashi 4:11d4db00036f 45 OPERATE_INDIVIDUAL_SOLENOID =0b0100,
YutaTogashi 4:11d4db00036f 46 DATA_TYPE_NUMBER =0b1111,
YutaTogashi 4:11d4db00036f 47 };
YutaTogashi 4:11d4db00036f 48 }
YutaTogashi 5:e419661e0758 49
YutaTogashi 5:e419661e0758 50 namespace sensor_board {
YutaTogashi 5:e419661e0758 51 enum DATA_TYPE_NUMBER {
YutaTogashi 5:e419661e0758 52 DEBAG_MODE =0b0000,
YutaTogashi 5:e419661e0758 53 PARAMETER =0b0001,
YutaTogashi 5:e419661e0758 54 REQUEST =0b0010,
YutaTogashi 5:e419661e0758 55 DATA_TYPE_NUMBER =0b1111,
YutaTogashi 5:e419661e0758 56 };
YutaTogashi 5:e419661e0758 57 }
YutaTogashi 0:74bedeff0dc6 58 }
YutaTogashi 0:74bedeff0dc6 59 /***********************************************/
YutaTogashi 0:74bedeff0dc6 60 }
YutaTogashi 0:74bedeff0dc6 61
YutaTogashi 0:74bedeff0dc6 62 /***********************************識別子(ID)を計算**********************************/
YutaTogashi 0:74bedeff0dc6 63 uint16_t calCanId(uint8_t device_type,uint8_t device_number,uint8_t data_type) {
YutaTogashi 0:74bedeff0dc6 64 uint16_t id = 0;
YutaTogashi 0:74bedeff0dc6 65 id = ((device_type << 8)|(device_number << 4)|(data_type));
YutaTogashi 0:74bedeff0dc6 66 return id;
YutaTogashi 0:74bedeff0dc6 67 }
YutaTogashi 0:74bedeff0dc6 68 /************************************************************************************/
YutaTogashi 2:3ad888599f55 69
YutaTogashi 2:3ad888599f55 70 /*************************************IDより各種データを取得***************************/
YutaTogashi 2:3ad888599f55 71 uint8_t getCanIdData(uint16_t id,uint8_t use_parameter) {
YutaTogashi 2:3ad888599f55 72 uint8_t value = 0;
YutaTogashi 2:3ad888599f55 73 switch (use_parameter) {
YutaTogashi 2:3ad888599f55 74 case 0: //device_type
YutaTogashi 2:3ad888599f55 75 value = ((id >> 8) & 0b111);
YutaTogashi 2:3ad888599f55 76 break;
YutaTogashi 2:3ad888599f55 77 case 1: //device_number
YutaTogashi 2:3ad888599f55 78 value = ((id >> 4) & 0b1111);
YutaTogashi 2:3ad888599f55 79 break;
YutaTogashi 2:3ad888599f55 80 case 2: //data_type
YutaTogashi 2:3ad888599f55 81 value = ((id >> 0) & 0b1111);
YutaTogashi 2:3ad888599f55 82 break;
YutaTogashi 2:3ad888599f55 83 default:
YutaTogashi 2:3ad888599f55 84 break;
YutaTogashi 2:3ad888599f55 85 }
YutaTogashi 2:3ad888599f55 86 return value;
YutaTogashi 2:3ad888599f55 87 }
YutaTogashi 2:3ad888599f55 88 /**************************************************************************************/
YutaTogashi 2:3ad888599f55 89
YutaTogashi 0:74bedeff0dc6 90 /****************************************************************************************************************/
YutaTogashi 0:74bedeff0dc6 91
YutaTogashi 0:74bedeff0dc6 92
YutaTogashi 0:74bedeff0dc6 93
YutaTogashi 0:74bedeff0dc6 94 /*
YutaTogashi 0:74bedeff0dc6 95 →MD_MCU DataFlame
YutaTogashi 0:74bedeff0dc6 96 namespace md_can_flame{
YutaTogashi 0:74bedeff0dc6 97 enum command_number{
YutaTogashi 0:74bedeff0dc6 98 SEND_KP,
YutaTogashi 0:74bedeff0dc6 99 SEND_KI,
YutaTogashi 0:74bedeff0dc6 100 SEND_KD,
YutaTogashi 0:74bedeff0dc6 101 SEND_ACCELERATION,
YutaTogashi 0:74bedeff0dc6 102 SEND_CONTROL_DUTY,
YutaTogashi 0:74bedeff0dc6 103 SEND_CONTROL_RPM,
YutaTogashi 0:74bedeff0dc6 104 REQUEST_RECEIVE_CURRENT,
YutaTogashi 0:74bedeff0dc6 105 REQUEST_RECEIVE_ERROR,
YutaTogashi 0:74bedeff0dc6 106 REQUEST_RECEIVE_POSITION,
YutaTogashi 0:74bedeff0dc6 107 REQUEST_RECEIVE_ROTATION,
YutaTogashi 0:74bedeff0dc6 108 REQUEST_RECEIVE_RPS,
YutaTogashi 0:74bedeff0dc6 109 REQUEST_RECEIVE_RPM,
YutaTogashi 0:74bedeff0dc6 110 REQUEST_PRINTF_DEBAG,
YutaTogashi 0:74bedeff0dc6 111 REQUEST_PRINTF_FORMAT_CSV,
YutaTogashi 0:74bedeff0dc6 112 REQUEST_RESET_QEI,
YutaTogashi 0:74bedeff0dc6 113 REQUEST_RESET_MCU,
YutaTogashi 0:74bedeff0dc6 114 COMMAND_NUMBER,
YutaTogashi 0:74bedeff0dc6 115 };
YutaTogashi 0:74bedeff0dc6 116 }
YutaTogashi 0:74bedeff0dc6 117 */
YutaTogashi 0:74bedeff0dc6 118 #endif