Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: handlers.cpp
- Revision:
- 6:e510aab8f2ce
- Parent:
- 3:32e67d121c7f
- Child:
- 7:c268547fb6c8
--- a/handlers.cpp Fri Jul 12 22:55:02 2013 +0000 +++ b/handlers.cpp Sat Jul 13 18:02:38 2013 +0000 @@ -6,4 +6,97 @@ *state = sel - '0'; //select a mode else *state = MODE_IDLE; +} + + +int parse_phase(char* line_buf, char* adam_pha) +{ + + char temp = 0; + + if(line_buf[3] == LINEBUF_EMPTY) + return PARSE_EMPTY; //empty line + if(line_buf[3] == LINEBUF_TOOLONG) + return PARSE_LONG; //buffer too long + + if(line_buf[0] == '0') + { + if(line_buf[1] == 255 && line_buf[2] == 255) + { + *adam_pha = 0; + return PARSE_OK; + } + else + return PARSE_ERR; //value is zero + } + + + + + if(line_buf[1]>='0' && line_buf[1]<='4' && line_buf[2]>='0'&& line_buf[2]<='9' && line_buf[0] == '-') + { + temp = (line_buf[1] - '0')*10; + temp += line_buf[2] - '0'; + *adam_pha = temp/7; + + if(temp % 7 == 0) + return PARSE_OK; + else + return PARSE_ROUNDED; + } //double digit input + else if(line_buf[2] == 255 && line_buf[1]>='0' && line_buf[1] <= '9' && line_buf[0] == '-') + { + temp = line_buf[1] - '0'; + *adam_pha = temp/7; + + if(temp % 7 == 0) + return PARSE_OK; + else + return PARSE_ROUNDED; + } //single digit input + else + return PARSE_ERR; +} + +int parse_amp(char* line_buf, char* adam_amp) +{ + + char temp = 0; + + if(line_buf[3] == LINEBUF_EMPTY) + return PARSE_EMPTY; + if(line_buf[3] == LINEBUF_TOOLONG) + return PARSE_LONG; + + if(line_buf[0] == '0') + { + if((line_buf[1] == 255 && line_buf[2] == 255) ||(line_buf[1] == '.' && line_buf[2] == '0')) + { + *adam_amp = 0; + return PARSE_OK; + } + else + return PARSE_ERR; + } //zero input + if(line_buf[0]>='0' && line_buf[0]<='7' && line_buf[1] == 255 && line_buf[2] == 255) + { + temp = (line_buf[0] - '0')*10; + *adam_amp = temp/5; + return PARSE_OK; + } //single digit input + else if(line_buf[0]>='0' && line_buf[0]<='7' && line_buf[2]>='0'&& line_buf[2]<='9' && line_buf[1] == '.') + { + temp = (line_buf[0] - '0')*10; + temp += line_buf[2] - '0'; + *adam_amp = temp / 5; + + if(temp % 5 == 0) + return PARSE_OK; + else + return PARSE_ROUNDED; + } + else + return PARSE_ERR; + + } \ No newline at end of file