Add to 11U68 11E68

Dependencies:   DirectoryList MODSERIAL mbed

Fork of ika_shouyu_poppoyaki by Tedd OKANO

Committer:
okano
Date:
Fri Sep 20 02:21:58 2013 +0000
Revision:
30:e0d7524661ca
Parent:
29:96e28bc1bd99
Child:
35:0b434ef4af49
** version 0.95. redundant code and files are removed

Who changed what in which revision?

UserRevisionLine numberNew 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 29:96e28bc1bd99 4 #include "_user_settings.h"
okano 22:bd98a782fba6 5
okano 22:bd98a782fba6 6
okano 22:bd98a782fba6 7 int try_and_check( char *command, char *expected_return_str, int mode )
okano 22:bd98a782fba6 8 {
okano 22:bd98a782fba6 9 char rtn_str[ STR_BUFF_SIZE ];
okano 22:bd98a782fba6 10 int result = 1;
okano 22:bd98a782fba6 11
okano 22:bd98a782fba6 12 print_command( command );
okano 22:bd98a782fba6 13 put_string( command );
okano 22:bd98a782fba6 14
okano 22:bd98a782fba6 15 get_string( rtn_str );
okano 22:bd98a782fba6 16 print_result( result = strcmp( expected_return_str, rtn_str ) );
okano 22:bd98a782fba6 17
okano 22:bd98a782fba6 18 if ( result && !mode )
okano 22:bd98a782fba6 19 error( "command failed\r\n" );
okano 22:bd98a782fba6 20
okano 22:bd98a782fba6 21 return ( result );
okano 22:bd98a782fba6 22 }
okano 22:bd98a782fba6 23
okano 22:bd98a782fba6 24
okano 22:bd98a782fba6 25 int try_and_check2( char *command, char *expected_return_str, int mode )
okano 22:bd98a782fba6 26 {
okano 22:bd98a782fba6 27 char rtn_str[ STR_BUFF_SIZE ];
okano 22:bd98a782fba6 28 int result = 1;
okano 22:bd98a782fba6 29
okano 22:bd98a782fba6 30 print_command( command );
okano 22:bd98a782fba6 31 put_string( command );
okano 22:bd98a782fba6 32
okano 22:bd98a782fba6 33 get_string( rtn_str ); // just readout echoback
okano 22:bd98a782fba6 34 get_string( rtn_str );
okano 22:bd98a782fba6 35 print_result( result = strcmp( expected_return_str, rtn_str ) );
okano 22:bd98a782fba6 36
okano 22:bd98a782fba6 37 if ( result && !mode )
okano 22:bd98a782fba6 38 error( "command failed\r\n" );
okano 22:bd98a782fba6 39
okano 22:bd98a782fba6 40 return ( result );
okano 22:bd98a782fba6 41 }
okano 22:bd98a782fba6 42
okano 22:bd98a782fba6 43
okano 22:bd98a782fba6 44 void print_command( char *command )
okano 22:bd98a782fba6 45 {
okano 22:bd98a782fba6 46 char s[ STR_BUFF_SIZE ];
okano 22:bd98a782fba6 47 char *pos;
okano 22:bd98a782fba6 48
okano 22:bd98a782fba6 49 strcpy( s, command );
okano 22:bd98a782fba6 50
okano 22:bd98a782fba6 51 if ( pos = strchr( s, '\r' ) )
okano 22:bd98a782fba6 52 *pos = '\0';
okano 22:bd98a782fba6 53
okano 22:bd98a782fba6 54 if ( pos = strchr( s, '\n' ) )
okano 22:bd98a782fba6 55 *pos = '\0';
okano 22:bd98a782fba6 56
okano 22:bd98a782fba6 57 printf( " command-\"%s\" : ", s );
okano 22:bd98a782fba6 58 }
okano 22:bd98a782fba6 59
okano 22:bd98a782fba6 60
okano 22:bd98a782fba6 61 void print_result( int r )
okano 22:bd98a782fba6 62 {
okano 22:bd98a782fba6 63 printf( "%s\r\n", r ? "Fail" : "Pass" );
okano 22:bd98a782fba6 64 }
okano 22:bd98a782fba6 65
okano 22:bd98a782fba6 66
okano 27:2b5c1eb39bb5 67 int send_RAM_transfer_checksum( int checksum )
okano 22:bd98a782fba6 68 {
okano 22:bd98a782fba6 69 char command[ 16 ];
okano 22:bd98a782fba6 70
okano 22:bd98a782fba6 71 sprintf( command, "%d\n", checksum );
okano 27:2b5c1eb39bb5 72
okano 27:2b5c1eb39bb5 73 return ( try_and_check( command, "OK", 0 ) );
okano 22:bd98a782fba6 74 }
okano 22:bd98a782fba6 75
okano 22:bd98a782fba6 76
okano 27:2b5c1eb39bb5 77 int erase_sectors( int last_sector )
okano 26:a63e73885b21 78 {
okano 26:a63e73885b21 79 char command_str[ STR_BUFF_SIZE ];
okano 22:bd98a782fba6 80
okano 26:a63e73885b21 81 sprintf( command_str, "P 0 %d\r\n", last_sector );
okano 27:2b5c1eb39bb5 82 if ( try_and_check( command_str, "0", 0 ) )
okano 27:2b5c1eb39bb5 83 return ( 1 );
okano 26:a63e73885b21 84
okano 26:a63e73885b21 85 *(command_str) = 'E';
okano 27:2b5c1eb39bb5 86 return ( try_and_check( command_str, "0", 0 ) );
okano 26:a63e73885b21 87 }
okano 26:a63e73885b21 88
okano 26:a63e73885b21 89