]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/commitdiff
nc - preparations for raw LwIP api version
authorJan Dolezal <pm.jenik@gmail.com>
Fri, 16 Aug 2013 12:09:29 +0000 (14:09 +0200)
committerJan Dolezal <pm.jenik@gmail.com>
Fri, 16 Aug 2013 12:09:29 +0000 (14:09 +0200)
commands/cmd_lwip.c
rpp-lib

index 6f6f8ba0e87fd76a6f55717d1703709047e7fb4e..fef57e03366bd908790ce1a5b324f52e392a817f 100644 (file)
@@ -70,22 +70,8 @@ int cmd_do_read_ip(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
     return SUCCESS;
 }
 
-/* argument storing parameters from command line, if started as thread, they are coppied to stack of thread and cmd_do_init_nc() is acknowledged by semaphore */
-struct nc_arg{
-       uint16_t portNO, srcPortNO;
-       ip_addr_t remoteIP;
-#if !NO_SYS
-       xSemaphoreHandle args_coppied;
-       boolean_t thread; /* variable controling whether this instance should run as thread */
-#endif
-       boolean_t udp, listen, netLoop, test, srcPortSpec;
-       err_t err;
-};
 
 #define BUF_SIZE 80
-uint8_t tasks_running = 0, taskNameNum = 0;
-boolean_t closeths; /* variable controling threads closing */
-
 /* only for use in interactive mode (not thread) */
 char in_buffer[BUF_SIZE];
 uint8_t buff_index = 0;
@@ -96,6 +82,21 @@ uint8_t buff_index = 0;
  * there next port NO prepared to be used */
 uint16_t srcPort = 1025; /* initial value */
 
