u-blox
/
C027_ProductionTestLoobback
loopback helper
main.cpp@0:9d92ed28d5a7, 2013-11-19 (annotated)
- Committer:
- mazgch
- Date:
- Tue Nov 19 16:00:33 2013 +0000
- Revision:
- 0:9d92ed28d5a7
loopback ETH/CAN helper for Production Test Sw
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mazgch | 0:9d92ed28d5a7 | 1 | #include "mbed.h" |
mazgch | 0:9d92ed28d5a7 | 2 | #include "C027.h" |
mazgch | 0:9d92ed28d5a7 | 3 | |
mazgch | 0:9d92ed28d5a7 | 4 | #define NL "\r\n" |
mazgch | 0:9d92ed28d5a7 | 5 | #define T_RETRY 1 |
mazgch | 0:9d92ed28d5a7 | 6 | |
mazgch | 0:9d92ed28d5a7 | 7 | int main() { |
mazgch | 0:9d92ed28d5a7 | 8 | C027 c027; |
mazgch | 0:9d92ed28d5a7 | 9 | Serial pc(USBTXD, USBRXD); |
mazgch | 0:9d92ed28d5a7 | 10 | pc.baud(115200); |
mazgch | 0:9d92ed28d5a7 | 11 | |
mazgch | 0:9d92ed28d5a7 | 12 | CAN can(CANRD, CANTD); |
mazgch | 0:9d92ed28d5a7 | 13 | can.frequency(500000); |
mazgch | 0:9d92ed28d5a7 | 14 | DigitalOut canS(CANS); |
mazgch | 0:9d92ed28d5a7 | 15 | canS = 0; |
mazgch | 0:9d92ed28d5a7 | 16 | CANMessage msg; |
mazgch | 0:9d92ed28d5a7 | 17 | |
mazgch | 0:9d92ed28d5a7 | 18 | Ethernet eth; |
mazgch | 0:9d92ed28d5a7 | 19 | bool ethLink = false; |
mazgch | 0:9d92ed28d5a7 | 20 | int len; |
mazgch | 0:9d92ed28d5a7 | 21 | |
mazgch | 0:9d92ed28d5a7 | 22 | printf(NL NL); |
mazgch | 0:9d92ed28d5a7 | 23 | printf("TestVer = \"" __DATE__ " " __TIME__ "\"" NL); |
mazgch | 0:9d92ed28d5a7 | 24 | |
mazgch | 0:9d92ed28d5a7 | 25 | while (1) |
mazgch | 0:9d92ed28d5a7 | 26 | { |
mazgch | 0:9d92ed28d5a7 | 27 | if (can.read(msg)) |
mazgch | 0:9d92ed28d5a7 | 28 | { |
mazgch | 0:9d92ed28d5a7 | 29 | printf("Can: id %03X, len %d, data \"%.*s\"" NL, msg.id, msg.len, msg.len, msg.data); |
mazgch | 0:9d92ed28d5a7 | 30 | can.write(msg); |
mazgch | 0:9d92ed28d5a7 | 31 | } |
mazgch | 0:9d92ed28d5a7 | 32 | bool link = eth.link(); |
mazgch | 0:9d92ed28d5a7 | 33 | if (ethLink ^ link) |
mazgch | 0:9d92ed28d5a7 | 34 | { |
mazgch | 0:9d92ed28d5a7 | 35 | printf("Eth: link %s" NL, link ? "OK" : "ERROR"); |
mazgch | 0:9d92ed28d5a7 | 36 | ethLink = link; |
mazgch | 0:9d92ed28d5a7 | 37 | } |
mazgch | 0:9d92ed28d5a7 | 38 | if (link && ((len = eth.receive()) > 0)) |
mazgch | 0:9d92ed28d5a7 | 39 | { |
mazgch | 0:9d92ed28d5a7 | 40 | char data[256]; |
mazgch | 0:9d92ed28d5a7 | 41 | len = eth.read(data,len); |
mazgch | 0:9d92ed28d5a7 | 42 | printf("Eth: len %d, data \"%.*s\"" NL, len, len, data); |
mazgch | 0:9d92ed28d5a7 | 43 | eth.write(data, len); |
mazgch | 0:9d92ed28d5a7 | 44 | eth.send(); |
mazgch | 0:9d92ed28d5a7 | 45 | } |
mazgch | 0:9d92ed28d5a7 | 46 | wait_ms(1); |
mazgch | 0:9d92ed28d5a7 | 47 | } |
mazgch | 0:9d92ed28d5a7 | 48 | } |