working on l452
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -13,11 +13,10 @@ volatile extern bool usb_ready;
|
||||
// if not we switch banks and write out the now unactive databank
|
||||
template<typename packet_type>
|
||||
void write(packet_type packet) {
|
||||
if (pos + sizeof(packet) + 4 < sizeof(databank1)) {
|
||||
*(uint16_t*)(&databank1[pos]) = sizeof(packet);
|
||||
*(uint16_t*)(&databank1[pos + 2]) = typecode(packet);
|
||||
memcpy(databank1 + pos + 4, &packet, sizeof(packet));
|
||||
pos += sizeof(packet) + 4;
|
||||
if (pos + sizeof(packet) + 2 < sizeof(databank1)) {
|
||||
*(uint16_t*)(&databank1[pos]) = typecode<packet_type>();
|
||||
memcpy(databank1 + pos + 2, &packet, sizeof(packet));
|
||||
pos += sizeof(packet) + 2;
|
||||
return;
|
||||
} else if (pos < sizeof(databank1)) {
|
||||
if (usb_ready) {
|
||||
@@ -27,12 +26,11 @@ void write(packet_type packet) {
|
||||
memset(databank2, 0, sizeof(databank2));
|
||||
pos = sizeof(databank1);
|
||||
return write(packet);
|
||||
} else if (pos + sizeof(packet) + 4 <
|
||||
} else if (pos + sizeof(packet) + 2 <
|
||||
sizeof(databank1) + sizeof(databank2)) {
|
||||
*(uint16_t*)(&databank2[pos - sizeof(databank1)]) = sizeof(packet);
|
||||
*(uint16_t*)(&databank2[pos + 2 - sizeof(databank1)]) = typecode(packet);
|
||||
memcpy(databank2 + pos + 4 - sizeof(databank1), &packet, sizeof(packet));
|
||||
pos += sizeof(packet) + 4;
|
||||
*(uint16_t*)(&databank2[pos - sizeof(databank1)]) = typecode<packet_type>();
|
||||
memcpy(databank2 + pos + 2 - sizeof(databank1), &packet, sizeof(packet));
|
||||
pos += sizeof(packet) + 2;
|
||||
return;
|
||||
} else {
|
||||
if (usb_ready) {
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
void data_description();
|
||||
@@ -1,102 +1,105 @@
|
||||
//#pragma once
|
||||
#pragma once
|
||||
|
||||
//#include "rtc.h"
|
||||
|
||||
//#include <refl.hpp>
|
||||
//#include <type_traits>
|
||||
//#include <cstdio>
|
||||
//#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
struct timer_time {
|
||||
uint16_t tim6_value;
|
||||
uint16_t tim6_reloads;
|
||||
};
|
||||
#include "rtc.h"
|
||||
|
||||
struct packet_rtc {
|
||||
struct timer_time t;
|
||||
uint32_t t;
|
||||
RTC_TimeTypeDef sTime;
|
||||
RTC_DateTypeDef sDate;
|
||||
};
|
||||
|
||||
struct packet_vbatt {
|
||||
struct timer_time t;
|
||||
uint32_t t;
|
||||
uint16_t vbatt_cnts;
|
||||
};
|
||||
|
||||
struct packet_imu {
|
||||
struct timer_time t;
|
||||
uint32_t t;
|
||||
uint16_t readings_cnts[4];
|
||||
};
|
||||
|
||||
struct packet_ekg {
|
||||
struct timer_time t;
|
||||
uint32_t t;
|
||||
uint8_t index;
|
||||
uint32_t readings_cnts[50];
|
||||
};
|
||||
|
||||
struct packet_strain {
|
||||
struct timer_time t;
|
||||
uint32_t t;
|
||||
uint8_t index;
|
||||
uint32_t readings_cnts[5];
|
||||
};
|
||||
|
||||
struct packet_outsideT {
|
||||
struct timer_time t;
|
||||
uint32_t t;
|
||||
uint8_t index;
|
||||
uint32_t readings_cnts[5];
|
||||
};
|
||||
|
||||
struct packet_insideT {
|
||||
struct timer_time t;
|
||||
uint32_t t;
|
||||
uint8_t index;
|
||||
uint32_t readings_cnts[5];
|
||||
};
|
||||
|
||||
struct packet_button {
|
||||
struct timer_time t;
|
||||
uint32_t t;
|
||||
uint8_t button_vec;
|
||||
};
|
||||
|
||||
struct packet_spo2 {
|
||||
struct timer_time t;
|
||||
uint32_t t;
|
||||
uint32_t green_cnts[25];
|
||||
uint32_t red_cnts[25];
|
||||
uint32_t ir_cnts[25];
|
||||
};
|
||||
|
||||
// __inline__ uint8_t typecode(struct packet_rtc) {
|
||||
// return 1;
|
||||
// }
|
||||
template<typename T>
|
||||
__inline__ uint8_t typecode() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// __inline__ uint8_t typecode(struct packet_vbatt) {
|
||||
// return 2;
|
||||
// }
|
||||
template<>
|
||||
__inline__ uint8_t typecode<struct packet_rtc>() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// __inline__ uint8_t typecode(struct packet_ekg) {
|
||||
// return 3;
|
||||
// }
|
||||
template<>
|
||||
__inline__ uint8_t typecode<struct packet_vbatt>() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
// __inline__ uint8_t typecode(struct packet_strain) {
|
||||
// return 4;
|
||||
// }
|
||||
template<>
|
||||
__inline__ uint8_t typecode<struct packet_ekg>() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
// __inline__ uint8_t typecode(struct packet_outsideT) {
|
||||
// return 5;
|
||||
// }
|
||||
template<>
|
||||
__inline__ uint8_t typecode<struct packet_strain>() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
// __inline__ uint8_t typecode(struct packet_insideT) {
|
||||
// return 6;
|
||||
// }
|
||||
template<>
|
||||
__inline__ uint8_t typecode<struct packet_outsideT>() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
// __inline__ uint8_t typecode(struct packet_button) {
|
||||
// return 7;
|
||||
// }
|
||||
template<>
|
||||
__inline__ uint8_t typecode<struct packet_insideT>() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
// __inline__ uint8_t typecode(struct packet_spo2) {
|
||||
// return 8;
|
||||
// }
|
||||
template<>
|
||||
__inline__ uint8_t typecode<struct packet_button>() {
|
||||
return 7;
|
||||
}
|
||||
|
||||
// __inline__ uint8_t typecode(struct packet_imu) {
|
||||
// return 9;
|
||||
// }
|
||||
template<>
|
||||
__inline__ uint8_t typecode<struct packet_spo2>() {
|
||||
return 8;
|
||||
}
|
||||
|
||||
template<>
|
||||
__inline__ uint8_t typecode<struct packet_imu>() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
||||
#include "ads131.hpp"
|
||||
#include "tim.h"
|
||||
#include "gpio.h"
|
||||
#include <cstring>
|
||||
#include "packet.hpp"
|
||||
@@ -51,7 +52,7 @@ struct packet_insideT p_insideT;
|
||||
extern volatile uint16_t tim6_reloads;
|
||||
|
||||
void read_ads131(SPI_HandleTypeDef *hspi1) {
|
||||
|
||||
|
||||
if (HAL_GPIO_ReadPin(GPIOA, ADC_DRDY_Pin) != GPIO_PIN_RESET) {
|
||||
return;
|
||||
}
|
||||
@@ -66,11 +67,11 @@ void read_ads131(SPI_HandleTypeDef *hspi1) {
|
||||
HAL_GPIO_WritePin(GPIOA, ADC_CS_Pin, GPIO_PIN_RESET);
|
||||
HAL_SPI_TransmitReceive(hspi1, (uint8_t*) cmd, (uint8_t*) rx_buff, 18, HAL_MAX_DELAY);
|
||||
HAL_GPIO_WritePin(GPIOA, ADC_CS_Pin, GPIO_PIN_SET);
|
||||
|
||||
// WARNING AVERAGING LATER PROBABLY WON'T WORK - 2s COMPLEMENT!!!
|
||||
//--------------
|
||||
if (p_ekg.index == 0) {
|
||||
p_ekg.t.tim6_reloads = tim6_reloads;
|
||||
p_ekg.t.tim6_value = TIM6->CNT;
|
||||
p_ekg.t = ((uint32_t)tim6_reloads) * (htim6.Init.Period + 1) + TIM6->CNT;
|
||||
|
||||
}
|
||||
p_ekg.readings_cnts[p_ekg.index] = (((uint32_t)rx_buff[3]<<16) +
|
||||
((uint32_t)rx_buff[4]<<8) +
|
||||
@@ -83,8 +84,7 @@ void read_ads131(SPI_HandleTypeDef *hspi1) {
|
||||
}
|
||||
//-------------
|
||||
if (p_strain.index == 0) {
|
||||
p_strain.t.tim6_reloads = tim6_reloads;
|
||||
p_strain.t.tim6_value = TIM6->CNT;
|
||||
p_strain.t = ((uint32_t)tim6_reloads) * (htim6.Init.Period + 1) + TIM6->CNT;
|
||||
}
|
||||
p_strain.readings_cnts[p_strain.index / 10] += (((uint32_t)rx_buff[6]<<16) +
|
||||
((uint32_t)rx_buff[7]<<8) +
|
||||
@@ -99,8 +99,7 @@ void read_ads131(SPI_HandleTypeDef *hspi1) {
|
||||
}
|
||||
//-------------
|
||||
if (p_outsideT.index == 0) {
|
||||
p_outsideT.t.tim6_reloads = tim6_reloads;
|
||||
p_outsideT.t.tim6_value = TIM6->CNT;
|
||||
p_outsideT.t = ((uint32_t)tim6_reloads) * (htim6.Init.Period + 1) + TIM6->CNT;
|
||||
}
|
||||
p_outsideT.readings_cnts[p_outsideT.index / 10] += (((uint32_t)rx_buff[9]<<16) +
|
||||
((uint32_t)rx_buff[10]<<8) +
|
||||
@@ -115,8 +114,7 @@ void read_ads131(SPI_HandleTypeDef *hspi1) {
|
||||
}
|
||||
//-------------
|
||||
if (p_insideT.index == 0) {
|
||||
p_insideT.t.tim6_reloads = tim6_reloads;
|
||||
p_insideT.t.tim6_value = TIM6->CNT;
|
||||
p_insideT.t = ((uint32_t)tim6_reloads) * (htim6.Init.Period + 1) + TIM6->CNT;
|
||||
}
|
||||
p_insideT.readings_cnts[p_insideT.index / 10] += (((uint32_t)rx_buff[12]<<16) +
|
||||
((uint32_t)rx_buff[13]<<8) +
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "datadescriptor.hpp"
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include "usbd_cdc_if.h"
|
||||
#include "packet.hpp"
|
||||
|
||||
void data_description() {
|
||||
char buff[200];
|
||||
int cx;
|
||||
|
||||
cx = snprintf(buff, sizeof(buff), "%s %d %d %s %d %d %s %d %d %s %d %d\n\r", "packet_rtc", typecode<packet_rtc>(), sizeof(packet_rtc), "uint32_t t", offsetof(packet_rtc, t), sizeof(uint32_t), "RTC_TimeTypeDef sTime", offsetof(packet_rtc, sTime), sizeof(RTC_TimeTypeDef), "RTC_DateTypeDef sDate", offsetof(packet_rtc, sDate), sizeof(RTC_DateTypeDef));
|
||||
CDC_Transmit_FS((uint8_t*)buff, cx);
|
||||
HAL_Delay(10);
|
||||
|
||||
cx = snprintf(buff, sizeof(buff), "%s %d %d %s %d %d %s %d %d\n\r", "packet_vbatt", typecode<packet_vbatt>(), sizeof(packet_vbatt), "uint32_t t", offsetof(packet_vbatt, t), sizeof(uint32_t), "uint16_t vbatt_cnts", offsetof(packet_vbatt, vbatt_cnts), sizeof(uint16_t));
|
||||
CDC_Transmit_FS((uint8_t*)buff, cx);
|
||||
HAL_Delay(10);
|
||||
|
||||
cx = snprintf(buff, sizeof(buff), "%s %d %d %s %d %d %s %d %d\n\r", "packet_imu", typecode<packet_imu>(), sizeof(packet_imu), "uint32_t t", offsetof(packet_imu, t), sizeof(uint32_t), "uint16_t readings_cnts[4]", offsetof(packet_imu, readings_cnts), sizeof(uint16_t));
|
||||
CDC_Transmit_FS((uint8_t*)buff, cx);
|
||||
HAL_Delay(10);
|
||||
|
||||
cx = snprintf(buff, sizeof(buff), "%s %d %d %s %d %d %s %d %d %s %d %d\n\r", "packet_ekg", typecode<packet_ekg>(), sizeof(packet_ekg), "uint32_t t", offsetof(packet_ekg, t), sizeof(uint32_t), "uint8_t index", offsetof(packet_ekg, index), sizeof(uint8_t), "uint32_t readings_cnts[50]", offsetof(packet_ekg, readings_cnts), sizeof(uint32_t));
|
||||
CDC_Transmit_FS((uint8_t*)buff, cx);
|
||||
HAL_Delay(10);
|
||||
|
||||
cx = snprintf(buff, sizeof(buff), "%s %d %d %s %d %d %s %d %d %s %d %d\n\r", "packet_strain", typecode<packet_strain>(), sizeof(packet_strain), "uint32_t t", offsetof(packet_strain, t), sizeof(uint32_t), "uint8_t index", offsetof(packet_strain, index), sizeof(uint8_t), "uint32_t readings_cnts[5]", offsetof(packet_strain, readings_cnts), sizeof(uint32_t));
|
||||
CDC_Transmit_FS((uint8_t*)buff, cx);
|
||||
HAL_Delay(10);
|
||||
|
||||
cx = snprintf(buff, sizeof(buff), "%s %d %d %s %d %d %s %d %d %s %d %d\n\r", "packet_outsideT", typecode<packet_outsideT>(), sizeof(packet_outsideT), "uint32_t t", offsetof(packet_outsideT, t), sizeof(uint32_t), "uint8_t index", offsetof(packet_outsideT, index), sizeof(uint8_t), "uint32_t readings_cnts[5]", offsetof(packet_outsideT, readings_cnts), sizeof(uint32_t));
|
||||
CDC_Transmit_FS((uint8_t*)buff, cx);
|
||||
HAL_Delay(10);
|
||||
|
||||
cx = snprintf(buff, sizeof(buff), "%s %d %d %s %d %d %s %d %d %s %d %d\n\r", "packet_insideT", typecode<packet_insideT>(), sizeof(packet_insideT), "uint32_t t", offsetof(packet_insideT, t), sizeof(uint32_t), "uint8_t index", offsetof(packet_insideT, index), sizeof(uint8_t), "uint32_t readings_cnts[5]", offsetof(packet_insideT, readings_cnts), sizeof(uint32_t));
|
||||
CDC_Transmit_FS((uint8_t*)buff, cx);
|
||||
HAL_Delay(10);
|
||||
|
||||
cx = snprintf(buff, sizeof(buff), "%s %d %d %s %d %d %s %d %d\n\r", "packet_button", typecode<packet_button>(), sizeof(packet_button), "uint32_t t", offsetof(packet_button, t), sizeof(uint32_t), "uint8_t button_vec", offsetof(packet_button, button_vec), sizeof(uint8_t));
|
||||
CDC_Transmit_FS((uint8_t*)buff, cx);
|
||||
HAL_Delay(10);
|
||||
|
||||
cx = snprintf(buff, sizeof(buff), "%s %d %d %s %d %d %s %d %d %s %d %d %s %d %d\n\r", "packet_spo2", typecode<packet_spo2>(), sizeof(packet_spo2), "uint32_t t", offsetof(packet_spo2, t), sizeof(uint32_t), "uint32_t green_cnts[25]", offsetof(packet_spo2, green_cnts), sizeof(uint32_t), "uint32_t red_cnts[25]", offsetof(packet_spo2, red_cnts), sizeof(uint32_t), "uint32_t ir_cnts[25]", offsetof(packet_spo2, ir_cnts), sizeof(uint32_t));
|
||||
CDC_Transmit_FS((uint8_t*)buff, cx);
|
||||
HAL_Delay(10);
|
||||
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "lsm6dsv.hpp"
|
||||
#include "packet.hpp"
|
||||
#include "gpio.h"
|
||||
#include "tim.h"
|
||||
#include "buff.hpp"
|
||||
|
||||
extern volatile uint16_t tim6_reloads;
|
||||
@@ -65,7 +66,7 @@ void initialize_lsm6dsv(SPI_HandleTypeDef *hspi1) {
|
||||
struct packet_imu p_imu;
|
||||
|
||||
void read_lsm6dsv(SPI_HandleTypeDef *hspi1) {
|
||||
|
||||
|
||||
if (HAL_GPIO_ReadPin(GPIOC, IMU_DRDY_Pin) != GPIO_PIN_RESET) {
|
||||
return;
|
||||
}
|
||||
@@ -93,8 +94,7 @@ void read_lsm6dsv(SPI_HandleTypeDef *hspi1) {
|
||||
HAL_GPIO_WritePin(GPIOC, IMU_CS_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
p_imu.t.tim6_reloads = tim6_reloads;
|
||||
p_imu.t.tim6_value = TIM6->CNT;
|
||||
p_imu.t = ((uint32_t)tim6_reloads) * (htim6.Init.Period + 1) + TIM6->CNT;
|
||||
p_imu.readings_cnts[0] = rx_buff[1];
|
||||
p_imu.readings_cnts[1] = ((uint16_t)rx_buff[2] << 8) + rx_buff[3];
|
||||
p_imu.readings_cnts[2] = ((uint16_t)rx_buff[4] << 8) + rx_buff[5];
|
||||
|
||||
@@ -38,8 +38,7 @@
|
||||
#include "buff.hpp"
|
||||
#include "ads131.hpp"
|
||||
#include "lsm6dsv.hpp"
|
||||
#include "refl.hpp"
|
||||
#include <tuple>
|
||||
#include "datadescriptor.hpp"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -80,6 +79,7 @@ volatile uint16_t adc_value = 0;
|
||||
volatile uint8_t adc_ready = 0;
|
||||
volatile uint16_t tim6_reloads = 0;
|
||||
volatile bool usb_ready = false;
|
||||
volatile bool print_desc = false;
|
||||
|
||||
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) {
|
||||
if (hadc->Instance == ADC1) {
|
||||
@@ -100,6 +100,9 @@ void USB_CDC_RxHandler(uint8_t* Buf, uint32_t Len) {
|
||||
if (memcmp(Buf, "R", Len) == 0) {
|
||||
usb_ready = true;
|
||||
}
|
||||
if (memcmp(Buf, "?", Len) == 0) {
|
||||
print_desc = true;
|
||||
}
|
||||
//if (Len == 1) {
|
||||
// return;
|
||||
//}
|
||||
@@ -108,56 +111,6 @@ void USB_CDC_RxHandler(uint8_t* Buf, uint32_t Len) {
|
||||
//int i = snprintf(buffer, sizeof(buffer), "Length: %d\n\r", Len);
|
||||
//
|
||||
}
|
||||
|
||||
REFL_TYPE(packet_imu)
|
||||
REFL_END
|
||||
|
||||
|
||||
// #include <cstdint>
|
||||
// template<std::intmax_t N>
|
||||
// class to_string_t {
|
||||
|
||||
// constexpr static auto buflen() noexcept {
|
||||
// unsigned int len = N > 0 ? 1 : 2;
|
||||
// for (auto n = N; n; len++, n /= 10);
|
||||
// return len;
|
||||
// }
|
||||
|
||||
// char buf[buflen()] = {};
|
||||
|
||||
// public:
|
||||
// constexpr to_string_t() noexcept {
|
||||
// auto ptr = buf + buflen();
|
||||
// *--ptr = '\0';
|
||||
|
||||
// if (N != 0) {
|
||||
// for (auto n = N; n; n /= 10)
|
||||
// *--ptr = "0123456789"[(N < 0 ? -1 : 1) * (n % 10)];
|
||||
// if (N < 0)
|
||||
// *--ptr = '-';
|
||||
// } else {
|
||||
// buf[0] = '0';
|
||||
// }
|
||||
// }
|
||||
|
||||
// constexpr operator const char *() const { return buf; }
|
||||
// };
|
||||
|
||||
// template<std::intmax_t N>
|
||||
// constexpr to_string_t<N> to_string;
|
||||
// // shamelessly stolen from https://stackoverflow.com/questions/6713420/c-convert-integer-to-string-at-compile-time
|
||||
|
||||
// auto c = to_string<555>;
|
||||
|
||||
//string_writer(c);
|
||||
|
||||
packet_imu p;
|
||||
//auto name = refl::reflect(p).name
|
||||
// for member in x, we wnat the offset_of
|
||||
int x = offsetof(packet_imu, readings_cnts);
|
||||
|
||||
//const uint8_t[100] str;
|
||||
//consteval snprintf(str, "%s", 100)
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
@@ -252,15 +205,15 @@ int main(void)
|
||||
// CDC_Transmit_FS((uint8_t*) "Not Detected\n\r", 14);
|
||||
// HAL_Delay(10);
|
||||
// }
|
||||
//CDC_Transmit_FS((uint8_t*) name, sizeof(name));
|
||||
HAL_Delay(1000);
|
||||
continue;
|
||||
|
||||
if (print_desc) {
|
||||
data_description();
|
||||
print_desc = false;
|
||||
}
|
||||
|
||||
if (to_recordTime) {
|
||||
struct timer_time t;
|
||||
t.tim6_reloads = tim6_reloads;
|
||||
t.tim6_value = TIM6->CNT;
|
||||
struct packet_rtc p_rtc;
|
||||
p_rtc.t = t;
|
||||
p_rtc.t = ((uint32_t)tim6_reloads) * (htim6.Init.Period + 1) + TIM6->CNT;
|
||||
HAL_RTC_GetTime(&hrtc, &p_rtc.sTime, RTC_FORMAT_BCD);
|
||||
HAL_RTC_GetDate(&hrtc, &p_rtc.sDate, RTC_FORMAT_BCD);
|
||||
write(p_rtc);
|
||||
@@ -275,11 +228,8 @@ int main(void)
|
||||
|
||||
if (adc_ready) {
|
||||
adc_ready = 0;
|
||||
struct timer_time t;
|
||||
t.tim6_reloads = tim6_reloads;
|
||||
t.tim6_value = TIM6->CNT;
|
||||
struct packet_vbatt p_vbatt;
|
||||
p_vbatt.t = t;
|
||||
p_vbatt.t = ((uint32_t)tim6_reloads) * (htim6.Init.Period + 1) + TIM6->CNT;
|
||||
p_vbatt.vbatt_cnts = HAL_ADC_GetValue(&hadc1);
|
||||
write(p_vbatt);
|
||||
}
|
||||
@@ -305,10 +255,10 @@ int main(void)
|
||||
// }
|
||||
// }
|
||||
|
||||
//HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin|LED3_Pin, GPIO_PIN_SET);
|
||||
//HAL_Delay(100);
|
||||
//HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin|LED3_Pin, GPIO_PIN_RESET);
|
||||
//HAL_Delay(100);
|
||||
// HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin|LED3_Pin, GPIO_PIN_SET);
|
||||
// HAL_Delay(100);
|
||||
// HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin|LED3_Pin, GPIO_PIN_RESET);
|
||||
// HAL_Delay(100);
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ void MX_SPI1_Init(void)
|
||||
hspi1.Instance = SPI1;
|
||||
hspi1.Init.Mode = SPI_MODE_MASTER;
|
||||
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
hspi1.Init.DataSize = SPI_DATASIZE_8BIT; // low + 2 edge for adc
|
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; // high
|
||||
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
||||
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
|
||||
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [4.9.0-B19] date: [Wed Apr 22 08:28:17 MST 2026]
|
||||
# File automatically-generated by tool: [projectgenerator] version: [4.9.0-B19] date: [Tue Apr 28 17:15:25 CDT 2026]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import cxxheaderparser.simple
|
||||
|
||||
header_text = open("Core/Inc/packet.hpp","r").read().replace("__inline__", "")
|
||||
|
||||
data = cxxheaderparser.simple.parse_string(header_text)
|
||||
|
||||
work_string = ""
|
||||
|
||||
for class_type in data.namespace.classes:
|
||||
class_name = class_type.class_decl.typename.segments[0].name
|
||||
to_format_string = "%s %d %d"
|
||||
format_args = f'"{class_name}", typecode<{class_name}>(), sizeof({class_name})'
|
||||
for field in class_type.fields:
|
||||
if isinstance(field.type, cxxheaderparser.types.Array):
|
||||
element_type = field.type.array_of.typename.segments[0].name
|
||||
element_num = field.type.size.tokens[0].value
|
||||
element_name = field.name
|
||||
to_format_string += " %s %d %d"
|
||||
format_args += f', "{element_type} {element_name}[{element_num}]", offsetof({class_name}, {element_name}), sizeof({element_type})'
|
||||
elif isinstance(field.type, cxxheaderparser.types.Type):
|
||||
element_type = field.type.typename.segments[0].name
|
||||
element_name = field.name
|
||||
to_format_string += " %s %d %d"
|
||||
format_args += f', "{element_type} {element_name}", offsetof({class_name}, {element_name}), sizeof({element_type})'
|
||||
to_format_string += "\\n\\r"
|
||||
work_string += f' cx = snprintf(buff, sizeof(buff), "{to_format_string}", {format_args});\n'
|
||||
work_string += f' CDC_Transmit_FS((uint8_t*)buff, cx);\n'
|
||||
work_string += f' HAL_Delay(10);\n\n'
|
||||
|
||||
h_file_text = """
|
||||
void data_description();
|
||||
"""
|
||||
|
||||
c_file_text = ("""#include "datadescriptor.hpp"
|
||||
#include <cstddef>
|
||||
#include <cstdio>
|
||||
#include "usbd_cdc_if.h"
|
||||
#include "packet.hpp"
|
||||
|
||||
void data_description() {
|
||||
char buff[200];
|
||||
int cx;
|
||||
|
||||
""" + work_string +
|
||||
"}\n")
|
||||
|
||||
with open("Core/Src/datadescriptor.cpp", "w") as f:
|
||||
f.write(c_file_text)
|
||||
|
||||
with open("Core/Inc/datadescriptor.hpp", "w") as f:
|
||||
f.write(h_file_text)
|
||||
|
||||
|
||||
@@ -1,27 +1,81 @@
|
||||
import serial
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
from scipy import signal
|
||||
|
||||
ser = serial.Serial(port='/dev/ttyACM1', baudrate=115200)
|
||||
#should be running at 244Hz
|
||||
|
||||
fs = 244
|
||||
b, a = signal.butter(
|
||||
N = 2,
|
||||
Wn = [30],
|
||||
btype = 'lowpass',
|
||||
fs = fs)
|
||||
|
||||
ser = serial.Serial(port='/dev/ttyACM1', baudrate=115200, timeout = 0.5)
|
||||
ser.flush()
|
||||
|
||||
data = bytes()
|
||||
|
||||
ready = False
|
||||
|
||||
f = open('data_dump.dat','wb')
|
||||
ser.write(b'?')
|
||||
|
||||
for i in range(5):
|
||||
ser.write(b'R')
|
||||
data = ser.read(1024)
|
||||
index = 0
|
||||
while (index < 1024):
|
||||
packet_length = (data[index + 1]<<8) + data[index]
|
||||
packet_type = (data[index + 3]<<8) + data[index + 2]
|
||||
print(packet_type, packet_length)
|
||||
if packet_type not in range(1,10):
|
||||
break
|
||||
#print(packet_type, packet_length, data[index + 4: index + 4 + packet_length])
|
||||
index += packet_length + 4
|
||||
ser.flush()
|
||||
# if packet_type in [1,2,3,4,5,6,7,8,9] and packet_length > 6:
|
||||
# dat = ser.read(packet_length)
|
||||
# print(packet_type, packet_length, dat)
|
||||
types = []
|
||||
|
||||
def arr_sizes(s):
|
||||
if s[-1:] != b']' or b'[' not in s:
|
||||
return 1
|
||||
v = int(s[s.rindex(b'[') + 1:-1])
|
||||
return v
|
||||
|
||||
for i in range(13):
|
||||
line = ser.readline().strip(b'\n').strip(b'\r')
|
||||
if line != b'':
|
||||
L = line.split(b" ")
|
||||
types.append({'type_name' : L[0],
|
||||
'type_code' : int(L[1]),
|
||||
'size' : int(L[2]),
|
||||
'elements' : []
|
||||
})
|
||||
i = 3
|
||||
while i < len(L):
|
||||
types[-1]['elements'].append({'type_name' : L[i], 'name' : L[i + 1], 'offset' : int(L[i + 2]), 'n_elements' : arr_sizes(L[i + 1]), 'size' : int(L[i + 3]) * arr_sizes(L[i + 1]), 'readings' : []})
|
||||
i += 4
|
||||
|
||||
ser.flush()
|
||||
ser.timeout = 5
|
||||
|
||||
ys = []
|
||||
|
||||
for i in range(1000):
|
||||
ser.write(b'R')
|
||||
data = ser.read(1024)
|
||||
index = 0
|
||||
while (index < 1024):
|
||||
packet_type = (data[index + 1]<<8) + data[index]
|
||||
ind = [i for i,t in enumerate(types) if t['type_code'] == packet_type]
|
||||
if len(ind) != 1:
|
||||
break
|
||||
t = types[ind[0]]
|
||||
d = data[index + 2 : index + 2 + t['size']]
|
||||
for e in t['elements']:
|
||||
block = d[e['offset']:e['offset'] + e['size']]
|
||||
element_size = int(len(block) / e['n_elements'])
|
||||
if t['type_name'] == b'packet_ekg' and e['name'] == b'readings_cnts[50]':
|
||||
chunked = [int.from_bytes(block[i:i + element_size - 1], byteorder='little', signed = True) for i in range(0, len(block), element_size)]
|
||||
#BB = [block[i:i + element_size] for i in range(0, len(block), element_size)]
|
||||
#if t['type_name'] == b'packet_ekg' and e['name'] == b'readings_cnts[50]':
|
||||
ys += chunked
|
||||
plt.clf()
|
||||
dat = np.array(ys[-1000:])
|
||||
plt.plot(dat, 'k.', linestyle = '--')#signal.filtfilt(b, a, dat))
|
||||
plt.pause(0.01)
|
||||
##print(BB)
|
||||
e['readings'].append(chunked)
|
||||
index += 2 + t['size']
|
||||
|
||||
#for t in types:
|
||||
# if t['type_name'] == b'packet_ekg':
|
||||
# print(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user