Legen Dary / Mbed 2 deprecated APP4

Dependencies:   mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers trame.cpp Source File

trame.cpp

00001 #include "trame.h"
00002 
00003 trame::trame( string msg )
00004 {
00005     std::printf("debug : creating trame with %s \n\r", msg);
00006     length = ( msg.length() * 8 ) + ( 7 * 8 );
00007     dataLength = ( msg.length() * 8 );
00008     preambule = 0x55;
00009     start = 0x7E;
00010     type_flags = 0x0;
00011     end = 0x7E;
00012     message_length = msg.length()*8;
00013     
00014     string temp = "";
00015     for (int i = 0; i < msg.length(); i++)
00016         {
00017             temp += bitset<8>( msg.c_str()[ i ]).to_string<char, string::traits_type, string::allocator_type>();
00018         }
00019     message = bitset<640>( temp );
00020     char msg_c[ msg.length() ];
00021     strcpy( msg_c, msg.c_str() );
00022     unsigned short crc_t = CRC16::calculateCRC16( msg_c, msg.length() );
00023     crc16 = crc_t;
00024 }
00025 
00026 bitset<696>* trame::getBitset()
00027 {
00028     bitFrame = new bitset<696>;
00029     for( int i = 0; i < 8; i++ )
00030     {
00031         (*bitFrame)[i] = preambule[7-i];
00032     }
00033     
00034     for( int i = 0; i < 8; i++ )
00035     {
00036         (*bitFrame)[i+8] = start[7-i];
00037     }
00038     
00039     for( int i = 0; i < 8; i++ )
00040     {
00041         (*bitFrame)[i+16] = type_flags[7-i];
00042     }
00043     
00044     for( int i = 0; i < 8; i++ )
00045     {
00046         (*bitFrame)[i+24] = message_length[7-i];
00047     }
00048     
00049     for( int i = 0; i < dataLength; i++ )
00050     {
00051         (*bitFrame)[i+32] = message[dataLength-1-i];
00052     }
00053     
00054     for( int i = 0; i < 16; i++ )
00055     {
00056         (*bitFrame)[i+32+dataLength] = crc16[15-i];
00057     }
00058     
00059     for( int i = 0; i < 8; i++ )
00060     {
00061         (*bitFrame)[i+48+dataLength] = end[7-i];
00062     }
00063     
00064     for( int i = i+56+dataLength; i < 696; i++)
00065     {
00066         (*bitFrame)[i] = 0;
00067     }
00068     for(int i = 0; i<length; i++)
00069     {
00070         std::printf("%d", (*bitFrame)[i] & 0x1);
00071     }
00072     return bitFrame;
00073 }