Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
interpret.cpp
00001 #include "interpret.h" 00002 #include "uart.h" 00003 #include "mbed_unit.h" 00004 #include "pt100.h" 00005 #include "di.h" 00006 #include "do.h" 00007 #include "RS485.h" 00008 00009 00010 //--------------------------------------- 00011 // Hardware recources 00012 //--------------------------------------- 00013 DigitalOut led_system_ready(LED1); 00014 00015 00016 //--------------------------------------- 00017 // Prototypes 00018 //--------------------------------------- 00019 00020 void INT_selectDeviceID( void ); 00021 void INT_deviceID_process_Broadcast( void ); 00022 00023 00024 //--------------------------------------- 00025 // Internal variables 00026 //--------------------------------------- 00027 static sINT_handler INT_handler; 00028 00029 //--------------------------------------- 00030 // External variables 00031 //--------------------------------------- 00032 00033 00034 //--------------------------------------- 00035 // Global Functions 00036 //--------------------------------------- 00037 00038 void INT_init( void ) 00039 { 00040 INT_handler.state = INT_STATE_INIT; 00041 INT_handler.receivedDeviceID = 0; 00042 INT_handler.receivedCommand = 0; 00043 led_system_ready = 0; 00044 } 00045 00046 00047 00048 void INT_poll( void ) 00049 { 00050 switch( INT_handler.state ) 00051 { 00052 //--------------------------- 00053 case INT_STATE_INIT: 00054 //--------------------------- 00055 { 00056 led_system_ready = 0; 00057 DI_init(); 00058 MBED_init(); // PWM, CAN, RS232,... 00059 PT100_init(); 00060 DO_init(); 00061 RS485_init(); 00062 led_system_ready = 1; 00063 INT_handler.state = INT_STATE_IDLE; 00064 00065 break; 00066 } 00067 00068 00069 //--------------------------- 00070 case INT_STATE_IDLE: 00071 //--------------------------- 00072 { 00073 if( UART_newFrame() ) 00074 { 00075 INT_handler.state = INT_STATE_CHECK; 00076 } 00077 00078 break; 00079 } 00080 00081 00082 //--------------------------- 00083 case INT_STATE_CHECK: 00084 //--------------------------- 00085 { 00086 //--------------------------------- 00087 if( UART_checkReceivedCRC() ) 00088 //--------------------------------- 00089 { 00090 // backup device ID and command for acknowledge 00091 INT_handler.receivedDeviceID = uartBuffer[INT_BUF_DEVICEID]; 00092 INT_handler.receivedCommand = uartBuffer[INT_BUF_COMMAND]; 00093 INT_handler.state = INT_STATE_INTERPRET; 00094 } 00095 //------------------------ 00096 else // CRC check failed --> ignore frame 00097 //------------------------ 00098 { 00099 UART_reset(); 00100 INT_handler.state = INT_STATE_IDLE; 00101 } 00102 00103 break; 00104 } 00105 00106 00107 //--------------------------- 00108 case INT_STATE_INTERPRET: 00109 //--------------------------- 00110 { 00111 INT_selectDeviceID(); 00112 INT_handler.state = INT_STATE_ACK; 00113 break; 00114 } 00115 00116 00117 //--------------------------- 00118 case INT_STATE_ACK: 00119 //--------------------------- 00120 { 00121 // INT_selectDeviceID() has already updated UART_buffer[] --> just send 00122 UART_sendData(); 00123 INT_handler.state = INT_STATE_IDLE; 00124 break; 00125 } 00126 00127 00128 //--------------------------- 00129 default: 00130 //--------------------------- 00131 { 00132 INT_handler.state = INT_STATE_INIT; 00133 } 00134 00135 }//switch 00136 00137 } 00138 00139 00140 void INT_generateACKFrame(char deviceID, char command) 00141 { 00142 uartBuffer[INT_BUF_DEVICEID] = deviceID; 00143 uartBuffer[INT_BUF_COMMAND] = command; 00144 uartBuffer[INT_BUF_NUM] = 0; 00145 UART_handler.bytesToWrite = 3; 00146 } 00147 00148 00149 //--------------------------------------- 00150 // Local Functions 00151 //--------------------------------------- 00152 00153 00154 // Here, the DeviceID gets used to communicate with the requested HW-unit 00155 // Modify this function, if new HW-units are integreted. 00156 // The XXX_deviceID_process() function also generates the acknowledge frame and 00157 // place it in the uartBuffer[]. 00158 // The next state, INT_STATE_ACK, of the Interprete FSM is than sending these data 00159 void INT_selectDeviceID( void ) 00160 { 00161 switch( INT_handler.receivedDeviceID ) 00162 { 00163 //---------------------- 00164 case INT_ID_BROADCAST: 00165 //---------------------- 00166 { 00167 INT_deviceID_process_Broadcast(); 00168 break; 00169 } 00170 00171 00172 //---------------------- 00173 case INT_ID_MBED: 00174 //---------------------- 00175 { 00176 MBED_deviceID_process(); 00177 break; 00178 } 00179 00180 00181 //---------------------- 00182 case INT_ID_PT100: 00183 //---------------------- 00184 { 00185 PT100_deviceID_process(); 00186 break; 00187 } 00188 00189 00190 //---------------------- 00191 case INT_ID_DI: 00192 //---------------------- 00193 { 00194 DI_deviceID_process(); 00195 break; 00196 } 00197 00198 00199 //---------------------- 00200 case INT_ID_DO: 00201 //---------------------- 00202 { 00203 DO_deviceID_process(); 00204 break; 00205 } 00206 00207 00208 //---------------------- 00209 default: 00210 //---------------------- 00211 { 00212 // Device ID is not supported, send ack. 00213 INT_generateACKFrame(INT_handler.receivedDeviceID, INT_COM_DEV_NOTSUPP); 00214 } 00215 }//switch 00216 } 00217 00218 00219 00220 00221 // Interprete Command for broadcast 00222 void INT_deviceID_process_Broadcast( void ) 00223 { 00224 00225 00226 }
Generated on Sat Jul 16 2022 03:23:51 by
