/***************************************************************************** * * connect_to_exosite * * \param None * * \return success: socket handle; failure: -1; * * \brief Establishes a connection with Exosite API server * *****************************************************************************/ long connect_to_exosite(void) { unsigned char connectRetries = 0; unsigned char server[META_SERVER_SIZE]; long sock = -1; exosite_meta_read(server, META_SERVER_SIZE, META_SERVER); while (connectRetries++ <= EXOSITE_MAX_CONNECT_RETRY_COUNT) { sock = exoHAL_SocketOpenTCP(server); if (sock < 0) { continue; } if (exoHAL_ServerConnect(sock) < 0) // Try to connect { // TODO - the typical reason the connect doesn't work is because // something was wrong in the way the comms hardware was initialized (timing, bit // error, etc...). There may be a graceful way to kick the hardware // back into gear at the right state, but for now, we just // return and let the caller retry us if they want continue; } else { connectRetries = 0; break; } } // Success return sock; }
/***************************************************************************** * * exosite_meta_init * * \param int reset : 1 - reset meta data * * \return None * * \brief Does whatever we need to do to initialize the NV meta structure * *****************************************************************************/ void exosite_meta_init(int reset) { char strBuf[META_MARK_SIZE]; exoHAL_EnableMeta(); //turn on the necessary hardware / peripherals //check our meta mark - if it isn't there, we wipe the meta structure exosite_meta_read((unsigned char *)strBuf, META_MARK_SIZE, META_MARK); if (strncmp(strBuf, EXOMARK, META_MARK_SIZE) || reset) exosite_meta_defaults(); return; }
/***************************************************************************** * * Exosite_GetCIK * * \param pointer to buffer to receive CIK or NULL * * \return 1 - CIK was valid, 0 - CIK was invalid. * * \brief Retrieves a CIK from flash / non volatile and verifies the CIK * format is valid * *****************************************************************************/ int Exosite_GetCIK(char * pCIK) { unsigned char i; char tempCIK[CIK_LENGTH + 1]; exosite_meta_read((unsigned char *)tempCIK, CIK_LENGTH, META_CIK); tempCIK[CIK_LENGTH] = 0; for (i = 0; i < CIK_LENGTH; i++) { if (!(tempCIK[i] >= 'a' && tempCIK[i] <= 'f' || tempCIK[i] >= '0' && tempCIK[i] <= '9')) { status_code = EXO_STATUS_BAD_CIK; return 0; } } if (NULL != pCIK) memcpy(pCIK ,tempCIK ,CIK_LENGTH + 1); return 1; }
/***************************************************************************** * * Exosite_GetMRF * * \param char *buffer, int length * * \return None * * \brief Retrieves a MRF structure from flash / non volatile * *****************************************************************************/ void Exosite_GetMRF(char *buffer, int length) { exosite_meta_read((unsigned char *)buffer, length, META_MFR); }