Commit 0da7fda3 authored by yoogx's avatar yoogx

* Added minepump variant using the BA

        For openaadl/ocarina#190
parent 8c22a624
......@@ -98,6 +98,7 @@ AC_OUTPUT([
examples/line_follower/Makefile
examples/memory/Makefile
examples/minepump/Makefile
examples/minepump_ba/Makefile
examples/mixin/Makefile
examples/mjpeg/Makefile
examples/mosart/Makefile
......
......@@ -5,7 +5,7 @@ SUBDIRS= adiru ahrs_discovery aocs aram ardupilot arinc653_annex asl \
rap rap_code redundancy rma robot round_robin time_triggered \
units uxv voter satellite stm32discovery_ada robot_ba \
pacemaker doors rosace mjpeg crazyflie air minepump \
producer_consumer_ba
producer_consumer_ba minepump_ba
EXTRA_DIST=$(srcdir)/Makefile.common
......
AADL_SOURCES = $(srcdir)/minepump_ba.aadl
AADL_ROOT = minepump.impl
OTHER_FILES = $(srcdir)/simu.c $(srcdir)/simu.h
CLEANDIRS = minepump_impl
CLEANFILES = *.lnt demo.svl
include $(srcdir)/../Makefile.common
AVAILABLE_TARGETS= parse-aadl c
package MinePump
public
with Data_Model; -- For data representation (integer, ...)
with Deployment; -- For execution platform
-- Basic integer data type
data Int
-- Definition of an integer type
properties
Data_Model::Data_Representation => Integer;
end Int;
-- ReadHLS Subprogram
subprogram ReadHLS
features
HLS : out parameter Int;
properties
Source_Language => (C);
Source_Name => "readhls";
Source_Text => ("simu.c");
end ReadHLS;
-- ReadLLS Subprogram
subprogram ReadLLS
features
LLS : out parameter Int;
properties
Source_Language => (C);
Source_Name => "readlls";
Source_Text => ("simu.c");
end ReadLLS;
-- ReadMS Subprogram
subprogram ReadMS
features
MS : out parameter Int;
properties
Source_Language => (C);
Source_Name => "readms";
Source_Text => ("simu.c");
end ReadMS;
-- CmdPump Subprogram
subprogram CmdPump
features
cmd : in parameter Int;
properties
Source_Language => (C);
Source_Name => "cmdpump";
Source_Text => ("simu.c");
end CmdPump;
-- CmdAlarm Subprogram
subprogram CmdAlarm
features
cmd : in parameter Int;
properties
Source_Language => (C);
Source_Name => "cmdalarm";
Source_Text => ("simu.c");
end CmdAlarm;
-- WaterLevelMonitorig task
thread WaterLevelMonitoring
features
WaterAlarm : out data port Int;
properties
Dispatch_Protocol => Periodic; -- Concurrency configuration
Period => 250 ms;
Compute_Execution_Time => 1 ms .. 2 ms;
Priority => 2;
annex behavior_specification {**
variables
HLS, LLS : Int;
waterlvl : Int;
states
s : initial complete final state;
transitions
s -[on dispatch]-> s
{
ReadHLS!(HLS);
if (HLS = 1)
waterlvl := 1
else
ReadLLS!(LLS);
if (LLs = 0)
waterlvl := 0
end if
end if;
WaterAlarm!(waterlvl)
};
**};
end WaterLevelMonitoring;
-- MethaneMonitoring task
thread MethaneMonitoring
features
MethaneLevel : out data port int;
properties
Dispatch_Protocol => Periodic; -- Concurrency configuration
Period => 100 ms;
Compute_Execution_Time => 1 ms .. 2 ms;
Priority => 2;
annex behavior_specification {**
variables
MS : Int;
level : Int;
states
s : initial complete final state;
transitions
s -[on dispatch]-> s
{
ReadMS!(MS);
if (MS > 100)
level := 2
elsif (MS > 70)
level := 1
else
level := 0
end if;
MethaneLevel!(level)
};
**};
end MethaneMonitoring;
thread PumpCtrl
features
MethaneLevel : in event data port Int;
WaterLevel : in event data port Int;
WaterAlarm : out data port Int;
properties
Dispatch_Protocol => Sporadic; -- Concurrency configuration
Period => 100 ms;
Compute_Execution_Time => 1 ms .. 2 ms;
Priority => 2;
annex behavior_specification {**
variables
niveau_eau, niveau_alarme, alarme : Int;
cmd : Int;
states
s : initial complete final state;
transitions
s -[on dispatch MethaneLevel and WaterLevel]-> s
{
cmd := 0;
niveau_alarme := MethaneLevel;
if (niveau_alarme = 0)
alarme := 0
else
alarme := 1
end if;
WaterAlarm!(alarme);
if (niveau_alarme = 2)
cmd := 0
else
niveau_eau := WaterLevel;
if (niveau_eau = 1)
cmd := 1
elsif (niveau_eau = 0)
cmd := 0
end if
end if;
cmdpump!(cmd)
};
**};
end PumpCtrl;
thread WaterAlarm
features
WaterAlarm : in event data port Int;
properties
Dispatch_Protocol => Sporadic; -- Concurrency configuration
Period => 100 ms;
Compute_Execution_Time => 1 ms .. 2 ms;
Priority => 2;
annex behavior_specification {**
variables
value : Int;
states
s : initial complete final state;
transitions
s -[on dispatch WaterAlarm]-> s
{
value := WaterAlarm;
CmdAlarm!(value)
};
**};
end WaterAlarm;
-- MinePump software process
process MinePump_Software
end MinePump_Software;
process implementation MinePump_Software.impl
subcomponents
WaterLevelMonitoring_Thread : thread WaterLevelMonitoring;
MethaneMonitoring_Thread : thread MethaneMonitoring;
PumpCtrl_Thread : thread PumpCtrl;
WaterAlarm_Thread : thread WaterAlarm;
connections
C1 : port MethaneMonitoring_Thread.MethaneLevel
-> PumpCtrl_Thread.MethaneLevel;
C2 : port WaterLevelMonitoring_Thread.WaterAlarm
-> PumpCtrl_Thread.WaterLevel;
C3 : port PumpCtrl_Thread.WaterAlarm
-> WaterAlarm_Thread.WaterAlarm;
end MinePump_Software.impl;
processor CPU
properties
Scheduling_Protocol => (POSIX_1003_HIGHEST_PRIORITY_FIRST_PROTOCOL);
Deployment::Execution_Platform => Native;
end CPU;
system MinePump
end MinePump;
system implementation MinePump.impl
subcomponents
Software : process MinePump_Software.impl;
Hardware : processor CPU;
properties
Actual_Processor_Binding => (reference (Hardware)) applies to Software;
end MinePump.impl;
end MinePump;
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#ifdef __SIMU_SOCKET__
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#endif /* __SIMU_SOCKET__ */
#include "simu.h"
#ifdef __SIMU_SOCKET__
FILE * sockin;
#endif /* __SIMU_SOCKET__ */
FILE * sockout;
pthread_mutex_t mutex_simu_minepump;
int CmdPump_Value = 0; /* c = 0, pump is off, c = 1, pump is on */
int WaterLevel_Value = 50;
/*****************************************************************************/
void InitSimu(void) {
if (sockout != NULL)
return;
#ifdef __SIMU_SOCKET__
int sock;
struct sockaddr_in address;
if ((sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP)) < 0)
perror("Can't open socket");
address.sin_family = AF_INET; /* Internet address family */
address.sin_addr.s_addr=inet_addr("127.0.0.1"); /* Server IP address */
address.sin_port =htons(4242); /* Server port */
if (connect(sock, (struct sockaddr*)&address,sizeof(address)) < 0)
perror("Je ne peux me connecter au simulateur. Assurez-vous que minepump.tcl s'execute");
sockin=fdopen(sock,"r");
sockout=fdopen(sock,"w");
#else
sockout=stdout;
#endif /* __SIMU_SOCKET__ */
pthread_mutex_init(&mutex_simu_minepump,0);
}
/*****************************************************************************/
readhls (int *hls) {
InitSimu();
int b;
pthread_mutex_lock (&mutex_simu_minepump);
#ifdef __SIMU_SOCKET__
fprintf(sockout,"HLS\n");
fflush(sockout);
b=fgetc(sockin);
#else
WaterLevel_Value = WaterLevel_Value - CmdPump_Value*4 + 2;
b = (WaterLevel_Value > 100)?1:0;
#endif /* __SIMU_SOCKET__ */
pthread_mutex_unlock (&mutex_simu_minepump);
*hls = b;
}
/*****************************************************************************/
readlls(int *lls) {
InitSimu ();
int b;
pthread_mutex_lock (&mutex_simu_minepump);
#ifdef __SIMU_SOCKET__
fprintf(sockout,"LLS\n");
fflush(sockout);
b=fgetc(sockin);
#else
b = (WaterLevel_Value > 80)?1:0;
#endif /* __SIMU_SOCKET__ */
pthread_mutex_unlock (&mutex_simu_minepump);
*lls = b;
}
/*****************************************************************************/
readms(int *ms) {
InitSimu ();
static int b = 50;
pthread_mutex_lock (&mutex_simu_minepump);
#ifdef __SIMU_SOCKET__
fprintf(sockout,"MS\n");
fflush(sockout);
b=fgetc(sockin);
#else
/* If there is no GUI, we simply emulate the methane sensor. The methane
gets up and down */
static int b_increment = 2;
b += b_increment;
if (b == 100 || b == 40)
b_increment = - b_increment;
#endif /* __SIMU_SOCKET__ */
pthread_mutex_unlock (&mutex_simu_minepump);
*ms = b;
}
/*****************************************************************************/
void cmdpump(int cmd) {
InitSimu ();
pthread_mutex_lock (&mutex_simu_minepump);
CmdPump_Value = cmd ? 1 : 0;
#ifndef __SIMU_SOCKET__
fprintf(sockout,"WL = %3d\t", WaterLevel_Value);
#endif /* __SIMU_SOCKET__ */
fprintf(sockout,"Pump %d\n",CmdPump_Value);
fflush(sockout);
pthread_mutex_unlock (&mutex_simu_minepump);
}
/*****************************************************************************/
void cmdalarm(int cmd) {
InitSimu ();
int c=cmd?1:0; /* c = 0, alarm is off, c = 1, alarm is on */
pthread_mutex_lock (&mutex_simu_minepump);
fprintf(sockout,"Alarm %d\t",c);
fflush(sockout);
pthread_mutex_unlock (&mutex_simu_minepump);
}
/**
* simu.h: simulator for the mine pump
*/
#ifndef _SIMU_H_
#define _SIMU_H_
#ifndef BYTE
#define BYTE unsigned char
#endif
void InitSimu(void);
/* Initialize simulator, should be called before any other function
* from this unit
*/
readhls (int *hls); /* Set hls status from HLS sensor */
readlls (int *lls); /* Set lls status from LLS sensor */
readms (int *ms); /* Set ms status from MS sensor */
void cmdpump (int cmd); /* Command pump, 1 = on, 0 = off */
void cmdalarm(int cmd); /* Command alarm, 1 = on, 0 = off */
//BYTE ReadHLS(void); /* Return status byte from HLS sensor */
//BYTE ReadLLS(void); /* Return status byte from LLS sensor */
//BYTE ReadMS(void); /* Return status byte from MS sensor */
//void CmdPump(BYTE cmd); /* Command pump, 1 = on, 0 = off */
//void CmdAlarm(BYTE cmd); /* Command alarm, 1 = on, 0 = off */
#endif /* _SIMU_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment