2017-05-30 22:58:20 +00:00
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
#include "debug.h"
|
2017-07-26 22:35:48 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "config.h"
|
2017-09-08 14:28:01 +00:00
|
|
|
#include "image.h"
|
2017-09-10 01:22:58 +00:00
|
|
|
#include "tracking.h"
|
2017-05-30 22:58:20 +00:00
|
|
|
|
|
|
|
const SerialConfig uart_config =
|
|
|
|
{
|
|
|
|
115200, // baud rate
|
|
|
|
0, // CR1 register
|
|
|
|
0, // CR2 register
|
|
|
|
0 // CR3 register
|
|
|
|
};
|
|
|
|
|
|
|
|
mutex_t trace_mtx; // Used internal to synchronize multiple chprintf in debug.h
|
|
|
|
|
2017-09-10 01:22:58 +00:00
|
|
|
bool debug_on_usb = false;
|
2017-07-26 22:35:48 +00:00
|
|
|
|
|
|
|
void debugOnUSB_Off(BaseSequentialStream *chp, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
(void)chp;
|
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
debug_on_usb = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void debugOnUSB_On(BaseSequentialStream *chp, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
(void)chp;
|
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
debug_on_usb = true;
|
|
|
|
}
|
2017-09-08 14:28:01 +00:00
|
|
|
|
2017-09-08 22:00:55 +00:00
|
|
|
static uint8_t usb_buffer[96*1024] __attribute__((aligned(32))); // USB image buffer
|
2017-09-08 14:28:01 +00:00
|
|
|
void printPicture(BaseSequentialStream *chp, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
|
|
|
|
// Take picture
|
|
|
|
ssdv_conf_t conf = {
|
|
|
|
.res = RES_VGA,
|
|
|
|
.quality = 4,
|
|
|
|
.ram_buffer = usb_buffer,
|
|
|
|
.ram_size = sizeof(usb_buffer),
|
|
|
|
};
|
|
|
|
bool camera_found = takePicture(&conf, false);
|
|
|
|
|
|
|
|
// Transmit image via USB
|
|
|
|
if(camera_found)
|
|
|
|
{
|
|
|
|
bool start_detected = false;
|
|
|
|
for(uint32_t i=0; i<conf.size_sampled; i++)
|
|
|
|
{
|
|
|
|
// Look for APP0 instead of SOI because SOI is lost sometimes, but we can add SOI easily later on
|
|
|
|
if(!start_detected && conf.ram_buffer[i] == 0xFF && conf.ram_buffer[i+1] == 0xE0) {
|
|
|
|
start_detected = true;
|
|
|
|
TRACE_USB("DATA > image/jpeg,%d", conf.size_sampled-i+1); // Flag the data on serial output
|
2017-09-10 01:22:58 +00:00
|
|
|
streamPut(chp, 0xFF);
|
|
|
|
streamPut(chp, 0xD8);
|
2017-09-08 14:28:01 +00:00
|
|
|
}
|
|
|
|
if(start_detected)
|
2017-09-10 01:22:58 +00:00
|
|
|
streamPut(chp, conf.ram_buffer[i]);
|
|
|
|
}
|
|
|
|
if(!start_detected)
|
|
|
|
{
|
|
|
|
TRACE_USB("DATA > image,jpeg,0");
|
|
|
|
TRACE_USB("DATA > error,no SOI flag found");
|
2017-09-08 14:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else { // No camera found
|
|
|
|
|
2017-09-10 01:22:58 +00:00
|
|
|
TRACE_USB("DATA > image,jpeg,0");
|
|
|
|
TRACE_USB("DATA > error,no camera found");
|
2017-09-08 14:28:01 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2017-09-10 01:22:58 +00:00
|
|
|
|
|
|
|
trackPoint_t* getLogBuffer(uint16_t id)
|
|
|
|
{
|
|
|
|
if(sizeof(trackPoint_t)*id < LOG_SECTOR_SIZE-sizeof(trackPoint_t))
|
|
|
|
{
|
|
|
|
return (trackPoint_t*)(LOG_FLASH_ADDR1 + id * sizeof(trackPoint_t));
|
|
|
|
} else if((id-(LOG_SECTOR_SIZE/sizeof(trackPoint_t)))*sizeof(trackPoint_t) < LOG_SECTOR_SIZE-sizeof(trackPoint_t)) {
|
|
|
|
return (trackPoint_t*)(LOG_FLASH_ADDR2 + (id-(LOG_SECTOR_SIZE/sizeof(trackPoint_t))) * sizeof(trackPoint_t));
|
|
|
|
} else { // Outside of memory address allocation
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void readLog(BaseSequentialStream *chp, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
|
|
|
|
|
|
|
trackPoint_t *tp;
|
|
|
|
for(uint16_t i=0; (tp = getLogBuffer(i)) != NULL; i++)
|
|
|
|
if(tp->id != 0xFFFFFFFF)
|
|
|
|
{
|
|
|
|
chprintf( chp,
|
|
|
|
"%d,%04d-%02d-%02d,%02d:%02d:%02d,%d.%05d,%d.%05d,%d,%d,%d,%d.%03d,%d.%03d,%d.%03d,%d,%d,%d.%01d,%2d.%02d,%2d.%01d\r\n",
|
|
|
|
tp->id,tp->time.year, tp->time.month, tp->time.day, tp->time.hour, tp->time.minute, tp->time.day,
|
|
|
|
tp->gps_lat/10000000, (tp->gps_lat > 0 ? 1:-1)*(tp->gps_lat/100)%100000, tp->gps_lon/10000000, (tp->gps_lon > 0 ? 1:-1)*(tp->gps_lon/100)%100000, tp->gps_alt,
|
|
|
|
tp->gps_sats, tp->gps_ttff,
|
|
|
|
tp->adc_vbat/1000, (tp->adc_vbat%1000), tp->adc_vsol/1000, (tp->adc_vsol%1000), tp->adc_vusb/1000, (tp->adc_vusb%1000), tp->adc_pbat, tp->adc_rbat,
|
|
|
|
tp->air_press/10, tp->air_press%10, tp->air_temp/100, tp->air_temp%100, tp->air_hum/10, tp->air_hum%10
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-07-26 22:35:48 +00:00
|
|
|
|
|
|
|
void printConfig(BaseSequentialStream *chp, int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if(argc < 1)
|
|
|
|
{
|
|
|
|
chprintf(chp, "Argument missing!\r\n");
|
|
|
|
chprintf(chp, "Argument 1: Id of config!\r\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t id = atoi(argv[0]);
|
|
|
|
chprintf(chp, "Config ID=%d\r\n", id);
|
|
|
|
|
|
|
|
chprintf(chp, "Power: %d\r\n", config[id].power);
|
|
|
|
|
|
|
|
if(config[id].frequency.type == FREQ_STATIC) {
|
|
|
|
chprintf(chp, "Frequency: %d Hz\r\n", config[id].frequency.hz);
|
|
|
|
} else {
|
|
|
|
chprintf(chp, "Frequency: APRS region dependent (currently %d Hz\r\n", getFrequency(&config[id].frequency));
|
|
|
|
}
|
|
|
|
|
|
|
|
chprintf(chp, "Protocol: %d\r\n", config[id].protocol);
|
|
|
|
chprintf(chp, "Initial Delay: %d\r\n", config[id].init_delay);
|
|
|
|
chprintf(chp, "Packet Spacing: %d\r\n", config[id].packet_spacing);
|
|
|
|
chprintf(chp, "Sleep config: xx\r\n");
|
|
|
|
chprintf(chp, "Trigger config: xx\r\n");
|
|
|
|
|
|
|
|
chprintf(chp, "Modulation config: xx\r\n");
|
|
|
|
|
|
|
|
chprintf(chp, "Protocol config: xx\r\n");
|
|
|
|
|
|
|
|
chprintf(chp, "SSDV config: xx\r\n");
|
|
|
|
|
|
|
|
chprintf(chp, "Watchdog timeout: %d\r\n", config[id].wdg_timeout);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|