示例#1
0
uint8_t fsmanInit(uint8_t * result_code, uint8_t* buffer){
    
    struct tm ts;
    
    fsbuf =  buffer;
    RTC_GetTimeDateDecimal(&ts);
    SetClockVars (ts.tm_year, ts.tm_mon, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec);
    
    fsmanInitHardwareSD();
    if (!fsmanMountSD(result_code)){
        
        *result_code = UNKNOWN_SD_MOUNT_ERROR;//from FILEIO_ERROR_TYPE
        return 0;
    }

    //Create a VI_LOG directory if there isnt already one

    if(FSchdir("VI_LOG") != CE_GOOD){
        __debug("VI_LOG Directory was not found, creating it");    
        if(FSmkdir(".\\VI_LOG") != CE_GOOD){
            __debug("Unable to create a VI_LOG directory");
             *result_code = UNKNOWN_WRITE_ERROR;
            return 0;
        }
        else{
            if(FSchdir ("VI_LOG") != CE_GOOD){
                *result_code = UNKNOWN_WRITE_ERROR;
                __debug("VI_LOG Directory was created but not found");
                return 0;
            }
        }
    }
    return 1;
}
示例#2
0
uint8_t fsmanSessionStart(uint8_t * result_code){
    //open file here
    char file_name[25];
    struct tm ts;
    
    uint32_t tm_code;
    
    tm_code =  (uint32_t)RTC_GetTimeDateUnix();
    
    RTC_GetTimeDateDecimal(&ts);
    
    SetClockVars (ts.tm_year, ts.tm_mon, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec);
    
    sprintf(file_name,"%X.TXT", tm_code);
                            
    __debug("Creating %s",file_name);
    
    file = FSfopen (file_name,"w");
    
    if (file == NULL){
        *result_code = UNKNOWN_WRITE_ERROR;
        return FALSE;
    }
    return TRUE;
}
示例#3
0
/*=====================================================================================================================
 * Parameters: void
 *
 * Return: void
 *
 * Description: 
 *===================================================================================================================*/
HRESULT FSIOMain_SetTimeDate(tNMEA_GPS_Data *GpsData)
{
    S16 s16res;
    HRESULT res = S_NOK;

    s16res = SetClockVars( GpsData->DateTime.tm_year, 
                           GpsData->DateTime.tm_mon,
                           GpsData->DateTime.tm_mday,
                           GpsData->DateTime.tm_hour,
                           GpsData->DateTime.tm_min, 
                           GpsData->DateTime.tm_sec);
    if(s16res != -1)
        res = S_OK;

    return res;
}
示例#4
0
/******************************************************************************
 * Main Program Loop
 ******************************************************************************/
