ABELI
/
LineSensTest
LineSensTest
LineSensTest.cpp@0:555a6e520a51, 2015-03-24 (annotated)
- Committer:
- hollegha2
- Date:
- Tue Mar 24 18:17:53 2015 +0000
- Revision:
- 0:555a6e520a51
LineSensTest
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hollegha2 | 0:555a6e520a51 | 1 | #include "mbed.h" |
hollegha2 | 0:555a6e520a51 | 2 | #include "Serial_HL.h" |
hollegha2 | 0:555a6e520a51 | 3 | #include "Bertl14.h" |
hollegha2 | 0:555a6e520a51 | 4 | #include "BertlObjects.h" |
hollegha2 | 0:555a6e520a51 | 5 | |
hollegha2 | 0:555a6e520a51 | 6 | SerialBLK pc(USBTX, USBRX); |
hollegha2 | 0:555a6e520a51 | 7 | SvProtocol ua0(&pc); |
hollegha2 | 0:555a6e520a51 | 8 | |
hollegha2 | 0:555a6e520a51 | 9 | void CommandHandler(); |
hollegha2 | 0:555a6e520a51 | 10 | |
hollegha2 | 0:555a6e520a51 | 11 | AnalogInHL ls1(p18), ls2(p16), ls3(p19), ls4(p17); |
hollegha2 | 0:555a6e520a51 | 12 | |
hollegha2 | 0:555a6e520a51 | 13 | int main(void) |
hollegha2 | 0:555a6e520a51 | 14 | { |
hollegha2 | 0:555a6e520a51 | 15 | pc.format(8,SerialBLK::None,1); pc.baud(500000); // 115200 |
hollegha2 | 0:555a6e520a51 | 16 | leds = 9; |
hollegha2 | 0:555a6e520a51 | 17 | ua0.SvMessage("LineSensTest"); // Meldung zum PC senden |
hollegha2 | 0:555a6e520a51 | 18 | |
hollegha2 | 0:555a6e520a51 | 19 | Timer stw; stw.start(); |
hollegha2 | 0:555a6e520a51 | 20 | while(1) |
hollegha2 | 0:555a6e520a51 | 21 | { |
hollegha2 | 0:555a6e520a51 | 22 | CommandHandler(); |
hollegha2 | 0:555a6e520a51 | 23 | if( (stw.read_ms()>10) ) // 100Hz |
hollegha2 | 0:555a6e520a51 | 24 | { // dieser Teil wird mit 100Hz aufgerufen |
hollegha2 | 0:555a6e520a51 | 25 | stw.reset(); |
hollegha2 | 0:555a6e520a51 | 26 | if( ua0.acqON ) { |
hollegha2 | 0:555a6e520a51 | 27 | // nur wenn vom PC aus das Senden eingeschaltet wurde |
hollegha2 | 0:555a6e520a51 | 28 | // wird auch etwas gesendet |
hollegha2 | 0:555a6e520a51 | 29 | ua0.WriteSvI16(1, ls1.Read()); |
hollegha2 | 0:555a6e520a51 | 30 | ua0.WriteSvI16(2, ls2.Read()); |
hollegha2 | 0:555a6e520a51 | 31 | ua0.WriteSvI16(3, ls3.Read()); |
hollegha2 | 0:555a6e520a51 | 32 | ua0.WriteSvI16(4, ls4.Read()); |
hollegha2 | 0:555a6e520a51 | 33 | } |
hollegha2 | 0:555a6e520a51 | 34 | } |
hollegha2 | 0:555a6e520a51 | 35 | } |
hollegha2 | 0:555a6e520a51 | 36 | return 1; |
hollegha2 | 0:555a6e520a51 | 37 | } |
hollegha2 | 0:555a6e520a51 | 38 | |
hollegha2 | 0:555a6e520a51 | 39 | void CommandHandler() |
hollegha2 | 0:555a6e520a51 | 40 | { |
hollegha2 | 0:555a6e520a51 | 41 | uint8_t cmd; |
hollegha2 | 0:555a6e520a51 | 42 | int16_t idata1, idata2; |
hollegha2 | 0:555a6e520a51 | 43 | |
hollegha2 | 0:555a6e520a51 | 44 | // Fragen ob überhaupt etwas im RX-Reg steht |
hollegha2 | 0:555a6e520a51 | 45 | if( !pc.IsDataAvail() ) |
hollegha2 | 0:555a6e520a51 | 46 | return; |
hollegha2 | 0:555a6e520a51 | 47 | |
hollegha2 | 0:555a6e520a51 | 48 | // wenn etwas im RX-Reg steht |
hollegha2 | 0:555a6e520a51 | 49 | // Kommando lesen |
hollegha2 | 0:555a6e520a51 | 50 | cmd = ua0.GetCommand(); |
hollegha2 | 0:555a6e520a51 | 51 | |
hollegha2 | 0:555a6e520a51 | 52 | if( cmd==2 ) |
hollegha2 | 0:555a6e520a51 | 53 | { |
hollegha2 | 0:555a6e520a51 | 54 | // cmd2 hat 2 int16 Parameter |
hollegha2 | 0:555a6e520a51 | 55 | idata1 = ua0.ReadI16(); idata2 = ua0.ReadI16(); |
hollegha2 | 0:555a6e520a51 | 56 | // für die Analyse den Wert einfach nur zum PC zurücksenden |
hollegha2 | 0:555a6e520a51 | 57 | ua0.SvPrintf("Command2 %d %d", idata1, idata2); |
hollegha2 | 0:555a6e520a51 | 58 | } |
hollegha2 | 0:555a6e520a51 | 59 | if( cmd==3 ) |
hollegha2 | 0:555a6e520a51 | 60 | { |
hollegha2 | 0:555a6e520a51 | 61 | idata1 = ua0.ReadI16(); |
hollegha2 | 0:555a6e520a51 | 62 | leds = idata1; |
hollegha2 | 0:555a6e520a51 | 63 | ua0.SvMessage("Leds schalten"); |
hollegha2 | 0:555a6e520a51 | 64 | } |
hollegha2 | 0:555a6e520a51 | 65 | if( cmd==4 ) |
hollegha2 | 0:555a6e520a51 | 66 | { |
hollegha2 | 0:555a6e520a51 | 67 | idata1 = leds; |
hollegha2 | 0:555a6e520a51 | 68 | ua0.SvPrintf("LEDS %d", idata1); |
hollegha2 | 0:555a6e520a51 | 69 | } |
hollegha2 | 0:555a6e520a51 | 70 | } |
hollegha2 | 0:555a6e520a51 | 71 | |
hollegha2 | 0:555a6e520a51 | 72 | |
hollegha2 | 0:555a6e520a51 | 73 |