Philip Heron 2010-07-06 12:16:42 +01:00
rodzic 908f4f46dd
commit cbdc235291
2 zmienionych plików z 148 dodań i 15 usunięć

15
c328.c
Wyświetl plik

@ -6,7 +6,7 @@
#include "c328.h"
/* >10ms timeout at 300 hz */
#define CMD_TIMEOUT (4)
#define CMD_TIMEOUT (20)
/* Wait longer for the camera to take the image and return DATA response */
#define PIC_TIMEOUT (200)
@ -14,9 +14,9 @@
#define RXREADY (UCSR0A & (1 << RXC0))
/* Receive buffer */
#define RXBUF_LEN (64)
static uint8_t rxbuf[RXBUF_LEN];
static uint16_t rxbuf_len = 0;
#define RXBUF_LEN (256)
uint8_t rxbuf[RXBUF_LEN];
uint16_t rxbuf_len = 0;
/* Expected package size */
static uint8_t pkg_len = 64; /* Default is 64 according to datasheet */
@ -82,9 +82,9 @@ static char c3_cmd(uint8_t cmd, uint8_t a1, uint8_t a2, uint8_t a3, uint8_t a4)
void c3_init(void)
{
/* Do UART initialisation, port 0 @ 57600 baud for 7.3728 MHz clock */
/* Do UART initialisation, port 0 @ 9600 baud for 7.3728 MHz clock */
UBRR0H = 0;
UBRR0L = 7;
UBRR0L = 47;
/* Enable TX & RX */
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
@ -108,6 +108,7 @@ char c3_sync(void)
/* ACK the SYNC and return success code */
c3_tx(CMD_ACK, CMD_SYNC, 0, 0, 0);
return(0);
}
@ -186,7 +187,7 @@ char c3_get_package(uint16_t id, uint8_t **dst, uint16_t *length)
/* Test for timeout or incomplete package */
if(rxbuf_len != s) return(-1);
/* Test checksum */
/* Fix and test checksum */
checksum -= rxbuf[rxbuf_len - 2];
if(checksum != rxbuf[rxbuf_len - 2]) return(-1);

148
hadie.c
Wyświetl plik

@ -8,34 +8,166 @@
/* copy should be included with this source. */
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <util/delay.h>
#include <util/crc16.h>
#include <avr/interrupt.h>
#include "rtty.h"
#include "c328.h"
#include "rs8.h"
uint16_t gps_CRC16_checksum(char *s)
/* Message buffer */
#define MSG_SIZE (100)
char msg[MSG_SIZE];
/* Image TX data */
#define PKT_SIZE (0x100)
#define PKT_SIZE_HEADER (0x06)
#define PKT_SIZE_RSCODES (0x20)
#define PKT_SIZE_PAYLOAD (PKT_SIZE - PKT_SIZE_HEADER - PKT_SIZE_RSCODES)
uint8_t pkt[PKT_SIZE];
uint16_t pkt_len;
uint16_t image_len;
void init_packet(uint8_t *packet, uint8_t imageid, uint8_t pktid, uint16_t filesize)
{
uint16_t x;
packet[0] = 0x55; /* Preamble */
packet[1] = 0x66; /* Marker */
packet[2] = imageid; /* Image ID */
packet[3] = pktid; /* Packet ID */
packet[4] = filesize & 0XFF; /* Filesize LSB */
packet[5] = filesize >> 8; /* Filesize MSB */
memset(&packet[PKT_SIZE_HEADER], 0, PKT_SIZE_PAYLOAD);
}
char setup_camera(void)
{
if(c3_sync() != 0)
{
rtx_string_P(PSTR("$$" CALLSIGN ":Camera sync failed...\n"));
return(-1);
}
for(x = 0xFFFF; *s; s++)
x = _crc_xmodem_update(x, (uint8_t) *s);
/* Setup the camera */
if(c3_setup(CT_JPEG, 0, SR_320x240) != 0)
{
rtx_string_P(PSTR("$$" CALLSIGN ":Camera setup failed...\n"));
return(-1);
}
return(x);
/* Set the package size */
if(c3_set_package_size(PKT_SIZE_PAYLOAD + 6) != 0)
{
rtx_string_P(PSTR("$$" CALLSIGN ":Package size set failed!\n"));
return(-1);
}
/* Take the image */
if(c3_snapshot(ST_JPEG, 0) != 0)
{
rtx_string_P(PSTR("$$" CALLSIGN ":Snapshot failed!\n"));
return(-1);
}
/* Get the image size and begin the transfer */
if(c3_get_picture(PT_SNAPSHOT, &image_len) != 0)
{
rtx_string_P(PSTR("$$" CALLSIGN ":Get picture failed\n"));
return(-1);
}
/* Camera is ready to transfer the image data */
return(0);
}
char tx_image(void)
{
static char setup = 0;
static uint16_t pkg_id;
static uint8_t *pkg;
static uint16_t pkg_len;
static uint8_t img_id = 0;
static uint8_t pkt_id;
if(!setup)
{
if(setup_camera() != 0) return(-1);
setup = -1;
pkt_id = 0;
pkg_len = 0;
pkg_id = 0;
}
/* Initialise the packet -- make sure previous packet has finished TX'ing! */
init_packet(pkt, img_id, pkt_id++, image_len);
pkt_len = 0;
while(pkt_len < PKT_SIZE_PAYLOAD)
{
if(pkg_len == 0)
{
char msg[100];
if(c3_get_package(pkg_id++, &pkg, &pkg_len) != 0)
{
snprintf(msg, 100, "$$" CALLSIGN ",Get package %i failed, had %i bytes: %02X %02X %02X %02X\n", pkg_id - 1, pkg_len, pkg[0], pkg[1], pkg[2], pkg[3]);
rtx_string(msg);
rtx_wait();
setup = 0;
return(-1);
}
snprintf(msg, 100, "$$" CALLSIGN ",Got package %i, %i bytes, %i in pkt\n", pkg_id - 1, pkg_len, pkt_len);
rtx_string(msg);
rtx_wait();
/* Skip the package header */
pkg += 4;
pkg_len -= 6;
}
if(pkg_len > 0)
{
uint16_t l = PKT_SIZE_PAYLOAD - pkt_len;
if(pkg_len < l) l = pkg_len;
memcpy(pkt + PKT_SIZE_HEADER + pkt_len, pkg, l);
pkg += l;
pkg_len -= l;
pkt_len += l;
}
}
rtx_string_P(PSTR("TX'ing packet\n"));
encode_rs_8(&pkt[1], &pkt[PKT_SIZE_HEADER + PKT_SIZE_PAYLOAD], 0);
rtx_data(pkt, PKT_SIZE);
return(0);
}
int main(void)
{
/* Initalise the radio, and let it settle */
/* Initalise the various bits */
rtx_init();
c3_init();
/* Let the radio settle before beginning */
_delay_ms(2000);
/* Start interrupts and enter main loop */
/* Start interrupts and enter the main loop */
sei();
while(1)
{
rtx_string_P(PSTR("Hello, World!\n"));
tx_image();
rtx_wait();
//rtx_string_P(PSTR("$$" CALLSIGN ",TEST\n"));
}
return(0);