add example bin file creator, strart to write the readme file. fix a missing offest calculation.

This commit is contained in:
stubbfel
2018-01-14 01:27:50 +01:00
parent e7d8117982
commit a97b41be55
5 changed files with 117 additions and 5 deletions

6
example/CMakeLists.txt Normal file
View File

@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 2.4.2)
project (b2ws_example_project)
file(GLOB_RECURSE b2ws_example_project_src_files "*.h" "*.c")
add_executable(b2ws_example_blob_writer ${b2ws_example_project_src_files} )

View File

@@ -0,0 +1,36 @@
#include <stdlib.h>
#include<stdio.h>
#include "b2ws_example_proto_t.h"
int main(void) {
uint8_t ip_count = 8;
uint16_t second_layer_size = sizeof(b2ws_second_layer_s) + ip_count * sizeof(uint32_t);
size_t blob_size =sizeof (b2ws_first_layer_s) + second_layer_size;
ptr_b2ws_first_layer_s first_layer = (ptr_b2ws_first_layer_s) malloc(blob_size);
first_layer->id = 4711;
first_layer->size = second_layer_size;
first_layer->other_four_header_options[0] = 16;
first_layer->other_four_header_options[1] = 24;
first_layer->other_four_header_options[2] = 32;
first_layer->other_four_header_options[3] = 36;
ptr_b2ws_second_layer_s second_layer = (ptr_b2ws_second_layer_s) &first_layer->second_layer[0];
second_layer->enabled = 1;
second_layer->bigger_flag = 4;
second_layer->ip_count = ip_count;
second_layer->ip_addresses[0] = 1;
second_layer->ip_addresses[1] = (uint32_t)-1;
second_layer->ip_addresses[2] = 255;
second_layer->ip_addresses[3] = 1255;
second_layer->ip_addresses[4] = 255255;
second_layer->ip_addresses[5] = 1255255;
second_layer->ip_addresses[6] = 255255255;
second_layer->ip_addresses[7] = 1255255255;
FILE * example_bin_file = fopen("b2ws_example.bin","wb");
fwrite(first_layer, blob_size ,1,example_bin_file);
fclose(example_bin_file);
free(first_layer);
}

View File

@@ -0,0 +1,27 @@
#ifndef B2WS_EXAMPLE_PROTO_T_H
#define B2WS_EXAMPLE_PROTO_T_H
#include <stdint.h>
#pragma pack (push, 1)
typedef struct b2ws_first_layer_sTag
{
int32_t id;
uint16_t size;
uint8_t other_four_header_options[4];
uint8_t second_layer[];
} b2ws_first_layer_s, *ptr_b2ws_first_layer_s;
typedef struct b2ws_second_layer_sTag
{
uint8_t enabled:1;
uint8_t other_flag:1;
uint8_t bigger_flag:6;
uint8_t ip_count;
uint32_t ip_addresses[];
} b2ws_second_layer_s, *ptr_b2ws_second_layer_s;
#pragma pack (pop)
#endif