Added JPEG validation filter, changed method of last packet detection

Develop
Sven Steudte 2017-08-21 05:00:23 +02:00
rodzic a855c4e7d8
commit 685d4c9165
2 zmienionych plików z 49 dodań i 32 usunięć

Wyświetl plik

@ -10,6 +10,7 @@
#include "board.h"
#include "defines.h"
#include "debug.h"
#include "ssdv.h"
#include <string.h>
#define OV5640_I2C_ADR 0x3C
@ -733,14 +734,55 @@ static bool vsync;
static bool dma_fault;
static bool dma_overrun;
/**
* Analyzes the image for JPEG errors. Returns true if the image is error free.
*/
static bool analyze_image(uint8_t *image, uint32_t image_len)
{
ssdv_t ssdv;
uint8_t pkt[SSDV_PKT_SIZE];
uint8_t *b;
uint32_t bi = 0;
uint8_t c = SSDV_OK;
uint16_t packet_count = 0;
ssdv_enc_init(&ssdv, SSDV_TYPE_NORMAL, "", 0);
ssdv_enc_set_buffer(&ssdv, pkt);
while(true)
{
while((c = ssdv_enc_get_packet(&ssdv)) == SSDV_FEED_ME)
{
b = &image[bi];
uint8_t r = bi < image_len-128 ? 128 : image_len - bi;
bi += r;
if(r <= 0)
break;
ssdv_enc_feed(&ssdv, b, r);
}
if(c == SSDV_EOI) // End of image
return true;
if(c != SSDV_OK) // Error in JPEG image
return false;
packet_count++;
}
TRACE_INFO("SSDV > %i packets", packet_count);
}
/**
* Captures an image from the camera.
*/
bool OV5640_Snapshot2RAM(void)
{
// Capture enable
TRACE_INFO("CAM > Capture image");
OV5640_Capture();
// Capture image until we get a good image (max 5 tries)
uint8_t cntr = 5;
do {
TRACE_INFO("CAM > Capture image");
OV5640_Capture();
} while(!analyze_image(ov5640_conf->ram_buffer, ov5640_conf->ram_size) && cntr--);
return true;
}

Wyświetl plik

@ -27,33 +27,8 @@ void encode_ssdv(uint8_t *image, uint32_t image_len, module_conf_t* conf, uint8_
uint8_t *b;
uint32_t bi = 0;
uint8_t c = SSDV_OK;
uint16_t packet_count = 0;
uint16_t i = 0;
// Count packets
ssdv_enc_init(&ssdv, SSDV_TYPE_NORMAL, conf->ssdv_conf.callsign, image_id);
ssdv_enc_set_buffer(&ssdv, pkt);
while(true)
{
while((c = ssdv_enc_get_packet(&ssdv)) == SSDV_FEED_ME)
{
b = &image[bi];
uint8_t r = bi < image_len-128 ? 128 : image_len - bi;
bi += r;
if(r <= 0)
break;
ssdv_enc_feed(&ssdv, b, r);
}
if(c == SSDV_EOI || c != SSDV_OK)
break;
packet_count++;
}
TRACE_INFO("SSDV > %i packets", packet_count);
// Init SSDV (FEC at 2FSK, non FEC at APRS)
bi = 0;
ssdv_enc_init(&ssdv, SSDV_TYPE_NORMAL, conf->ssdv_conf.callsign, image_id);
@ -106,8 +81,8 @@ void encode_ssdv(uint8_t *image, uint32_t image_len, module_conf_t* conf, uint8_
msg.bin_len = aprs_encode_experimental('I', msg.msg, msg.mod, &conf->aprs_conf, pkt_base91, strlen((char*)pkt_base91));
// Transmit on radio (keep transmitter switched on if packet spacing=0ms and it isnt the last packet being sent)
if(redudantTx) transmitOnRadio(&msg, false);
transmitOnRadio(&msg, conf->packet_spacing != 0 || i == packet_count-1);
if(redudantTx) transmitOnRadio(&msg, false); // Redundant transmission
transmitOnRadio(&msg, conf->packet_spacing != 0 || c == SSDV_EOI || c != SSDV_OK);
break;
case PROT_SSDV_2FSK:
@ -117,8 +92,8 @@ void encode_ssdv(uint8_t *image, uint32_t image_len, module_conf_t* conf, uint8_
memcpy(msg.msg, pkt, sizeof(pkt));
msg.bin_len = 8*sizeof(pkt);
if(redudantTx) transmitOnRadio(&msg, false);
transmitOnRadio(&msg, conf->packet_spacing != 0 || i == packet_count-1);
if(redudantTx) transmitOnRadio(&msg, false); // Redundant transmission
transmitOnRadio(&msg, conf->packet_spacing != 0 || c == SSDV_EOI || c != SSDV_OK);
break;
default: