EMIR - Ekvitermní mikroprocesorová regulace https://code.google.com/p/emir/ https://code.google.com/p/emir/wiki/DesignV3

Dependencies:   ConfigFile DS1307 OneWire SDFileSystem USBDeviceLite mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers comm.cpp Source File

comm.cpp

00001 #include "mbed.h"
00002 #include "rtos.h"
00003 #include "USBSerial.h"
00004 #include "rtc.h"
00005 #include "sensor.h"
00006 #include "comm.h"
00007 
00008 void comm_thread(void const *args)
00009 {
00010     USBSerial usb(0x1f00, 0x2012, 0x0001, false);
00011     Timer t;
00012     char c;
00013     
00014     while (1) 
00015     {
00016         c = usb.getc();
00017 
00018         if (c == 'r') {
00019             //  perform read
00020             t.reset();
00021             t.start();
00022             time_t m_time = get_rtc();
00023             t.stop();
00024 
00025             struct tm *now;
00026             now = localtime(&m_time);
00027             
00028             usb.printf("Current time is %lu, %02d:%02d:%02d, %d.%d.%04d\n", 
00029                 m_time, 
00030                 now->tm_hour, now->tm_min, now->tm_sec, 
00031                 now->tm_mday, now->tm_mon+1, now->tm_year+1900
00032             );
00033             usb.printf("Internal datetime format is %s\n", asctime(now));
00034             usb.printf("Read complete, elapsed %uus\n", t.read_us());
00035             
00036         }
00037         else if (c == 'i') {
00038             //  perform read
00039             time_t m_time = time(NULL);
00040 
00041             struct tm *now;
00042             now = localtime(&m_time);
00043             
00044             usb.printf("Internal datetime format is %s\n", asctime(now));
00045         }
00046         else if (c == 'w') {
00047             //  perform write
00048             int date, month, year, hours, minutes, seconds;
00049             usb.printf("Enter the date (date 1..31)\n"); usb.scanf("%d", &date);
00050             usb.printf("Enter the date (month 1..12)\n"); usb.scanf("%d", &month);
00051             usb.printf("Enter the date (year >2000)\n"); usb.scanf("%d", &year);
00052             usb.printf("Enter the time (hours 0..23)\n"); usb.scanf("%d", &hours);
00053             usb.printf("Enter the time (minutes 0..59)\n"); usb.scanf("%d", &minutes);
00054             usb.printf("Enter the time (seconds 0..59)\n"); usb.scanf("%d", &seconds);
00055             
00056             struct tm now = {seconds, minutes, hours, date, month-1, year-1900};
00057             time_t m_time = mktime(&now);
00058                 
00059             t.reset();
00060             t.start();
00061             bool b = set_rtc(m_time);
00062             t.stop();
00063             
00064             usb.printf("Write complete (UNIX %lu, result %d), elapsed %uus\n", m_time, b, t.read_us());
00065         }
00066         else if (c == 't') {
00067             sensor_mutex.lock();
00068             for (int j = 0; j < sensor_count; j++) {
00069                 for (int i = 0; i < 8; i++) usb.printf("%.2X", sensor_roms[j][i]);
00070                 usb.printf(": temperature %.2f'C\n", sensor_temps[j] / 100.);
00071             }
00072             sensor_mutex.unlock();
00073             usb.printf("Done\n");
00074         }
00075         else {
00076             usb.printf("Syntax error, use {r|i|w|t}\n");
00077         }
00078 
00079         usb.printf("\n");
00080     }
00081     
00082 }
00083