15 #define EPS_BAUDRATE 57600
17 #define EPS_REG_CONFIG 0x00
18 #define EPS_REG_STATUS 0x01
19 #define EPS_REG_SW_ON 0x02
20 #define EPS_REG_POWER 0x03
21 #define EPS_REG_BAT_V 0x04
22 #define EPS_REG_BAT_I 0x05
23 #define EPS_REG_BAT_T 0x06
24 #define EPS_REG_SOLAR_N1_I 0x07
25 #define EPS_REG_SOLAR_N2_I 0x08
26 #define EPS_REG_SOLAR_S1_I 0x09
27 #define EPS_REG_SOLAR_S2_I 0x0A
28 #define EPS_REG_SOLAR_E1_I 0x0B
29 #define EPS_REG_SOLAR_E2_I 0x0C
30 #define EPS_REG_SOLAR_W1_I 0x0D
31 #define EPS_REG_SOLAR_W2_I 0x0E
32 #define EPS_REG_SOLAR_T1_I 0x0F
33 #define EPS_REG_SOLAR_T2_I 0x10
34 #define EPS_REG_RESERVED 0x11 // Maybe make known ID? ( https://github.com/uos3/eps-firmware/issues/1 )
35 #define EPS_REG_SOLAR_2_V 0x12
36 #define EPS_REG_RAIL1_BOOT 0x13
37 #define EPS_REG_RAIL1_FAIL 0x14
38 #define EPS_REG_RAIL1_V 0x15
39 #define EPS_REG_RAIL1_I 0x16
40 #define EPS_REG_RAIL2_BOOT 0x17
41 #define EPS_REG_RAIL2_FAIL 0x18
42 #define EPS_REG_RAIL2_V 0x19
43 #define EPS_REG_RAIL2_I 0x1A
44 #define EPS_REG_RAIL3_BOOT 0x1B
45 #define EPS_REG_RAIL3_FAIL 0x1C
46 #define EPS_REG_RAIL3_V 0x1D
47 #define EPS_REG_RAIL3_I 0x1E
48 #define EPS_REG_RAIL4_BOOT 0x1F
49 #define EPS_REG_RAIL4_FAIL 0x20
50 #define EPS_REG_RAIL4_V 0x21
51 #define EPS_REG_RAIL4_I 0x22
52 #define EPS_REG_RAIL5_BOOT 0x23
53 #define EPS_REG_RAIL5_FAIL 0x24
54 #define EPS_REG_RAIL5_V 0x25
55 #define EPS_REG_RAIL5_I 0x26
56 #define EPS_REG_RAIL6_BOOT 0x27
57 #define EPS_REG_RAIL6_FAIL 0x28
58 #define EPS_REG_RAIL6_V 0x29
59 #define EPS_REG_RAIL6_I 0x2A
60 #define EPS_REG_SUPPLY_3_V 0x2B
61 #define EPS_REG_SUPPLY_3_I 0x2C
62 #define EPS_REG_SUPPLY_5_V 0x2D
63 #define EPS_REG_SUPPLY_5_I 0x2E
64 #define EPS_REG_CHARGE_I 0x2F
65 #define EPS_REG_MPPT_BUS_V 0x30
66 #define EPS_REG_CRC_ER_CNT 0x31
67 #define EPS_REG_DROP_CNT 0x32
71 uint8_t register_id:7;
80 uint8_t register_id:7;
82 uint8_t register_quantity:7;
92 static uint16_t EPS_crc(uint8_t *message, int32_t offset, int32_t length);
111 if(EPS_readRegister(EPS_REG_BAT_V, &eps_slave_packet_single))
113 *voltage = eps_slave_packet_single.value;
122 uint16_t crc, bytes_expected, bytes_received;
123 uint32_t timeout, current_time;
126 eps_master_packet.write =
false;
127 eps_master_packet.register_id = (uint8_t)(register_id & 0x7F);
128 eps_master_packet.value_l = 1;
129 eps_master_packet.value_h = 0;
130 crc = EPS_crc((uint8_t *)&eps_master_packet, 0, 3);
131 eps_master_packet.crc_l = (uint8_t)crc & 0xFF;
132 eps_master_packet.crc_h = (uint8_t)((crc >> 8) & 0xFF);
135 UART_putb(UART_EPS, (
char *)&eps_master_packet, 5);
140 timeout = current_time;
141 while(current_time < (timeout + 2))
145 ((
char *)(data))[bytes_received] = c;
146 if(++bytes_received == bytes_expected)
153 if(bytes_received != bytes_expected)
158 crc = EPS_crc((uint8_t *)data, 0, 4);
168 static uint16_t EPS_crc(uint8_t *message, int32_t offset, int32_t length)
170 uint16_t crcFull = 0xFFFF;
173 for (i = offset; i < length; i++)
175 crcFull = (uint16_t)(crcFull ^ message[i]);
177 for (j = 0; j < 8; j++)
179 uint8_t crcLsb = (uint8_t)(crcFull & 0x0001);
180 crcFull = (uint16_t)((crcFull >> 1) & 0x7FFF);
183 crcFull = (uint16_t)(crcFull ^ 0xA001);
void RTC_getTime(uint32_t *time)
void UART_init(uint8_t uart_num, uint32_t baudrate)
bool UART_getc_nonblocking(uint8_t uart_num, char *c)
bool EPS_getBatteryVoltage(uint16_t *voltage)
void UART_putb(uint8_t uart_num, char *str, uint32_t len)