CORDET Framework - C2 Implementation
CrMaMain.c
Go to the documentation of this file.
1 
54 #include <stdio.h>
55 #include <stdlib.h>
56 #include <string.h>
57 #include <unistd.h>
58 /* Include Master Demo Files */
59 #include "CrMaConstants.h"
60 /* Include Common Demo Files */
61 #include "CrDaConstants.h"
62 #include "CrDaClientSocket.h"
63 #include "CrDaServerSocket.h"
64 /* Include FW Profile files */
65 #include "FwSmConstants.h"
66 #include "FwSmConfig.h"
67 #include "FwSmCore.h"
68 #include "FwPrConfig.h"
69 #include "FwPrCore.h"
70 #include "FwPrConstants.h"
71 /* Include framework files */
73 #include "Aux/CrFwAux.h"
74 #include "BaseCmp/CrFwBaseCmp.h"
75 #include "Pckt/CrFwPckt.h"
76 #include "OutCmp/CrFwOutCmp.h"
82 #include "InStream/CrFwInStream.h"
83 #include "CrFwTime.h"
84 #include "CrFwRepErr.h"
86 /* Include configuration files */
87 #include "CrFwOutRegistryUserPar.h"
88 #include "CrFwOutFactoryUserPar.h"
89 #include "CrFwInFactoryUserPar.h"
90 #include "CrFwCmpData.h"
91 
118 int main() {
119  FwSmDesc_t fwCmp[CR_MA_N_OF_FW_CMP];
120  FwSmDesc_t inStreamSlave1, inStreamSlave2;
121  FwSmDesc_t outStreamSlave1, outStreamSlave2;
122  CrFwConfigCheckOutcome_t configCheckOutcome;
123  FwSmDesc_t outCmd;
124  int i;
125 
126  /* User warning about order in which demo applications are started */
127  printf("MA: The Slave 1 Application (Server Socket) must be started before the Master Application\n");
128 
129  /* Check consistency of configuration parameters */
130  configCheckOutcome = CrFwAuxConfigCheck();
131  if (configCheckOutcome != crConsistencyCheckSuccess) {
132  if (configCheckOutcome == crOutRegistryConfigParInconsistent)
133  printf("Consistency check of OutRegistry parameters failed\n");
134  if (configCheckOutcome == crOutFactoryConfigParInconsistent)
135  printf("Consistency check of OutFactory parameters failed\n");
136  if (configCheckOutcome == crInFactoryInCmdConfigParInconsistent)
137  printf("Consistency check of InCommand parameters in InFactory failed\n");
138  if (configCheckOutcome == crInFactoryInRepConfigParInconsistent)
139  printf("Consistency check of InRepot parameters in InFactory failed\n");
140  return EXIT_SUCCESS;
141  }
142  printf("MA: Consistency check of configuration parameters ran successfully.\n");
143 
144  /* Create In- and OutStreams */
145  inStreamSlave1 = CrFwInStreamMake(0);
146  inStreamSlave2 = CrFwInStreamMake(1);
147  outStreamSlave1 = CrFwOutStreamMake(0);
148  outStreamSlave2 = CrFwOutStreamMake(1);
149 
150  /* Set port number and host name */
152  CrDaClientSocketSetHost("localhost");
153 
154  /* Initialize the InStreams and OutStreams */
155  CrFwCmpInit(outStreamSlave1);
156  if (!CrFwCmpIsInInitialized(outStreamSlave1))
157  return 0;
158  CrFwCmpInit(outStreamSlave2);
159  if (!CrFwCmpIsInInitialized(outStreamSlave2))
160  return 0;
161  CrFwCmpInit(inStreamSlave1);
162  if (!CrFwCmpIsInInitialized(inStreamSlave1))
163  return 0;
164  CrFwCmpInit(inStreamSlave2);
165  if (!CrFwCmpIsInInitialized(inStreamSlave2))
166  return 0;
167 
168  /* Configure the InStream and OutStream */
169  CrFwCmpReset(inStreamSlave1);
170  CrFwCmpReset(inStreamSlave2);
171  CrFwCmpReset(outStreamSlave1);
172  CrFwCmpReset(outStreamSlave2);
173  if (!CrFwCmpIsInConfigured(inStreamSlave1))
174  return 0;
175  if (!CrFwCmpIsInConfigured(inStreamSlave2))
176  return 0;
177  if (!CrFwCmpIsInConfigured(outStreamSlave1))
178  return 0;
179  if (!CrFwCmpIsInConfigured(outStreamSlave2))
180  return 0;
181 
182  /* Initialize and reset framework components */
183  fwCmp[0] = CrFwOutFactoryMake();
184  fwCmp[1] = CrFwInFactoryMake();
185  fwCmp[2] = CrFwInLoaderMake();
186  fwCmp[3] = CrFwInManagerMake(0);
187  fwCmp[4] = CrFwInManagerMake(1);
188  fwCmp[5] = CrFwInRegistryMake();
189  fwCmp[6] = CrFwOutLoaderMake();
190  fwCmp[7] = CrFwOutRegistryMake();
191  fwCmp[8] = CrFwOutManagerMake(0);
192  for (i=0; i<CR_MA_N_OF_FW_CMP; i++) {
193  CrFwCmpInit(fwCmp[i]);
194  if (!CrFwCmpIsInInitialized(fwCmp[i]))
195  return 0;
196  CrFwCmpReset(fwCmp[i]);
197  if (!CrFwCmpIsInConfigured(fwCmp[i]))
198  return 0;
199  }
200 
201  /* Execute control cycles */
202  for (i=1; i<100; i++) {
203  printf("MA: Starting cycle %d\n",i);
204  /* Set temperature limit in Slave 1 */
205  if (i == 10) {
209  CrFwOutLoaderLoad(outCmd);
210  printf("MA: Sending command to set the temperature limit in Slave 1 to %d degC\n",TEMP_LIMIT);
211  }
212  /* Set temperature limit in Slave 2 */
213  if (i == 11) {
217  CrFwOutLoaderLoad(outCmd);
218  printf("MA: Sending command to set the temperature limit in Slave 2 to %d degC\n",TEMP_LIMIT);
219  }
220  /* Enable temperature monitoring in Slave 1 in cycles which are multiples of 12 */
221  if ((i % 12) == 0) {
224  CrFwOutLoaderLoad(outCmd);
225  printf("MA: Sending command to enable temperature monitoring in Slave 1\n");
226  }
227  /* Enable temperature monitoring in Slave 2 in cycles which are multiples of 15 */
228  if ((i % 15) == 0) {
231  CrFwOutLoaderLoad(outCmd);
232  printf("MA: Sending command to enable temperature monitoring in Slave 2\n");
233  }
234  /* Disable temperature monitoring in Slave 1 in cycles which are multiples of 18 */
235  if ((i % 18) == 0) {
238  CrFwOutLoaderLoad(outCmd);
239  printf("MA: Sending command to disable temperature monitoring in Slave 1\n");
240  }
241  /* Disable temperature monitoring in Slave 2 in cycles which are multiples of 60 */
242  if ((i % 60) == 0) {
245  CrFwOutLoaderLoad(outCmd);
246  printf("MA: Sending command to disable temperature monitoring in Slave 2\n");
247  }
248  /* Poll socket for incoming reports */
250 
251  /* Load packets from the two InStreams */
252  CrFwInLoaderSetInStream(inStreamSlave1);
253  FwSmExecute(CrFwInLoaderMake());
254  CrFwInLoaderSetInStream(inStreamSlave2);
255  FwSmExecute(CrFwInLoaderMake());
256 
257  /* Execute Managers */
258  FwSmExecute(CrFwInManagerMake(1)); /* The first InManager is not used */
259  FwSmExecute(CrFwOutManagerMake(0));
260 
261  /* Check application errors */
262  if (CrFwGetAppErrCode() != crNoAppErr) {
263  printf("MA: Application Error Code is set and is equal to: %d\n",CrFwGetAppErrCode());
264  }
265 
266  /* Wait 1 second and then continue */
267  sleep(1);
268  }
269 
270  return EXIT_SUCCESS;
271 }
272 
#define CR_MA_N_OF_FW_CMP
The number of framework components.
Definition: CrMaConstants.h:25
void CrDaClientSocketSetHost(char *name)
Set the host name of the server.
#define TEMP_LIMIT
The temperature limit.
Definition: CrMaConstants.h:28
Interface for the client socket used in the CORDET Demo.
Interface through which framework components access the current time.
void CrFwCmpInit(FwSmDesc_t smDesc)
Initialize a framework component.
Definition: CrFwBaseCmp.c:112
#define CR_DA_SERV_SUBTYPE_SET
The identifier of the service sub-type to set the temperature limit.
int main()
Main program for the Master Application.
Definition: CrMaMain.c:118
CrFwBool_t CrFwCmpIsInConfigured(FwSmDesc_t smDesc)
Return true if the argument component is in state CONFIGURED.
Definition: CrFwBaseCmp.c:177
Header file to define constants and types for the CORDET Demo.
InFactory configuration parameters for InCommands are inconsistent (see CrFwAuxInFactoryInCmdConfigCh...
Definition: CrFwAux.h:51
#define CR_DA_SOCKET_PORT
The port number for the socket port.
Auxiliary module to check the static part of an application&#39;s configuration.
Definition of the OutStream component.
Definition of the OutFactory component.
#define CR_DA_SERV_TYPE
The identifier of the service type supported by the demo application.
FwSmDesc_t CrFwOutManagerMake(CrFwInstanceId_t i)
Factory function to retrieve the i-th OutManager State Machine instance.
Interface for creating and accessing a report or command packet.
Definition of the InStream component.
#define CR_DA_SERV_SUBTYPE_DIS
The identifier of the service sub-type to disable temperature monitoring.
#define CR_DA_SLAVE_2
The identifier of the first Slave Application of the CORDET Demo.
Definition of the OutRegistry Component.
Definition of the InRegistry Component.
CrFwBool_t CrFwCmpIsInInitialized(FwSmDesc_t smDesc)
Return true if the argument component is in state INITIALIZED.
Definition: CrFwBaseCmp.c:172
CrFwConfigCheckOutcome_t CrFwAuxConfigCheck()
Check the configuration of an application.
Definition: CrFwAux.c:55
Interface for reporting an error detected by a framework component.
FwSmDesc_t CrFwInRegistryMake()
Factory function for the singleton instance of the InRegistry.
CrFwConfigCheckOutcome_t
Type for the outcome of the consistency check on the configuration parameters.
Definition: CrFwAux.h:43
#define CR_DA_SERV_SUBTYPE_EN
The identifier of the service sub-type to enable temperature monitoring.
OutFactory configuration parameters are inconsistent (see CrFwAuxOutFactoryConfigCheck.h)
Definition: CrFwAux.h:49
All configuration consistency checks have been passed.
Definition: CrFwAux.h:45
FwSmDesc_t CrFwInLoaderMake()
Factory function to retrieve the state machine implementing the InLoader singleton component...
Definition: CrFwInLoader.c:86
FwSmDesc_t CrFwOutLoaderMake()
Factory function to retrieve the OutLoader State Machine instance.
Definition: CrFwOutLoader.c:75
FwSmDesc_t CrFwInManagerMake(CrFwInstanceId_t i)
Factory function to retrieve the i-th InManager State Machine instance.
Definition: CrFwInManager.c:96
Definition of the InFactory component.
InFactory configuration parameters for InReports are inconsistent (see CrFwAuxInFactoryInRepConfigChe...
Definition: CrFwAux.h:53
Definition of the utility functions for the CORDET Framework.
FwSmDesc_t CrFwOutRegistryMake()
Factory function for the singleton instance of the OutRegistry.
void CrFwCmpReset(FwSmDesc_t smDesc)
Reset a framework component.
Definition: CrFwBaseCmp.c:117
#define CR_DA_SLAVE_1
The identifier of the first Slave Application of the CORDET Demo.
void CrMaOutCmpSetTempLimitSetTempLimit(char tempLimit)
Set the value of the temperature limit (an integer in the range 0 to 127).
Interface for the server socket used in the CORDET Demo.
Definition of Base Component.
FwSmDesc_t CrFwInFactoryMake()
Factory function for the singleton instance of the InFactory.
void CrFwInLoaderSetInStream(FwSmDesc_t inStream)
Set the InStream from which the packets will be retrieved the next time the InLoader is executed...
Definition: CrFwInLoader.c:128
Definition of the OutComponent Component of the framework.
FwSmDesc_t CrFwOutFactoryMake()
Factory function for the singleton instance of the OutFactory.
FwSmDesc_t CrFwOutStreamMake(CrFwInstanceId_t i)
Factory function to retrieve the i-th OutStream State Machine instance.
void CrFwOutCmpSetDest(FwSmDesc_t smDesc, CrFwDestSrc_t dest)
Set the destination of the OutComponent.
Definition: CrFwOutCmp.c:192
FwSmDesc_t CrFwInStreamMake(CrFwInstanceId_t i)
Factory function to retrieve the i-th InStream State Machine instance.
Definition: CrFwInStream.c:121
CrFwBool_t CrFwOutLoaderLoad(FwSmDesc_t outCmp)
Load an OutComponent into its OutManager.
No application errors have been detected.
void CrDaClientSocketPoll()
Poll the client socket to check whether a new packet has arrived.
void CrDaClientSocketSetPort(int n)
Set the port number for the socket.
Definition of the OutLoader component.
FwSmDesc_t CrFwOutFactoryMakeOutCmp(CrFwServType_t type, CrFwServSubType_t subType, CrFwDiscriminant_t discriminant, CrFwPcktLength_t length)
Make function for an OutComponent.
Header file to define constants and types for the Master Application of the CORDET Demo...
CrFwAppErrCode_t CrFwGetAppErrCode()
Return the value of the application error code.
OutRegistry configuration parameters are inconsistent (see CrFwAuxOutRegistryConfigCheck.h)
Definition: CrFwAux.h:47
P&P Software GmbH, Copyright 2012-2013, All Rights Reserved