+#if !NO_SYS
+uint8_t tasks_running = 0, taskNameNum = 0;
+boolean_t closeths; /* variable controling threads closing */
+
+/* argument storing parameters from command line, if started as thread, they are coppied to stack of thread and cmd_do_init_nc() is acknowledged by semaphore */
+struct nc_arg{
+       uint16_t portNO, srcPortNO;
+       ip_addr_t remoteIP;
+       xSemaphoreHandle args_coppied;
+       boolean_t thread; /* variable controling whether this instance should run as thread */
+       boolean_t udp, listen, netLoop, test, srcPortSpec;
+       err_t err;
+};
+
+
 /* nc task */
 void run_nc(void *arg){
     err_t err = ERR_OK;
@@ -116,9 +117,7 @@ void run_nc(void *arg){
        uint16_t portNO = nc_arg->portNO, srcPortNO = nc_arg->srcPortNO;
        ip_addr_t remoteIP = nc_arg->remoteIP;
        boolean_t udp = nc_arg->udp, listen = nc_arg->listen, srcPortSpec = nc_arg->srcPortSpec, netLoop = nc_arg->netLoop, test = nc_arg->test;
-#if !NO_SYS
        boolean_t thread = nc_arg->thread; /* variable controling whether this instance should run as thread */
-#endif
        uint8_t thread_inst = tasks_running++;
 
 
@@ -128,10 +127,8 @@ void run_nc(void *arg){
 
     /*** make connection ***/
        while(!closeths){ /* shouldn't get here twice, used only for break which leads us to unalocating of sources */
-#if !NO_SYS
                /* let nc initiator go */
                if(thread && /* just in case --> */ nc_arg->args_coppied != NULL && xSemaphoreGive(nc_arg->args_coppied) != pdTRUE)break;
-#endif
            /* fill netconn struct */
                netconn = netconn_new(udp?NETCONN_UDP:NETCONN_TCP);
                if(netconn == NULL){
@@ -156,11 +153,7 @@ void run_nc(void *arg){
                                /* make listening netconn */
                                netconn_listen(netconn);
                                /* accept connection to newconn */
-#if !NO_SYS
                                while( tries-- && (err = netconn_accept(netconn, &newconn)) == ERR_TIMEOUT && (thread || rpp_sci_read_nb(1, &input) != SUCCESS));
-#else
-                               while( tries-- && (err = netconn_accept(netconn, &newconn)) == ERR_TIMEOUT && rpp_sci_read_nb(1, &input) != SUCCESS);
-#endif
                                if(err != ERR_OK)
                                {
                                        newconn = netconn;
@@ -176,19 +169,12 @@ void run_nc(void *arg){
                        {
                                while(tries-- && !closeths)
                                {
-#if !NO_SYS         /* allow user to interrupt waiting for "udp connection" - in case this is not thread */
+                    /* allow user to interrupt waiting for "udp connection" - in case this is not thread */
                                        if(!thread && (rpp_sci_read_nb(1, &input) == SUCCESS)){
-#else
-                                       if(rpp_sci_read_nb(1,&input) == SUCCESS){
-#endif
                                                newconn = netconn; /* deleting newconn is done anyway, so delete netconn this way */
                                        err = ERR_CONNECTING;
                                        break;
-#if !NO_SYS /* just for eclipse handling brackets right way */
-                                       }
-#else
                                        }
-#endif
 
                                        if((err = netconn_recv(netconn, &remoteData)) == ERR_OK) /* wait for data, from which we will determine our peer address and portNO */
                                        {
@@ -244,11 +230,8 @@ void run_nc(void *arg){
                        char strbuf[10];
                        int strlen;
                        while(!closeths && index++ < 500000){
-#if !NO_SYS     /* allow user to interrupt sending */
+                /* allow user to interrupt sending */
                                if(!thread && (rpp_sci_read_nb(1, &input) == SUCCESS))break;
-#else
-                               if(rpp_sci_read_nb(1,&input) == SUCCESS)break;
-#endif
                        strlen = sprintf(strbuf,"%d\r\n",index);
                        if(!udp)
                        {
@@ -291,13 +274,8 @@ void run_nc(void *arg){
                        break;
                        }
                        }
-                       /* TODO: user interrupt only when not thread */
                        while(!closeths){ /* allow user to interrupt operation */
-#if !NO_SYS
                                if(!thread && (rpp_sci_read_nb(1, &input) == SUCCESS))break;
-#else
-                               if(rpp_sci_read_nb(1,&input) == SUCCESS)break;
-#endif
                                if( remoteData != NULL ||  (err = netconn_recv ( newconn, &remoteData )) != ERR_TIMEOUT )
                                {
                                        if(err == ERR_OK){
@@ -339,9 +317,9 @@ void run_nc(void *arg){
                }
 
                /* only active user can control this section XXX: maybe should move to init startup condition handler */
-#if !NO_SYS
                if(thread)break;
-#endif
+
+               /* INTERACTIVE PART */
 
            /* receive remote data and print them to sci, receive sci data and write them to netconn */
                while(!ncStop)
@@ -442,45 +420,32 @@ void run_nc(void *arg){
                break;
     }
 #ifdef DEBUG
-#if !NO_SYS
        if(thread)rpp_sci_printf((const char *) "NC: THREAD NO.%d FINISHED\r\n", thread_inst);
-#endif
 #endif
        if(udp && localData != NULL)netbuf_delete(localData);
        if(remoteData != NULL)netbuf_delete(remoteData);
        if(!udp)netconn_close(newconn);
        netconn_delete(newconn);
        tasks_running--;
-#if !NO_SYS
        if(!thread)
-#endif
                nc_arg->err = err; /* only user controlled task is in front */
-#if !NO_SYS
        if(thread)vTaskDelete(NULL);
-#endif
 }
+#endif /* !NO_SYS */
 
 int cmd_do_init_nc(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
-       struct nc_arg nc_arg; /* create space for handing args to nc_run() */
     err_t err = ERR_OK;
-    boolean_t help = FALSE;
+       uint16_t portNO, srcPortNO = 0;
+       ip_addr_t remoteIP;
+       boolean_t help = FALSE, udp = FALSE, listen = FALSE, netLoop = FALSE, test = FALSE, srcPortSpec = FALSE;
     uint8_t pindex;
     uint8_t name[5] = "nc";
     name[4] = '\0';
 
        /* initialize arguments */
-#if 0
-    nc_arg.portNO = 0;
-    nc_arg.remoteIP.addr = 0;
-#endif
-       nc_arg.srcPortNO = 0;
-       nc_arg.udp = FALSE;
-       nc_arg.listen = FALSE;
-       nc_arg.netLoop = FALSE;
-       nc_arg.test = FALSE;
-       nc_arg.srcPortSpec = FALSE;
 #if !NO_SYS
+       struct nc_arg nc_arg; /* create space for handing args to nc_run() */
        nc_arg.thread = FALSE;
 #endif
 
@@ -491,7 +456,7 @@ int cmd_do_init_nc(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
             help = TRUE;
             break;
        } else if (strncmp((char *) param[pindex], "-u", 3) == 0) {
-               nc_arg.udp = TRUE;
+               udp = TRUE;
 #if !NO_SYS
        } else if (strncmp((char *) param[pindex], "-t", 3) == 0) {
                nc_arg.thread = TRUE;
@@ -499,30 +464,30 @@ int cmd_do_init_nc(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
                closeths = TRUE;
                return ERR_OK;
 #endif
-       } else if (strncmp((char *) param[pindex], "-l", 3) == 0 && !nc_arg.srcPortSpec) {
-               nc_arg.listen = TRUE;
-               nc_arg.srcPortNO = rpp_eth_portStrToInt((uint8_t *)param[++pindex]);
-                       if(nc_arg.srcPortNO == 0)
+       } else if (strncmp((char *) param[pindex], "-l", 3) == 0 && !srcPortSpec) {
+               listen = TRUE;
+               srcPortNO = rpp_eth_portStrToInt((uint8_t *)param[++pindex]);
+                       if(srcPortNO == 0)
                        {
                                rpp_sci_printf((const char *) "E wrong portNO, portNO must follow immediately after -l option\r\n");
                                return BAD_PORT_NO;
                        }
-                       nc_arg.srcPortSpec = TRUE;
-       } else if (strncmp((char *) param[pindex], "-p", 3) == 0 && !nc_arg.srcPortSpec) {
-               nc_arg.srcPortNO = rpp_eth_portStrToInt((uint8_t *)param[++pindex]);
-                       if(nc_arg.srcPortNO == 0)
+                       srcPortSpec = TRUE;
+       } else if (strncmp((char *) param[pindex], "-p", 3) == 0 && !srcPortSpec) {
+               srcPortNO = rpp_eth_portStrToInt((uint8_t *)param[++pindex]);
+                       if(srcPortNO == 0)
                        {
                                rpp_sci_printf((const char *) "E wrong portNO, portNO must follow immediately after -p option\r\n");
                                return BAD_PORT_NO;
                        }
-                       nc_arg.srcPortSpec = TRUE;
+                       srcPortSpec = TRUE;
        } else if (strncmp((char *) param[pindex], "-m", 3) == 0) {
-               nc_arg.netLoop = TRUE;
+               netLoop = TRUE;
        } else if (strncmp((char *) param[pindex], "-d", 3) == 0) {
-            nc_arg.test = TRUE;
-       } else if ( (err = rpp_eth_stringToIP(&nc_arg.remoteIP, (uint8_t *) param[pindex])) == SUCCESS ) {
-               nc_arg.portNO = rpp_eth_portStrToInt((uint8_t *)param[++pindex]);
-                       if(nc_arg.portNO == 0)
+            test = TRUE;
+       } else if ( (err = rpp_eth_stringToIP(&remoteIP, (uint8_t *) param[pindex])) == SUCCESS ) {
+               portNO = rpp_eth_portStrToInt((uint8_t *)param[++pindex]);
+                       if(portNO == 0)
                        {
                                rpp_sci_printf((const char *) "E wrong portNO, portNO must follow immediately after IP address\r\n");
                                return BAD_PORT_NO;
@@ -559,18 +524,22 @@ nc -l <port> -d [-u] [-t]
        return err;
     }
 
-    /* determine srcPortNO from predefined value if not done yet */
-    if(!nc_arg.srcPortSpec)
+    /* determine srcPortNO from predefined value if not done yet (from argument given) */
+    if(!srcPortSpec)
     {
-       nc_arg.srcPortNO = srcPort++;
+       srcPortNO = srcPort++;
     }
 
-#if NO_SYS /* raw LwIP API */
-    rpp_sci_printf((const char *) "nc does not support NO_SYS yet\r\n");
-    return 1;
-#endif
+#if !NO_SYS /* netconn api */
+
+    /* prepare args */
+       nc_arg.srcPortNO = srcPortNO;
+       nc_arg.udp = udp;
+       nc_arg.listen = listen;
+       nc_arg.netLoop = netLoop;
+       nc_arg.test = test;
+       nc_arg.srcPortSpec = srcPortSpec;
 
-#if !NO_SYS
     if(nc_arg.thread){
         /* prepare semaphore */
        vSemaphoreCreateBinary(nc_arg.args_coppied);
@@ -592,11 +561,11 @@ nc -l <port> -d [-u] [-t]
     }
     else
     {
-#endif
         run_nc(&nc_arg);
         return nc_arg.err;
-#if !NO_SYS
     }
+#else /* raw LwIP API */
+    rpp_sci_printf((const char *) "nc does not support NO_SYS yet\r\n");
 #endif
     return ERR_OK;
 }
diff --git a/rpp-lib b/rpp-lib
index 3cca591de8291f94ccc5471abfc6c35daa538528..b54eef044251b25459c94e0b80d1ca8b0b4c22e3 160000 (submodule)
--- a/rpp-lib
+++ b/rpp-lib
@@ -1 +1 @@
-Subproject commit 3cca591de8291f94ccc5471abfc6c35daa538528
+Subproject commit b54eef044251b25459c94e0b80d1ca8b0b4c22e3