Skip to content

Instantly share code, notes, and snippets.

@jkalmar
jkalmar / stl_bit_functions.cpp
Created November 10, 2019 21:24
Example of some funtions from c++20 <bit> header
/**
* These examples show how to do bit manipulations and operation in C++
* Standart bit operation are shown as well as utility functions from C++20 STL bit.h
*/
void bit_examples()
{
endian_example();
uint16_t number = 0x1D10u; // 0b0001110100010000u;
@jkalmar
jkalmar / rgba_red_mask.cpp
Created November 10, 2019 21:21
Example showing how to pick red color value from RGBA variable (32bits)
SCENARIO( "Representing colors as RGB with alpha value" )
{
uint32_t RGBA = 0xE64155FF; // Redish fully opaque color
WHEN( "Need to get RED value" )
{
// Lets first prepare the mask, remember that bitwise AND works 1 & 1 = 1 and everything
// else is 0
// We can use this to zero everything else except for RED value
uint32_t mask = 0xFF000000;
@jkalmar
jkalmar / bit_operations.cpp
Created November 10, 2019 21:01
Example of 6 build in bitwise operation in c++
SCENARIO( "Bit manipulations" )
{
// We can also use uint16_t, uint32_t or uint64_t (1B, 4B, 8B) variable
uint8_t bits = 0b01001011u;
SECTION( "Bitwise AND" )
{
uint8_t mask = 0x0F; // 0b00001111
uint8_t result = bits & mask;
rec1value PDUSessionResourceSetupRequestTransfer ::=
{
--TYPE INFORMATION: SEQUENCE
--OFFSET: 0,0
--extension flag: <.0>
protocolIEs
{
--TYPE INFORMATION: SEQUENCE (SIZE(0..65535)) OF
--OFFSET: 0,1
--padding: <0000000>
@jkalmar
jkalmar / asn_debug.txt
Created March 20, 2019 17:28
Debug info for 5g N2 asn1c failed decoded message
jkalmar@supercomp:~/projects/5g/app/build> ./app -iaper in.hex -dd
AD: Processing in.hex
AD: Decoding 61 bytes
Decoding PDUSessionResourceSetupRequestTransfer as SEQUENCE (APER) (/home/jkalmar/projects/5g/app/constr_SEQUENCE.c:1509)
[PER got 1<=488 bits => span 1 +0[1..488]:00 (487) => 0x0] (/home/jkalmar/projects/5g/app/asn_bit_data.c:139)
Decoding member "protocolIEs" in PDUSessionResourceSetupRequestTransfer (/home/jkalmar/projects/5g/app/constr_SEQUENCE.c:1599)
getting nsnnwn with range 65536 (/home/jkalmar/projects/5g/app/per_support.c:361)
Aligning 7 bits (/home/jkalmar/projects/5g/app/per_support.c:301)
[PER got 7<=487 bits => span 8 +0[8..488]:00 (480) => 0x0] (/home/jkalmar/projects/5g/app/asn_bit_data.c:139)
[PER got 16<=480 bits => span 24 +1[16..480]:00 (464) => 0x4] (/home/jkalmar/projects/5g/app/asn_bit_data.c:139)
@jkalmar
jkalmar / main.c
Created March 20, 2019 17:17
Test file for 5g N2 ASN
#include <PDUSessionResourceSetupRequestTransfer.h>
void testAsn( void )
{
char theData[] =
{
0x00, 0x00, 0x04, 0x00, 0x82, 0x00, 0x08, 0x08,
0x1e, 0x84, 0x80, 0x20, 0x3d, 0x09, 0x00, 0x00,
0x86, 0x00, 0x01, 0x00, 0x00, 0x8b, 0x00, 0x1a,
0x09, 0xf0, 0x11, 0x46, 0x10, 0x10, 0x3f, 0xfe,