bosko lekovic
/
IO_board
IO plocana FRDM K64
SPIprotokol/IOspitelegram.h@16:a3085300cac3, 2021-04-30 (annotated)
- Committer:
- bosko001
- Date:
- Fri Apr 30 00:08:07 2021 +0200
- Revision:
- 16:a3085300cac3
- Parent:
- 7:4aa3dac73b66
i zero crossing dodat
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko001 | 7:4aa3dac73b66 | 1 | #ifndef IOSPITELEGRAM_H |
bosko001 | 7:4aa3dac73b66 | 2 | #define IOSPITELEGRAM_H |
bosko001 | 7:4aa3dac73b66 | 3 | |
bosko001 | 7:4aa3dac73b66 | 4 | //#define Adresa 1 |
bosko001 | 7:4aa3dac73b66 | 5 | |
bosko001 | 7:4aa3dac73b66 | 6 | union S_logTelegram |
bosko001 | 7:4aa3dac73b66 | 7 | { |
bosko001 | 7:4aa3dac73b66 | 8 | char poruka[100]; |
bosko001 | 7:4aa3dac73b66 | 9 | }; |
bosko001 | 7:4aa3dac73b66 | 10 | |
bosko001 | 7:4aa3dac73b66 | 11 | |
bosko001 | 7:4aa3dac73b66 | 12 | |
bosko001 | 7:4aa3dac73b66 | 13 | void loguj_telegram( const char* opis, const char *niz ); |
bosko001 | 7:4aa3dac73b66 | 14 | void loguj_poruku( const char *p ); |
bosko001 | 7:4aa3dac73b66 | 15 | void loguj_broj( int i); |
bosko001 | 7:4aa3dac73b66 | 16 | void loguj_string_broj( char *s,int i); |
bosko001 | 7:4aa3dac73b66 | 17 | |
bosko001 | 7:4aa3dac73b66 | 18 | class C_telegram |
bosko001 | 7:4aa3dac73b66 | 19 | { |
bosko001 | 7:4aa3dac73b66 | 20 | static char myAddress; |
bosko001 | 7:4aa3dac73b66 | 21 | union |
bosko001 | 7:4aa3dac73b66 | 22 | { |
bosko001 | 7:4aa3dac73b66 | 23 | struct |
bosko001 | 7:4aa3dac73b66 | 24 | { |
bosko001 | 7:4aa3dac73b66 | 25 | struct //S_address |
bosko001 | 7:4aa3dac73b66 | 26 | { |
bosko001 | 7:4aa3dac73b66 | 27 | unsigned char address :6; |
bosko001 | 7:4aa3dac73b66 | 28 | unsigned char zero_crossing: 1; |
bosko001 | 7:4aa3dac73b66 | 29 | unsigned char reset: 1; |
bosko001 | 7:4aa3dac73b66 | 30 | }; |
bosko001 | 7:4aa3dac73b66 | 31 | struct |
bosko001 | 7:4aa3dac73b66 | 32 | { |
bosko001 | 7:4aa3dac73b66 | 33 | unsigned char cmd_read: 4; |
bosko001 | 7:4aa3dac73b66 | 34 | unsigned char cmd_write: 4; |
bosko001 | 7:4aa3dac73b66 | 35 | }; |
bosko001 | 7:4aa3dac73b66 | 36 | unsigned char data; |
bosko001 | 7:4aa3dac73b66 | 37 | unsigned char sum; |
bosko001 | 7:4aa3dac73b66 | 38 | }; |
bosko001 | 7:4aa3dac73b66 | 39 | unsigned char niz[4]; |
bosko001 | 7:4aa3dac73b66 | 40 | }; |
bosko001 | 7:4aa3dac73b66 | 41 | |
bosko001 | 7:4aa3dac73b66 | 42 | char calc_sum( void ) { return niz[0]+niz[1]+niz[2]; } |
bosko001 | 7:4aa3dac73b66 | 43 | public: |
bosko001 | 7:4aa3dac73b66 | 44 | |
bosko001 | 7:4aa3dac73b66 | 45 | static void set_myAddress( char a ) { myAddress = a; } |
bosko001 | 7:4aa3dac73b66 | 46 | static char get_myAddress( void ) { return myAddress; } |
bosko001 | 7:4aa3dac73b66 | 47 | |
bosko001 | 7:4aa3dac73b66 | 48 | C_telegram( ); |
bosko001 | 7:4aa3dac73b66 | 49 | bool check_addressValidy( void ); |
bosko001 | 7:4aa3dac73b66 | 50 | bool check_groupAddressValidy( void ); |
bosko001 | 7:4aa3dac73b66 | 51 | |
bosko001 | 7:4aa3dac73b66 | 52 | void set_reset( bool r ) { reset = r; } |
bosko001 | 7:4aa3dac73b66 | 53 | |
bosko001 | 7:4aa3dac73b66 | 54 | void set_zeroCrossing( bool z ) { zero_crossing = z; } |
bosko001 | 7:4aa3dac73b66 | 55 | |
bosko001 | 7:4aa3dac73b66 | 56 | |
bosko001 | 7:4aa3dac73b66 | 57 | virtual void do_writeCommand( const char command, const char data) {} |
bosko001 | 7:4aa3dac73b66 | 58 | virtual char do_readCommand( const char command){ return 0;} |
bosko001 | 7:4aa3dac73b66 | 59 | virtual void do_readGroupCommand( const char command){ } |
bosko001 | 7:4aa3dac73b66 | 60 | |
bosko001 | 7:4aa3dac73b66 | 61 | char get_address( void ) { return address;} |
bosko001 | 7:4aa3dac73b66 | 62 | void set_address( void ) { address = myAddress;} |
bosko001 | 7:4aa3dac73b66 | 63 | |
bosko001 | 7:4aa3dac73b66 | 64 | char get_readCommand() { return cmd_read;} |
bosko001 | 7:4aa3dac73b66 | 65 | void set_readCommand( char cmd ) { cmd_read = cmd; } |
bosko001 | 7:4aa3dac73b66 | 66 | |
bosko001 | 7:4aa3dac73b66 | 67 | char get_writeCommand() { return cmd_write;} |
bosko001 | 7:4aa3dac73b66 | 68 | void set_writeCommand( char cmd ) { cmd_write = cmd; } |
bosko001 | 7:4aa3dac73b66 | 69 | |
bosko001 | 7:4aa3dac73b66 | 70 | void set_data( char d ) { data = d;} |
bosko001 | 7:4aa3dac73b66 | 71 | char get_data( void ) { return data; } |
bosko001 | 7:4aa3dac73b66 | 72 | |
bosko001 | 7:4aa3dac73b66 | 73 | void set_sum( void ) { sum = calc_sum();} |
bosko001 | 7:4aa3dac73b66 | 74 | char get_sum( void ) { return sum;} |
bosko001 | 7:4aa3dac73b66 | 75 | bool check_sum( void ) { return (sum == calc_sum()) ? true: false;} |
bosko001 | 7:4aa3dac73b66 | 76 | |
bosko001 | 7:4aa3dac73b66 | 77 | |
bosko001 | 7:4aa3dac73b66 | 78 | const char *get_telegram( void ); |
bosko001 | 7:4aa3dac73b66 | 79 | const char * make_telegram( char cmd_write, char cmd_read, char data ); |
bosko001 | 7:4aa3dac73b66 | 80 | |
bosko001 | 7:4aa3dac73b66 | 81 | void set_byte( int i, char c) { if( i >=0 && i < 4) niz[i] = c; } |
bosko001 | 7:4aa3dac73b66 | 82 | char get_byte( int i) { return niz[i]; } |
bosko001 | 7:4aa3dac73b66 | 83 | }; |
bosko001 | 7:4aa3dac73b66 | 84 | |
bosko001 | 7:4aa3dac73b66 | 85 | |
bosko001 | 7:4aa3dac73b66 | 86 | #endif |