int main () { std::cout << "--- Testing the encode and decode functions of Eurobalise Telegram consecutively with conditional packets." << std::endl; // declare a telegram Eurobalise_Telegram telegram; // declare and initialize a telegram header // telegram.header = create_Telegram_Header_TrainToTrack(); telegram.header = create_Telegram_Header_TrackToTrain(); // create a pointer to a data packet including core data packet 1 // and push this pointer into the telegam packet vector // telegram.add(std::make_shared<Train_running_number>(create_Train_running_number())); // telegram.add(std::make_shared<Error_Reporting>(create_Error_Reporting())); telegram.add(std::make_shared<Temporary_Speed_Restriction>(create_Temporary_Speed_Restriction())); telegram.add(std::make_shared<Adhesion_Factor>(create_Adhesion_Factor())); telegram.add(std::make_shared<Infill_location_reference>(create_Infill_location_reference(1))); telegram.add(std::make_shared<Infill_location_reference>(create_Infill_location_reference(0))); // add end of information package to packet sequence telegram.add(std::make_shared<End_of_Information>()); std::cout << " Encoder Input: " << telegram << std::endl; // declare and initialize the stream std::vector<uint8_t> raw_stream(1000); Bitstream stream; Bitstream_Init(&stream, &(raw_stream[0]), raw_stream.size(), 73); // save the old bitpos uint32_t init_pos = stream.bitpos; // *** encode the telegram to the stream *** std::cout << " Encoding Eurobalise Telegram." << std::endl; telegram.encode(stream); // reset to the old bitpos stream.bitpos = init_pos; // declare a new telegram Eurobalise_Telegram telegram_new; // *** decode from the stream to the new telegram *** std::cout << " Decoding Eurobalise Telegram." << std::endl; telegram_new.decode(stream); std::cout << " Decoder Ouput: " << telegram_new << std::endl; assert(telegram_new == telegram); std::cout << " Test successfull.\n" << std::endl; return EXIT_SUCCESS; }
int main () { std::cout << "\n--- Testing the en-/decode bit functions of Eurobalise Telegram with conditional packets" << std::endl; // construct telegram from header // telegram.header = create_TelegramHeader_TrainToTrack(); EurobaliseTelegram telegram(create_TelegramHeader_TrackToTrain()); telegram.add(std::make_shared<Temporary_Speed_Restriction>(create_Temporary_Speed_Restriction())); telegram.add(std::make_shared<Adhesion_Factor>(create_Adhesion_Factor())); telegram.add(std::make_shared<Infill_location_reference>(create_Infill_location_reference(1))); telegram.add(std::make_shared<Infill_location_reference>(create_Infill_location_reference(0))); // add end of information package to packet sequence telegram.add(std::make_shared<End_of_Information>()); //std::cout << " Encoder Input: " << telegram << std::endl; // declare and initialize the stream std::vector<uint8_t> raw_stream(1000); Bitstream stream; Bitstream_Init(&stream, &(raw_stream[0]), raw_stream.size(), 73); // save the old bitpos uint32_t init_pos = stream.bitpos; //std::cout << " Encoding Eurobalise Telegram." << std::endl; telegram.encode(stream); // reset to the old bitpos stream.bitpos = init_pos; // declare a new telegram EurobaliseTelegram telegram_new; //std::cout << " Decoding Eurobalise Telegram." << std::endl; telegram_new.decode(stream); //std::cout << " Decoder Ouput: " << telegram_new << std::endl; assert(telegram_new == telegram); std::cout << " Test successfull." << std::endl; return EXIT_SUCCESS; }
int main () { std::cout << "\n--- Testing the en-/decode bit functions of Eurobalise Telegram" << std::endl; // declare and initialize a telegram header EurobaliseTelegram telegram(create_TelegramHeader_TrainToTrack()); telegram.add(std::make_shared<Train_running_number>(create_Train_running_number())); telegram.add(std::make_shared<Error_Reporting>(create_Error_Reporting())); telegram.add(std::make_shared<End_of_Information>()); //std::cout << " Encoder Input: " << telegram << std::endl; // declare and initialize the stream std::vector<uint8_t> raw_stream(1000); Bitstream stream; Bitstream_Init(&stream, &(raw_stream[0]), raw_stream.size(), 73); // save the old bitpos uint32_t init_pos = stream.bitpos; // *** encode the telegram to the stream *** //std::cout << " Encoding Eurobalise Telegram." << std::endl; telegram.encode(stream); // reset to the old bitpos stream.bitpos = init_pos; // declare a new telegram EurobaliseTelegram telegram_new; // *** decode from the stream to the new telegram *** //std::cout << " Decoding Eurobalise Telegram." << std::endl; telegram_new.decode(stream); //std::cout << " Decoder Output: " << telegram_new << std::endl; assert(telegram_new == telegram); std::cout << " Test successfull." << std::endl; return EXIT_SUCCESS; }
/* * Initializes a new decompression run */ bool BitmapDecompress_Init( BitmapDecompressState *state, unsigned char *inData, int inDataSize) { uint32 tmp; Bitstream_Init(&state->bitstream, inData, inDataSize); if (!Bitstream_Get(&state->bitstream, 1, &tmp)) return false; state->compressionType = tmp; if (!Bitstream_Skip(&state->bitstream, 3)) return false; if (!Bitstream_Get(&state->bitstream, 12, &tmp)) return false; state->blockCount = tmp; return true; }
/* * Compresses the given bitmap data. * * bitmapDataSize in uint32-words. */ int Bitmap_Compress( BitmapCompressionType compressionType, uint32* bitmap, int bitmapDataSize, unsigned char *outData, int maxOutDataSize) { Bitstream bitstream; int blockCount; Assert(maxOutDataSize >= (bitmapDataSize * sizeof(uint32) + 2)); memset(outData, 0, maxOutDataSize); blockCount = bitmapDataSize; /* Header */ Bitstream_Init(&bitstream, outData, maxOutDataSize); if (!Bitmap_Compress_Write_Header(compressionType,blockCount, &bitstream)) elog(ERROR, "Failed to write bitmap compression header"); /* bitmap content */ switch (compressionType) { case BITMAP_COMPRESSION_TYPE_NO: // By assertion I know that I have sufficient space for this if (bitmapDataSize == 0) { /* we only have the header */ return 2; } memcpy(Bitstream_GetAlignedData(&bitstream, 16), bitmap, bitmapDataSize * sizeof(uint32)); return (bitmapDataSize * sizeof(uint32)) + 2; case BITMAP_COMPRESSION_TYPE_DEFAULT: if (!Bitmap_Compress_Default(bitmap, blockCount, &bitstream)) { /* This may happen when the input bitmap is not nicely compressible */ /* Fall back */ memset(outData, 0, maxOutDataSize); return Bitmap_Compress( BITMAP_COMPRESSION_TYPE_NO, bitmap, bitmapDataSize, outData, maxOutDataSize); } else { return Bitstream_GetLength(&bitstream); } default: elog(ERROR, "illegal compression type during bitmap compression: " "compression type %d", compressionType); return 0; } }
int main () { std::cout << "\n--- Testing the decode function of Eurobalise Telegram with N_ITER packets." << std::endl; std::vector<uint8_t> raw_stream(1000); Bitstream stream; Bitstream_Init(&stream, &(raw_stream[0]), raw_stream.size(), 73); uint32_t init_pos = stream.bitpos; // TelegramHeader header = create_TelegramHeader_TrainToTrack(); std::cout << " Encoding Telegram Header: " << header << std::endl; TelegramHeader header = create_TelegramHeader_TrackToTrain(); encode(stream, header); Temporary_Speed_Restriction a = create_Temporary_Speed_Restriction(); { std::cout << " Encoding packet " << a << std::endl; encode(stream, a.header); encode(stream, a.core); } Adhesion_Factor b = create_Adhesion_Factor(); { std::cout << " Encoding packet " << b << std::endl; encode(stream, b.header); encode(stream, b.core); } Infill_location_reference c = create_Infill_location_reference(1); { std::cout << " Encoding packet " << c << std::endl; encode(stream, c.header); encode(stream, c.core); } Infill_location_reference d = create_Infill_location_reference(0); { std::cout << " Encoding packet " << d << std::endl; encode(stream, d.header); encode(stream, d.core); } Gradient_Profile e = create_Gradient_Profile(); { std::cout << " Encoding packet " << e << std::endl; encode(stream, e.header); encode(stream, e.core); } End_of_Information f; { std::cout << " Encoding packet " << f << std::endl; encode(stream, f.header); encode(stream, f.core); } stream.bitpos = init_pos; EurobaliseTelegram telegram; std::cout << " Decoding Eurobalise Telegram." << std::endl; telegram.decode(stream); std::cout << " Decoder Output: " << telegram << std::endl; assert(telegram.header == header); assert_equal(a, telegram.packets[0]); assert_equal(b, telegram.packets[1]); assert_equal(c, telegram.packets[2]); std::cout << " Test successful." << std::endl; return EXIT_SUCCESS; }
int main(void) { AdhesionFactor_Tests(); TemporarySpeedRestriction_Tests(); ErrorReporting_Tests(); Level23TransitionInformation_Tests(); EndOfInformation_Tests(); { printf("\nstart test_packets\n"); // set up test data EurobaliseTelegram t; EurobaliseTelegram_Init(&t); t.header.Q_UPDOWN = 1; //printf("telegram size of t = %d\n", EurobaliseTelegram_Size(&t)); EurobaliseTelegram_Print(&t, stdout); AdhesionFactor a; AdhesionFactor_Init(&a); a.L_PACKET = 56; a.D_ADHESION = 2; EurobaliseTelegram_Add(&t, &a.header); EurobaliseTelegram_Print(&t, stdout); AdhesionFactor a1; AdhesionFactor_Init(&a1); a1.L_PACKET = 56; a1.D_ADHESION = 3; EurobaliseTelegram_Add(&t, &a1.header); EurobaliseTelegram_Print(&t, stdout); EndOfInformation e; EndOfInformation_Init(&e); EurobaliseTelegram_Add(&t, &e.header); EurobaliseTelegram_Print(&t, stdout); // encode uint8_t raw[1024]; Bitstream stream1; Bitstream_Init(&stream1, raw, 1024, 0); TelegramHeader_EncodeBit(&t.header, &stream1); PacketHeader_EncodeBit(&a.header, &stream1); AdhesionFactor_EncodeBit((const AdhesionFactor*)EurobaliseTelegram_Get(&t, 0), &stream1); PacketHeader_EncodeBit(&a1.header, &stream1); AdhesionFactor_EncodeBit((const AdhesionFactor*)EurobaliseTelegram_Get(&t, 1), &stream1); PacketHeader_EncodeBit(&e.header, &stream1); EndOfInformation_EncodeBit((const EndOfInformation*)EurobaliseTelegram_Get(&t, 1), &stream1); stream1.bitpos = 0; // reset EurobaliseTelegram u1; EurobaliseTelegram_Init(&u1); EurobaliseTelegram_DecodeBit(&u1, &stream1); EurobaliseTelegram_Print(&u1, stdout); assert(EurobaliseTelegram_Equal(&t, &u1)); Bitstream stream2; Bitstream_Init(&stream2, raw, 1024, 0); EurobaliseTelegram_EncodeBit(&t, &stream2); stream2.bitpos = 0; // reset EurobaliseTelegram u2; EurobaliseTelegram_Init(&u2); EurobaliseTelegram_DecodeBit(&u2, &stream2); EurobaliseTelegram_Print(&u2, stdout); EurobaliseTelegram_Print(&u1, stdout); assert(EurobaliseTelegram_Equal(&t, &u2)); assert(EurobaliseTelegram_Equal(&u2, &t)); assert(EurobaliseTelegram_Equal(&u1, &u2)); assert(EurobaliseTelegram_Equal(&u2, &u1)); EurobaliseTelegram_Clear(&u1); EurobaliseTelegram_Clear(&u2); } printf("end test_packets\n"); return EXIT_SUCCESS; }