Commit 85d04e5dea55ce21e8452d9eee30b5439402ee7a
1 parent
608a4af6
Added Scripts for Building
Showing
4 changed files
with
179 additions
and
0 deletions
documentation/graphics/originals/modbus_drawings.odg
No preview for this file type
scripts/setup_submodules
0 → 100755
| 1 | +#!/bin/bash | ||
| 2 | + | ||
| 3 | +# =============================================== | ||
| 4 | +# == Setting some environment variables | ||
| 5 | +# =============================================== | ||
| 6 | +GIT_URL_OPEN="http://gitlab.osdev.nl/open_source" | ||
| 7 | +GIT_URL_CLOSED="git@gitlab.osdev.nl:closed_source" | ||
| 8 | + | ||
| 9 | +FUNC_RESULT="-1" | ||
| 10 | + | ||
| 11 | +# Name : print_usage_exit() | ||
| 12 | +# Description : Print the way this script is intended to be used and exit. | ||
| 13 | +# Parameters : None. | ||
| 14 | +# Returns : err_code 1 to the Operating System | ||
| 15 | +# -------------------------------------------------------------------------------------- | ||
| 16 | +function print_usage_exit() | ||
| 17 | +{ | ||
| 18 | + echo "Usage $0 -i|--install|-u|--update" | ||
| 19 | + echo " -i or --install Install the submodules mentioned in the submodules.list" | ||
| 20 | + echo " -u or --update Update the submodules mentioned in the submodules.list" | ||
| 21 | + echo " " | ||
| 22 | + exit 1 | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +# Name : check_top_or_sub | ||
| 26 | +# Description : Determine if we're running in a "single" lib-build or part of a | ||
| 27 | +# "meta"-repository ( submodule ). | ||
| 28 | +# Parameters : None | ||
| 29 | +# Returns : Updates the value FUNC_RESULT. | ||
| 30 | +# -1 - We're neither a git-repo or submodule. | ||
| 31 | +# 0 - We're a submodule | ||
| 32 | +# 1 - We're a top-repo ( Single library ) | ||
| 33 | +# -------------------------------------------------------------------------------------- | ||
| 34 | +function check_top_or_sub() | ||
| 35 | +{ | ||
| 36 | + # This function checks if we're the top-repository. | ||
| 37 | + # In that case we need the submodules.. If we're already a submodule, | ||
| 38 | + # we simply exit this script with a message | ||
| 39 | + if [ -e ./.git ]; then | ||
| 40 | + FUNC_RESULT="1" | ||
| 41 | + return | ||
| 42 | + elif [ -e ../.git ]; then | ||
| 43 | + if [ -e ../.submodules ]; then | ||
| 44 | + echo "Seems like we're already a submodule. Nothing to do here." | ||
| 45 | + FUNC_RESULT="0" | ||
| 46 | + return | ||
| 47 | + fi | ||
| 48 | + fi | ||
| 49 | + FUNC_RESULT="-1" | ||
| 50 | + return | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +# Name : check_working_dir | ||
| 54 | +# Description : If we're in the top of our repo, we can run this script further. | ||
| 55 | +# Parameters : None. | ||
| 56 | +# Returns : Updates the value FUNC_RESULT. | ||
| 57 | +# -1 - Not used. | ||
| 58 | +# 0 - We're not on the top-level | ||
| 59 | +# 1 - We're at the top-level. Good to go. | ||
| 60 | +# -------------------------------------------------------------------------------------- | ||
| 61 | +function check_working_dir() | ||
| 62 | +{ | ||
| 63 | + FUNC_RESULT="-1" | ||
| 64 | + # Check if we're in the top-level directory of our repository. | ||
| 65 | + if [ -f ./scripts/submodules.list ]; then | ||
| 66 | + # We're good to go | ||
| 67 | + FUNC_RESULT="1" | ||
| 68 | + return | ||
| 69 | + fi | ||
| 70 | + FUNC_RESULT="0" | ||
| 71 | + return | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +# Name : read_submodules | ||
| 75 | +# Description : Read the list of submodules needed for this project | ||
| 76 | +# Parameters : None | ||
| 77 | +# Returns : Updates the value FUNC_RESULT | ||
| 78 | +# 0 - Module list was not found | ||
| 79 | +# 1 - Module list was found and read. | ||
| 80 | +# -------------------------------------------------------------------------------------- | ||
| 81 | +function read_submodules() | ||
| 82 | +{ | ||
| 83 | + FUNC_RESULT="-1" | ||
| 84 | + if [ -e ./scripts/submodules.list ]; then | ||
| 85 | + source ./scripts/submodules.list | ||
| 86 | + FUNC_RESULT="1" | ||
| 87 | + return | ||
| 88 | + fi | ||
| 89 | + | ||
| 90 | + echo "Submodules list not found...." | ||
| 91 | + FUNC_RESULT="0" | ||
| 92 | + return | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +# Name : add_submodules | ||
| 96 | +# Description : Configure the repo to add the submodules. | ||
| 97 | +# Parameters : None. | ||
| 98 | +# Returns : None. | ||
| 99 | +# -------------------------------------------------------------------------------------- | ||
| 100 | +function add_submodules() | ||
| 101 | +{ | ||
| 102 | + echo -e "Adding SubModule(s)." | ||
| 103 | + for SUB_MODULE in ${SUB_MODULES_OPEN} | ||
| 104 | + do | ||
| 105 | + git submodule add -f ${GIT_URL_OPEN}/${SUB_MODULE}.git submodules/${SUB_MODULE} | ||
| 106 | + git config submodule.${SUB_MODULE}.url ${GIT_URL_OPEN}/${SUB_MODULE}.git | ||
| 107 | + done | ||
| 108 | + | ||
| 109 | + for SUB_MODULE in ${SUB_MODULES_CLOSED} | ||
| 110 | + do | ||
| 111 | + echo {GIT_URL_CLOSED}/${SUB_MODULE}.git | ||
| 112 | + git submodule add -f ${GIT_URL_CLOSED}/${SUB_MODULE}.git submodules/${SUB_MODULE} | ||
| 113 | + git config submodule.${SUB_MODULE}.url ${GIT_URL_CLOSED}/${SUB_MODULE}.git | ||
| 114 | + done | ||
| 115 | + | ||
| 116 | +} | ||
| 117 | + | ||
| 118 | +# Name : get_submodules | ||
| 119 | +# Description : Actually get the submodules from gitlab and add them. | ||
| 120 | +# Parameters : None | ||
| 121 | +# Returns : None | ||
| 122 | +# -------------------------------------------------------------------------------------- | ||
| 123 | +function get_submodules() | ||
| 124 | +{ | ||
| 125 | + git submodule update --init --recursive | ||
| 126 | +} | ||
| 127 | + | ||
| 128 | +# Name : update_submodules | ||
| 129 | +# Description : Update the submodules already added. | ||
| 130 | +# Parameters : None | ||
| 131 | +# Returns : None | ||
| 132 | +# -------------------------------------------------------------------------------------- | ||
| 133 | +function update_submodules() | ||
| 134 | +{ | ||
| 135 | + git submodule update --recursive | ||
| 136 | +} | ||
| 137 | + | ||
| 138 | +# ============================================================================= | ||
| 139 | +# == T H E M A I N E N T R Y O F T H I S S C R I P T == | ||
| 140 | +# ============================================================================= | ||
| 141 | +check_top_or_sub | ||
| 142 | +if [ "${FUNC_RESULT}" == "0" ]; then | ||
| 143 | + echo "Seems like we're a submodule already or not part of a repository." | ||
| 144 | + exit 0 | ||
| 145 | +fi | ||
| 146 | + | ||
| 147 | +check_working_dir | ||
| 148 | +if [ "${FUNC_RESULT}" == "0" ]; then | ||
| 149 | + echo "Go to the top of this repository and type : scripts/setup_submodules [-i|--install]" | ||
| 150 | + exit 0 | ||
| 151 | +fi | ||
| 152 | + | ||
| 153 | +read_submodules | ||
| 154 | + | ||
| 155 | +case "$1" in | ||
| 156 | + -i*|--install*) | ||
| 157 | + echo "Installing submodules for this repository ( ${PWD} )" | ||
| 158 | + add_submodules | ||
| 159 | + get_submodules | ||
| 160 | + ;; | ||
| 161 | + -u*|--update*) | ||
| 162 | + echo "Update submodules : ${SUB_MODULES}" | ||
| 163 | + update_submodules | ||
| 164 | + ;; | ||
| 165 | + *) | ||
| 166 | + echo "No parameters found..." | ||
| 167 | + print_usage_exit | ||
| 168 | + ;; | ||
| 169 | +esac | ||
| 170 | + |
scripts/submodules.list
0 → 100644
src/modbusbase.h
| @@ -149,7 +149,9 @@ private: // Methods | @@ -149,7 +149,9 @@ private: // Methods | ||
| 149 | * \param function_code - Modbus Functional Code | 149 | * \param function_code - Modbus Functional Code |
| 150 | */ | 150 | */ |
| 151 | void buildRequest(uint8_t *to_send, uint16_t address, int function_code) const; | 151 | void buildRequest(uint8_t *to_send, uint16_t address, int function_code) const; |
| 152 | + | ||
| 152 | int modbusRead(uint16_t address, uint16_t amount, int function_code); | 153 | int modbusRead(uint16_t address, uint16_t amount, int function_code); |
| 154 | + | ||
| 153 | /*! | 155 | /*! |
| 154 | * Write Request Builder and Sender | 156 | * Write Request Builder and Sender |
| 155 | * \param address - Reference address | 157 | * \param address - Reference address |
| @@ -160,11 +162,15 @@ private: // Methods | @@ -160,11 +162,15 @@ private: // Methods | ||
| 160 | * \return int | 162 | * \return int |
| 161 | */ | 163 | */ |
| 162 | int modbusWrite(uint16_t address, uint16_t amount, int function_code, const uint16_t *value); | 164 | int modbusWrite(uint16_t address, uint16_t amount, int function_code, const uint16_t *value); |
| 165 | + | ||
| 163 | virtual ssize_t modbusSend(uint8_t *to_send, size_t length) = 0; | 166 | virtual ssize_t modbusSend(uint8_t *to_send, size_t length) = 0; |
| 167 | + | ||
| 164 | virtual ssize_t modbusReceive(uint8_t *buffer) const = 0; | 168 | virtual ssize_t modbusReceive(uint8_t *buffer) const = 0; |
| 165 | 169 | ||
| 166 | void modbusErrorHandle(const uint8_t *msg, int function_code); | 170 | void modbusErrorHandle(const uint8_t *msg, int function_code); |
| 171 | + | ||
| 167 | void setBadConnection(); | 172 | void setBadConnection(); |
| 173 | + | ||
| 168 | void setBadInput(); | 174 | void setBadInput(); |
| 169 | 175 | ||
| 170 | private: // Members (Giggity!) | 176 | private: // Members (Giggity!) |