Skip to content

Commit

Permalink
FW-280. Dynamic app compilation.
Browse files Browse the repository at this point in the history
  • Loading branch information
twatteyne committed Oct 6, 2014
1 parent 51c9b09 commit e13dafb
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 64 deletions.
2 changes: 2 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def validate_option(key, value, env):

def validate_apps(key, value, env):
assert key=='apps'
if not value.strip():
return
requestedApps = value.split(',')
availableApps = [f for f in os.listdir('openapps') if not os.path.isfile(os.path.join('openapps',f))]
unknownApps = list(set(requestedApps) - set(availableApps))
Expand Down
1 change: 0 additions & 1 deletion bsp/boards/python/openwsnmodule_obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ struct OpenMote {
cstorm_vars_t cstorm_vars;
cwellknown_vars_t cwellknown_vars;
tohlone_vars_t tohlone_vars;

};

#endif
118 changes: 82 additions & 36 deletions openapps/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,93 @@ import os

Import('env')

localEnv = env.Clone()
localEnv = env.Clone()

#===== retrieve the list of apps to build

# apps which should always be present
defaultApps = [
'c6t',
'cinfo',
'cleds',
'cwellknown',
'techo',
'uecho',
]

# additional apps the user wants to build
if localEnv['apps']:
userApps = localEnv['apps'].split(',')
else:
userApps = []

# union of default and additional apps (without duplicates)
apps = sorted(list(set(defaultApps+userApps)))

#===== rule to create a (temporary) openapps_dyn.c file

def dynify(env,target,source):

assert len(target)==1
assert len(source)==1

target = target[0].abspath
source = source[0].abspath

#=== create file

dynfile = '''
#include "opendefs.h"
{HEADERS_FILES}
void openapps_init(void) {{
{INIT_FUNCTIONS}
}}
'''.format(
HEADERS_FILES = '\n'.join(['#include "{0}.h"'.format(a) for a in apps]),
INIT_FUNCTIONS = '\n'.join([' {0}_init();'.format(a) for a in apps]),
)

# this is a workaround for the fact that leds_init() is called leds__init()
# which itself it due to possible confusion in the objecticication process
# between leds_init() and rleds_init()
dynfile = dynfile.replace('leds_init','leds__init')

#=== write

with open(target,'w') as f:
f.write(dynfile)

dynifyBuilder = Builder(
action = Action(dynify,'Dynifying $TARGET')
)

localEnv.Append(BUILDERS = {'Dynify' : dynifyBuilder})

dynapps = localEnv.Dynify(
target = 'openapps_dyn.c',
source = 'openapps.c'
)
localEnv.AlwaysBuild(dynapps)
localEnv.Alias('dynapps', dynapps)

#===== pick the correct source files

target = 'libopenapps'
sources_c = [
os.path.join('openapps.c'),
os.path.join('c6t', 'c6t.c'),
os.path.join('cexample', 'cexample.c'),
os.path.join('cinfo', 'cinfo.c'),
os.path.join('cleds', 'cleds.c'),
os.path.join('cstorm', 'cstorm.c'),
os.path.join('cwellknown', 'cwellknown.c'),
os.path.join('techo', 'techo.c'),
os.path.join('tohlone', 'tohlone.c'),
os.path.join('tohlone', 'tohlone_webpages.c'),
os.path.join('uecho', 'uecho.c'),
]
os.path.join('openapps_dyn.c'),
]+[os.path.join(a,a+'.c') for a in apps]
sources_h = [
os.path.join('openapps.h'),
os.path.join('c6t', 'c6t.h'),
os.path.join('cexample', 'cexample.h'),
os.path.join('cinfo', 'cinfo.h'),
os.path.join('cleds', 'cleds.h'),
os.path.join('cstorm', 'cstorm.h'),
os.path.join('cwellknown', 'cwellknown.h'),
os.path.join('techo', 'techo.h'),
os.path.join('tohlone', 'tohlone.h'),
os.path.join('tohlone', 'tohlone_webpages.h'),
os.path.join('uecho', 'uecho.h'),
]
]+[os.path.join(a,a+'.c') for a in apps]

#===== build the openapps library

if localEnv['board']=='python':

if userApps:
raise SystemError("Dynamic app creation not yet supported in simulation mode")

