@@ -10,7 +10,7 @@ Authors : Nicolas Biri
10
10
'use strict'
11
11
12
12
// model imports
13
- const JSTL = require ( '../../index' )
13
+ const JSTL = require ( '../../src/ index' )
14
14
const Transformation = JSTL . Transformation
15
15
const NAV = require ( 'jsmf-magellan' )
16
16
const Model = require ( 'jsmf-core' ) . Model
@@ -24,99 +24,111 @@ const MMI = require('./MMArduinoML')
24
24
const MMO = require ( './MMAbstractCode' )
25
25
26
26
// input file
27
- const input = require ( './MArduinoML' ) . switchExample
27
+ const input = require ( './MArduinoML' ) . Switch
28
28
const output = new Model ( 'Out' )
29
29
30
- const transfo = new Transformation ( )
31
-
32
- transfo . addRule ( {
33
- in : x => NAV . allInstancesFromModel ( MMI . App , x ) ,
34
- out : function ( i ) {
35
- var app = MMO . App . newInstance ( )
36
- this . assign ( app , 'structural' , [ i ] )
37
- this . assign ( app , 'behavioural' , [ i ] )
38
- return [ app ]
39
- }
30
+ const arduinoToCode = new Transformation ( )
31
+
32
+ arduinoToCode . addRule ( {
33
+ name : 'Arduino App to Code App' ,
34
+ in : x => NAV . allInstancesFromModel ( MMI . App , x ) ,
35
+ out : function ( i ) {
36
+ const app = MMO . App . newInstance ( )
37
+ this . assign ( app , 'structural' , [ i ] )
38
+ this . assign ( app , 'behavioural' , [ i ] )
39
+ return [ app ]
40
+ }
40
41
} )
41
42
42
- transfo . addRule ( {
43
- in : x => NAV . allInstancesFromModel ( MMI . App , x ) ,
44
- out : function ( i ) {
45
- var s = MMO . StructuralConcerns . newInstance ( )
46
- this . assign ( s , 'alias' , i . brick )
47
- this . assign ( s , 'pinMode' , i . brick )
48
- return [ s ]
49
- }
43
+ arduinoToCode . addRule ( {
44
+ name : 'Structural concerns generation' ,
45
+ in : x => NAV . allInstancesFromModel ( MMI . App , x ) ,
46
+ out : function ( i ) {
47
+ const s = MMO . StructuralConcerns . newInstance ( )
48
+ this . assign ( s , 'alias' , i . brick )
49
+ this . assign ( s , 'pinMode' , i . brick )
50
+ return [ s ]
51
+ }
50
52
} )
51
53
52
- transfo . addRule ( {
53
- in : x => NAV . allInstancesFromModel ( MMI . Brick , x ) ,
54
- out : function ( i ) {
55
- return [ MMO . BrickAlias . newInstance ( { name : i . name , pin : i . pin } ) ]
56
- }
54
+ arduinoToCode . addRule ( {
55
+ name : 'Brick Alias generation' ,
56
+ in : x => NAV . allInstancesFromModel ( MMI . Brick , x ) ,
57
+ out : function ( i ) {
58
+ return [ MMO . BrickAlias . newInstance ( { name : i . name , pin : i . pin } ) ]
59
+ }
57
60
} )
58
61
59
- transfo . addRule ( {
60
- in : x => NAV . allInstancesFromModel ( MMI . Sensor , x ) ,
61
- out : function ( i ) {
62
- return [ MMO . PinMode . newInstance ( { name : i . name , mode : MMO . IO . INPUT } ) ]
63
- }
62
+ arduinoToCode . addRule ( {
63
+ name : 'Pin mode definition for sensors' ,
64
+ in : x => NAV . allInstancesFromModel ( MMI . Sensor , x ) ,
65
+ out : function ( i ) {
66
+ return [ MMO . PinMode . newInstance ( { name : i . name , mode : MMO . IO . INPUT } ) ]
67
+ }
64
68
} )
65
69
66
- transfo . addRule ( {
67
- in : x => NAV . allInstancesFromModel ( MMI . Actuator , x ) ,
68
- out : function ( i ) {
69
- return [ MMO . PinMode . newInstance ( { name : i . name , mode : MMO . IO . OUTPUT } ) ]
70
- }
70
+ arduinoToCode . addRule ( {
71
+ name : 'Pin mode definition for actuators' ,
72
+ in : x => NAV . allInstancesFromModel ( MMI . Actuator , x ) ,
73
+ out : function ( i ) {
74
+ return [ MMO . PinMode . newInstance ( { name : i . name , mode : MMO . IO . OUTPUT } ) ]
75
+ }
71
76
} )
72
77
73
- transfo . addRule ( {
74
- in : x => NAV . allInstancesFromModel ( MMI . App , x ) ,
75
- out : function ( i ) {
76
- var b = MMO . BehaviouralConcerns . newInstance ( )
77
- b . timeConfig = MMO . TimeConfig . newInstance ( { initialTime : 0 , debounce : 200 } )
78
- this . assign ( b , 'stateFunction' , i . state )
79
- this . assign ( b , 'mainLoop' , i . initial )
80
- return [ b ]
81
- }
78
+ arduinoToCode . addRule ( {
79
+ name : 'Behavioural concerns generation' ,
80
+ in : x => NAV . allInstancesFromModel ( MMI . App , x ) ,
81
+ out : function ( i ) {
82
+ const b = MMO . BehaviouralConcerns . newInstance ( )
83
+ b . timeConfig = MMO . TimeConfig . newInstance ( { initialTime : 0 , debounce : 200 } )
84
+ this . assign ( b , 'stateFunction' , i . state )
85
+ this . assign ( b , 'mainLoop' , i . initial )
86
+ return [ b ]
87
+ }
82
88
} )
83
89
84
- transfo . addRule ( {
85
- in : x => NAV . allInstancesFromModel ( MMI . State , x ) ,
86
- out : function ( i ) {
87
- var t = i . transition [ 0 ]
88
- var s = MMO . StateFunction . newInstance ( {
89
- name : i . name ,
90
- next : t . next [ 0 ] . name ,
91
- readOn : t . sensor [ 0 ] . name ,
92
- read : t . value
93
- } )
94
- this . assign ( s , 'write' , i . action )
95
- return [ s ]
96
- }
90
+ arduinoToCode . addRule ( {
91
+ name : 'Generate state function' ,
92
+ in : x => NAV . allInstancesFromModel ( MMI . State , x ) ,
93
+ out : function ( i ) {
94
+ const t = i . transition [ 0 ]
95
+ const s = MMO . StateFunction . newInstance ( {
96
+ name : i . name ,
97
+ next : t . next [ 0 ] . name ,
98
+ readOn : t . sensor [ 0 ] . name ,
99
+ read : t . value
100
+ } )
101
+ this . assign ( s , 'write' , i . action )
102
+ return [ s ]
103
+ }
97
104
} )
98
105
99
- transfo . addRule ( {
100
- in : x => NAV . allInstancesFromModel ( MMI . State , x ) ,
101
- out : function ( i ) {
102
- return [ MMO . MainLoop . newInstance ( { init : i . name } ) ]
103
- }
106
+ arduinoToCode . addRule ( {
107
+ name : 'Generate main loop' ,
108
+ in : x => NAV . allInstancesFromModel ( MMI . State , x ) ,
109
+ out : function ( i ) {
110
+ return [ MMO . MainLoop . newInstance ( { init : i . name } ) ]
111
+ }
104
112
} )
105
113
106
114
107
- transfo . addRule ( {
108
- in : x => NAV . allInstancesFromModel ( MMI . Action , x ) ,
109
- out : function ( i ) {
110
- return [ MMO . Write . newInstance ( {
111
- on : i . actuator [ 0 ] . name ,
112
- value : i . value
113
- } ) ]
114
- }
115
+ arduinoToCode . addRule ( {
116
+ name : 'Ganarate Writes' ,
117
+ in : x => NAV . allInstancesFromModel ( MMI . Action , x ) ,
118
+ out : function ( i ) {
119
+ return [ MMO . Write . newInstance ( {
120
+ on : i . actuator [ 0 ] . name ,
121
+ value : i . value
122
+ } ) ]
123
+ }
115
124
} )
116
125
117
126
118
127
// launch transformation
119
128
120
- const log = transfo . apply ( input , output , false )
129
+ const mapping = arduinoToCode . apply ( input , output , true )
130
+
131
+ module . exports = { arduinoToCode, mapping}
121
132
122
- _ . forEach ( NAV . allInstancesFromModel ( MMO . App , output ) , x => console . log ( x . toCode ( ) ) )
133
+ _ . forEach ( NAV . allInstancesFromModel ( MMO . App , output )
134
+ , x => console . log ( x . toCode ( ) ) )
0 commit comments