66
77from SpinCompiler import SpinCompiler
88from PropCCompiler import PropCCompiler
9+ import base64
910
1011__author__ = 'Michel'
1112
@@ -110,10 +111,10 @@ def multiple_c(action):
110111
111112
112113def handle_c (action , source_files , app_filename ):
113- # format data
114+ # format to upper case to make string compares easier
114115 action = action .upper ()
115116
116- # check data
117+ # Verify that we have received a valid action (COMPILE, BIN, EEPROM)
117118 if action not in actions :
118119 failure_data = {
119120 "success" : False ,
@@ -129,6 +130,8 @@ def handle_c(action, source_files, app_filename):
129130 "message" : "missing-main-filename"
130131 }
131132 return Response (json .dumps (failure_data ), 200 , mimetype = "application/json" )
133+
134+ # Is the application file name is in the list of files
132135 if app_filename not in source_files :
133136 failure_data = {
134137 "success" : False ,
@@ -137,6 +140,24 @@ def handle_c(action, source_files, app_filename):
137140 }
138141 return Response (json .dumps (failure_data ), 400 , mimetype = "application/json" )
139142
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+
140161 # call compiler and prepare return data
141162 (success , base64binary , extension , out , err ) = compilers ["PROP-C" ].compile (action , source_files , app_filename )
142163
@@ -148,12 +169,22 @@ def handle_c(action, source_files, app_filename):
148169 "compiler-output" : out ,
149170 "compiler-error" : err
150171 }
172+
151173 if action != "COMPILE" and success :
152174 data ['binary' ] = base64binary
153175 data ['extension' ] = extension
176+
154177 return Response (json .dumps (data ), 200 , mimetype = "application/json" )
155178
156179
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+
157188# --------------------------------------- Defaults and compiler initialization --------------------------------
158189defaults = {
159190 'c-compiler' : '/opt/parallax/bin/propeller-elf-gcc' ,
@@ -196,7 +227,7 @@ def handle_c(action, source_files, app_filename):
196227
197228# ----------------------------------------------- Development server -------------------------------------------
198229if __name__ == '__main__' :
199- app .debug = True
230+ app .debug = False
200231 app .run (host = '0.0.0.0' )
201232
202233
0 commit comments