bosko lekovic
/
EthTCPclient_05_03
p1
PGSdisplay.c@4:0aec01df33d2, 2020-02-22 (annotated)
- Committer:
- bosko001
- Date:
- Sat Feb 22 17:17:54 2020 +0000
- Revision:
- 4:0aec01df33d2
ttt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko001 | 4:0aec01df33d2 | 1 | |
bosko001 | 4:0aec01df33d2 | 2 | //#include "mbed.h" |
bosko001 | 4:0aec01df33d2 | 3 | //#include "platform/mbed_thread.h" |
bosko001 | 4:0aec01df33d2 | 4 | |
bosko001 | 4:0aec01df33d2 | 5 | |
bosko001 | 4:0aec01df33d2 | 6 | #include <string.h> |
bosko001 | 4:0aec01df33d2 | 7 | |
bosko001 | 4:0aec01df33d2 | 8 | #include "PGSdisplay.h" |
bosko001 | 4:0aec01df33d2 | 9 | #include "DigitalOut.h" |
bosko001 | 4:0aec01df33d2 | 10 | |
bosko001 | 4:0aec01df33d2 | 11 | extern DigitalOut tast; |
bosko001 | 4:0aec01df33d2 | 12 | //RawSerial rs485(PTC17,PTC16); |
bosko001 | 4:0aec01df33d2 | 13 | extern RawSerial rs485; |
bosko001 | 4:0aec01df33d2 | 14 | |
bosko001 | 4:0aec01df33d2 | 15 | |
bosko001 | 4:0aec01df33d2 | 16 | void ev(int) |
bosko001 | 4:0aec01df33d2 | 17 | { |
bosko001 | 4:0aec01df33d2 | 18 | tast=0; |
bosko001 | 4:0aec01df33d2 | 19 | } |
bosko001 | 4:0aec01df33d2 | 20 | |
bosko001 | 4:0aec01df33d2 | 21 | |
bosko001 | 4:0aec01df33d2 | 22 | |
bosko001 | 4:0aec01df33d2 | 23 | unsigned char buf_tel[100] = {0x71,0x00,0x0D,0x71,0x43,0x1,0x1B,0x4A,0x01,0x01, /*0x1b,0x45,0x1,*/ 0x1B,0x43,1,0x33,0xD5,0x16}; |
bosko001 | 4:0aec01df33d2 | 24 | #define NO_BEFORE_DATA 13 |
bosko001 | 4:0aec01df33d2 | 25 | #define NO_WITH_DATA (NO_BEFORE_DATA + strlen(s)) |
bosko001 | 4:0aec01df33d2 | 26 | |
bosko001 | 4:0aec01df33d2 | 27 | void putOnDisp( char *s, char boja) |
bosko001 | 4:0aec01df33d2 | 28 | { |
bosko001 | 4:0aec01df33d2 | 29 | int ubb = NO_BEFORE_DATA+strlen(s)+1+1-4-2; // ubb = ukupan broj bajtova |
bosko001 | 4:0aec01df33d2 | 30 | buf_tel[NO_BEFORE_DATA-1]=boja; |
bosko001 | 4:0aec01df33d2 | 31 | memcpy(buf_tel+NO_BEFORE_DATA, s, strlen(s)+2); |
bosko001 | 4:0aec01df33d2 | 32 | |
bosko001 | 4:0aec01df33d2 | 33 | char suma=0; |
bosko001 | 4:0aec01df33d2 | 34 | for(int i = 4; i < NO_WITH_DATA; i++) { |
bosko001 | 4:0aec01df33d2 | 35 | suma +=buf_tel[i]; |
bosko001 | 4:0aec01df33d2 | 36 | } |
bosko001 | 4:0aec01df33d2 | 37 | |
bosko001 | 4:0aec01df33d2 | 38 | buf_tel[NO_WITH_DATA] = suma; |
bosko001 | 4:0aec01df33d2 | 39 | buf_tel[NO_WITH_DATA+1] = 22; |
bosko001 | 4:0aec01df33d2 | 40 | buf_tel[1]=ubb>>8; |
bosko001 | 4:0aec01df33d2 | 41 | buf_tel[2]=ubb; |
bosko001 | 4:0aec01df33d2 | 42 | |
bosko001 | 4:0aec01df33d2 | 43 | |
bosko001 | 4:0aec01df33d2 | 44 | tast=1; |
bosko001 | 4:0aec01df33d2 | 45 | rs485.write(buf_tel, NO_WITH_DATA+2+2,ev); |
bosko001 | 4:0aec01df33d2 | 46 | } |
bosko001 | 4:0aec01df33d2 | 47 | |
bosko001 | 4:0aec01df33d2 | 48 | void putOnDispNo(int broj, char boja) |
bosko001 | 4:0aec01df33d2 | 49 | { |
bosko001 | 4:0aec01df33d2 | 50 | char s[10]; |
bosko001 | 4:0aec01df33d2 | 51 | sprintf( s, "%d", broj); |
bosko001 | 4:0aec01df33d2 | 52 | putOnDisp( s, boja); |
bosko001 | 4:0aec01df33d2 | 53 | } |
bosko001 | 4:0aec01df33d2 | 54 | |
bosko001 | 4:0aec01df33d2 | 55 | |
bosko001 | 4:0aec01df33d2 | 56 | void slanjefun() |
bosko001 | 4:0aec01df33d2 | 57 | { |
bosko001 | 4:0aec01df33d2 | 58 | |
bosko001 | 4:0aec01df33d2 | 59 | int j=0; |
bosko001 | 4:0aec01df33d2 | 60 | |
bosko001 | 4:0aec01df33d2 | 61 | |
bosko001 | 4:0aec01df33d2 | 62 | while (true) { |
bosko001 | 4:0aec01df33d2 | 63 | // printf("disp thred %d\n\r",j); |
bosko001 | 4:0aec01df33d2 | 64 | if(j >10 && j<15 ) putOnDisp("des",1); |
bosko001 | 4:0aec01df33d2 | 65 | else putOnDispNo(j,1); |
bosko001 | 4:0aec01df33d2 | 66 | j++; |
bosko001 | 4:0aec01df33d2 | 67 | thread_sleep_for(1000); |
bosko001 | 4:0aec01df33d2 | 68 | } |
bosko001 | 4:0aec01df33d2 | 69 | } |
bosko001 | 4:0aec01df33d2 | 70 | |
bosko001 | 4:0aec01df33d2 | 71 | |
bosko001 | 4:0aec01df33d2 | 72 | char * extract_string( char delimiter, char *ulazni_str, int n_str ) |
bosko001 | 4:0aec01df33d2 | 73 | { |
bosko001 | 4:0aec01df33d2 | 74 | int br_str=0; |
bosko001 | 4:0aec01df33d2 | 75 | char *ret_str=ulazni_str; |
bosko001 | 4:0aec01df33d2 | 76 | char* ptr = ulazni_str; |
bosko001 | 4:0aec01df33d2 | 77 | |
bosko001 | 4:0aec01df33d2 | 78 | while(*ptr) { |
bosko001 | 4:0aec01df33d2 | 79 | if(*ptr == delimiter) { |
bosko001 | 4:0aec01df33d2 | 80 | *ptr = 0; |
bosko001 | 4:0aec01df33d2 | 81 | if( br_str == n_str ) return ret_str; |
bosko001 | 4:0aec01df33d2 | 82 | else { |
bosko001 | 4:0aec01df33d2 | 83 | br_str++; |
bosko001 | 4:0aec01df33d2 | 84 | ret_str = ptr + 1; |
bosko001 | 4:0aec01df33d2 | 85 | } |
bosko001 | 4:0aec01df33d2 | 86 | } |
bosko001 | 4:0aec01df33d2 | 87 | ptr++; |
bosko001 | 4:0aec01df33d2 | 88 | } |
bosko001 | 4:0aec01df33d2 | 89 | if( br_str == n_str ) return ret_str; |
bosko001 | 4:0aec01df33d2 | 90 | return NULL; |
bosko001 | 4:0aec01df33d2 | 91 | } |
bosko001 | 4:0aec01df33d2 | 92 |