Fork for Get Started Demo

Dependencies:   DebouncedInterrupt dash7-alp mbed-rtos mbed wizzi-utils

Fork of D7A_Demo_full by WizziLab

main.cpp

Committer:
Jeej
Date:
2015-11-19
Revision:
2:c3cfaa7d5bb8
Parent:
1:49da0144dd4c
Child:
3:b77b01171cc0

File content as of revision 2:c3cfaa7d5bb8:

#include "mbed.h"
#include "rtos.h"
#include "dbg.h"
#include "shield.h"
#include "alp_serial.h"
#include "alp_device.h"
#include "alp_file.h"
#include "alp_report.h"

/*
These data are user defined and will be used by the dash7board
to identify the device
*/

#define __MANUFACTURER_ID__         0x01234567 // Identify the manufacturer
#define __DEVICE_ID__               0x89ABCDEF // Identify the device type

#define __FW_ID__                   0x01 // Device type option

// Software version
#define __FW_MAJOR__                0x02
#define __FW_MINOR__                0x03
#define __FW_PATCH__                0x0005
#define __FW_HASH__                 0x86605dba

#define __HW_ID__                   0x01520C02 // Hardware ID


revision_t revision = {
    // The two first bytes must be present in all reported files
    // They are parsed by the dash7board
    .nw_stat = 0,
    .nw_seq = 255,
    // These data are parsed to identify the device
    .manufacturer_id    = __MANUFACTURER_ID__,
    .device_id          = __DEVICE_ID__,
    .fw_version.fw_id   = __FW_ID__,
    .fw_version.major   = __FW_MAJOR__,
    .fw_version.minor   = __FW_MINOR__,
    .fw_version.patch   = __FW_PATCH__,
    .fw_version.hash    = __FW_HASH__,
    .hw_version         = __HW_ID__,
    .fs_crc             = 0
};

// Checks the status of the report send.
void check_status( AlpReport* report, void* param )
{
    char* message = (char*)param;
    uint8_t status = report->get_status();
    switch (status)
    {
        case ALP_CMD_OK: // message is send and acknowleged
            DPRINT("%s OK\r\n", message);
        break;
        case ALP_CMD_TIMEOUT: // message has not been acknowleged by modem
            DPRINT("%s CMD TIMEOUT\r\n", message);
        break;
        case ALP_CMD_ERROR: // message has been acknowleged by modem but returned an error
            DPRINT("%s CMD ERROR\r\n", message);
        break;
        case ALP_D7_TIMEOUT: // message has not been acknowleged by gateway
            DPRINT("%s D7 TIMEOUT\r\n", message);
        break;
        case ALP_D7_ERROR: // message has been acknowleged by gateway but returned an error
            DPRINT("%s D7 ERROR\r\n", message);
        break;
        default:
            DPRINT("%s UNKNOWN ERROR %d\r\n", message, status);
        break;
    }
}

int main()
{
    // ----- Debug session over USB Serial ----- //
    DBG_OPEN();
        
    // Clear some lines on the terminal
    DPRINT("\r\n\nBOOT\r\n");
    
    // Declare Shield NRST pin
    DigitalOut shield_nrst(PB_0);
    
    // Reset shield
    shield_nrst = 0;
    
    // Open ALP port over serial
    // This is the physical ALP serial port
    AlpSerial serial_shield;

    // Initialize ALP device
    // This creates an AlpDevice object abstracting the shield1001
    // The parameters describe how to access it
    AlpDevice shield(&serial_shield, 0, ACCESS_CLASS_EP, ALP_FILE_BLOCK_ISFB, true);

    // Release reset
    shield_nrst = 1;
    
    // Check the shield boot packets
    shield_check_boot(&shield);
    
    // Wait for Shield to notify its files if there is any
    Thread::wait(1000);
    
    // Add the Report file to the file system
    alp_file_add(REVISION_DEVICE_FILE_ID, REVISION_DEVICE_FILE_SIZE, (uint8_t*)&revision);
    
    // Create the Revision report
    AlpReport report_revision(&shield, REVISION_DEVICE_FILE_ID);
    
    // Attach callback after report is send
    report_revision.attach_after(check_status, (void*)"REPORT REVISION");
    
    // Send the Revision report
    DPRINT("SENDING REPORT REVISION\r\n");
    report_revision.send();
    
    // Set main task to lowest priority
    osThreadSetPriority(osThreadGetId(), osPriorityIdle);
    while(true)
    {
        // Wait to avoid beeing stuck in loop
        Thread::wait(osWaitForever);
    }
}