From 84e622da1a94063ad5f93ec15fd8a35840c2aed7 Mon Sep 17 00:00:00 2001 From: FraioVeio Date: Sat, 26 Mar 2022 17:54:37 +0100 Subject: [PATCH] First commit --- .gitignore | 237 ++++++++++++++++++++++++++++++++++++++++++ .idea/.gitignore | 8 ++ .idea/Marshalling.iml | 2 + .idea/misc.xml | 4 + .idea/modules.xml | 8 ++ CMakeLists.txt | 6 ++ README.md | 60 +++++++++++ main.c | 6 ++ 8 files changed, 331 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/Marshalling.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 main.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..43eb121 --- /dev/null +++ b/.gitignore @@ -0,0 +1,237 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/linux,windows,macos,clion,c++,cmake +# Edit at https://www.toptal.com/developers/gitignore?templates=linux,windows,macos,clion,c++,cmake + +### C++ ### +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +### CLion ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### CLion Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +# https://plugins.jetbrains.com/plugin/7973-sonarlint +.idea/**/sonarlint/ + +# SonarQube Plugin +# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator-enh.xml +.idea/**/markdown-navigator/ + +# Cache file creation bug +# See https://youtrack.jetbrains.com/issue/JBR-2257 +.idea/$CACHE_FILE$ + +# CodeStream plugin +# https://plugins.jetbrains.com/plugin/12206-codestream +.idea/codestream.xml + +### CMake ### +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps + +### CMake Patch ### +# External projects +*-prefix/ + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.toptal.com/developers/gitignore/api/linux,windows,macos,clion,c++,cmake + +build \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/Marshalling.iml b/.idea/Marshalling.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/Marshalling.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..bd69bae --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..1c080db --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.21) +project(Marshalling C) + +set(CMAKE_C_STANDARD 99) + +add_executable(Marshalling main.c) diff --git a/README.md b/README.md new file mode 100644 index 0000000..e058a10 --- /dev/null +++ b/README.md @@ -0,0 +1,60 @@ +# Marshalling + +## Descrizione esercizio + +### Problema + +Stai sviluppando un protocollo di comunicazione per un semplice localizzatore di veicoli. La comunicazione avviene tramite satellite, si ha quindi una larghezza di banda molto bassa e l’efficienza è quindi cruciale. + +I dati sono organizzati sotto forma di pacchetti di dimensioni 10 byte, con la seguente struttura: + +| Bit Offset | Size in bits | Type | Name | +|------------|--------------|--------------|------------------------------------| +| 0 | 16 | unsigned int | senderID | +| 16 | 8 | unsigned int | packetType | +| 24 | 16 | signed int | altitude, in decimetri (0.1 metri) | +| 40 | 14 | signed int | longitude, in 0.0000001 gradi | +| 54 | 14 | signed int | latitude, in 0.0000001 gradi | +| 68 | 4 | unsigned int | flags | +| 72 | 8 | unsigned int | ext | + +Una volta compattato, un pacchetto è rappresentato come array di byte di dimensione 10. + +Alla ricezione dei dati, essi vengono scompattati e devono essere rappresentati nel seguente formato: +```c +struct Packet { + UInt32 senderID; + UInt32 packetType; + Int32 altitude; + Int32 longitude; + Int32 latitude; + byte flags; + byte ext; +}; +``` + +### Task1 +Implementa la funzioni marshaling e unmarshaling per i dati sopra definiti. + +Le funzioni potrebbero avere la firma seguente: +```c +uint8_t* marshal(Packet* p); +Packet* unmarshal(uint8_t* data); +``` + +È possibile modificare le firme del metodo. + +Rispettare le seguenti specifiche: + +- Troncamento: se uno qualsiasi dei valori Int32 è troppo grande o troppo piccolo per i campi assegnati, mantieni le cifre più significative. Ad esempio, se l’altitudine è 3500.0 m, il valore codificato nel pacchetto è 3276.7 m (0x7FFF). Consultare https://en.wikipedia.org/wiki/Saturation_arithmetic per ulteriori dettagli. + +- Longitudine/Latitudine: solo i 14 bit più significativi devono essere sottoposti a marshalling/unmarshalling. + +## Come compilare + +```bash +mkdir build +cd build +cmake .. +make +``` \ No newline at end of file diff --git a/main.c b/main.c new file mode 100644 index 0000000..f26b97c --- /dev/null +++ b/main.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello, World!\n"); + return 0; +}