![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
JGtoJR
Dependencies: MODSERIAL Watchdog
main.cpp@0:1c1c9f47b8ad, 2017-06-15 (annotated)
- Committer:
- JavierGC
- Date:
- Thu Jun 15 12:01:36 2017 +0000
- Revision:
- 0:1c1c9f47b8ad
JG_to_JR
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JavierGC | 0:1c1c9f47b8ad | 1 | #include "main.h" |
JavierGC | 0:1c1c9f47b8ad | 2 | |
JavierGC | 0:1c1c9f47b8ad | 3 | int main() |
JavierGC | 0:1c1c9f47b8ad | 4 | { |
JavierGC | 0:1c1c9f47b8ad | 5 | pc.start(); |
JavierGC | 0:1c1c9f47b8ad | 6 | |
JavierGC | 0:1c1c9f47b8ad | 7 | if (wd.WatchdogCausedReset()) |
JavierGC | 0:1c1c9f47b8ad | 8 | pc.LoadMail(2,"Watchdog caused reset\r"); |
JavierGC | 0:1c1c9f47b8ad | 9 | |
JavierGC | 0:1c1c9f47b8ad | 10 | pc.LoadMail(2,"starting...\r"); |
JavierGC | 0:1c1c9f47b8ad | 11 | wait_ms(100); |
JavierGC | 0:1c1c9f47b8ad | 12 | |
JavierGC | 0:1c1c9f47b8ad | 13 | Setup(); |
JavierGC | 0:1c1c9f47b8ad | 14 | //set_time(0); |
JavierGC | 0:1c1c9f47b8ad | 15 | |
JavierGC | 0:1c1c9f47b8ad | 16 | while(true) { |
JavierGC | 0:1c1c9f47b8ad | 17 | wd.Service(); |
JavierGC | 0:1c1c9f47b8ad | 18 | wait_ms(10000); |
JavierGC | 0:1c1c9f47b8ad | 19 | } |
JavierGC | 0:1c1c9f47b8ad | 20 | } |
JavierGC | 0:1c1c9f47b8ad | 21 | |
JavierGC | 0:1c1c9f47b8ad | 22 | |
JavierGC | 0:1c1c9f47b8ad | 23 | |
JavierGC | 0:1c1c9f47b8ad | 24 | void GetConfig() |
JavierGC | 0:1c1c9f47b8ad | 25 | { |
JavierGC | 0:1c1c9f47b8ad | 26 | #define CfgNumParam 3 |
JavierGC | 0:1c1c9f47b8ad | 27 | #define CfgSizeParam 50 |
JavierGC | 0:1c1c9f47b8ad | 28 | |
JavierGC | 0:1c1c9f47b8ad | 29 | /*ConfigFile cfg; |
JavierGC | 0:1c1c9f47b8ad | 30 | |
JavierGC | 0:1c1c9f47b8ad | 31 | int i; |
JavierGC | 0:1c1c9f47b8ad | 32 | char Value[CfgNumParam][CfgSizeParam]; |
JavierGC | 0:1c1c9f47b8ad | 33 | char CfgK[CfgNumParam][CfgSizeParam]= {"InitialMessage","LOGPC"}; |
JavierGC | 0:1c1c9f47b8ad | 34 | */ |
JavierGC | 0:1c1c9f47b8ad | 35 | pc.LoadMail(2,"\r* * *\r* * *\r"); |
JavierGC | 0:1c1c9f47b8ad | 36 | wait_ms(100); |
JavierGC | 0:1c1c9f47b8ad | 37 | |
JavierGC | 0:1c1c9f47b8ad | 38 | /* if (!cfg.read("/local/config.cfg")) { |
JavierGC | 0:1c1c9f47b8ad | 39 | error("\rFailure to read a configuration file"); |
JavierGC | 0:1c1c9f47b8ad | 40 | } |
JavierGC | 0:1c1c9f47b8ad | 41 | |
JavierGC | 0:1c1c9f47b8ad | 42 | pc.LoadMail(2,"aqui\r"); |
JavierGC | 0:1c1c9f47b8ad | 43 | wait_ms(1000); |
JavierGC | 0:1c1c9f47b8ad | 44 | |
JavierGC | 0:1c1c9f47b8ad | 45 | char Tstr[10]; |
JavierGC | 0:1c1c9f47b8ad | 46 | for (i=0; i<CfgNumParam; i++) { |
JavierGC | 0:1c1c9f47b8ad | 47 | if (cfg.getValue(CfgK[i], &Value[i][0], sizeof(Value[i]))) { |
JavierGC | 0:1c1c9f47b8ad | 48 | //pc.TLogSTR(Tstr); |
JavierGC | 0:1c1c9f47b8ad | 49 | pc.printf("CFG_Param(%s): '%s'='%s'\r", Tstr,CfgK[i], Value[i]); |
JavierGC | 0:1c1c9f47b8ad | 50 | wait_ms(1000); |
JavierGC | 0:1c1c9f47b8ad | 51 | } else { |
JavierGC | 0:1c1c9f47b8ad | 52 | error("Failure Reading '%s'\r", CfgK[i]); |
JavierGC | 0:1c1c9f47b8ad | 53 | } |
JavierGC | 0:1c1c9f47b8ad | 54 | } |
JavierGC | 0:1c1c9f47b8ad | 55 | */ |
JavierGC | 0:1c1c9f47b8ad | 56 | strcpy(InitialMessage,"MBED Ready");//Value[0]); |
JavierGC | 0:1c1c9f47b8ad | 57 | pc.LOG=false;//(bool)atoi(Value[1]); |
JavierGC | 0:1c1c9f47b8ad | 58 | |
JavierGC | 0:1c1c9f47b8ad | 59 | pc.LoadMail(2,"* * *\r* * *\r"); |
JavierGC | 0:1c1c9f47b8ad | 60 | } |
JavierGC | 0:1c1c9f47b8ad | 61 | |
JavierGC | 0:1c1c9f47b8ad | 62 | |
JavierGC | 0:1c1c9f47b8ad | 63 | void Setup() |
JavierGC | 0:1c1c9f47b8ad | 64 | { |
JavierGC | 0:1c1c9f47b8ad | 65 | GetConfig(); |
JavierGC | 0:1c1c9f47b8ad | 66 | |
JavierGC | 0:1c1c9f47b8ad | 67 | pc.LoadMail(2,"\r"); |
JavierGC | 0:1c1c9f47b8ad | 68 | pc.LoadMail(2,"\r"); |
JavierGC | 0:1c1c9f47b8ad | 69 | pc.LoadMail(2,"\r"); |
JavierGC | 0:1c1c9f47b8ad | 70 | pc.LoadMail(2,"************************************************"); |
JavierGC | 0:1c1c9f47b8ad | 71 | pc.LoadMail(2,InitialMessage); |
JavierGC | 0:1c1c9f47b8ad | 72 | pc.LoadMail(2,"************************************************"); |
JavierGC | 0:1c1c9f47b8ad | 73 | pc.LoadMail(2,"\r"); |
JavierGC | 0:1c1c9f47b8ad | 74 | pc.LoadMail(2,"\r"); |
JavierGC | 0:1c1c9f47b8ad | 75 | pc.LoadMail(2,"\r"); |
JavierGC | 0:1c1c9f47b8ad | 76 | |
JavierGC | 0:1c1c9f47b8ad | 77 | // ************ WD ************* |
JavierGC | 0:1c1c9f47b8ad | 78 | wd.WatchdogCausedReset(); |
JavierGC | 0:1c1c9f47b8ad | 79 | wd.Configure(20.0); |
JavierGC | 0:1c1c9f47b8ad | 80 | // ************ WD_end ********* |
JavierGC | 0:1c1c9f47b8ad | 81 | |
JavierGC | 0:1c1c9f47b8ad | 82 | DigitalOut(LED1,0); |
JavierGC | 0:1c1c9f47b8ad | 83 | DigitalOut(LED2,0); |
JavierGC | 0:1c1c9f47b8ad | 84 | DigitalOut(LED3,0); |
JavierGC | 0:1c1c9f47b8ad | 85 | DigitalOut(LED4,0); |
JavierGC | 0:1c1c9f47b8ad | 86 | } |
JavierGC | 0:1c1c9f47b8ad | 87 | |
JavierGC | 0:1c1c9f47b8ad | 88 | |
JavierGC | 0:1c1c9f47b8ad | 89 | void PCEventHandler(int e, char *data) |
JavierGC | 0:1c1c9f47b8ad | 90 | { |
JavierGC | 0:1c1c9f47b8ad | 91 | switch(e) |
JavierGC | 0:1c1c9f47b8ad | 92 | { |
JavierGC | 0:1c1c9f47b8ad | 93 | case PC::eLOG: |
JavierGC | 0:1c1c9f47b8ad | 94 | pc.LoadMail(1,data); |
JavierGC | 0:1c1c9f47b8ad | 95 | break; |
JavierGC | 0:1c1c9f47b8ad | 96 | default: |
JavierGC | 0:1c1c9f47b8ad | 97 | break; |
JavierGC | 0:1c1c9f47b8ad | 98 | } |
JavierGC | 0:1c1c9f47b8ad | 99 | } |