CORDET Framework - C2 Implementation
CrS2Main.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 "CrS2Constants.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_S2_N_OF_FW_CMP];
119  FwSmDesc_t inStream1, outStream1;
120  CrFwConfigCheckOutcome_t configCheckOutcome;
121  int i;
122  char temp;
123 
124  /* User warning about order in which demo applications are started */
125  printf("S2: The Slave 1 Application (Server Socket) must be started before the Slave 2 Application\n");
126 
127  /* Check consistency of configuration parameters */
128  configCheckOutcome = CrFwAuxConfigCheck();
129  if (configCheckOutcome != crConsistencyCheckSuccess) {
130  if (configCheckOutcome == crOutRegistryConfigParInconsistent)
131  printf("Consistency check of OutRegistry parameters failed\n");
132  if (configCheckOutcome == crOutFactoryConfigParInconsistent)
133  printf("Consistency check of OutFactory parameters failed\n");
134  if (configCheckOutcome == crInFactoryInCmdConfigParInconsistent)
135  printf("Consistency check of InCommand parameters in InFactory failed\n");
136  if (configCheckOutcome == crInFactoryInRepConfigParInconsistent)
137  printf("Consistency check of InRepot parameters in InFactory failed\n");
138  return EXIT_SUCCESS;
139  }
140  printf("S2: Consistency check of configuration parameters ran successfully.\n");
141 
142  /* Create In- and OutStreams */
143  inStream1 = CrFwInStreamMake(0);
144  outStream1 = CrFwOutStreamMake(0);
145 
146  /* Set port number and host name */
148  CrDaClientSocketSetHost("localhost");
149 
150  /* Initialize the InStreams and OutStreams */
151  CrFwCmpInit(outStream1);
152  if (!CrFwCmpIsInInitialized(outStream1))
153  return 0;
154  CrFwCmpInit(inStream1);
155  if (!CrFwCmpIsInInitialized(inStream1))
156  return 0;
157 
158  /* Configure the InStream and OutStream */
159  CrFwCmpReset(inStream1);
160  CrFwCmpReset(outStream1);
161  if (!CrFwCmpIsInConfigured(inStream1))
162  return 0;
163  if (!CrFwCmpIsInConfigured(outStream1))
164  return 0;
165 
166  /* Initialize and reset framework components */
167  fwCmp[0] = CrFwOutFactoryMake();
168  fwCmp[1] = CrFwInFactoryMake();
169  fwCmp[2] = CrFwInLoaderMake();
170  fwCmp[3] = CrFwInManagerMake(0);
171  fwCmp[4] = CrFwInRegistryMake();
172  fwCmp[5] = CrFwOutLoaderMake();
173  fwCmp[6] = CrFwOutRegistryMake();
174  fwCmp[7] = CrFwOutManagerMake(0);
175  for (i=0; i<CR_S2_N_OF_FW_CMP; i++) {
176  CrFwCmpInit(fwCmp[i]);
177  if (!CrFwCmpIsInInitialized(fwCmp[i]))
178  return 0;
179  CrFwCmpReset(fwCmp[i]);
180  if (!CrFwCmpIsInConfigured(fwCmp[i]))
181  return 0;
182  }
183 
184  /* Execute control cycles */
185  for (i=1; i<100; i++) {
186  printf("S2: Starting cycle %d\n",i);
187  /* Set temperature value */
188  if (i%5 != 0)
189  temp = CR_S2_LOW_TEMP_VALUE;
190  else
191  temp = CR_S2_HIGH_TEMP_VALUE;
192  /* Perform temperature monitoring action */
194 
195  /* Poll socket for incoming commands */
197 
198  /* Load packets from the InStream */
199  CrFwInLoaderSetInStream(inStream1);
200  FwSmExecute(CrFwInLoaderMake());
201 
202  /* Execute Managers */
203  FwSmExecute(CrFwInManagerMake(0));
204  FwSmExecute(CrFwOutManagerMake(0));
205 
206  /* Check application errors */
207  if (CrFwGetAppErrCode() != crNoAppErr) {
208  printf("S2: Application Error Code is set and is equal to: %d\n",CrFwGetAppErrCode());
209  }
210 
211  /* Wait 1 second and then continue */
212  sleep(1);
213  }
214 
215  return EXIT_SUCCESS;
216 }
void CrDaClientSocketSetHost(char *name)
Set the host name of the server.
Interface through which framework components access the current time.
void CrFwCmpInit(FwSmDesc_t smDesc)
Initialize a framework component.
Definition: CrFwBaseCmp.c:112
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.
#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.
Interface for the server socket used in the CORDET Demo.
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
Header file to define constants and types for the Slave 2 Application of the CORDET Demo...
Interface for the client socket used in the CORDET Demo.
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
int main()
Main program for the Slave 2 Application.
Definition: CrS2Main.c:117
#define CR_S2_HIGH_TEMP_VALUE
The "high" temperature value.
Definition: CrS2Constants.h:31
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.
#define CR_S2_LOW_TEMP_VALUE
The "low" temperature value.
Definition: CrS2Constants.h:28
FwSmDesc_t CrFwOutFactoryMake()
Factory function for the singleton instance of the OutFactory.
#define CR_S2_N_OF_FW_CMP
The number of framework components.
Definition: CrS2Constants.h:25
FwSmDesc_t CrFwOutStreamMake(CrFwInstanceId_t i)
Factory function to retrieve the i-th OutStream State Machine instance.
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.
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.
Header file to define constants and types for 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