ver 2

Files at this revision

API Documentation at this revision

Comitter:
bosko001
Date:
Wed Feb 12 20:25:05 2020 +0000
Commit message:
verzija 2

Changed in this revision

.gitignore Show annotated file Show diff for this revision Revisions of this file
CONTRIBUTING.md Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
resources/official_armmbed_example_badge.png Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.gitignore	Wed Feb 12 20:25:05 2020 +0000
@@ -0,0 +1,4 @@
+.build
+.mbed
+projectfiles
+*.py*
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CONTRIBUTING.md	Wed Feb 12 20:25:05 2020 +0000
@@ -0,0 +1,5 @@
+# Contributing to Mbed OS
+
+Mbed OS is an open-source, device software platform for the Internet of Things. Contributions are an important part of the platform, and our goal is to make it as simple as possible to become a contributor.
+
+To encourage productive collaboration, as well as robust, consistent and maintainable code, we have a set of guidelines for [contributing to Mbed OS](https://os.mbed.com/docs/mbed-os/latest/contributing/index.html).
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.md	Wed Feb 12 20:25:05 2020 +0000
@@ -0,0 +1,64 @@
+![](./resources/official_armmbed_example_badge.png)
+# Blinky Mbed OS example
+
+The example project is part of the [Arm Mbed OS Official Examples](https://os.mbed.com/code/) and is the [getting started example for Mbed OS](https://os.mbed.com/docs/mbed-os/v5.14/quick-start/index.html). It contains an application that repeatedly blinks an LED on supported [Mbed boards](https://os.mbed.com/platforms/).
+
+You can build the project with all supported [Mbed OS build tools](https://os.mbed.com/docs/mbed-os/latest/tools/index.html). However, this example project specifically refers to the command-line interface tool [Arm Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
+(Note: To see a rendered example you can import into the Arm Online Compiler, please see our [import quick start](https://os.mbed.com/docs/mbed-os/latest/quick-start/online-with-the-online-compiler.html#importing-the-code).)
+
+1. [Install Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/quick-start/offline-with-mbed-cli.html).
+
+1. Clone this repository on your system, and change the current directory to where the project was cloned:
+
+    ```bash
+    $ git clone git@github.com:armmbed/mbed-os-example-blinky && cd mbed-os-example-blinky
+    ```
+
+    Alternatively, you can download the example project with Arm Mbed CLI using the `import` subcommand:
+
+    ```bash
+    $ mbed import mbed-os-example-blinky && cd mbed-os-example-blinky
+    ```
+
+
+## Application functionality
+
+The `main()` function is the single thread in the application. It toggles the state of a digital output connected to an LED on the board.
+
+## Building and running
+
+1. Connect a USB cable between the USB port on the board and the host computer.
+2. <a name="build_cmd"></a> Run the following command to build the example project and program the microcontroller flash memory:
+    ```bash
+    $ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash
+    ```
+The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-blinky.bin`.
+
+Alternatively, you can manually copy the binary to the board, which you mount on the host computer over USB.
+
+Depending on the target, you can build the example project with the `GCC_ARM`, `ARM` or `IAR` toolchain. After installing Arm Mbed CLI, run the command below to determine which toolchain supports your target:
+
+```bash
+$ mbed compile -S
+```
+
+## Expected output
+The LED on your target turns on and off every 500 milliseconds.
+
+
+## Troubleshooting
+If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
+
+## Related Links
+
+* [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html).
+* [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html).
+* [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html).
+* [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/latest/reference/mbed-os-bare-metal.html).
+* [Mbed boards](https://os.mbed.com/platforms/).
+
+### License and contributions
+
+The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see contributing.md for more info.
+
+This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Feb 12 20:25:05 2020 +0000
@@ -0,0 +1,220 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2019 ARM Limited
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+#include "mbed.h"
+#include "platform/mbed_thread.h"
+
+#include "EthernetInterface.h"
+
+#include <stdio.h>
+#include <string.h>
+#include "TCPSocket.h"
+
+
+void putOnDispNo(int broj, char boja);
+void putOnDisp(char *s, char boja);
+void slanjefun();
+
+#define IP_ADDR   "192.168.2.11"
+#define NET_MASK  "255.255.248.0"
+#define GATW_ADDR "192.168.1.1"
+#define IP_ADDR_R "192.168.1.9"
+
+
+
+EthernetInterface eth;
+nsapi_error_t err;
+
+
+int strcount( unsigned char *ps)
+{
+ int i=0;
+  for(i=0; ps[i] != 0; i++);
+  return i;   
+}
+
+void tcpThread_fun( EthernetInterface *e);
+
+ DigitalOut tast(PTB19,0);               
+//RawSerial rs485(PTC17,PTC16);           
+RawSerial rs485(PTD3,PTD2);
+ 
+
+int main(void)
+{
+ 
+ rs485.format(8, mbed::RawSerial::Even, 1);
+ 
+    Thread t;
+ //   t.start( slanjefun );
+
+ 
+ 
+     if( (err = eth.set_network(IP_ADDR,NET_MASK,GATW_ADDR))!= NSAPI_ERROR_OK )  { printf(" greska setovanja mreze %d \n\r", err); return 1; }    
+     if( (err = eth.connect())  != NSAPI_ERROR_OK )  { printf(" greska konekcije %d \n\r", err); return 1; }
+    
+    const char *ip = eth.get_ip_address() ;
+    
+    
+   printf( "MAC adresa: %s\n\r", eth.get_mac_address() );
+    printf( "IP adresa:  %s\n\r", ip);
+    printf( "net mask:   %s\n\r", eth.get_netmask() );
+    printf( "GW adresa:  %s\n\r", eth.get_gateway() );
+    
+    Thread TCPThread;
+    TCPThread.start( callback( tcpThread_fun, &eth ));
+ 
+    int i=0;
+  
+    while(true)
+    {
+      thread_sleep_for(20000);
+      printf("main %d\n\r",i++);
+    }
+ //   printf("\n\rmain: Kraj, error=%d\n\r",err);    fflush(stdout);
+}
+
+
+
+
+    unsigned char sendBuffer[]= "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/html\r\n\r\nMarko je ovde";                  // HTTP Message Body, length = 11
+unsigned char sb[1000]="HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n";
+
+
+
+unsigned char txbuf[100]="test konekcije";
+unsigned char rxbuf[100];
+
+void tcpThread_fun( EthernetInterface *e)
+{
+
+    TCPSocket tcpSocket;  
+    nsapi_error_t err=NULL;      
+    SocketAddress sa("192.168.2.254", 12197);
+    printf("ip= %s, ver= %d, port= %d\n\r", sa.get_ip_address(), sa.get_ip_version(), sa.get_port() ); 
+    int i=1;
+    
+    while(true)
+    {
+     if((err=tcpSocket.open( e )) ==0 )        
+     {
+        if((err = tcpSocket.connect(sa)) == 0)
+        {
+            while( true)
+            {
+                printf("iteracija %d   \n\r", i);
+                    if(strcount(txbuf) )
+                    {
+                        printf(" za slanje %d bajtova: %s\n\r", strcount(txbuf), txbuf);
+                        if( (err = tcpSocket.send(txbuf,strcount(txbuf))<0 ) )   {    printf("send err %d\n\r", err); break; }
+                        else(" poslano %d bajtova od: %s\n\r", err, txbuf);
+                        memset(txbuf, 0, sizeof(txbuf) );
+                    }
+                    else
+                    {
+                        if( (err = tcpSocket.recv(rxbuf,sizeof(rxbuf)) <0 )) {    printf("recv err %d\n\r", err); break;  }
+                        else                                                 
+                        {
+                          
+                                printf(" prim tel %d: %s\n\r", err, rxbuf) ; 
+                                {
+                                  extern  void putOnDisp(char *, char );
+                                     putOnDisp((char*)rxbuf, 1);
+                                }
+                                memcpy(txbuf, rxbuf, sizeof(txbuf) );
+                                memset(rxbuf, 0, sizeof(rxbuf)); 
+                        } 
+                    }
+                 printf("kraj iteracije %d   \n\r", i++);
+                 fflush(stdout);
+            }
+        }
+        else printf("greska otvaranja konekcije %d\n\r", err);
+      }
+      else printf("greska otvaranja socketa %d\n\r", err);
+      
+      printf("zatvaranje konekcije\n\r");
+      tcpSocket.close();
+      thread_sleep_for(2000);
+     }
+}
+
+    
+
+
+//
+//enum nsapi_error {
+//    NSAPI_ERROR_OK                  =  0,        /*!< no error */
+//    NSAPI_ERROR_WOULD_BLOCK         = -3001,     /*!< no data is not available but call is non-blocking */
+//    NSAPI_ERROR_UNSUPPORTED         = -3002,     /*!< unsupported functionality */
+//    NSAPI_ERROR_PARAMETER           = -3003,     /*!< invalid configuration */
+//    NSAPI_ERROR_NO_CONNECTION       = -3004,     /*!< not connected to a network */
+//    NSAPI_ERROR_NO_SOCKET           = -3005,     /*!< socket not available for use */
+//    NSAPI_ERROR_NO_ADDRESS          = -3006,     /*!< IP address is not known */
+//    NSAPI_ERROR_NO_MEMORY           = -3007,     /*!< memory resource not available */
+//    NSAPI_ERROR_NO_SSID             = -3008,     /*!< ssid not found */
+//    NSAPI_ERROR_DNS_FAILURE         = -3009,     /*!< DNS failed to complete successfully */
+//    NSAPI_ERROR_DHCP_FAILURE        = -3010,     /*!< DHCP failed to complete successfully */
+//    NSAPI_ERROR_AUTH_FAILURE        = -3011,     /*!< connection to access point failed */
+//    NSAPI_ERROR_DEVICE_ERROR        = -3012,     /*!< failure interfacing with the network processor */
+//    NSAPI_ERROR_IN_PROGRESS         = -3013,     /*!< operation (eg connect) in progress */
+//    NSAPI_ERROR_ALREADY             = -3014,     /*!< operation (eg connect) already in progress */
+//    NSAPI_ERROR_IS_CONNECTED        = -3015,     /*!< socket is already connected */
+//    NSAPI_ERROR_CONNECTION_LOST     = -3016,     /*!< connection lost */
+//    NSAPI_ERROR_CONNECTION_TIMEOUT  = -3017,     /*!< connection timed out */
+//};
+
+
+
+
+
+void ev(int){tast=0;}
+
+unsigned char buf_tel[100] = {0x71,0x00,0x0D,0x71,0x43,0x01,0x1B,0x4A,0x01,0x01,0x1B,0x43,1,0x33,0xD5,0x16};
+void putOnDisp( char *s, char boja)
+{
+    int ubb = 13+strlen(s)+1+1-4-2;
+    unsigned char lh, ll;
+    ll=ubb;
+    lh=ubb>>8;
+
+    memcpy(buf_tel+13, s, strlen(s)+2);
+    
+    int suma=0;
+    for(int i = 4; i < 13+strlen(s); i++) {
+        suma +=buf_tel[i]; 
+    }
+    
+    buf_tel[13+strlen(s)] = suma;
+    buf_tel[13+strlen(s)+1] = 22;
+    buf_tel[1]=lh;
+    buf_tel[2]=ll;
+   
+    fflush(stdout);
+    
+    tast=1;
+    rs485.write(buf_tel, 21,ev);
+}
+void putOnDispNo(int broj, char boja)
+{
+     char s[10];
+    sprintf( s, "%d", broj);  
+    putOnDisp( s, boja); 
+}
+
+
+void slanjefun(){
+    
+    int j=0;
+    
+
+    while (true) {
+ //       printf("disp thred %d\n\r",j);
+        if(j >10 && j<15 ) putOnDisp("des",1);
+        else putOnDispNo(j,1);
+        j++;
+        thread_sleep_for(1000);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Wed Feb 12 20:25:05 2020 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9
Binary file resources/official_armmbed_example_badge.png has changed