void main(void) {
    // SD Card variables
    FSFILE *csv_file; // The file to write to
    SearchRec rec; // The data structure to store the search results
    UINT8 i=0;
    char filename[] = "ACCEL00.CSV";
    char file_number[2];
    char attr0[] = "w";
    char attr1[] = "a";
    char headers[] = "X,Y,Z\n";
    char rangeString[] = "range=00\n";
    char buf[6] = "";
    ADXL345_AXIS_DATA *temp;
    UINT8 range = 0x03;    // The range to use the accelerometer with (initialize with a mask for the pins)
    boolean selfTest = FALSE;   // Selftest enable flag for the accelerometer (initialize with false)

    /*
     * Initialize the program
     */

    // TODO: Fix function prototype warning
    // Initialize the processor and peripherals
    config_proc();
    Delay10KTCYx(4);
    i2c_init();
    printf("\n\n\rProcessor Configuration Complete\n\r");
    printf("Delaying for 5...");
    Delay10KTCYx(FOSC);
    printf("4...");
    Delay10KTCYx(FOSC);
    printf("3...");
    Delay10KTCYx(FOSC);
    printf("2...");
    Delay10KTCYx(FOSC);
    printf("1...");
    Delay10KTCYx(FOSC);
    printf("0...\n\r");

    // Initialize the SD Card and set a default clock
    printf("Initializing SD Card\n\r");
    while (!FSInit()) {
        printf("Error Initializing SD Card: %d\n\r", FSerror());
    }
    if (SetClockVars (2013, 1, 1, 12, 0, 00))
        printf("Clock not set\n\r"); // It didn't work

    // Read the accelerometer range from the pins and make a string to say what it is
    range = range & ~( ( PORTAbits.RA0 << 1) | PORTAbits.RA1 );
    printf("Determining range setting\n\r");
    switch (range) {
        case ADXL345_RANGE_2G:
            rangeString[6] = '0';
            rangeString[7] = '2';
            break;
        case ADXL345_RANGE_4G:
            rangeString[6] = '0';
            rangeString[7] = '4';
            break;
        case ADXL345_RANGE_8G:
            rangeString[6] = '0';
            rangeString[7] = '8';
            break;
        case ADXL345_RANGE_16G:
            rangeString[6] = '1';
            rangeString[7] = '6';
            break;
        default:
            // Just leave the range as 00 to show an error condition has occured
            break;
    }
    printf("%s\r", rangeString);
    
    /*
     * Determine the filename to use for the new file.
     * The filename should be "accelx" where x is the next available integer.
     */
    // This code section causes the PIC to crash for some reason,
    // It was used previosuly so I have no idea what is going on
/*    printf("Searching for files\n\r");
    if (FindFirstpgm("accel*.csv", ATTR_MASK, &rec) == -1) {
        // No file was found so leave it at the default filename
        printf("No files found\n\r");
    } else {
        printf("Files found\n\r");
        // Files were found, so find the next unused number
        do{
            file_number[0] = rec.filename[5];
            file_number[1] = rec.filename[6];
        } while (FindNext(&rec) == 0);
        if(file_number[1] == '9') {
            file_number[0]++;
            file_number[1] = '0';
        } else {
            file_number[1]++;
        }
        filename[5] = file_number[0];
        filename[6] = file_number[1];
    }
 */
    // Open the file using the above name
    printf("Opening file %s\n\r",filename);
    csv_file = FSfopen(filename, attr0);
    if (csv_file == NULL) 
        printf("File not opened, error: %u\n\r",FSerror());

    // Write a header to the file saying the current measurement range
    if (FSfwrite((void*)rangeString , 1, 9, csv_file) != 9)
        printf("Unable to write measurement range to the file\n\r");

    // Write the column headers into the file
    if (FSfwrite((void *)headers, 1, 6, csv_file) != 6)
        printf("Unable to write headers to the file\n\r");

    // Close the file
    if (FSfclose(csv_file))
        printf("Unable to close file\n\r");

    /*
     * Perform configuration on the accelerometer
     */

    // Enable the selftest if neccessary
    if (PORTAbits.RA2 == 0) {
        selfTest = TRUE;
    }

    config_accel(range);
    printf("Accelerometer Configuration Complete\n\r");

    // Main program loop
    while(1)
    {
#ifdef PRINT_DEBUGS
printf("Waiting for watermark\n\r");
#endif

        // Loop and do nothing while waiting for the watermark to be triggered
        while (ADXL345_INT1_PORT == 0){};
        LATCbits.LATC1 = 1;     // Turn on the LED to show we are processing data

#ifdef PRINT_DEBUGS
printf("Watermark Received\n\r");
#endif
        // Read in the data
        for(i=0; i<12; i++) {
            // Read the data
            adxl345_data_read(temp);
#ifdef PRINT_DEBUGS
printf("%i, %i, %i\n\r", temp->x, temp->y, temp->z);
#endif
            // Convert the x-axis data into text
            padded_itoa(buf, temp->x);
            sendBuffer[(18*i)+0] = buf[0];
            sendBuffer[(18*i)+1] = buf[1];
            sendBuffer[(18*i)+2] = buf[2];
            sendBuffer[(18*i)+3] = buf[3];
            sendBuffer[(18*i)+4] = buf[4];
            sendBuffer[(18*i)+5] = ',';

            // Convert the y-axis data into text
            padded_itoa(buf, temp->y);
            sendBuffer[(18*i)+6] = buf[0];
            sendBuffer[(18*i)+7] = buf[1];
            sendBuffer[(18*i)+8] = buf[2];
            sendBuffer[(18*i)+9] = buf[3];
            sendBuffer[(18*i)+10] = buf[4];
            sendBuffer[(18*i)+11] = ',';

            // Convert the z-axis data into text
            padded_itoa(buf, temp->z);
            sendBuffer[(18*i)+12] = buf[0];
            sendBuffer[(18*i)+13] = buf[1];
            sendBuffer[(18*i)+14] = buf[2];
            sendBuffer[(18*i)+15] = buf[3];
            sendBuffer[(18*i)+16] = buf[4];
            sendBuffer[(18*i)+17] = '\n';
        }
        csv_file = FSfopen(filename, attr1);
        if (csv_file == NULL)
            printf("File not opened, error: %u\n\r",FSerror());
        
        FSfwrite((void *) sendBuffer, 1, 216, csv_file);
        
        FSfclose(csv_file);
        LATCbits.LATC1 = 0;
    }
}