Ika Shouyu Poppoyaki - LPC82x supported
Fork of ika_shouyu_poppoyaki by
command_interface.cpp@29:96e28bc1bd99, 2013-09-20 (annotated)
- Committer:
- okano
- Date:
- Fri Sep 20 01:48:26 2013 +0000
- Revision:
- 29:96e28bc1bd99
- Parent:
- 27:2b5c1eb39bb5
- Child:
- 30:e0d7524661ca
parameter added to writing and verifying functions to report transferred size
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 22:bd98a782fba6 | 1 | #include "mbed.h" |
okano | 22:bd98a782fba6 | 2 | #include "command_interface.h" |
okano | 22:bd98a782fba6 | 3 | #include "serial_utilities.h" |
okano | 22:bd98a782fba6 | 4 | #include "ika.h" |
okano | 29:96e28bc1bd99 | 5 | #include "_user_settings.h" |
okano | 22:bd98a782fba6 | 6 | |
okano | 22:bd98a782fba6 | 7 | |
okano | 22:bd98a782fba6 | 8 | int try_and_check( char *command, char *expected_return_str, int mode ) |
okano | 22:bd98a782fba6 | 9 | { |
okano | 22:bd98a782fba6 | 10 | char rtn_str[ STR_BUFF_SIZE ]; |
okano | 22:bd98a782fba6 | 11 | int result = 1; |
okano | 22:bd98a782fba6 | 12 | |
okano | 22:bd98a782fba6 | 13 | print_command( command ); |
okano | 22:bd98a782fba6 | 14 | put_string( command ); |
okano | 22:bd98a782fba6 | 15 | |
okano | 22:bd98a782fba6 | 16 | get_string( rtn_str ); |
okano | 22:bd98a782fba6 | 17 | print_result( result = strcmp( expected_return_str, rtn_str ) ); |
okano | 22:bd98a782fba6 | 18 | |
okano | 22:bd98a782fba6 | 19 | if ( result && !mode ) |
okano | 22:bd98a782fba6 | 20 | error( "command failed\r\n" ); |
okano | 22:bd98a782fba6 | 21 | |
okano | 22:bd98a782fba6 | 22 | error_state |= result; |
okano | 22:bd98a782fba6 | 23 | |
okano | 22:bd98a782fba6 | 24 | return ( result ); |
okano | 22:bd98a782fba6 | 25 | } |
okano | 22:bd98a782fba6 | 26 | |
okano | 22:bd98a782fba6 | 27 | |
okano | 22:bd98a782fba6 | 28 | int try_and_check2( char *command, char *expected_return_str, int mode ) |
okano | 22:bd98a782fba6 | 29 | { |
okano | 22:bd98a782fba6 | 30 | char rtn_str[ STR_BUFF_SIZE ]; |
okano | 22:bd98a782fba6 | 31 | int result = 1; |
okano | 22:bd98a782fba6 | 32 | |
okano | 22:bd98a782fba6 | 33 | print_command( command ); |
okano | 22:bd98a782fba6 | 34 | put_string( command ); |
okano | 22:bd98a782fba6 | 35 | |
okano | 22:bd98a782fba6 | 36 | get_string( rtn_str ); // just readout echoback |
okano | 22:bd98a782fba6 | 37 | get_string( rtn_str ); |
okano | 22:bd98a782fba6 | 38 | print_result( result = strcmp( expected_return_str, rtn_str ) ); |
okano | 22:bd98a782fba6 | 39 | |
okano | 22:bd98a782fba6 | 40 | if ( result && !mode ) |
okano | 22:bd98a782fba6 | 41 | error( "command failed\r\n" ); |
okano | 22:bd98a782fba6 | 42 | |
okano | 22:bd98a782fba6 | 43 | error_state |= result; |
okano | 22:bd98a782fba6 | 44 | |
okano | 22:bd98a782fba6 | 45 | return ( result ); |
okano | 22:bd98a782fba6 | 46 | } |
okano | 22:bd98a782fba6 | 47 | |
okano | 22:bd98a782fba6 | 48 | |
okano | 22:bd98a782fba6 | 49 | void print_command( char *command ) |
okano | 22:bd98a782fba6 | 50 | { |
okano | 22:bd98a782fba6 | 51 | char s[ STR_BUFF_SIZE ]; |
okano | 22:bd98a782fba6 | 52 | char *pos; |
okano | 22:bd98a782fba6 | 53 | |
okano | 22:bd98a782fba6 | 54 | strcpy( s, command ); |
okano | 22:bd98a782fba6 | 55 | |
okano | 22:bd98a782fba6 | 56 | if ( pos = strchr( s, '\r' ) ) |
okano | 22:bd98a782fba6 | 57 | *pos = '\0'; |
okano | 22:bd98a782fba6 | 58 | |
okano | 22:bd98a782fba6 | 59 | if ( pos = strchr( s, '\n' ) ) |
okano | 22:bd98a782fba6 | 60 | *pos = '\0'; |
okano | 22:bd98a782fba6 | 61 | |
okano | 22:bd98a782fba6 | 62 | printf( " command-\"%s\" : ", s ); |
okano | 22:bd98a782fba6 | 63 | } |
okano | 22:bd98a782fba6 | 64 | |
okano | 22:bd98a782fba6 | 65 | |
okano | 22:bd98a782fba6 | 66 | void print_result( int r ) |
okano | 22:bd98a782fba6 | 67 | { |
okano | 22:bd98a782fba6 | 68 | printf( "%s\r\n", r ? "Fail" : "Pass" ); |
okano | 22:bd98a782fba6 | 69 | } |
okano | 22:bd98a782fba6 | 70 | |
okano | 22:bd98a782fba6 | 71 | |
okano | 27:2b5c1eb39bb5 | 72 | int send_RAM_transfer_checksum( int checksum ) |
okano | 22:bd98a782fba6 | 73 | { |
okano | 22:bd98a782fba6 | 74 | char command[ 16 ]; |
okano | 22:bd98a782fba6 | 75 | |
okano | 22:bd98a782fba6 | 76 | sprintf( command, "%d\n", checksum ); |
okano | 27:2b5c1eb39bb5 | 77 | |
okano | 27:2b5c1eb39bb5 | 78 | return ( try_and_check( command, "OK", 0 ) ); |
okano | 22:bd98a782fba6 | 79 | } |
okano | 22:bd98a782fba6 | 80 | |
okano | 22:bd98a782fba6 | 81 | |
okano | 27:2b5c1eb39bb5 | 82 | int erase_sectors( int last_sector ) |
okano | 26:a63e73885b21 | 83 | { |
okano | 26:a63e73885b21 | 84 | char command_str[ STR_BUFF_SIZE ]; |
okano | 22:bd98a782fba6 | 85 | |
okano | 26:a63e73885b21 | 86 | sprintf( command_str, "P 0 %d\r\n", last_sector ); |
okano | 27:2b5c1eb39bb5 | 87 | if ( try_and_check( command_str, "0", 0 ) ) |
okano | 27:2b5c1eb39bb5 | 88 | return ( 1 ); |
okano | 26:a63e73885b21 | 89 | |
okano | 26:a63e73885b21 | 90 | *(command_str) = 'E'; |
okano | 27:2b5c1eb39bb5 | 91 | return ( try_and_check( command_str, "0", 0 ) ); |
okano | 26:a63e73885b21 | 92 | } |
okano | 26:a63e73885b21 | 93 | |
okano | 26:a63e73885b21 | 94 |