Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
COM_SND_TM.h
- Committer:
- ee12b079
- Date:
- 2016-01-20
- Revision:
- 84:b0f7a241ddf3
- Parent:
- 69:20f09a0c3fd2
- Child:
- 86:a26f5f22631d
File content as of revision 84:b0f7a241ddf3:
//void adf_not_SDcard();
//~ #include"SDcard.h"
#define T_frames 30
unsigned char buffer_112_counter,sent_tm = 0;
int disk_read(uint8_t *, uint64_t),j;
bool new_session = true;
bool last_buffer = false;
bool first_block = true;
bool last_block =false;
bool repeat_T_frame = false;
unsigned int counter_in_block=0,diff_prev=0;
unsigned char EOS_counter = 0;
unsigned char enable_T_frame = false;
uint64_t start_block_num ; // Read from TC
uint64_t end_block_num ; // Read from TC
uint64_t Number_of_blocks_to_read ;
uint64_t block_counter = 0;
unsigned char buffer_512[512], buffer_112[112],counter_in_S_frame=0,counter_in_SCH=0;
unsigned char make_EOS_flag = true;
bool reset = false;
#define S_FRAME_SIZE 48
#define ISR 40
#define TM_FRAME_SIZE 134 //in bytes
#define T_FRAME_SIZE 159
#define EOS_SIZE 120
#define MAX_ADF_LEN 65535
const unsigned char S_frame[] = {0x46,0x9D,0xFB,0xF0,0xD2,0xBA,0x89,0xE4,0x46,0x9D,0xFB,0xF0,0xD2,0xBA,0x89,0xE4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const unsigned char EoS[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x91,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x91,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const unsigned char FCCH80[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const unsigned char SCH40[] = {0x0a,0x3f,0x46,0xb4,0x00};
const unsigned char EXOR_SEQ[] = {0x55,0xF1,0x51,0x3D,0xA7,0x42,0xAE,0x2E,0x2E,0x28,0x76,0x80,0x62,0x41,0xC4,0x75,0x4D,0x87,0xDB,0xE1,0x02,0x61,0x60,0x96,0x9C,0xCB,0x8A,0xBD,0x37,0xE4,0x72,0x5D,0xF2,0x19,0x62,0x06,0x9A,0xF9,0x38,0xB0,0x49,0x75,0xD0,0x17,0x1B,0xCC,0x0B,0xEB,0x1B,0x50,0xA2,0x2A,0x8E,0xFA,0x4D,0x6F,0x1B,0xF8,0x0F,0x97,0x39,0x25,0x60,0x55,0x9A,0xDF,0x1D,0x10,0x7F,0xBD,0x3E,0xBF,0xE5,0x68,0x02,0xD1,0x99,0x0D,0xDF,0x84,0x2E,0x15,0xE3,0x08,0xD7,0x44,0x10,0x41,0xCE,0x93,0xF6,0x59,0x71,0xD2,0xF7,0x1C,0x4A,0x44,0x2D,0xA9,0x44,0x98,0x3A,0x00,0x71,0xCC,0x2A,0x35,0xC1,0x81,0xCF,0x44,0xF7,0x6A,0x0E,0xE4,0xF2,0xFC,0xD6,0x0B,0xA8,0x95,0x7B,0x86,0xB5,0xF8,0x33,0xE9,0xBF,0x6A,0x0E,0xE6,0x53,0x82};
#define print_tm(ptr) {\
for( int i = 0; i < 134; i++ ){\
gPC.putc(ptr[i]);\
}\
}
void send_tm_from_SD_card(){}
class SND_TM{
Base_tm * head_ptr;
// transmit data variables
unsigned char Tframe_c; //_c represents counter, counts Tframe written in a segment
unsigned char EOS_c; //count no of bytes of eos have been weitten in the rolling buffer
unsigned char Sframe_c; //count no of bytes of Sframe have been weitten in the rolling buffer
unsigned char SCH40_c; //count no of bytes of SCH40 have been weitten in the rolling buffer
unsigned char data_c;
unsigned char FCCH80_c;
unsigned char RB_c; //rolling buffer counter
unsigned char segment_c; //counts the numver of segments sent
unsigned char MAX_SEGMENT;
bool Sframe; //Sframe = 1bit of CF1
bool SCH40_f;
bool FCCH80_f;
bool data_f;
bool repeat_data_f;
bool transmit_data_f;
bool eos_f;
bool junk_f;
bool segment_r; //flag checking if more sessions are required
// type 1 frame
Base_tm *T0F_pointer ;
int diff_prev;
void differential_encode(unsigned char* ptr, int length){
for(int i=0; i<length;i++){
unsigned char s = ptr[i] , t;
t = s ^ (s >> 1);
(diff_prev == 0) ? t=t^0x00 : t=t^0x80 ;
diff_prev = int(s & 0x01);
ptr[i] = t;
}
}
int type0_no; //number of type zero frames
int type1_no;
int total_frames; //number of type one packe (TMP)
int SEGMENT_NO; //number of type one packe (TMP)
int TOTAL_SEGMENT_NO;
int LAST_SEGMENT_SIZE;
void inline data_number(){
int type1_frame_no;
Base_tm*head = head_ptr;
type0_no = 0;
type1_no = 0;
while(head != NULL){
switch( GETshort_or_long_tm(head->fields) ){
case 0:
type0_no++;
break;
case 1:
type1_no++;
break;
}
head=head->next_TM;
}
type1_frame_no = ( type1_no % 10 == 0 )? (type1_no / 10) : ( (type1_no / 10) + 1);
total_frames = type0_no + type1_frame_no ;
TOTAL_SEGMENT_NO = (total_frames*2 % (ISR) == 0) ? ( total_frames*2/(ISR) ) : (total_frames*2/(ISR) + 1); //subtracting 1 since the last SCH40_f is not detected
SEGMENT_NO = TOTAL_SEGMENT_NO;
if(SEGMENT_NO > MAX_SEGMENT)
{
SEGMENT_NO = MAX_SEGMENT;
}
if(SEGMENT_NO == 1) segment_r = 0; else segment_r = 1;
TOTAL_SEGMENT_NO -= SEGMENT_NO;
LAST_SEGMENT_SIZE = total_frames*2%ISR?total_frames*2%ISR:ISR;
}
#define next_type_structure(ptr){\
unsigned char temp = GETshort_or_long_tm(ptr->fields);\
if((temp == 0) && (ptr->next_TM != NULL) ){\
do{\
ptr = ptr->next_TM;\
temp = GETshort_or_long_tm(ptr->fields);\
}\
while(temp == 1 && ptr->next_TM != NULL);\
if(temp == 1){\
ptr = NULL;\
}\
}\
else if((temp == 1) && (ptr->next_TM != NULL)){\
do{\
ptr = ptr->next_TM;\
temp = GETshort_or_long_tm(ptr->fields);\
}\
while(temp == 0 && ptr->next_TM != NULL);\
if(temp == 0){\
ptr = NULL;\
}\
}\
else{\
ptr = NULL;\
}\
}
/*
brief: take input type 0 or 1 and return the address of the first node in the list that have that type
parameter: type 0 or 1
return: pointer of the first node having same type
*/
#define exor(ptr) { for(int i=0 ; i<134; i++ ) ptr[i]=ptr[i]^EXOR_SEQ[i];}
#define first_type_structure( type,return_ptr) {\
Base_tm* temp_ptr = head_ptr;\
if(type == 0){\
while(GETshort_or_long_tm(temp_ptr->fields) == 1){\
temp_ptr = temp_ptr->next_TM;\
if(temp_ptr == NULL){\
return_ptr = NULL ;\
}\
}\
}\
else if(type == 1){\
while(GETshort_or_long_tm(temp_ptr->fields) == 0){\
temp_ptr = temp_ptr->next_TM;\
if(temp_ptr == NULL){\
return_ptr = NULL;\
}\
}\
}\
return_ptr = temp_ptr;\
}
Base_tm *T1F_pointer ;
int T1F_counter;
unsigned char TMframe_type1[TM_FRAME_SIZE];
bool type1_frame_flag; //should be true for every new list
#define type1_frame(ptr){\
int i=4;\
if(type1_frame_flag){\
first_type_structure(1,T1F_pointer);\
T1F_counter = 0;\
type1_frame_flag = false;\
}\
for(i = 4 ; (i < 134) && (T1F_pointer != NULL) ; i++){\
TMframe_type1[i] = T1F_pointer->TM_string[T1F_counter];\
if(T1F_counter++ == 12){\
T1F_counter = 0;\
next_type_structure(T1F_pointer);\
}\
}\
TMframe_type1[0] = (1<<7) + (( (i-4)/13 )<<3);\
TMframe_type1[3] = crc8_gen(TMframe_type1,3);\
if(T1F_pointer == NULL && i>12){\
for( ; i < 134 ; i++){\
TMframe_type1[i] = TMframe_type1[i-13];\
}\
}\
ptr=TMframe_type1;\
}
bool type0_frame_flag;
#define type0_frame(ptr){\
if(type0_frame_flag){\
first_type_structure(0,T0F_pointer);\
type0_frame_flag = false;\
}\
else {\
next_type_structure(T0F_pointer);\
}\
ptr = T0F_pointer->TM_string;\
}
unsigned char convoluted_frame[270];
Convolution ConvObj2;
void convolution (unsigned char * ptr){
ConvObj2.convolutionEncode(ptr, convoluted_frame);
ConvObj2.convolutionEncode(ptr + 67, convoluted_frame + 135);
}
unsigned char interleave_data[2][144];
unsigned char DS_index;
bool DS_state;
int DS_counter;
bool DS_f;
bool make_DataStream_f;
#define make_DataStream {\
unsigned char* ptr;\
if(make_DataStream_f == true){\
DS_state = true;\
DS_counter = 0;\
DS_f = false;\
make_DataStream_f = false;\
}\
if(DS_state){\
if(DS_counter < total_frames-type0_no){\
type1_frame(ptr); \
DS_f = true;\
}\
else if(DS_counter < total_frames ){\
type0_frame(ptr);\
DS_f = true;\
}\
DS_counter++;\
}\
DS_state = !DS_state;\
if (DS_f){\
DS_f = false;\
if(bypass_adf == 1)\
print_tm(ptr);\
exor(ptr);\
convolution(ptr);\
interleave(convoluted_frame,interleave_data[0]);\
interleave(convoluted_frame+ 135,interleave_data[1]);}\
DS_index = (DS_state==true)?1:0;\
}
//
public:
bool reset_adf;
SND_TM(){
MAX_SEGMENT = (MAX_ADF_LEN-EOS_SIZE)/( S_FRAME_SIZE + ISR*T_FRAME_SIZE);
//(max length - eos size)/(sframe length + tFrameLength*ISR)
}
void head_pointer(Base_tm* ptr){
head_ptr = ptr ;
type1_frame_flag = true;
type0_frame_flag = true;
make_DataStream_f = true;
transmit_data_f = true;
diff_prev = 0;
data_number();
}
void inline transmit_data(unsigned char * transmit , bool * last_buffer){
if(transmit_data_f){
RB_c = 0;
Sframe_c = 0;
SCH40_c = 0;
FCCH80_c = 0;
Tframe_c = 0;
EOS_c = 0;
segment_c = 0;
data_c = 0;
Sframe = true;
SCH40_f = false;
data_f = false;
FCCH80_f = false;
transmit_data_f = false;
reset_adf = false;
*last_buffer = false;
}
for(RB_c = 0 ; RB_c<112 ; RB_c++){
if(junk_f || *last_buffer){
transmit[RB_c] = 0x00;
continue;
}
if(Sframe){
transmit[RB_c] = S_frame[Sframe_c++];
if(Sframe_c == 48){
// printf("exit s frame\n");
Sframe_c = 0;
Sframe = false;
SCH40_f =true;
}
continue;
}
//
if(SCH40_f){
transmit[RB_c] = SCH40[SCH40_c++];
if(SCH40_c == 5 ){
SCH40_c = 0;
SCH40_f = false;
if(Tframe_c >= LAST_SEGMENT_SIZE && segment_r == 0)
{
repeat_data_f = true;
DS_index = !DS_index;
}
else
{
data_f = true;
make_DataStream;
}
// printf("exit SCH40 frame\n");
}
continue;
}
//
if(data_f){
transmit[RB_c] = interleave_data[DS_index][data_c++];
if(data_c == 144){
data_c = 0;
FCCH80_f = true;
data_f = false;
// printf("exit Data\n");
}
continue;
}
if(repeat_data_f){
transmit[RB_c] = interleave_data[DS_index][data_c++];
if(data_c == 144){
data_c = 0;
FCCH80_f = true;
repeat_data_f = false;
// printf("exit Data\n");
}
continue;
}
if(FCCH80_f){
transmit[RB_c] = FCCH80[FCCH80_c++];
if(FCCH80_c == 10){
FCCH80_c = 0;
FCCH80_f = false;
// printf("exit FCCH80\n");
if(++Tframe_c != ISR)
SCH40_f = true;
else{
Tframe_c = 0;
segment_c++;
if(segment_c >= SEGMENT_NO - 1 && TOTAL_SEGMENT_NO == 0) segment_r = 0; else segment_r = 1;
if(segment_c == SEGMENT_NO)
{eos_f = true;}
else{
Sframe = true;
}
}
}
continue;
}
if(eos_f){
transmit[RB_c] = EoS[EOS_c++];
if(EOS_c == EOS_SIZE){
EOS_c = 0;
eos_f = false;
if(segment_c == SEGMENT_NO && segment_r == 0){
*last_buffer = true;
}
else if(segment_c == SEGMENT_NO && segment_r != 0){
segment_c = 0;
SEGMENT_NO = TOTAL_SEGMENT_NO;
if(SEGMENT_NO > MAX_SEGMENT)
{
SEGMENT_NO = MAX_SEGMENT;
}
if(SEGMENT_NO == 1) segment_r = 0; else segment_r = 1;
TOTAL_SEGMENT_NO -= SEGMENT_NO;
reset_adf = true;//what does this do??
Sframe = true;
}
junk_f = true;
}
continue;
}
}
differential_encode(transmit,112);
if(reset_adf == true){
diff_prev = 0;
junk_f = false;
}
}
};
SND_TM snd_tm;
