To call Azure Marketplace Translation (and Speech) service

Dependencies:   EthernetInterface-FRDM HTTPClient-SSL R_BSP SDFileSystem TLV320_RBSP USBHost mbed-rtos mbed-src

The program calls Azure Marketplace Translation (and Speech) service.

How to use - Create an account for Microsoft Azure Marketplace - Get client ID and client secret. - Change client ID and client secret in main.cpp

The program was created based on the following libraries.

CodePlex Text-To-Speech with Microsoft Translator Service http://translatorservice.codeplex.com/

MBED HTTPClient-SSL Library https://developer.mbed.org/teams/MultiTech/code/HTTPClient-SSL/

/media/uploads/ksekimoto/gr-peach_cloud_speech_01.jpg

Committer:
ksekimoto
Date:
Sat Nov 07 12:29:06 2015 +0000
Revision:
1:a2bd45c3b373
Parent:
0:40a09c55e5be
To call Azure Marketplace Translation (and Speech) service.; The first version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ksekimoto 0:40a09c55e5be 1 /*******************************************************************************
ksekimoto 0:40a09c55e5be 2 * DISCLAIMER
ksekimoto 0:40a09c55e5be 3 * This software is supplied by Renesas Electronics Corporation and is only
ksekimoto 0:40a09c55e5be 4 * intended for use with Renesas products. No other uses are authorized. This
ksekimoto 0:40a09c55e5be 5 * software is owned by Renesas Electronics Corporation and is protected under
ksekimoto 0:40a09c55e5be 6 * all applicable laws, including copyright laws.
ksekimoto 0:40a09c55e5be 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
ksekimoto 0:40a09c55e5be 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
ksekimoto 0:40a09c55e5be 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
ksekimoto 0:40a09c55e5be 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
ksekimoto 0:40a09c55e5be 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
ksekimoto 0:40a09c55e5be 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
ksekimoto 0:40a09c55e5be 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
ksekimoto 0:40a09c55e5be 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
ksekimoto 0:40a09c55e5be 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
ksekimoto 0:40a09c55e5be 16 * Renesas reserves the right, without notice, to make changes to this software
ksekimoto 0:40a09c55e5be 17 * and to discontinue the availability of this software. By using this software,
ksekimoto 0:40a09c55e5be 18 * you agree to the additional terms and conditions found by accessing the
ksekimoto 0:40a09c55e5be 19 * following link:
ksekimoto 0:40a09c55e5be 20 * http://www.renesas.com/disclaimer*
ksekimoto 0:40a09c55e5be 21 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
ksekimoto 0:40a09c55e5be 22 *******************************************************************************/
ksekimoto 0:40a09c55e5be 23 #ifndef MBED_ROMRAMFILESYSTEM_H
ksekimoto 0:40a09c55e5be 24 #define MBED_ROMRAMFILESYSTEM_H
ksekimoto 0:40a09c55e5be 25
ksekimoto 0:40a09c55e5be 26 #include "FATFileSystem.h"
ksekimoto 0:40a09c55e5be 27
ksekimoto 0:40a09c55e5be 28 #define NUM_OF_SECTORS (1000)
ksekimoto 0:40a09c55e5be 29 #define SECTOR_SIZE (512)
ksekimoto 0:40a09c55e5be 30
ksekimoto 0:40a09c55e5be 31 #if defined(TARGET_RZ_A1H)
ksekimoto 0:40a09c55e5be 32 #define ROM_START_ADDRESS (0x18000000uL) // for GR-PEACH
ksekimoto 0:40a09c55e5be 33 #define ROM_END_ADDRESS (0x1FFFFFFFuL) // for GR-PEACH
ksekimoto 0:40a09c55e5be 34 #else
ksekimoto 0:40a09c55e5be 35 #define ROM_START_ADDRESS (0xFFFFFFFFuL)
ksekimoto 0:40a09c55e5be 36 #define ROM_END_ADDRESS (0xFFFFFFFFuL)
ksekimoto 0:40a09c55e5be 37 #endif
ksekimoto 0:40a09c55e5be 38
ksekimoto 0:40a09c55e5be 39 using namespace mbed;
ksekimoto 0:40a09c55e5be 40
ksekimoto 0:40a09c55e5be 41 class RomRamFileSystem : public FATFileSystem {
ksekimoto 0:40a09c55e5be 42 public:
ksekimoto 0:40a09c55e5be 43 // NUM_OF_SECTORS sectors, each 512 bytes
ksekimoto 0:40a09c55e5be 44 char *sectors[NUM_OF_SECTORS];
ksekimoto 0:40a09c55e5be 45
ksekimoto 0:40a09c55e5be 46 RomRamFileSystem(const char* name) : FATFileSystem(name) {
ksekimoto 0:40a09c55e5be 47 memset(sectors, 0, sizeof(sectors));
ksekimoto 0:40a09c55e5be 48 }
ksekimoto 0:40a09c55e5be 49
ksekimoto 0:40a09c55e5be 50 virtual ~RomRamFileSystem() {
ksekimoto 0:40a09c55e5be 51 for (int i = 0; i < NUM_OF_SECTORS; i++) {
ksekimoto 0:40a09c55e5be 52 if ((sectors[i] != NULL) && (isRomAddress(sectors[i]) == false)) {
ksekimoto 0:40a09c55e5be 53 free(sectors[i]);
ksekimoto 0:40a09c55e5be 54 }
ksekimoto 0:40a09c55e5be 55 }
ksekimoto 0:40a09c55e5be 56 }
ksekimoto 0:40a09c55e5be 57
ksekimoto 0:40a09c55e5be 58 // read a sector in to the buffer, return 0 if ok
ksekimoto 0:40a09c55e5be 59 virtual int disk_read(uint8_t *buffer, uint64_t sector, uint8_t count) {
ksekimoto 0:40a09c55e5be 60 for (uint64_t sec_no = sector; sec_no < (sector + count); sec_no++) {
ksekimoto 0:40a09c55e5be 61 if (sectors[sec_no] == NULL) {
ksekimoto 0:40a09c55e5be 62 // nothing allocated means sector is empty
ksekimoto 0:40a09c55e5be 63 memset(buffer, 0, SECTOR_SIZE);
ksekimoto 0:40a09c55e5be 64 } else {
ksekimoto 0:40a09c55e5be 65 memcpy(buffer, sectors[sec_no], SECTOR_SIZE);
ksekimoto 0:40a09c55e5be 66 }
ksekimoto 0:40a09c55e5be 67 buffer += SECTOR_SIZE;
ksekimoto 0:40a09c55e5be 68 }
ksekimoto 0:40a09c55e5be 69 return 0;
ksekimoto 0:40a09c55e5be 70 }
ksekimoto 0:40a09c55e5be 71
ksekimoto 0:40a09c55e5be 72 // write a sector from the buffer, return 0 if ok
ksekimoto 0:40a09c55e5be 73 virtual int disk_write(const uint8_t *buffer, uint64_t sector, uint8_t count) {
ksekimoto 0:40a09c55e5be 74 for (uint64_t sec_no = sector; sec_no < (sector + count); sec_no++) {
ksekimoto 0:40a09c55e5be 75 bool all_zero = true;
ksekimoto 0:40a09c55e5be 76 for (int i = 0; i < SECTOR_SIZE; i++) {
ksekimoto 0:40a09c55e5be 77 if (buffer[i] != NULL) {
ksekimoto 0:40a09c55e5be 78 all_zero = false;
ksekimoto 0:40a09c55e5be 79 break;
ksekimoto 0:40a09c55e5be 80 }
ksekimoto 0:40a09c55e5be 81 }
ksekimoto 0:40a09c55e5be 82 if (all_zero != false) {
ksekimoto 0:40a09c55e5be 83 if (sectors[sec_no] != NULL) {
ksekimoto 0:40a09c55e5be 84 if (isRomAddress(sectors[sec_no]) == false) {
ksekimoto 0:40a09c55e5be 85 free(sectors[sec_no]);
ksekimoto 0:40a09c55e5be 86 }
ksekimoto 0:40a09c55e5be 87 sectors[sec_no] = NULL;
ksekimoto 0:40a09c55e5be 88 }
ksekimoto 0:40a09c55e5be 89 return 0;
ksekimoto 0:40a09c55e5be 90 }
ksekimoto 0:40a09c55e5be 91 // allocate a sector if needed, and write
ksekimoto 0:40a09c55e5be 92 if (isRomAddress((char *)buffer) == false) {
ksekimoto 0:40a09c55e5be 93 if ((sectors[sec_no] == NULL) || (isRomAddress(sectors[sec_no]) != false)) {
ksekimoto 0:40a09c55e5be 94 char *sec = (char*)malloc(SECTOR_SIZE);
ksekimoto 0:40a09c55e5be 95 if (sec == NULL) {
ksekimoto 0:40a09c55e5be 96 return 1; // out of memory
ksekimoto 0:40a09c55e5be 97 }
ksekimoto 0:40a09c55e5be 98 sectors[sec_no] = sec;
ksekimoto 0:40a09c55e5be 99 }
ksekimoto 0:40a09c55e5be 100 memcpy(sectors[sec_no], buffer, SECTOR_SIZE);
ksekimoto 0:40a09c55e5be 101 } else {
ksekimoto 0:40a09c55e5be 102 if (isRomAddress(sectors[sec_no]) == false) {
ksekimoto 0:40a09c55e5be 103 free(sectors[sec_no]);
ksekimoto 0:40a09c55e5be 104 }
ksekimoto 0:40a09c55e5be 105 sectors[sec_no] = (char *)buffer;
ksekimoto 0:40a09c55e5be 106 }
ksekimoto 0:40a09c55e5be 107 buffer += SECTOR_SIZE;
ksekimoto 0:40a09c55e5be 108 }
ksekimoto 0:40a09c55e5be 109 return 0;
ksekimoto 0:40a09c55e5be 110 }
ksekimoto 0:40a09c55e5be 111
ksekimoto 0:40a09c55e5be 112 // return the number of sectors
ksekimoto 0:40a09c55e5be 113 virtual uint64_t disk_sectors() {
ksekimoto 0:40a09c55e5be 114 return NUM_OF_SECTORS;
ksekimoto 0:40a09c55e5be 115 }
ksekimoto 0:40a09c55e5be 116
ksekimoto 0:40a09c55e5be 117 void dump(FILE *fp) {
ksekimoto 0:40a09c55e5be 118 for (int i = 0; i < NUM_OF_SECTORS; i++) {
ksekimoto 0:40a09c55e5be 119 fwrite(&sectors[i], sizeof(int), 1, fp);
ksekimoto 0:40a09c55e5be 120 if (sectors[i] != NULL) {
ksekimoto 0:40a09c55e5be 121 fwrite(sectors[i], sizeof(char), SECTOR_SIZE, fp);
ksekimoto 0:40a09c55e5be 122 }
ksekimoto 0:40a09c55e5be 123 }
ksekimoto 0:40a09c55e5be 124 }
ksekimoto 0:40a09c55e5be 125
ksekimoto 0:40a09c55e5be 126 void load(FILE *fp) {
ksekimoto 0:40a09c55e5be 127 int sec_info = 0;
ksekimoto 0:40a09c55e5be 128 for (int i = 0; i < NUM_OF_SECTORS; i++) {
ksekimoto 0:40a09c55e5be 129 fread(&sec_info, sizeof(int), 1, fp);
ksekimoto 0:40a09c55e5be 130 if (sec_info != 0) {
ksekimoto 0:40a09c55e5be 131 char *sec = (char *)malloc(SECTOR_SIZE);
ksekimoto 0:40a09c55e5be 132 fread(sec, sizeof(char), SECTOR_SIZE, fp);
ksekimoto 0:40a09c55e5be 133 sectors[i] = sec;
ksekimoto 0:40a09c55e5be 134 }
ksekimoto 0:40a09c55e5be 135 }
ksekimoto 0:40a09c55e5be 136 }
ksekimoto 0:40a09c55e5be 137
ksekimoto 0:40a09c55e5be 138 private:
ksekimoto 0:40a09c55e5be 139 bool isRomAddress(char * address) {
ksekimoto 0:40a09c55e5be 140 if (((uint32_t)address >= ROM_START_ADDRESS)
ksekimoto 0:40a09c55e5be 141 && ((uint32_t)address <= (ROM_END_ADDRESS - SECTOR_SIZE + 1))) {
ksekimoto 0:40a09c55e5be 142 return true;
ksekimoto 0:40a09c55e5be 143 }
ksekimoto 0:40a09c55e5be 144 return false;
ksekimoto 0:40a09c55e5be 145 }
ksekimoto 0:40a09c55e5be 146 };
ksekimoto 0:40a09c55e5be 147 #endif