Skip to content

Commit

Permalink
retrieve device identifiers from HAL and send after each handshake. a…
Browse files Browse the repository at this point in the history
…ddresses FIRM-199
  • Loading branch information
m-mcgowan committed Sep 1, 2015
1 parent 811a9c4 commit 73df5a4
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 3 deletions.
7 changes: 7 additions & 0 deletions hal/inc/cellular_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@
#define CELLULAR_HAL_H

#include <stdint.h>
#include <string.h>

struct CellularDevice
{
uint16_t size;
char iccid[21];
char imei[16];

CellularDevice()
{
memset(this, 0, sizeof(*this));
size = sizeof(*this);
}
};

int cellular_device_info(CellularDevice* device, void* reserved);
Expand Down
7 changes: 7 additions & 0 deletions hal/inc/deviceid_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define DEVICEID_HAL_H

#include <stdint.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -51,6 +52,12 @@ unsigned HAL_device_ID(uint8_t* dest, unsigned destLen);
*/
unsigned HAL_Platform_ID();

/**
*
*/
int HAL_Get_Device_Identifier(const char** name, char* buf, size_t buflen, unsigned index, void* reserved);


#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions hal/src/core/deviceid_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ unsigned HAL_Platform_ID()
{
return PLATFORM_ID;
}

int HAL_Get_Device_Identifier(const char** name, char* buf, size_t buflen, unsigned index, void* reserved)
{
return -1;
}
24 changes: 23 additions & 1 deletion hal/src/electron/deviceid_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,26 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
*/


#include <string.h>
#include "cellular_hal.h"
#include "deviceid_hal.h"


int HAL_Get_Device_Identifier(const char** name, char* buf, size_t buflen, unsigned index, void* reserved)
{
if (index!=0)
return -1;

if (name)
*name = "imei+iccid";

CellularDevice device;
cellular_device_info(&device, NULL);

strcpy(buf, device.imei);
strcat(buf, "-");
strcat(buf, device.iccid);

return 0;
}
25 changes: 25 additions & 0 deletions hal/src/photon/deviceid_hal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
******************************************************************************
* Copyright (c) 2015 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
******************************************************************************
*/

#include "deviceid_hal.h"

int HAL_Get_Device_Identifier(const char** name, char* buf, size_t buflen, unsigned index, void* reserved)
{
return -1;
}
5 changes: 5 additions & 0 deletions system/src/system_cloud_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ int Spark_Handshake(void)
Particle.publish("spark/device/claim/code", buf, 60, PRIVATE);
}

// open up for possibility of retrieving multiple ID datums
if (!HAL_Get_Device_Identifier(NULL, buf, sizeof(buf), 0, NULL) && *buf) {
Particle.publish("spark/device/ident/0", buf, 60, PRIVATE);
}

ultoa(HAL_OTA_FlashLength(), buf, 10);
Particle.publish("spark/hardware/max_binary", buf, 60, PRIVATE);

Expand Down
2 changes: 0 additions & 2 deletions system/src/system_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ void CellularSetupConsole::handle(char c)
if (c=='e')
{
CellularDevice dev;
memset(&dev, 0, sizeof(dev));
dev.size = sizeof(dev);
cellular_device_info(&dev, NULL);

print("IMEI: ");
Expand Down

0 comments on commit 73df5a4

Please sign in to comment.