66
77from SpinCompiler import SpinCompiler
88from PropCCompiler import PropCCompiler
9+ import base64
910
1011__author__ = 'Michel'
1112
13+ version = "1.0.0"
1214app = Flask (__name__ )
1315
1416
@@ -110,10 +112,10 @@ def multiple_c(action):
110112
111113
112114def handle_c (action , source_files , app_filename ):
113- # format data
115+ # format to upper case to make string compares easier
114116 action = action .upper ()
115117
116- # check data
118+ # Verify that we have received a valid action (COMPILE, BIN, EEPROM)
117119 if action not in actions :
118120 failure_data = {
119121 "success" : False ,
@@ -129,6 +131,8 @@ def handle_c(action, source_files, app_filename):
129131 "message" : "missing-main-filename"
130132 }
131133 return Response (json .dumps (failure_data ), 200 , mimetype = "application/json" )
134+
135+ # Is the application file name is in the list of files
132136 if app_filename not in source_files :
133137 failure_data = {
134138 "success" : False ,
@@ -137,6 +141,24 @@ def handle_c(action, source_files, app_filename):
137141 }
138142 return Response (json .dumps (failure_data ), 400 , mimetype = "application/json" )
139143
144+ # --------------------------------------------------------------
145+ # Custom hook to trap the S3 Scribbler demo/initialization block
146+ # Look for a specific string in the source file (single.c)
147+ # --------------------------------------------------------------
148+ if '#pragma load_default_scribbler_binary' in source_files ['single.c' ]:
149+ out = "Loading S3 Demo App..."
150+ data = {
151+ "success" : True ,
152+ "compiler-output" : out ,
153+ "compiler-error" : ''
154+ }
155+
156+ if action != "COMPILE" :
157+ data ['binary' ] = s3_load_init_binary ()
158+ data ['extension' ] = 'elf'
159+
160+ return Response (json .dumps (data ), 200 , mimetype = "application/json" )
161+
140162 # call compiler and prepare return data
141163 (success , base64binary , extension , out , err ) = compilers ["PROP-C" ].compile (action , source_files , app_filename )
142164
@@ -148,12 +170,22 @@ def handle_c(action, source_files, app_filename):
148170 "compiler-output" : out ,
149171 "compiler-error" : err
150172 }
173+
151174 if action != "COMPILE" and success :
152175 data ['binary' ] = base64binary
153176 data ['extension' ] = extension
177+
154178 return Response (json .dumps (data ), 200 , mimetype = "application/json" )
155179
156180
181+ def s3_load_init_binary ():
182+ with open ('scribbler_default.binary' , 'rb' ) as f :
183+ encoded = base64 .b64encode (f .read ())
184+
185+ f .close ()
186+ return encoded
187+
188+
157189# --------------------------------------- Defaults and compiler initialization --------------------------------
158190defaults = {
159191 'c-compiler' : '/opt/parallax/bin/propeller-elf-gcc' ,
@@ -163,6 +195,7 @@ def handle_c(action, source_files, app_filename):
163195}
164196
165197configfile = expanduser ("~/cloudcompiler.properties" )
198+
166199if isfile (configfile ):
167200 configs = ConfigParser (defaults )
168201 configs .readfp (FakeSecHead (open (configfile )))
@@ -196,7 +229,7 @@ def handle_c(action, source_files, app_filename):
196229
197230# ----------------------------------------------- Development server -------------------------------------------
198231if __name__ == '__main__' :
199- app .debug = True
232+ app .debug = False
200233 app .run (host = '0.0.0.0' )
201234
202235
0 commit comments