\doxysection{modbus\+\_\+coils.\+c} \hypertarget{modbus__coils_8c_source}{}\label{modbus__coils_8c_source}\index{E:/.WORK/STM32/Diod\_Test/diode\_tester/Core/Modbus/Src/modbus\_coils.c@{E:/.WORK/STM32/Diod\_Test/diode\_tester/Core/Modbus/Src/modbus\_coils.c}} \mbox{\hyperlink{modbus__coils_8c}{Go to the documentation of this file.}} \begin{DoxyCode}{0} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00001}00001\ \textcolor{comment}{/**}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00002}00002\ \textcolor{comment}{*******************************************************************************}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00003}00003\ \textcolor{comment}{*\ @file\ modbus\_coils.c}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00004}00004\ \textcolor{comment}{*\ @brief\ Реализация\ работы\ с\ коилами\ Modbus}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00005}00005\ \textcolor{comment}{*******************************************************************************}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00006}00006\ \textcolor{comment}{*\ @details}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00007}00007\ \textcolor{comment}{Модуль\ для\ доступа\ к\ coils\ внутри\ программы:}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00008}00008\ \textcolor{comment}{-\/\ Функции\ для\ доступа\ к\ coils\ по\ глобальным\ адресам}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00009}00009\ \textcolor{comment}{-\/\ Макросы\ для\ доступа\ к\ coils\ по\ локальным\ адресам}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00010}00010\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00011}00011\ \textcolor{comment}{Модуль\ обработки\ команд\ для\ coils\ (битовых\ данных):}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00012}00012\ \textcolor{comment}{-\/\ Чтение\ coils\ (0x01)\ -\/\ упаковка\ битов\ в\ байты\ для\ передачи}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00013}00013\ \textcolor{comment}{-\/\ Запись\ одиночного\ coil\ (0x05)\ -\/\ установка/сброс\ бита}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00014}00014\ \textcolor{comment}{-\/\ Запись\ множественных\ coils\ (0x0F)\ -\/\ распаковка\ битов\ из\ байтов}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00015}00015\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00016}00016\ \textcolor{comment}{@section\ cvalid\ Валидация\ данных:}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00017}00017\ \textcolor{comment}{-\/\ Проверка\ соответствия\ количества\ байт\ и\ регистров}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00018}00018\ \textcolor{comment}{-\/\ Валидация\ адресов\ через\ MB\_DefineRegistersAddress()}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00019}00019\ \textcolor{comment}{-\/\ Обработка\ исключений\ при\ некорректных\ запросах}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00020}00020\ \textcolor{comment}{******************************************************************************/}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00021}00021\ \textcolor{preprocessor}{\#include\ "{}\mbox{\hyperlink{modbus__coils_8h}{modbus\_coils.h}}"{}}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00022}00022\ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00023}00023\ \textcolor{preprocessor}{\#ifdef\ MODBUS\_ENABLE\_COILS}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00024}00024\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00025}00025\ \textcolor{comment}{/**\ }} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00026}00026\ \textcolor{comment}{\ \ *\ @brief\ \ \ \ Выставить/сбросить\ коил\ по\ глобальному\ адресу.}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00027}00027\ \textcolor{comment}{\ \ *\ @param\ \ \ \ Addr\ \ \ \ \ \ \ \ \ \ Адрес\ коила.}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00028}00028\ \textcolor{comment}{\ \ *\ @param\ \ \ \ WriteVal\ \ \ \ \ \ Что\ записать\ в\ коил:\ 0\ или\ 1.}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00029}00029\ \textcolor{comment}{\ \ *\ @return\ \ \ ExceptionCode\ Код\ исключения\ если\ коила\ по\ адресу\ не\ существует,\ и\ ET\_NO\_ERRORS\ если\ все\ ок.}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00030}00030\ \textcolor{comment}{\ \ *}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00031}00031\ \textcolor{comment}{\ \ *\ @details\ \ Позволяет\ обратиться\ к\ любому\ коилу\ по\ его\ глобальному\ адрессу.}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00032}00032\ \textcolor{comment}{\ \ \ \ \ \ \ \ \ \ \ \ \ \ Вне\ зависимости\ от\ того\ как\ коилы\ размещены\ в\ памяти.}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00033}00033\ \textcolor{comment}{\ \ */}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00034}\mbox{\hyperlink{group___m_o_d_b_u_s___d_a_t_a___a_c_c_e_s_s___f_u_n_c_t_i_o_n_s_gae9b8595911d93cfbf8597f3356a494cc}{00034}}\ \mbox{\hyperlink{group___m_o_d_b_u_s___m_e_s_s_a_g_e___d_e_f_i_n_e_s_ga4ade64cb3fabf37f010c1e297489980c}{MB\_ExceptionTypeDef}}\ \mbox{\hyperlink{group___m_o_d_b_u_s___d_a_t_a___a_c_c_e_s_s___f_u_n_c_t_i_o_n_s_gae9b8595911d93cfbf8597f3356a494cc}{MB\_Coil\_Write\_Global}}(uint16\_t\ Addr,\ \mbox{\hyperlink{group___m_o_d_b_u_s___d_a_t_a___a_c_c_e_s_s___f_u_n_c_t_i_o_n_s_ga8ccf569b78a17a10ac7c80d52730753a}{MB\_CoilsOpTypeDef}}\ WriteVal)} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00035}00035\ \{} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00036}00036\ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/CHECK\ FOR\ ERRORS-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00037}00037\ \ \ \mbox{\hyperlink{group___m_o_d_b_u_s___m_e_s_s_a_g_e___d_e_f_i_n_e_s_ga4ade64cb3fabf37f010c1e297489980c}{MB\_ExceptionTypeDef}}\ Exception\ =\ \mbox{\hyperlink{group___m_o_d_b_u_s___m_e_s_s_a_g_e___d_e_f_i_n_e_s_gga4ade64cb3fabf37f010c1e297489980caa6980c7a8d924dd975b8fa06a300eb74}{ET\_NO\_ERRORS}};} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00038}00038\ \ \ uint16\_t\ *coils;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00039}00039\ \ \ uint16\_t\ start\_shift\ =\ 0;\ \textcolor{comment}{//\ shift\ in\ coils\ register}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00040}00040\ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00041}00041\ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/WRITE\ COIL-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00042}00042\ \ \ Exception\ =\ \mbox{\hyperlink{group___m_o_d_b_u_s___c_m_d___p_r_o_c_e_s_s___f_u_n_c_t_i_o_n_s_gade717a6829a062a8a198bd933c8b2221}{MB\_DefineCoilsAddress}}(\&coils,\ Addr,\ 1,\ \&start\_shift,\ 1);} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00043}00043\ \ \ \textcolor{keywordflow}{if}(Exception\ ==\ \mbox{\hyperlink{group___m_o_d_b_u_s___m_e_s_s_a_g_e___d_e_f_i_n_e_s_gga4ade64cb3fabf37f010c1e297489980caa6980c7a8d924dd975b8fa06a300eb74}{ET\_NO\_ERRORS}})} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00044}00044\ \ \ \{} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00045}00045\ \ \ \ \ \textcolor{keywordflow}{switch}(WriteVal)} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00046}00046\ \ \ \ \ \{} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00047}00047\ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ SET\_COIL:} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00048}00048\ \ \ \ \ \ \ \ \ *coils\ |=\ (1<\mbox{\hyperlink{struct_r_s___msg_type_def_a3dab5eaf3a1dd5719b8bfec1adad0d39}{Except\_Code}}\ =\ \mbox{\hyperlink{group___m_o_d_b_u_s___c_m_d___p_r_o_c_e_s_s___f_u_n_c_t_i_o_n_s_gade717a6829a062a8a198bd933c8b2221}{MB\_DefineCoilsAddress}}(\&coils,\ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_af99048a71119ba4c17772bd5544b3eef}{Addr}},\ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a1ccb2bf492218a6ae3a5b6ad5cd4c82f}{Qnt}},\ \&start\_shift,\ 0);} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00110}00110\ \ \ \textcolor{keywordflow}{if}(modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a3dab5eaf3a1dd5719b8bfec1adad0d39}{Except\_Code}}\ !=\ \mbox{\hyperlink{group___m_o_d_b_u_s___m_e_s_s_a_g_e___d_e_f_i_n_e_s_gga4ade64cb3fabf37f010c1e297489980caa6980c7a8d924dd975b8fa06a300eb74}{ET\_NO\_ERRORS}})} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00111}00111\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00112}00112\ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00113}00113\ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/READING\ COIL-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00114}00114\ \ \ \textcolor{comment}{//\ setup\ output\ message\ data\ size\ }} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00115}00115\ \ \ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a5c69bf212dc5e7dc2eaa50971e27e2a6}{ByteCnt}}\ =\ Divide\_Up(modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a1ccb2bf492218a6ae3a5b6ad5cd4c82f}{Qnt}},\ 8);} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00116}00116\ \ \ \textcolor{comment}{//\ create\ mask\ for\ coils}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00117}00117\ \ \ uint16\_t\ mask\_for\_coils\ =\ 0;\ \ \textcolor{comment}{//\ mask\ for\ coils\ that've\ been\ chosen}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00118}00118\ \ \ uint16\_t\ setted\_coils\ =\ 0;\ \ \ \ \textcolor{comment}{//\ value\ of\ setted\ coils}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00119}00119\ \ \ uint16\_t\ temp\_reg\ =\ 0;\ \ \ \ \ \ \ \ \textcolor{comment}{//\ temp\ register\ for\ saving\ coils\ that\ hasnt\ been\ chosen}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00120}00120\ \ \ uint16\_t\ coil\_cnt\ =\ 0;\ \ \ \ \ \ \ \ \textcolor{comment}{//\ counter\ for\ processed\ coils}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00121}00121\ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00122}00122\ \ \ \textcolor{comment}{//\ cycle\ until\ all\ registers\ with\ requered\ coils\ would\ be\ processed}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00123}00123\ \ \ \textcolor{keywordtype}{int}\ shift\ =\ start\_shift;\ \ \textcolor{comment}{//\ set\ shift\ to\ first\ coil\ in\ first\ register}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00124}00124\ \ \ \textcolor{keywordtype}{int}\ ind\ =\ 0;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ index\ for\ coils\ registers\ and\ data}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00125}00125\ \ \ \textcolor{keywordflow}{for}(;\ ind\ <=\ Divide\_Up(start\_shift\ +\ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a1ccb2bf492218a6ae3a5b6ad5cd4c82f}{Qnt}},\ 16);\ ind++)} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00126}00126\ \ \ \{\ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00127}00127\ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/SET\ MASK\ FOR\ COILS\ REGISTER-\/-\/-\/-\/}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00128}00128\ \ \ \ \ mask\_for\_coils\ =\ 0;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00129}00129\ \ \ \ \ \textcolor{keywordflow}{for}(;\ shift\ <\ 0x10;\ shift++)} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00130}00130\ \ \ \ \ \{} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00131}00131\ \ \ \ \ \ \ mask\_for\_coils\ |=\ 1<<(shift);\ \textcolor{comment}{//\ choose\ certain\ coil}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00132}00132\ \ \ \ \ \ \ \textcolor{keywordflow}{if}(++coil\_cnt\ >=\ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a1ccb2bf492218a6ae3a5b6ad5cd4c82f}{Qnt}})} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00133}00133\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00134}00134\ \ \ \ \ \}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00135}00135\ \ \ \ \ shift\ =\ 0;\ \textcolor{comment}{//\ set\ shift\ to\ zero\ for\ the\ next\ step}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00136}00136\ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00137}00137\ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/READ\ COILS-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00138}00138\ \ \ \ \ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_aacbc6754621bd84742cd6c2ba65ad094}{MbData}}[ind]\ =\ (*(coils+ind)\&mask\_for\_coils)\ >>\ start\_shift;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00139}00139\ \ \ \ \ \textcolor{keywordflow}{if}(ind\ >\ 0)} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00140}00140\ \ \ \ \ \ \ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_aacbc6754621bd84742cd6c2ba65ad094}{MbData}}[ind-\/1]\ |=\ ((*(coils+ind)\&mask\_for\_coils)\ <<\ 16)\ >>\ start\_shift;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00141}00141\ \ \ \ \ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00142}00142\ \ \ \}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00143}00143\ \ \ \textcolor{comment}{//\ т.к.\ MbData\ 16-\/битная,\ для\ 8-\/битной\ передачи,\ надо\ поменять\ местами\ верхний\ и\ нижний\ байты}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00144}00144\ \ \ \textcolor{keywordflow}{for}(;\ ind\ >=\ 0;\ -\/-\/ind)\ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00145}00145\ \ \ \ \ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_aacbc6754621bd84742cd6c2ba65ad094}{MbData}}[ind]\ =\ ByteSwap16(modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_aacbc6754621bd84742cd6c2ba65ad094}{MbData}}[ind]);} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00146}00146\ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00147}00147\ \ \ \textcolor{keywordflow}{return}\ 1;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00148}00148\ \}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00149}00149\ \textcolor{comment}{}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00150}00150\ \textcolor{comment}{/**}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00151}00151\ \textcolor{comment}{\ \ *\ @brief\ \ \ \ Обработать\ функцию\ Write\ Single\ Coils\ (05\ -\/\ 0x05).}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00152}00152\ \textcolor{comment}{\ \ *\ @param\ \ \ \ modbus\_msg\ \ \ \ \ \ \ \ Указатель\ на\ структуру\ собщения\ modbus.}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00153}00153\ \textcolor{comment}{\ \ *\ @return\ \ \ fMessageHandled\ \ \ Статус\ о\ результате\ обработки\ комманды.}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00154}00154\ \textcolor{comment}{\ \ *\ @details\ \ Обработка\ команды\ Write\ Single\ Coils.}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00155}00155\ \textcolor{comment}{\ \ */}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00156}\mbox{\hyperlink{group___m_o_d_b_u_s___c_m_d___p_r_o_c_e_s_s___f_u_n_c_t_i_o_n_s_ga918102931c9125a5e44a30e103d17e14}{00156}}\ uint8\_t\ \mbox{\hyperlink{group___m_o_d_b_u_s___c_m_d___p_r_o_c_e_s_s___f_u_n_c_t_i_o_n_s_ga918102931c9125a5e44a30e103d17e14}{MB\_Process\_Write\_Single\_Coil}}(\mbox{\hyperlink{struct_r_s___msg_type_def}{RS\_MsgTypeDef}}\ *modbus\_msg)} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00157}00157\ \{} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00158}00158\ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/CHECK\ FOR\ ERRORS-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00159}00159\ \ \ \textcolor{keywordflow}{if}\ ((modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a1ccb2bf492218a6ae3a5b6ad5cd4c82f}{Qnt}}\ !=\ 0x0000)\ \&\&\ (modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a1ccb2bf492218a6ae3a5b6ad5cd4c82f}{Qnt}}\ !=\ 0xFF00))} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00160}00160\ \ \ \{} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00161}00161\ \ \ \ \ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a3dab5eaf3a1dd5719b8bfec1adad0d39}{Except\_Code}}\ =\ \mbox{\hyperlink{group___m_o_d_b_u_s___m_e_s_s_a_g_e___d_e_f_i_n_e_s_gga4ade64cb3fabf37f010c1e297489980ca47d6168d0692ccb7e09e19084287aba3}{ET\_ILLEGAL\_DATA\_VALUE}};} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00162}00162\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00163}00163\ \ \ \}\ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00164}00164\ \ \ \textcolor{comment}{//\ define\ position\ of\ coil}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00165}00165\ \ \ uint16\_t\ *coils;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00166}00166\ \ \ uint16\_t\ start\_shift\ =\ 0;\ \textcolor{comment}{//\ shift\ in\ coils\ register}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00167}00167\ \ \ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a3dab5eaf3a1dd5719b8bfec1adad0d39}{Except\_Code}}\ =\ \mbox{\hyperlink{group___m_o_d_b_u_s___c_m_d___p_r_o_c_e_s_s___f_u_n_c_t_i_o_n_s_gade717a6829a062a8a198bd933c8b2221}{MB\_DefineCoilsAddress}}(\&coils,\ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_af99048a71119ba4c17772bd5544b3eef}{Addr}},\ 0,\ \&start\_shift,\ 1);} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00168}00168\ \ \ \textcolor{keywordflow}{if}(modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a3dab5eaf3a1dd5719b8bfec1adad0d39}{Except\_Code}}\ !=\ \mbox{\hyperlink{group___m_o_d_b_u_s___m_e_s_s_a_g_e___d_e_f_i_n_e_s_gga4ade64cb3fabf37f010c1e297489980caa6980c7a8d924dd975b8fa06a300eb74}{ET\_NO\_ERRORS}})} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00169}00169\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00170}00170\ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00171}00171\ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00172}00172\ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/WRITTING\ COIL-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00173}00173\ \ \ \textcolor{keywordflow}{if}(modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a1ccb2bf492218a6ae3a5b6ad5cd4c82f}{Qnt}}\ ==\ 0xFF00)} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00174}00174\ \ \ \ \ *(coils)\ |=\ 1<\mbox{\hyperlink{struct_r_s___msg_type_def_a5c69bf212dc5e7dc2eaa50971e27e2a6}{ByteCnt}}\ !=\ Divide\_Up(modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a1ccb2bf492218a6ae3a5b6ad5cd4c82f}{Qnt}},\ 8))} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00191}00191\ \ \ \{\ \textcolor{comment}{//\ if\ quantity\ too\ large\ OR\ if\ quantity\ and\ bytes\ count\ arent\ match}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00192}00192\ \ \ \ \ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a3dab5eaf3a1dd5719b8bfec1adad0d39}{Except\_Code}}\ =\ \mbox{\hyperlink{group___m_o_d_b_u_s___m_e_s_s_a_g_e___d_e_f_i_n_e_s_gga4ade64cb3fabf37f010c1e297489980ca47d6168d0692ccb7e09e19084287aba3}{ET\_ILLEGAL\_DATA\_VALUE}};} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00193}00193\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00194}00194\ \ \ \}\ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00195}00195\ \ \ \textcolor{comment}{//\ define\ position\ of\ coil}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00196}00196\ \ \ uint16\_t\ *coils;\ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ pointer\ to\ coils}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00197}00197\ \ \ uint16\_t\ start\_shift\ =\ 0;\ \textcolor{comment}{//\ shift\ in\ coils\ register}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00198}00198\ \ \ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a3dab5eaf3a1dd5719b8bfec1adad0d39}{Except\_Code}}\ =\ \mbox{\hyperlink{group___m_o_d_b_u_s___c_m_d___p_r_o_c_e_s_s___f_u_n_c_t_i_o_n_s_gade717a6829a062a8a198bd933c8b2221}{MB\_DefineCoilsAddress}}(\&coils,\ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_af99048a71119ba4c17772bd5544b3eef}{Addr}},\ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a1ccb2bf492218a6ae3a5b6ad5cd4c82f}{Qnt}},\ \&start\_shift,\ 1);} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00199}00199\ \ \ \textcolor{keywordflow}{if}(modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a3dab5eaf3a1dd5719b8bfec1adad0d39}{Except\_Code}}\ !=\ \mbox{\hyperlink{group___m_o_d_b_u_s___m_e_s_s_a_g_e___d_e_f_i_n_e_s_gga4ade64cb3fabf37f010c1e297489980caa6980c7a8d924dd975b8fa06a300eb74}{ET\_NO\_ERRORS}})} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00200}00200\ \ \ \ \ \textcolor{keywordflow}{return}\ 0;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00201}00201\ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00202}00202\ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/WRITTING\ COILS-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00203}00203\ \ \ \textcolor{comment}{//\ create\ mask\ for\ coils}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00204}00204\ \ \ uint16\_t\ mask\_for\_coils\ =\ 0;\ \ \textcolor{comment}{//\ mask\ for\ coils\ that've\ been\ chosen}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00205}00205\ \ \ uint32\_t\ setted\_coils\ =\ 0;\ \ \ \ \textcolor{comment}{//\ value\ of\ setted\ coils}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00206}00206\ \ \ uint16\_t\ temp\_reg\ =\ 0;\ \ \ \ \ \ \ \ \textcolor{comment}{//\ temp\ register\ for\ saving\ coils\ that\ hasnt\ been\ chosen}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00207}00207\ \ \ uint16\_t\ coil\_cnt\ =\ 0;\ \ \ \ \ \ \ \ \textcolor{comment}{//\ counter\ for\ processed\ coils}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00208}00208\ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00209}00209\ \ \ \textcolor{comment}{//\ cycle\ until\ all\ registers\ with\ requered\ coils\ would\ be\ processed}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00210}00210\ \ \ \textcolor{keywordtype}{int}\ shift\ =\ start\_shift;\ \textcolor{comment}{//\ set\ shift\ to\ first\ coil\ in\ first\ register}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00211}00211\ \ \ \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int}\ ind\ =\ 0;\ ind\ <=\ Divide\_Up(start\_shift\ +\ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a1ccb2bf492218a6ae3a5b6ad5cd4c82f}{Qnt}},\ 16);\ ind++)} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00212}00212\ \ \ \{\ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00213}00213\ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/SET\ MASK\ FOR\ COILS\ REGISTER-\/-\/-\/-\/}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00214}00214\ \ \ \ \ mask\_for\_coils\ =\ 0;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00215}00215\ \ \ \ \ \textcolor{keywordflow}{for}(;\ shift\ <\ 0x10;\ shift++)} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00216}00216\ \ \ \ \ \{} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00217}00217\ \ \ \ \ \ \ mask\_for\_coils\ |=\ 1<<(shift);\ \textcolor{comment}{//\ choose\ certain\ coil}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00218}00218\ \ \ \ \ \ \ \textcolor{keywordflow}{if}(++coil\_cnt\ >=\ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a1ccb2bf492218a6ae3a5b6ad5cd4c82f}{Qnt}})} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00219}00219\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00220}00220\ \ \ \ \ \}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00221}00221\ \ \ \ \ shift\ =\ 0;\ \textcolor{comment}{//\ set\ shift\ to\ zero\ for\ the\ next\ step}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00222}00222\ \ \ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00223}00223\ \ \ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00224}00224\ \ \ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00225}00225\ \ \ \ \ \textcolor{comment}{//-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/WRITE\ COILS-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/-\/}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00226}00226\ \ \ \ \ \textcolor{comment}{//\ get\ current\ coils}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00227}00227\ \ \ \ \ temp\_reg\ =\ *(coils+ind);} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00228}00228\ \ \ \ \ \textcolor{comment}{//\ set\ coils}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00229}00229\ \ \ \ \ setted\_coils\ =\ ByteSwap16(modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_aacbc6754621bd84742cd6c2ba65ad094}{MbData}}[ind])\ <<\ start\_shift;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00230}00230\ \ \ \ \ \textcolor{keywordflow}{if}(ind\ >\ 0)} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00231}00231\ \ \ \ \ \{} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00232}00232\ \ \ \ \ \ \ setted\_coils\ |=\ ((ByteSwap16(modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_aacbc6754621bd84742cd6c2ba65ad094}{MbData}}[ind-\/1])\ <<\ start\_shift)\ >>\ 16);} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00233}00233\ \ \ \ \ \}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00234}00234\ \ \ \ \ \textcolor{comment}{//\ write\ coils}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00235}00235\ \ \ \ \ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00236}00236\ \ \ \ \ *(coils+ind)\ =\ setted\_coils\ \&\ mask\_for\_coils;\ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00237}00237\ \ \ \ \ \ \textcolor{comment}{//\ restore\ untouched\ coils}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00238}00238\ \ \ \ \ *(coils+ind)\ |=\ temp\_reg\&(\string~mask\_for\_coils);} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00239}00239\ \ \ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00240}00240\ \ \ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00241}00241\ \ \ \ \ \textcolor{keywordflow}{if}(coil\_cnt\ >=\ modbus\_msg-\/>\mbox{\hyperlink{struct_r_s___msg_type_def_a1ccb2bf492218a6ae3a5b6ad5cd4c82f}{Qnt}})\ \textcolor{comment}{//\ if\ all\ coils\ written\ -\/\ break\ cycle}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00242}00242\ \ \ \ \ \ \ \textcolor{keywordflow}{break};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ *kind\ of\ unnecessary}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00243}00243\ \ \ \}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00244}00244\ \ \ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00245}00245\ \ \ \textcolor{keywordflow}{return}\ 1;} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00246}00246\ \}} \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00247}00247\ } \DoxyCodeLine{\Hypertarget{modbus__coils_8c_source_l00248}00248\ \textcolor{preprocessor}{\#endif\ }\textcolor{comment}{//MODBUS\_ENABLE\_COILS}} \end{DoxyCode}