C Language Development Kit/Functions/RunApplFromFile

From OptiWiki

Jump to: navigation, search
Description This function loads a file, pointed to by filename, in the application flash memory of the handheld terminal, and then restarts the handheld terminal. The function is useful for application maintenance. It is more secure than the related function

downloadapplication().

Syntax
int runapplfromfile(char * filename);
Arguments
char * filename
char *filename
Returns On successful execution of runapplfromfile(), the application in filename will be running.
-1 filename is not an S2 file or contains an error.
-2 The application in filename is built for a different type of handheld terminal.
-3 The application in filename needs a higher version of the operating system.
-4 filename does not exist.
Remarks A new application file (e.g. APPL.S2) can be uploaded to the handheld terminal by any means. The application can verify the integrity of the transfer.

When the transfer was successful, the application can call runapplfromfile(). This way, the application remains in complete control, until the new application is uploaded correctly. runapplfromfile() first performs a number of checks on the contents of filename. If errors are found, runapplfromfile() does not erase the old application, but returns with an error code.

OPH100x: Unless explicitly specified by the file name (i.e. "A:APPL.S2"), the selected application is read from the default drive. Use the function set_default_drive to select that drive.

Example
#include "lib.h"
#include <stdio.h>
#include <stdlib.h>
 
int received_file( char (*filename)[12+1] )
{
    int returncode;
 
    cursor( NOWRAP );
    printf("\fSend application\nby upload.exe");
    systemsetting("K7");    // 19200 baud
    comopen( COM1 );        // IrDA / Cradle
 
    returncode = neto_receive2( filename, "&&&&&&", 10*50, CLR_KEY, 3);
    // Receive S2 file.
    // On PC: Send one S2 file to terminal by using UPLOAD.EXE
    comclose( COM1 );
    return( returncode > 0 );
}
 
void main( void )
{
    char filename[1][12+1];
    int errorcode;
 
    while( 1 )
    {
        while( !received_file( filename ))
            delay( 50 );
 
        errorcode = runapplfromfile( filename[0] );
        printf("\frunapplfromfile\nwent wrong");
        printf("\n\nerror = %d",errorcode);
        delay(2*50);
    }
}


Views
Personal tools