test
This commit is contained in:
@@ -13,6 +13,12 @@
|
|||||||
#define DownlinkPacketType_Ping 1
|
#define DownlinkPacketType_Ping 1
|
||||||
#define DownlinkPacketType_ACK 255
|
#define DownlinkPacketType_ACK 255
|
||||||
|
|
||||||
|
#define BME680_PRESENT_BIT (1 << 0)
|
||||||
|
#define CCS811_PRESENT_BIT (1 << 1)
|
||||||
|
#define MPU9250_PRESENT_BIT (1 << 2)
|
||||||
|
#define INA260_PRESENT_BIT (1 << 3)
|
||||||
|
#define MCP23018_PRESENT_BIT (1 << 4)
|
||||||
|
|
||||||
typedef struct __attribute__((packed))
|
typedef struct __attribute__((packed))
|
||||||
{
|
{
|
||||||
char syncPhrase[10];
|
char syncPhrase[10];
|
||||||
@@ -91,6 +97,8 @@ typedef struct __attribute__((packed))
|
|||||||
int16_t currentServoB;
|
int16_t currentServoB;
|
||||||
int16_t targetServoB;
|
int16_t targetServoB;
|
||||||
|
|
||||||
|
uint8_t presentDevices;
|
||||||
|
|
||||||
uint8_t telemetryIndex;
|
uint8_t telemetryIndex;
|
||||||
|
|
||||||
} TelemetryPacket;
|
} TelemetryPacket;
|
||||||
|
39
main/radio.c
39
main/radio.c
@@ -8,7 +8,6 @@
|
|||||||
#include "packets.h"
|
#include "packets.h"
|
||||||
#include "esp_rom_crc.h"
|
#include "esp_rom_crc.h"
|
||||||
|
|
||||||
|
|
||||||
#define TAG "LoRaGS"
|
#define TAG "LoRaGS"
|
||||||
|
|
||||||
uint32_t uplinkPacketIndex = 0;
|
uint32_t uplinkPacketIndex = 0;
|
||||||
@@ -70,6 +69,8 @@ void printTelemetryPacket(const TelemetryPacket *packet)
|
|||||||
|
|
||||||
temp_f = (packet->accelerometer_temperature / 333.87) + 21.0; // Temperature in °C
|
temp_f = (packet->accelerometer_temperature / 333.87) + 21.0; // Temperature in °C
|
||||||
|
|
||||||
|
if (packet->presentDevices & MPU9250_PRESENT_BIT)
|
||||||
|
{
|
||||||
// MPU Data
|
// MPU Data
|
||||||
ESP_LOGI(TAG, " MPU:");
|
ESP_LOGI(TAG, " MPU:");
|
||||||
ESP_LOGI(TAG, " Acceleration [X: %d, Y: %d, Z: %d]", packet->accelerationX, packet->accelerationY, packet->accelerationZ);
|
ESP_LOGI(TAG, " Acceleration [X: %d, Y: %d, Z: %d]", packet->accelerationX, packet->accelerationY, packet->accelerationZ);
|
||||||
@@ -83,14 +84,24 @@ void printTelemetryPacket(const TelemetryPacket *packet)
|
|||||||
ESP_LOGI(TAG, " Gyroscope [X: %.3f deg/s, Y: %.3f deg/s, Z: %.3f deg/s]", gyro_f[0], gyro_f[1], gyro_f[2]);
|
ESP_LOGI(TAG, " Gyroscope [X: %.3f deg/s, Y: %.3f deg/s, Z: %.3f deg/s]", gyro_f[0], gyro_f[1], gyro_f[2]);
|
||||||
ESP_LOGI(TAG, " Magnetometer [X: %.3f uT, Y: %.3f uT, Z: %.3f uT]", magnet_f[0], magnet_f[1], magnet_f[2]);
|
ESP_LOGI(TAG, " Magnetometer [X: %.3f uT, Y: %.3f uT, Z: %.3f uT]", magnet_f[0], magnet_f[1], magnet_f[2]);
|
||||||
ESP_LOGI(TAG, " Accelerometer Temp: %f °C", temp_f);
|
ESP_LOGI(TAG, " Accelerometer Temp: %f °C", temp_f);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, " MPU9250 not plugged in");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packet->presentDevices & CCS811_PRESENT_BIT)
|
||||||
|
{
|
||||||
// CCS Data
|
// CCS Data
|
||||||
ESP_LOGI(TAG, " CCS:");
|
ESP_LOGI(TAG, " CCS:");
|
||||||
ESP_LOGI(TAG, " eCO2: %u ppm", packet->eCO2);
|
ESP_LOGI(TAG, " eCO2: %u ppm", packet->eCO2);
|
||||||
ESP_LOGI(TAG, " TVOC: %u ppb", packet->tvoc);
|
ESP_LOGI(TAG, " TVOC: %u ppb", packet->tvoc);
|
||||||
ESP_LOGI(TAG, " Current CCS: %u", packet->currentCCS);
|
ESP_LOGI(TAG, " Current CCS: %u", packet->currentCCS);
|
||||||
ESP_LOGI(TAG, " Raw CCS Data: %u", packet->rawCCSData);
|
ESP_LOGI(TAG, " Raw CCS Data: %u", packet->rawCCSData);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, " CCS811 not plugged in");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packet->presentDevices & INA260_PRESENT_BIT)
|
||||||
|
{
|
||||||
float miliVolts = packet->volts * 1.25;
|
float miliVolts = packet->volts * 1.25;
|
||||||
float miliAmps = packet->current * 1.25;
|
float miliAmps = packet->current * 1.25;
|
||||||
float power = packet->power * 10;
|
float power = packet->power * 10;
|
||||||
@@ -100,6 +111,12 @@ void printTelemetryPacket(const TelemetryPacket *packet)
|
|||||||
ESP_LOGI(TAG, " Voltage: %f mV", miliVolts);
|
ESP_LOGI(TAG, " Voltage: %f mV", miliVolts);
|
||||||
ESP_LOGI(TAG, " Current: %f mA", miliAmps);
|
ESP_LOGI(TAG, " Current: %f mA", miliAmps);
|
||||||
ESP_LOGI(TAG, " Power: %f mW", power);
|
ESP_LOGI(TAG, " Power: %f mW", power);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ESP_LOGE(TAG, " INA260 not plugged in");
|
||||||
|
}
|
||||||
|
if (packet->presentDevices & BME680_PRESENT_BIT)
|
||||||
|
{
|
||||||
|
|
||||||
// BME Data
|
// BME Data
|
||||||
ESP_LOGI(TAG, " BME:");
|
ESP_LOGI(TAG, " BME:");
|
||||||
@@ -122,6 +139,9 @@ void printTelemetryPacket(const TelemetryPacket *packet)
|
|||||||
ESP_LOGI(TAG, " Temperature Score: %.2f", packet->temperature_score);
|
ESP_LOGI(TAG, " Temperature Score: %.2f", packet->temperature_score);
|
||||||
ESP_LOGI(TAG, " Humidity Score: %.2f", packet->humidity_score);
|
ESP_LOGI(TAG, " Humidity Score: %.2f", packet->humidity_score);
|
||||||
ESP_LOGI(TAG, " Gas Score: %.2f", packet->gas_score);
|
ESP_LOGI(TAG, " Gas Score: %.2f", packet->gas_score);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, " BME680 not plugged in");
|
||||||
|
}
|
||||||
|
|
||||||
// GPS Data
|
// GPS Data
|
||||||
ESP_LOGI(TAG, " GPS:");
|
ESP_LOGI(TAG, " GPS:");
|
||||||
@@ -139,19 +159,23 @@ void printTelemetryPacket(const TelemetryPacket *packet)
|
|||||||
ESP_LOGI(TAG, " Predicted Longitude: %.4f°", packet->predicted_longitude_centi_degrees / 10000.0f);
|
ESP_LOGI(TAG, " Predicted Longitude: %.4f°", packet->predicted_longitude_centi_degrees / 10000.0f);
|
||||||
ESP_LOGI(TAG, " Predicted Altitude: %.2f m", packet->predicted_altitude_centi_meters / 100.0f);
|
ESP_LOGI(TAG, " Predicted Altitude: %.2f m", packet->predicted_altitude_centi_meters / 100.0f);
|
||||||
|
|
||||||
|
if (packet->presentDevices & MCP23018_PRESENT_BIT)
|
||||||
|
{
|
||||||
// ADC Data
|
// ADC Data
|
||||||
ESP_LOGI(TAG, " ADC Sensors:");
|
ESP_LOGI(TAG, " ADC Sensors:");
|
||||||
ESP_LOGI(TAG, " NH3: %d", packet->NH3);
|
ESP_LOGI(TAG, " NH3: %d", packet->NH3);
|
||||||
ESP_LOGI(TAG, " CO: %d", packet->CO);
|
ESP_LOGI(TAG, " CO: %d", packet->CO);
|
||||||
ESP_LOGI(TAG, " NO2: %d", packet->NO2);
|
ESP_LOGI(TAG, " NO2: %d", packet->NO2);
|
||||||
ESP_LOGI(TAG, " UVC: %d", packet->UVC);
|
ESP_LOGI(TAG, " UVC: %d", packet->UVC);
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, " IO Expander not plugged in");
|
||||||
|
}
|
||||||
|
|
||||||
// Servo Data
|
// Servo Data
|
||||||
ESP_LOGI(TAG, " Servos:");
|
ESP_LOGI(TAG, " Servos:");
|
||||||
ESP_LOGI(TAG, " Servo A: Current = %d, Target = %d", packet->currentServoA, packet->targetServoA);
|
ESP_LOGI(TAG, " Servo A: Current = %d, Target = %d", packet->currentServoA, packet->targetServoA);
|
||||||
ESP_LOGI(TAG, " Servo B: Current = %d, Target = %d", packet->currentServoB, packet->targetServoB);
|
ESP_LOGI(TAG, " Servo B: Current = %d, Target = %d", packet->currentServoB, packet->targetServoB);
|
||||||
ESP_LOGI(TAG, " TelemetryIndex: %d", packet->telemetryIndex);
|
ESP_LOGI(TAG, " TelemetryIndex: %d", packet->telemetryIndex);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_downlink_packet(uint8_t *buf, uint8_t rxLen)
|
void handle_downlink_packet(uint8_t *buf, uint8_t rxLen)
|
||||||
@@ -179,7 +203,8 @@ void handle_downlink_packet(uint8_t *buf, uint8_t rxLen)
|
|||||||
|
|
||||||
uint32_t crcCheck = esp_rom_crc32_le(0, payload, payloadSize);
|
uint32_t crcCheck = esp_rom_crc32_le(0, payload, payloadSize);
|
||||||
|
|
||||||
if (crcCheck != down.CRCCheck) {
|
if (crcCheck != down.CRCCheck)
|
||||||
|
{
|
||||||
ESP_LOGE(TAG, "Received BAD CRC for packet %d, crc is %ld, should be %ld", down.packetIndex, crcCheck, down.CRCCheck);
|
ESP_LOGE(TAG, "Received BAD CRC for packet %d, crc is %ld, should be %ld", down.packetIndex, crcCheck, down.CRCCheck);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -213,8 +238,10 @@ void handle_downlink_packet(uint8_t *buf, uint8_t rxLen)
|
|||||||
|
|
||||||
uint32_t crc = esp_rom_crc32_le(0, &(buf[0]) + sizeof(DownBoundPacket), payloadSize);
|
uint32_t crc = esp_rom_crc32_le(0, &(buf[0]) + sizeof(DownBoundPacket), payloadSize);
|
||||||
|
|
||||||
|
if (down.packetType != DownlinkPacketType_ACK && down.packetType != DownlinkPacketType_Telemetry)
|
||||||
|
{
|
||||||
send_ack(down.packetIndex, crc);
|
send_ack(down.packetIndex, crc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lora_comms_task(void *pvParameters)
|
void lora_comms_task(void *pvParameters)
|
||||||
@@ -240,10 +267,10 @@ void lora_comms_task(void *pvParameters)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t spreadingFactor = 7;
|
uint8_t spreadingFactor = 8;
|
||||||
uint8_t bandwidth = SX126X_LORA_BW_250_0;
|
uint8_t bandwidth = SX126X_LORA_BW_250_0;
|
||||||
uint8_t codingRate = SX126X_LORA_CR_4_8;
|
uint8_t codingRate = SX126X_LORA_CR_4_8;
|
||||||
uint16_t preambleLength = 8;
|
uint16_t preambleLength = 4;
|
||||||
bool crcOn = true;
|
bool crcOn = true;
|
||||||
bool invertIrq = false;
|
bool invertIrq = false;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user