![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
PLC
Dependencies: EthernetNetIf HTTPServer TextLCD mbed
Fork of ethernet_test_http by
main.cpp@1:7097c8844b71, 2014-05-12 (annotated)
- Committer:
- twinkling
- Date:
- Mon May 12 04:55:35 2014 +0000
- Revision:
- 1:7097c8844b71
- Parent:
- 0:7dcfd77d344d
PLC??
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yueee_yt | 0:7dcfd77d344d | 1 | #include "mbed.h" |
yueee_yt | 0:7dcfd77d344d | 2 | #include "TextLCD.h" |
yueee_yt | 0:7dcfd77d344d | 3 | #include "EthernetNetIf.h" |
yueee_yt | 0:7dcfd77d344d | 4 | #include "HTTPServer.h" |
twinkling | 1:7097c8844b71 | 5 | #include "adc.h" |
twinkling | 1:7097c8844b71 | 6 | |
yueee_yt | 0:7dcfd77d344d | 7 | |
yueee_yt | 0:7dcfd77d344d | 8 | DigitalOut led1(LED1,"led1"); |
yueee_yt | 0:7dcfd77d344d | 9 | DigitalOut led2(LED2,"led2"); |
yueee_yt | 0:7dcfd77d344d | 10 | DigitalOut led3(LED3,"led3"); |
yueee_yt | 0:7dcfd77d344d | 11 | DigitalOut led4(LED4,"led4"); |
twinkling | 1:7097c8844b71 | 12 | InterruptIn pin5(p5); |
yueee_yt | 0:7dcfd77d344d | 13 | |
yueee_yt | 0:7dcfd77d344d | 14 | TextLCD lcd(p24, p26, p27, p28, p29, p30); |
twinkling | 1:7097c8844b71 | 15 | EthernetNetIf ethif(IpAddr(192,168,11,26), IpAddr(255,255,255,0), IpAddr(192,168,11,1), IpAddr(192,168,11,1)); |
yueee_yt | 0:7dcfd77d344d | 16 | HTTPServer server; |
yueee_yt | 0:7dcfd77d344d | 17 | LocalFileSystem local("local"); |
twinkling | 1:7097c8844b71 | 18 | FILE *fp; |
twinkling | 1:7097c8844b71 | 19 | |
twinkling | 1:7097c8844b71 | 20 | void int_rise() { |
twinkling | 1:7097c8844b71 | 21 | led4 = 1; |
twinkling | 1:7097c8844b71 | 22 | if ( NULL == (fp = fopen( "/local/test.txt", "w" )) ) |
twinkling | 1:7097c8844b71 | 23 | error( "" ); |
twinkling | 1:7097c8844b71 | 24 | fprintf( fp, "st detect"); |
twinkling | 1:7097c8844b71 | 25 | lcd.locate(0,1); |
twinkling | 1:7097c8844b71 | 26 | lcd.printf("Detect"); |
twinkling | 1:7097c8844b71 | 27 | wait( 0.1 ); |
twinkling | 1:7097c8844b71 | 28 | fclose( fp ); |
twinkling | 1:7097c8844b71 | 29 | } |
twinkling | 1:7097c8844b71 | 30 | void int_fall() { |
twinkling | 1:7097c8844b71 | 31 | led4 = 0; |
twinkling | 1:7097c8844b71 | 32 | if ( NULL == (fp = fopen( "/local/test.txt", "w" )) ) |
twinkling | 1:7097c8844b71 | 33 | error( "" ); |
twinkling | 1:7097c8844b71 | 34 | fprintf( fp, "%st undetect"); |
twinkling | 1:7097c8844b71 | 35 | lcd.locate(0,1); |
twinkling | 1:7097c8844b71 | 36 | lcd.printf("Undetect"); |
twinkling | 1:7097c8844b71 | 37 | wait( 0.1 ); |
twinkling | 1:7097c8844b71 | 38 | fclose( fp ); |
twinkling | 1:7097c8844b71 | 39 | } |
yueee_yt | 0:7dcfd77d344d | 40 | |
yueee_yt | 0:7dcfd77d344d | 41 | int main(void) { |
twinkling | 1:7097c8844b71 | 42 | |
yueee_yt | 0:7dcfd77d344d | 43 | Base::add_rpc_class<DigitalOut>(); |
yueee_yt | 0:7dcfd77d344d | 44 | |
yueee_yt | 0:7dcfd77d344d | 45 | lcd.cls(); |
yueee_yt | 0:7dcfd77d344d | 46 | lcd.locate(0,0); |
yueee_yt | 0:7dcfd77d344d | 47 | lcd.printf("Program init.. "); |
yueee_yt | 0:7dcfd77d344d | 48 | |
yueee_yt | 0:7dcfd77d344d | 49 | if (ethif.setup()) { |
yueee_yt | 0:7dcfd77d344d | 50 | error("Ethernet setup failed."); |
yueee_yt | 0:7dcfd77d344d | 51 | return 1; |
yueee_yt | 0:7dcfd77d344d | 52 | } |
twinkling | 1:7097c8844b71 | 53 | |
twinkling | 1:7097c8844b71 | 54 | led1=1; |
twinkling | 1:7097c8844b71 | 55 | wait(1); |
twinkling | 1:7097c8844b71 | 56 | led1=0; |
twinkling | 1:7097c8844b71 | 57 | server.addHandler<SimpleHandler>("/hello"); |
twinkling | 1:7097c8844b71 | 58 | server.addHandler<RPCHandler>("/rpc"); |
twinkling | 1:7097c8844b71 | 59 | FSHandler::mount("/local", "/"); |
twinkling | 1:7097c8844b71 | 60 | server.addHandler<FSHandler>("/"); |
twinkling | 1:7097c8844b71 | 61 | server.bind(80); |
twinkling | 1:7097c8844b71 | 62 | |
twinkling | 1:7097c8844b71 | 63 | pin5.rise(&int_rise); // attach the address of the flip function to the rising edge |
twinkling | 1:7097c8844b71 | 64 | pin5.fall(&int_fall); |
twinkling | 1:7097c8844b71 | 65 | |
twinkling | 1:7097c8844b71 | 66 | lcd.locate(0,0); |
twinkling | 1:7097c8844b71 | 67 | lcd.printf("Now mode is "); |
yueee_yt | 0:7dcfd77d344d | 68 | |
twinkling | 1:7097c8844b71 | 69 | int volt[2000]; |
twinkling | 1:7097c8844b71 | 70 | int a[5]; |
twinkling | 1:7097c8844b71 | 71 | int n=0, m=0, p=0, v=0, q=0; |
twinkling | 1:7097c8844b71 | 72 | int v1, v2, v3; |
twinkling | 1:7097c8844b71 | 73 | int min; |
twinkling | 1:7097c8844b71 | 74 | check = 0; |
twinkling | 1:7097c8844b71 | 75 | |
twinkling | 1:7097c8844b71 | 76 | adc.setup(p19,1); |
twinkling | 1:7097c8844b71 | 77 | volt_max=0; |
twinkling | 1:7097c8844b71 | 78 | mled1 = 1; |
twinkling | 1:7097c8844b71 | 79 | Base::add_rpc_class<DigitalOut>(); |
twinkling | 1:7097c8844b71 | 80 | |
twinkling | 1:7097c8844b71 | 81 | lcd.cls(); |
twinkling | 1:7097c8844b71 | 82 | lcd.locate(0,0); |
twinkling | 1:7097c8844b71 | 83 | lcd.printf("Program init.. "); |
twinkling | 1:7097c8844b71 | 84 | |
twinkling | 1:7097c8844b71 | 85 | if (ethif.setup()) { |
twinkling | 1:7097c8844b71 | 86 | error("Ethernet setup failed."); |
twinkling | 1:7097c8844b71 | 87 | return 1; |
twinkling | 1:7097c8844b71 | 88 | } |
twinkling | 1:7097c8844b71 | 89 | |
yueee_yt | 0:7dcfd77d344d | 90 | wait(1); |
yueee_yt | 0:7dcfd77d344d | 91 | server.addHandler<SimpleHandler>("/hello"); |
yueee_yt | 0:7dcfd77d344d | 92 | server.addHandler<RPCHandler>("/rpc"); |
yueee_yt | 0:7dcfd77d344d | 93 | FSHandler::mount("/local", "/"); |
yueee_yt | 0:7dcfd77d344d | 94 | server.addHandler<FSHandler>("/"); |
yueee_yt | 0:7dcfd77d344d | 95 | server.bind(80); |
twinkling | 1:7097c8844b71 | 96 | |
twinkling | 1:7097c8844b71 | 97 | while(1){ |
yueee_yt | 0:7dcfd77d344d | 98 | Net::poll(); |
yueee_yt | 0:7dcfd77d344d | 99 | } |
yueee_yt | 0:7dcfd77d344d | 100 | } |