CORDET Framework - C2 Implementation
CrS1Main.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 "CrS1Constants.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 
117 int main() {
118  FwSmDesc_t fwCmp[CR_S1_N_OF_FW_CMP];
119  FwSmDesc_t inStream1, inStream2, outStream1, outStream2;
120  CrFwConfigCheckOutcome_t configCheckOutcome;
121  int i;
122  char temp;
123 
124  /* Check consistency of configuration parameters */
125  configCheckOutcome = CrFwAuxConfigCheck();
126  if (configCheckOutcome != crConsistencyCheckSuccess) {
127  if (configCheckOutcome == crOutRegistryConfigParInconsistent)
128  printf("Consistency check of OutRegistry parameters failed\n");
129  if (configCheckOutcome == crOutFactoryConfigParInconsistent)
130  printf("Consistency check of OutFactory parameters failed\n");
131  if (configCheckOutcome == crInFactoryInCmdConfigParInconsistent)
132  printf("Consistency check of InCommand parameters in InFactory failed\n");
133  if (configCheckOutcome == crInFactoryInRepConfigParInconsistent)
134  printf("Consistency check of InRepot parameters in InFactory failed\n");
135  return EXIT_SUCCESS;
136  }
137  printf("S1: Consistency check of configuration parameters ran successfully.\n");
138 
139  /* Create In- and OutStreams */
140  inStream1 = CrFwInStreamMake(0);
141  inStream2 = CrFwInStreamMake(1);
142  outStream1 = CrFwOutStreamMake(0);
143  outStream2 = CrFwOutStreamMake(1);
144 
145  /* Set port number */
147 
148  /* Initialize the InStreams and OutStreams */
149  CrFwCmpInit(outStream1);
150  if (!CrFwCmpIsInInitialized(outStream1))
151  return 0;
152  CrFwCmpInit(outStream2);
153  if (!CrFwCmpIsInInitialized(outStream2))
154  return 0;
155  CrFwCmpInit(inStream1);
156  if (!CrFwCmpIsInInitialized(inStream1))
157  return 0;
158  CrFwCmpInit(inStream2);
159  if (!CrFwCmpIsInInitialized(inStream2))
160  return 0;
161 
162  printf("S1: Wait 5 seconds (to give time to the client sockets applications to start) and then continue\n");
163  sleep(5);
164 
165  /* Configure the InStream and OutStream */
166  CrFwCmpReset(inStream1);
167  CrFwCmpReset(inStream2);
168  CrFwCmpReset(outStream1);
169  CrFwCmpReset(outStream2);
170  if (!CrFwCmpIsInConfigured(inStream1))
171  return 0;
172  if (!CrFwCmpIsInConfigured(inStream2))
173  return 0;
174  if (!CrFwCmpIsInConfigured(outStream1))
175  return 0;
176  if (!CrFwCmpIsInConfigured(outStream2))
177  return 0;
178 
179  /* Initialize and reset framework components */
180  fwCmp[0] = CrFwOutFactoryMake();
181  fwCmp[1] = CrFwInFactoryMake();
182  fwCmp[2] = CrFwInLoaderMake();
183  fwCmp[3] = CrFwInManagerMake(0);
184  fwCmp[4] = CrFwInRegistryMake();
185  fwCmp[5] = CrFwOutLoaderMake();
186  fwCmp[6] = CrFwOutRegistryMake();
187  fwCmp[7] = CrFwOutManagerMake(0);
188  for (i=0; i<CR_S1_N_OF_FW_CMP; i++) {
189  CrFwCmpInit(fwCmp[i]);
190  if (!CrFwCmpIsInInitialized(fwCmp[i]))
191  return 0;
192  CrFwCmpReset(fwCmp[i]);
193  if (!CrFwCmpIsInConfigured(fwCmp[i]))
194  return 0;
195  }
196 
197  /* Execute control cycles */
198  for (i=1; i<100; i++) {
199  printf("S1: Starting cycle %d\n",i);
200  /* Set temperature value */
201  if (i%10 != 0)
202  temp = CR_S1_LOW_TEMP_VALUE;
203  else
204  temp = CR_S1_HIGH_TEMP_VALUE;
205  /* Perform temperature monitoring action */
207 
208  /* Poll socket for incoming reports */
210 
211  /* Load packets from the two InStreams */
212  CrFwInLoaderSetInStream(inStream1);
213  FwSmExecute(CrFwInLoaderMake());
214  CrFwInLoaderSetInStream(inStream2);
215  FwSmExecute(CrFwInLoaderMake());
216 
217  /* Execute Managers */
218  FwSmExecute(CrFwInManagerMake(0));
219  FwSmExecute(CrFwOutManagerMake(0));
220 
221  /* Check application errors */
222  if (CrFwGetAppErrCode() != crNoAppErr) {
223  printf("S1: Application Error Code is set and is equal to: %d\n",CrFwGetAppErrCode());
224  }
225 
226  /* Wait 1 second and then continue */
227  sleep(1);
228  }
229 
230  return EXIT_SUCCESS;
231 }
#define CR_S1_HIGH_TEMP_VALUE
The "high" temperature value.
Definition: CrS1Constants.h:31
Interface through which framework components access the current time.
Interface for the client socket used in the CORDET Demo.
void CrFwCmpInit(FwSmDesc_t smDesc)
Initialize a framework component.
Definition: CrFwBaseCmp.c:112
void CrDaServerSocketSetPort(int n)
Set the port number for the socket.
CrFwBool_t CrFwCmpIsInConfigured(FwSmDesc_t smDesc)
Return true if the argument component is in state CONFIGURED.
Definition: CrFwBaseCmp.c:177
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.
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.
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
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.
int main()
Main program for the Slave 1 Application.
Definition: CrS1Main.c:117
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_S1_LOW_TEMP_VALUE
The "low" temperature value.
Definition: CrS1Constants.h:28
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.
Interface for the server socket used in the CORDET Demo.
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.
Header file to define constants and types for the CORDET Demo.
FwSmDesc_t CrFwInStreamMake(CrFwInstanceId_t i)
Factory function to retrieve the i-th InStream State Machine instance.
Definition: CrFwInStream.c:121
void CrDaTempMonitoringExec(char temp, CrFwDestSrc_t appId)
Execute a temperature monitoring action on the argument temperature.
#define CR_FW_HOST_APP_ID
The identifier of the Master Application of the CORDET Demo.
void CrDaServerSocketPoll()
Poll the server socket to check whether a new packet has arrived from either client.
No application errors have been detected.
#define CR_S1_N_OF_FW_CMP
The number of framework components.
Definition: CrS1Constants.h:25
Definition of the OutLoader component.
Header file to define constants and types for the Slave 1 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