6
6
7
7
from SpinCompiler import SpinCompiler
8
8
from PropCCompiler import PropCCompiler
9
+ import base64
9
10
10
11
__author__ = 'Michel'
11
12
@@ -110,10 +111,10 @@ def multiple_c(action):
110
111
111
112
112
113
def handle_c (action , source_files , app_filename ):
113
- # format data
114
+ # format to upper case to make string compares easier
114
115
action = action .upper ()
115
116
116
- # check data
117
+ # Verify that we have received a valid action (COMPILE, BIN, EEPROM)
117
118
if action not in actions :
118
119
failure_data = {
119
120
"success" : False ,
@@ -129,6 +130,8 @@ def handle_c(action, source_files, app_filename):
129
130
"message" : "missing-main-filename"
130
131
}
131
132
return Response (json .dumps (failure_data ), 200 , mimetype = "application/json" )
133
+
134
+ # Is the application file name is in the list of files
132
135
if app_filename not in source_files :
133
136
failure_data = {
134
137
"success" : False ,
@@ -137,6 +140,24 @@ def handle_c(action, source_files, app_filename):
137
140
}
138
141
return Response (json .dumps (failure_data ), 400 , mimetype = "application/json" )
139
142
143
+ # --------------------------------------------------------------
144
+ # Custom hook to trap the S3 Scribbler demo/initialization block
145
+ # Look for a specific string in the source file (single.c)
146
+ # --------------------------------------------------------------
147
+ if '#pragma load_default_scribbler_binary' in source_files ['single.c' ]:
148
+ out = "Loading S3 Demo App..."
149
+ data = {
150
+ "success" : True ,
151
+ "compiler-output" : out ,
152
+ "compiler-error" : ''
153
+ }
154
+
155
+ if action != "COMPILE" :
156
+ data ['binary' ] = s3_load_init_binary ()
157
+ data ['extension' ] = 'elf'
158
+
159
+ return Response (json .dumps (data ), 200 , mimetype = "application/json" )
160
+
140
161
# call compiler and prepare return data
141
162
(success , base64binary , extension , out , err ) = compilers ["PROP-C" ].compile (action , source_files , app_filename )
142
163
@@ -148,12 +169,22 @@ def handle_c(action, source_files, app_filename):
148
169
"compiler-output" : out ,
149
170
"compiler-error" : err
150
171
}
172
+
151
173
if action != "COMPILE" and success :
152
174
data ['binary' ] = base64binary
153
175
data ['extension' ] = extension
176
+
154
177
return Response (json .dumps (data ), 200 , mimetype = "application/json" )
155
178
156
179
180
+ def s3_load_init_binary ():
181
+ with open ('scribbler_default.binary' , 'rb' ) as f :
182
+ encoded = base64 .b64encode (f .read ())
183
+
184
+ f .close ()
185
+ return encoded
186
+
187
+
157
188
# --------------------------------------- Defaults and compiler initialization --------------------------------
158
189
defaults = {
159
190
'c-compiler' : '/opt/parallax/bin/propeller-elf-gcc' ,
@@ -196,7 +227,7 @@ def handle_c(action, source_files, app_filename):
196
227
197
228
# ----------------------------------------------- Development server -------------------------------------------
198
229
if __name__ == '__main__' :
199
- app .debug = True
230
+ app .debug = False
200
231
app .run (host = '0.0.0.0' )
201
232
202
233
0 commit comments