prva verzija, poslednji bajt je sporan

Committer:
bosko001
Date:
Sun Jul 12 10:23:39 2020 +0200
Revision:
1:dd44d6b64300
Parent:
0:c06c791ca345
Child:
2:190bae43eca9
funkcionalan kod, bez MiWi thread-a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bosko001 0:c06c791ca345 1 /* mbed Microcontroller Library
bosko001 0:c06c791ca345 2 * Copyright (c) 2019 ARM Limited
bosko001 0:c06c791ca345 3 * SPDX-License-Identifier: Apache-2.0
bosko001 0:c06c791ca345 4 */
bosko001 0:c06c791ca345 5
bosko001 0:c06c791ca345 6 #include "mbed.h"
bosko001 0:c06c791ca345 7 #include "platform/mbed_thread.h"
bosko001 0:c06c791ca345 8
bosko001 0:c06c791ca345 9 #include "MiWiApp.h"
bosko001 1:dd44d6b64300 10 #include "SerialCom.h"
bosko001 0:c06c791ca345 11 // Blinking rate in milliseconds
bosko001 0:c06c791ca345 12 #define BLINKING_RATE_MS 200
bosko001 0:c06c791ca345 13
bosko001 1:dd44d6b64300 14 #define MINIMUM( A, B) A<B ? A:B
bosko001 0:c06c791ca345 15
bosko001 0:c06c791ca345 16
bosko001 0:c06c791ca345 17 DigitalIn b2(SW2);
bosko001 0:c06c791ca345 18
bosko001 0:c06c791ca345 19
bosko001 0:c06c791ca345 20
bosko001 0:c06c791ca345 21 char tx_niz[] = { 7,0,1,2,3, 4, 5 , 6, 7, 8};
bosko001 1:dd44d6b64300 22 char rx_niz[100];
bosko001 1:dd44d6b64300 23 int rx_br;
bosko001 0:c06c791ca345 24
bosko001 0:c06c791ca345 25 void consolafun( void );
bosko001 0:c06c791ca345 26 Thread th_consola( consolafun );
bosko001 0:c06c791ca345 27
bosko001 1:dd44d6b64300 28 void refreshMiWifun( void );
bosko001 1:dd44d6b64300 29 Thread th_refreshMiWi( refreshMiWifun );
bosko001 1:dd44d6b64300 30
bosko001 0:c06c791ca345 31 int main()
bosko001 0:c06c791ca345 32 {
bosko001 0:c06c791ca345 33 // Initialise the digital pin LED1 as an output
bosko001 0:c06c791ca345 34 printf("\n\n\r ____________ POCETAK MiWI RX_______________\n\r");
bosko001 0:c06c791ca345 35
bosko001 0:c06c791ca345 36 inic_MiWi( );
bosko001 0:c06c791ca345 37
bosko001 0:c06c791ca345 38 DigitalOut led(LED1,1);
bosko001 0:c06c791ca345 39 DigitalOut ledB(LED3,1);
bosko001 1:dd44d6b64300 40 DigitalOut ledG(LED2,1);
bosko001 0:c06c791ca345 41
bosko001 0:c06c791ca345 42
bosko001 0:c06c791ca345 43
bosko001 0:c06c791ca345 44 set_mode( 3 ); //prijem
bosko001 0:c06c791ca345 45
bosko001 0:c06c791ca345 46
bosko001 0:c06c791ca345 47 //for( int i=0; i<10; i++)
bosko001 0:c06c791ca345 48 {
bosko001 0:c06c791ca345 49 char r = readMiWiReg( 0x14 ); // read GCONFIG
bosko001 0:c06c791ca345 50 printf("rssi = %d\n\r", r );
bosko001 1:dd44d6b64300 51 // print_regs();
bosko001 0:c06c791ca345 52 }
bosko001 0:c06c791ca345 53
bosko001 0:c06c791ca345 54 int b = b2;
bosko001 0:c06c791ca345 55
bosko001 1:dd44d6b64300 56 wait(0.5);
bosko001 1:dd44d6b64300 57 start_SerialCom( );
bosko001 0:c06c791ca345 58
bosko001 0:c06c791ca345 59 while (true)
bosko001 0:c06c791ca345 60 {
bosko001 0:c06c791ca345 61 // led = !led;
bosko001 0:c06c791ca345 62
bosko001 0:c06c791ca345 63 extern DigitalIn pin_irq0, pin_irq1;
bosko001 0:c06c791ca345 64 //
bosko001 0:c06c791ca345 65 // unsigned char r = readMiWiReg( 0x14 ); // read GCONFIG
bosko001 0:c06c791ca345 66 // printf("rssi = %d ", r );
bosko001 0:c06c791ca345 67 // printf(" irq0=%d irq1=%d\n\r", pin_irq0.read(), pin_irq1.read() ); fflush(stdout);
bosko001 0:c06c791ca345 68 ////if( r> 50 )
bosko001 0:c06c791ca345 69
bosko001 0:c06c791ca345 70 if( get_mode( ) == 3 )
bosko001 0:c06c791ca345 71 {
bosko001 0:c06c791ca345 72 if( pin_irq0.read() )
bosko001 0:c06c791ca345 73 {
bosko001 1:dd44d6b64300 74
bosko001 1:dd44d6b64300 75 rx_br = 0;
bosko001 1:dd44d6b64300 76 // print_regs();
bosko001 0:c06c791ca345 77 while( pin_irq0.read() )
bosko001 0:c06c791ca345 78 {
bosko001 1:dd44d6b64300 79 rx_niz[rx_br++]= readMiWiData();
bosko001 1:dd44d6b64300 80
bosko001 1:dd44d6b64300 81
bosko001 0:c06c791ca345 82 }
bosko001 1:dd44d6b64300 83 for(int i=0; i<rx_br;i++) { printf(" %d ", rx_niz[i]); }
bosko001 1:dd44d6b64300 84 printf("\n\rrx_br %d\n\r", rx_br);
bosko001 1:dd44d6b64300 85 if( rx_br <= 4) { ledG=0; wait(0.1); ledG=1;}
bosko001 1:dd44d6b64300 86 else if(rx_br>3) {led = 0;sendToScom(rx_niz+2, rx_niz[0]-2/* MINIMUM(rx_br, rx_niz[0]-2)* */ ); }
bosko001 1:dd44d6b64300 87 rx_br = 0;
bosko001 1:dd44d6b64300 88 }
bosko001 0:c06c791ca345 89 else { if(!led ) led = 1; }
bosko001 0:c06c791ca345 90 }
bosko001 0:c06c791ca345 91 // else
bosko001 0:c06c791ca345 92 {
bosko001 0:c06c791ca345 93
bosko001 0:c06c791ca345 94 if( b!= b2)
bosko001 0:c06c791ca345 95 {
bosko001 0:c06c791ca345 96 b = b2;
bosko001 0:c06c791ca345 97 if( b ) {/*set_mode( 1 );*/ ledB = 1;}
bosko001 0:c06c791ca345 98 else { ledB = 0; txMiWi( tx_niz ); }
bosko001 0:c06c791ca345 99 }
bosko001 0:c06c791ca345 100
bosko001 0:c06c791ca345 101 }
bosko001 0:c06c791ca345 102
bosko001 0:c06c791ca345 103
bosko001 0:c06c791ca345 104
bosko001 0:c06c791ca345 105 thread_sleep_for(BLINKING_RATE_MS);
bosko001 0:c06c791ca345 106 }
bosko001 0:c06c791ca345 107 }
bosko001 0:c06c791ca345 108
bosko001 1:dd44d6b64300 109 char refrtx[10]={3,1,2, 3};
bosko001 1:dd44d6b64300 110 void refreshMiWifun( void )
bosko001 1:dd44d6b64300 111 {
bosko001 1:dd44d6b64300 112 while(true)
bosko001 1:dd44d6b64300 113 {
bosko001 1:dd44d6b64300 114 wait(10);
bosko001 1:dd44d6b64300 115 txMiWi(refrtx);
bosko001 1:dd44d6b64300 116 }
bosko001 1:dd44d6b64300 117 }
bosko001 0:c06c791ca345 118
bosko001 0:c06c791ca345 119
bosko001 0:c06c791ca345 120 void consolafun( void )
bosko001 0:c06c791ca345 121 {
bosko001 0:c06c791ca345 122 while( true )
bosko001 0:c06c791ca345 123 {
bosko001 0:c06c791ca345 124
bosko001 0:c06c791ca345 125 char uc = getchar( );
bosko001 0:c06c791ca345 126 switch( (unsigned char) uc )
bosko001 0:c06c791ca345 127 {
bosko001 0:c06c791ca345 128 case 'r': case 'R':
bosko001 0:c06c791ca345 129
bosko001 0:c06c791ca345 130 printf("\n\rcitanje registra, unesi broj:\n\r");
bosko001 0:c06c791ca345 131 int r;
bosko001 0:c06c791ca345 132 scanf("%x", &r);
bosko001 0:c06c791ca345 133 printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r));
bosko001 0:c06c791ca345 134
bosko001 0:c06c791ca345 135 break;
bosko001 0:c06c791ca345 136 case 'w': case 'W':
bosko001 0:c06c791ca345 137 {
bosko001 0:c06c791ca345 138 printf("\n\rupis registra, unesi broj registra:");
bosko001 0:c06c791ca345 139 int r;
bosko001 0:c06c791ca345 140 scanf("%x", &r);
bosko001 0:c06c791ca345 141 printf( " %x", r );
bosko001 0:c06c791ca345 142 printf("\n\runesi vrednost registra:");
bosko001 0:c06c791ca345 143 int v;
bosko001 0:c06c791ca345 144 scanf("%x", &v);
bosko001 0:c06c791ca345 145 printf( " %x", v );
bosko001 0:c06c791ca345 146 printf( "\n\rregistar %x ima vrednost %x\n\r", r, readMiWiReg(r));
bosko001 0:c06c791ca345 147 }
bosko001 0:c06c791ca345 148 break;
bosko001 1:dd44d6b64300 149 case 's': case 'S':
bosko001 1:dd44d6b64300 150 printf("aktivacija serijala\n\r");
bosko001 1:dd44d6b64300 151 start_SerialCom( );
bosko001 1:dd44d6b64300 152 break;
bosko001 0:c06c791ca345 153 }
bosko001 0:c06c791ca345 154
bosko001 0:c06c791ca345 155 }
bosko001 0:c06c791ca345 156 }