for s in sources_c+sources_h:
temp = localEnv.Objectify(
target = localEnv.ObjectifiedFilename(s),
Expand All @@ -53,24 +108,15 @@ else:
CPPPATH = [
# inc
os.path.join('#','inc'),
# openapps
os.path.join('#','openapps'),
os.path.join('#','openapps','c6t'),
os.path.join('#','openapps','cexample'),
os.path.join('#','openapps','cinfo'),
os.path.join('#','openapps','cleds'),
os.path.join('#','openapps','cstorm'),
os.path.join('#','openapps','cwellknown'),
os.path.join('#','openapps','techo'),
os.path.join('#','openapps','tohlone'),
os.path.join('#','openapps','uecho'),
# openstack
os.path.join('#','openstack','04-TRAN'),
os.path.join('#','openstack','cross-layers'),
os.path.join('#','openstack','02a-MAClow'),
os.path.join('#','openstack','02b-MAChigh'),
os.path.join('#','openstack','03b-IPv6'),
],
# openapps
os.path.join('#','openapps'),
]+[os.path.join('#','openapps',a) for a in apps],
)

libopenapps = localEnv.Library(
Expand Down
11 changes: 0 additions & 11 deletions openapps/openapps.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include "opendefs.h"

//=== default applications
// CoAP
#include "c6t.h"
#include "cinfo.h"
Expand All @@ -17,9 +16,6 @@
// UDP
#include "uecho.h"

//=== user applications
// MARKER_USER_APPS_INCLUDES_HERE (don't remove this line)

//=========================== variables =======================================

//=========================== prototypes ======================================
Expand All @@ -29,8 +25,6 @@
//=========================== private =========================================

void openapps_init(void) {

//=== default applications
// CoAP
c6t_init();
cinfo_init();
Expand All @@ -40,9 +34,4 @@ void openapps_init(void) {
techo_init();
// UDP
uecho_init();

//=== user applications
// These applications are added on-the-fly by the SCons build system by
// using the 'apps=udprand,ohlone' switch
// MARKER_USER_APPS_INITS_HERE (don't remove this line)
}
16 changes: 0 additions & 16 deletions openstack/04-TRAN/opentcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "scheduler.h"
#include "opentimers.h"
// applications
#include "tohlone.h"
#include "techo.h"

//=========================== variables =======================================
Expand Down Expand Up @@ -117,9 +116,6 @@ void opentcp_sendDone(OpenQueueEntry_t* msg, owerror_t error) {
openqueue_freePacketBuffer(msg);
tcp_change_state(TCP_STATE_ESTABLISHED);
switch(tcp_vars.myPort) {
case WKP_TCP_HTTP:
tohlone_connectDone(E_SUCCESS);
break;
case WKP_TCP_ECHO:
techo_connectDone(E_SUCCESS);
break;
Expand All @@ -139,9 +135,6 @@ void opentcp_sendDone(OpenQueueEntry_t* msg, owerror_t error) {
openqueue_freePacketBuffer(msg);
tcp_change_state(TCP_STATE_ESTABLISHED);
switch(tcp_vars.myPort) {
case WKP_TCP_HTTP:
tohlone_receive(tcp_vars.dataReceived);
break;
case WKP_TCP_ECHO:
techo_receive(tcp_vars.dataReceived);
break;
Expand Down Expand Up @@ -238,9 +231,6 @@ void opentcp_receive(OpenQueueEntry_t* msg) {
switch (tcp_vars.state) {
case TCP_STATE_CLOSED: //[receive] establishement
switch(msg->l4_destination_port) {
case WKP_TCP_HTTP:
shouldIlisten = tohlone_shouldIlisten();
break;
case WKP_TCP_ECHO:
shouldIlisten = techo_shouldIlisten();
break;
Expand Down Expand Up @@ -414,9 +404,6 @@ void opentcp_receive(OpenQueueEntry_t* msg) {
if (containsControlBits(msg,TCP_ACK_YES,TCP_RST_NO,TCP_SYN_NO,TCP_FIN_NO)) {
//I receive ACK, data message sent
switch(tcp_vars.myPort) {
case WKP_TCP_HTTP:
tohlone_sendDone(tcp_vars.dataToSend,E_SUCCESS);
break;
case WKP_TCP_ECHO:
techo_sendDone(tcp_vars.dataToSend,E_SUCCESS);
break;
Expand All @@ -431,9 +418,6 @@ void opentcp_receive(OpenQueueEntry_t* msg) {
} else if (containsControlBits(msg,TCP_ACK_WHATEVER,TCP_RST_NO,TCP_SYN_NO,TCP_FIN_YES)) {
//I receive FIN[+ACK], I send ACK
switch(tcp_vars.myPort) {
case WKP_TCP_HTTP:
tohlone_sendDone(tcp_vars.dataToSend,E_SUCCESS);
break;
case WKP_TCP_ECHO:
techo_sendDone(tcp_vars.dataToSend,E_SUCCESS);
break;
Expand Down

0 comments on commit e13dafb

Please sign in to comment.