[Date Prev][Date Next][Thread Prev][Thread Next] - [Date Index][Thread Index][Author Index]
Re: D-block utility
I think I posted this before, but here is a routine the allows you to
decode D-blocks. Feel free to use it...
Standard Disclaimer: I want to be a programmer when I grow up; I am
not yet grown.
-------------------------------------------------------------------------------------------------------------------------
#include <math.h>
#include <stdio.h>
#include<stat.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
struct dblock {
char ID[5];
short NB; // NB=Number of blocks
short NS; // NS sequence number
short N; // N = number of bytes in block
};
// This routine is passed a telmetry block,
// it is assumed the input routine has already done a CRC check.
void d_decode(unsigned char block[])
{
time_t lclTime;
struct tm *now;
char ts[256]; /* time string */
extern struct Pref_conf Pref;
unsigned short x,i;
unsigned char Dblock[500];
char temp[255];
FILE *fp6,*fp7;
struct dblock bIndex;
// get time UTC
lclTime = time(NULL);
now = gmtime(&lclTime);
// setup directories
strftime(ts, 256, ":TLM Folder:%Y", now);
mkdir(ts,0);
strftime(ts, 256, ":TLM Folder:%Y:%b", now);
mkdir(ts,0);
strftime(ts, 256, ":TLM Folder:%Y:%b:%d", now);
mkdir(ts,0);
strftime(ts, 256, ":TLM Folder:%Y:%b:%d:", now);
// pull fileID from telemetry block
bIndex.ID[0]=block[2];
bIndex.ID[1]=block[3];
bIndex.ID[2]='\0';
sprintf(temp,"%sd.%s.raw",ts,bIndex.ID);
fp6=fopen(temp,"a+b");
sprintf(temp,"%sd.%s.index",ts,bIndex.ID);
fp7=fopen(temp,"ab");
// pull the other header information from the block.
bIndex.NB = (block[5] << 8) + (0x00ff & block[4]);
bIndex.NS = (block[7] << 8) + (0x00ff & block[6]);
bIndex.N = (block[509] << 8) + (0x00ff & block[508]);
//sprintf(temp,"\rFileID = %s , NS= %d",bIndex.ID,bIndex.NB); // debug
//TlmDraw(temp);
sprintf(temp,"\rSN= %d , N= %d\r",bIndex.NS,bIndex.N); // debug
TlmDraw(temp);
for(x=8,i=0;i<bIndex.N;x++,i++){
if(!Pref.exor){ // If the D block has not already been XORed
Dblock[i]=(unsigned char)(x ^ block[x]);
}else{
Dblock[i]=block[x]; // If we are reading from
archived D block that has been XORed
}
}
// seek offset NS*500
fseek(fp6,(bIndex.NS*500),0);
// write block N in length
fwrite(Dblock,1,bIndex.N,fp6);
fclose(fp6);
// update index
fwrite(&bIndex,1,sizeof(struct dblock ),fp7);
fclose(fp7);
}
// Routine that tracks percent of file received
void checkIndex(void)
{
SFTypeList typeList={'TEXT','????',0,0};
StandardFileReply reply;
short fileRefNum;
struct dblock bIndex;
unsigned char i=0,j;
float x=0;
long c;
char temp[255];//t[11];
unsigned short NSarray[4096]; // Support 2MB filesize. Note the
spec allows for files with upto 32MB in length.
c=sizeof(struct dblock);
StandardGetFile(nil,0,typeList,&reply);
if(reply.sfGood == 0)
{
return;
}
FSpOpenDF(&reply.sfFile,fsRdPerm,&fileRefNum); // use file
selection dialog
while ( !(FSRead(fileRefNum,&c,&bIndex)) ) // read in index.
{
NSarray[bIndex.NS]=12340; // mark this sequence
//sprintf(temp,"\r%s NS=%d",bIndex.ID,bIndex.NS); // debug
//TlmDraw(temp);
}
FSClose(fileRefNum);
// Count how many blocks we have
for(i=0,j=0;i<bIndex.NB;i++){
if(NSarray[i] == 12340){
j++;}
}
x=(float)j/bIndex.NB; // what percentae of "D" blocks have been
captured
sprintf(temp,"\r%s NB=%d x=%2.2f \r",bIndex.ID,bIndex.NB,x); // debug
TlmDraw(temp);
}
Gilbert Mackall
N3RZN
----
Via the amsat-bb mailing list at AMSAT.ORG courtesy of AMSAT-NA.
To unsubscribe, send "unsubscribe amsat-bb" to Majordomo@amsat.org
AMSAT Home