![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
二期c++接口
Dependencies: EthernetInterface mbed-rtos mbed uniqueCPUID
Fork of bcsdk by
main.cpp@17:82d09b5a9189, 2018-06-08 (annotated)
- Committer:
- MrAI
- Date:
- Fri Jun 08 01:40:23 2018 +0000
- Revision:
- 17:82d09b5a9189
- Parent:
- 16:17d0db6c449d
????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gsteiert | 0:28bc7ce77e20 | 1 | #include "mbed.h" |
gsteiert | 0:28bc7ce77e20 | 2 | #include "EthernetInterface.h" |
MrAI | 11:6d9cefb14158 | 3 | //#include "SDFileSystem.h" |
gsteiert | 0:28bc7ce77e20 | 4 | #include <stdio.h> |
webmaster | 9:d7468574ef8f | 5 | #include "uniqueCPUID.h" |
webmaster | 8:f2a567ee3a46 | 6 | |
webmaster | 8:f2a567ee3a46 | 7 | #include <iostream> |
webmaster | 8:f2a567ee3a46 | 8 | #include <string> |
webmaster | 8:f2a567ee3a46 | 9 | #include "UnitTest.h" |
webmaster | 8:f2a567ee3a46 | 10 | //#include "BlockChain.h" |
webmaster | 8:f2a567ee3a46 | 11 | #include "MockHsm.h" |
webmaster | 10:aabd720e632c | 12 | #include "Asset.h" |
webmaster | 10:aabd720e632c | 13 | #include "Transaction.h" |
webmaster | 10:aabd720e632c | 14 | #include "Account.h" |
webmaster | 10:aabd720e632c | 15 | #include "Key.h" |
MrAI | 12:1b24ea479a59 | 16 | #include "Payment.h" |
MrAI | 12:1b24ea479a59 | 17 | #include "ServerInfo.h" |
MrAI | 12:1b24ea479a59 | 18 | #include "Order.h" |
MrAI | 16:17d0db6c449d | 19 | #include <sstream> |
MrAI | 16:17d0db6c449d | 20 | //#include "rtos.h" |
webmaster | 8:f2a567ee3a46 | 21 | using namespace std; |
gsteiert | 0:28bc7ce77e20 | 22 | |
gsteiert | 0:28bc7ce77e20 | 23 | #define HTTPD_SERVER_PORT 80 |
gsteiert | 0:28bc7ce77e20 | 24 | #define HTTPD_MAX_REQ_LENGTH 1023 |
gsteiert | 0:28bc7ce77e20 | 25 | #define HTTPD_MAX_HDR_LENGTH 255 |
gsteiert | 0:28bc7ce77e20 | 26 | #define HTTPD_MAX_FNAME_LENGTH 127 |
gsteiert | 3:4f71a37a1ed2 | 27 | #define HTTPD_MAX_DNAME_LENGTH 127 |
gsteiert | 3:4f71a37a1ed2 | 28 | |
webmaster | 10:aabd720e632c | 29 | #define DEBUG_LOG 1 |
webmaster | 10:aabd720e632c | 30 | |
webmaster | 8:f2a567ee3a46 | 31 | const char* ECHO_SERVER_ADDRESS = "192.168.31.185"; |
webmaster | 8:f2a567ee3a46 | 32 | const int ECHO_SERVER_PORT = 10003; |
webmaster | 8:f2a567ee3a46 | 33 | |
gsteiert | 3:4f71a37a1ed2 | 34 | Serial uart(USBTX, USBRX); |
gsteiert | 0:28bc7ce77e20 | 35 | |
gsteiert | 6:ca17ce165ebc | 36 | //SDFileSystem sd(p5, p6, p7, p8, "sd"); // LPC1768 MBD2PMD |
gsteiert | 5:27b09a0f3fb6 | 37 | //SDFileSystem sd(P0_18, P0_17, P0_15, P0_16, "sd"); // Seeeduino Arch Pro SPI2SD |
MrAI | 11:6d9cefb14158 | 38 | //SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // K64F |
gsteiert | 3:4f71a37a1ed2 | 39 | |
gsteiert | 0:28bc7ce77e20 | 40 | EthernetInterface eth; |
gsteiert | 0:28bc7ce77e20 | 41 | TCPSocketServer server; |
gsteiert | 0:28bc7ce77e20 | 42 | TCPSocketConnection client; |
webmaster | 8:f2a567ee3a46 | 43 | TCPSocketConnection my_client; |
gsteiert | 0:28bc7ce77e20 | 44 | |
gsteiert | 0:28bc7ce77e20 | 45 | char buffer[HTTPD_MAX_REQ_LENGTH+1]; |
gsteiert | 0:28bc7ce77e20 | 46 | char httpHeader[HTTPD_MAX_HDR_LENGTH+1]; |
gsteiert | 3:4f71a37a1ed2 | 47 | char fileName[HTTPD_MAX_FNAME_LENGTH+1]; |
gsteiert | 3:4f71a37a1ed2 | 48 | char dirName[HTTPD_MAX_DNAME_LENGTH+1]; |
gsteiert | 0:28bc7ce77e20 | 49 | char *uristr; |
gsteiert | 0:28bc7ce77e20 | 50 | char *eou; |
gsteiert | 0:28bc7ce77e20 | 51 | char *qrystr; |
gsteiert | 0:28bc7ce77e20 | 52 | |
gsteiert | 0:28bc7ce77e20 | 53 | FILE *fp; |
gsteiert | 0:28bc7ce77e20 | 54 | int rdCnt; |
gsteiert | 0:28bc7ce77e20 | 55 | |
webmaster | 8:f2a567ee3a46 | 56 | // function declation |
webmaster | 8:f2a567ee3a46 | 57 | int test_socket_client(void); |
webmaster | 8:f2a567ee3a46 | 58 | int socket_init(); |
webmaster | 8:f2a567ee3a46 | 59 | int socket_fini(); |
webmaster | 8:f2a567ee3a46 | 60 | |
webmaster | 10:aabd720e632c | 61 | |
webmaster | 9:d7468574ef8f | 62 | void test_uuid() |
webmaster | 9:d7468574ef8f | 63 | { |
webmaster | 9:d7468574ef8f | 64 | char pUUID[128] = {0}; |
webmaster | 9:d7468574ef8f | 65 | getUniqueIDAsStr(pUUID); |
webmaster | 9:d7468574ef8f | 66 | printf("CPUID = %s \n",pUUID); |
webmaster | 9:d7468574ef8f | 67 | //printUniqueId(uart); |
webmaster | 9:d7468574ef8f | 68 | } |
webmaster | 8:f2a567ee3a46 | 69 | |
webmaster | 10:aabd720e632c | 70 | int test_MockHsm() |
webmaster | 10:aabd720e632c | 71 | { |
webmaster | 10:aabd720e632c | 72 | MockHsm mh; |
webmaster | 10:aabd720e632c | 73 | mh.setAlias("t_key_6"); |
webmaster | 10:aabd720e632c | 74 | cout<<mh.getAlias()<<endl; |
webmaster | 10:aabd720e632c | 75 | cout<<mh.createKey()<<endl; |
webmaster | 10:aabd720e632c | 76 | cout<< mh.listKeys() <<endl; |
webmaster | 10:aabd720e632c | 77 | return 0; |
webmaster | 10:aabd720e632c | 78 | } |
webmaster | 10:aabd720e632c | 79 | |
webmaster | 10:aabd720e632c | 80 | int test_Asset() |
webmaster | 10:aabd720e632c | 81 | { |
webmaster | 10:aabd720e632c | 82 | Asset asset; |
webmaster | 10:aabd720e632c | 83 | asset.setAlias("t_asset_6"); |
webmaster | 10:aabd720e632c | 84 | |
webmaster | 10:aabd720e632c | 85 | cout<< asset.createAsset() << endl; |
webmaster | 10:aabd720e632c | 86 | cout<< asset.listAssets() << endl; |
webmaster | 10:aabd720e632c | 87 | |
webmaster | 10:aabd720e632c | 88 | |
webmaster | 10:aabd720e632c | 89 | return 0; |
webmaster | 10:aabd720e632c | 90 | } |
webmaster | 10:aabd720e632c | 91 | |
webmaster | 10:aabd720e632c | 92 | int test_Account() |
webmaster | 10:aabd720e632c | 93 | { |
webmaster | 10:aabd720e632c | 94 | Key key; |
webmaster | 10:aabd720e632c | 95 | key.setAlias("t_key"); |
webmaster | 10:aabd720e632c | 96 | key.listKeys(); |
webmaster | 10:aabd720e632c | 97 | |
webmaster | 10:aabd720e632c | 98 | Account act(key); |
webmaster | 10:aabd720e632c | 99 | act.setAlias("t_acc_8"); |
webmaster | 10:aabd720e632c | 100 | act.listAccounts(); |
webmaster | 10:aabd720e632c | 101 | |
webmaster | 10:aabd720e632c | 102 | return 0; |
webmaster | 10:aabd720e632c | 103 | } |
webmaster | 10:aabd720e632c | 104 | |
webmaster | 10:aabd720e632c | 105 | int test_transaction(string type) |
webmaster | 10:aabd720e632c | 106 | { |
webmaster | 10:aabd720e632c | 107 | Transaction ts; |
webmaster | 10:aabd720e632c | 108 | //cout << ts.buildTransaction() << endl; |
webmaster | 10:aabd720e632c | 109 | ts.buildTransaction(type); |
webmaster | 10:aabd720e632c | 110 | ts.signTransaction(); |
webmaster | 10:aabd720e632c | 111 | ts.submitTransaction(); |
webmaster | 10:aabd720e632c | 112 | ts.listTransactions(); |
webmaster | 10:aabd720e632c | 113 | return 0; |
webmaster | 10:aabd720e632c | 114 | } |
webmaster | 10:aabd720e632c | 115 | |
webmaster | 10:aabd720e632c | 116 | int test_transaction() |
webmaster | 10:aabd720e632c | 117 | { |
webmaster | 10:aabd720e632c | 118 | vector<Actions> vActions; |
webmaster | 10:aabd720e632c | 119 | Actions act; |
webmaster | 10:aabd720e632c | 120 | MbedJSONValue reference_data; |
webmaster | 10:aabd720e632c | 121 | |
webmaster | 10:aabd720e632c | 122 | act.accounts_alias = "t_acc_1"; |
webmaster | 10:aabd720e632c | 123 | act.amount = 51; |
webmaster | 10:aabd720e632c | 124 | act.asset_alias = "t_asset"; |
webmaster | 10:aabd720e632c | 125 | act.reference_data = reference_data; |
webmaster | 10:aabd720e632c | 126 | act.type = "spend_account"; |
webmaster | 10:aabd720e632c | 127 | vActions.push_back(act); |
webmaster | 10:aabd720e632c | 128 | |
webmaster | 10:aabd720e632c | 129 | Actions act1 = {"t_acc_2", "t_asset", 49, reference_data, "spend_account" }; |
webmaster | 10:aabd720e632c | 130 | Actions act2 = {"tom", "t_asset", 80, reference_data, "control_account"}; |
webmaster | 10:aabd720e632c | 131 | Actions act3 = {"Jerry", "t_asset", 20, reference_data, "control_account"}; |
webmaster | 10:aabd720e632c | 132 | |
webmaster | 10:aabd720e632c | 133 | vActions.push_back(act1); |
webmaster | 10:aabd720e632c | 134 | vActions.push_back(act2); |
webmaster | 10:aabd720e632c | 135 | vActions.push_back(act3); |
webmaster | 10:aabd720e632c | 136 | printf("=============2========\r\n"); |
webmaster | 10:aabd720e632c | 137 | Transaction ts; |
webmaster | 10:aabd720e632c | 138 | ts.buildTransaction(vActions); |
webmaster | 10:aabd720e632c | 139 | ts.signTransaction(); |
webmaster | 10:aabd720e632c | 140 | ts.submitTransaction(); |
webmaster | 10:aabd720e632c | 141 | ts.listTransactions(); |
webmaster | 10:aabd720e632c | 142 | |
webmaster | 10:aabd720e632c | 143 | return 0; |
webmaster | 10:aabd720e632c | 144 | } |
webmaster | 10:aabd720e632c | 145 | |
MrAI | 16:17d0db6c449d | 146 | // cover int to string |
MrAI | 16:17d0db6c449d | 147 | void int2str(const int &int_temp,string &string_temp) |
MrAI | 16:17d0db6c449d | 148 | { |
MrAI | 16:17d0db6c449d | 149 | stringstream stream; |
MrAI | 16:17d0db6c449d | 150 | stream<<int_temp; |
MrAI | 16:17d0db6c449d | 151 | string_temp=stream.str(); //此处也可以用 stream>>string_temp |
MrAI | 16:17d0db6c449d | 152 | } |
MrAI | 16:17d0db6c449d | 153 | |
MrAI | 16:17d0db6c449d | 154 | // cover string to int |
MrAI | 16:17d0db6c449d | 155 | void str2int(int &int_temp,const string &string_temp) |
MrAI | 16:17d0db6c449d | 156 | { |
MrAI | 16:17d0db6c449d | 157 | stringstream stream(string_temp); |
MrAI | 16:17d0db6c449d | 158 | stream>>int_temp; |
MrAI | 16:17d0db6c449d | 159 | } |
MrAI | 16:17d0db6c449d | 160 | |
MrAI | 16:17d0db6c449d | 161 | // cover string to long |
MrAI | 16:17d0db6c449d | 162 | void str2long(long &long_temp,const string &string_temp) |
MrAI | 16:17d0db6c449d | 163 | { |
MrAI | 16:17d0db6c449d | 164 | stringstream stream(string_temp); |
MrAI | 16:17d0db6c449d | 165 | stream>>long_temp; |
MrAI | 16:17d0db6c449d | 166 | } |
MrAI | 15:7b56d49392be | 167 | DigitalOut myled1(LED1,1); |
MrAI | 15:7b56d49392be | 168 | DigitalOut myled2(LED2,1); |
MrAI | 15:7b56d49392be | 169 | DigitalOut myled3(LED3,1); |
MrAI | 17:82d09b5a9189 | 170 | bool isRunning = false;//蓝灯闪烁条件 |
MrAI | 17:82d09b5a9189 | 171 | void setLedStatus(DigitalOut myled)//指定某一种颜色亮 |
MrAI | 15:7b56d49392be | 172 | { |
MrAI | 15:7b56d49392be | 173 | myled = 0; |
MrAI | 15:7b56d49392be | 174 | } |
MrAI | 17:82d09b5a9189 | 175 | void setLedStatusErr(DigitalOut myled)//出错指示灯:红灯闪烁 |
MrAI | 15:7b56d49392be | 176 | { |
MrAI | 15:7b56d49392be | 177 | int nCount = 3; |
MrAI | 15:7b56d49392be | 178 | while(nCount-- > 0) |
MrAI | 15:7b56d49392be | 179 | { |
MrAI | 15:7b56d49392be | 180 | myled = 1; // set LED1 pin to high |
MrAI | 15:7b56d49392be | 181 | wait(0.3); |
MrAI | 15:7b56d49392be | 182 | myled = 0; // set LED1 pin to low |
MrAI | 15:7b56d49392be | 183 | wait(0.3); |
MrAI | 15:7b56d49392be | 184 | } |
MrAI | 15:7b56d49392be | 185 | } |
webmaster | 10:aabd720e632c | 186 | |
MrAI | 17:82d09b5a9189 | 187 | void setLedOff()//关闭led |
MrAI | 15:7b56d49392be | 188 | { |
MrAI | 15:7b56d49392be | 189 | myled1 = 1; |
MrAI | 15:7b56d49392be | 190 | myled2 = 1; |
MrAI | 15:7b56d49392be | 191 | myled3 = 1; |
MrAI | 15:7b56d49392be | 192 | } |
MrAI | 17:82d09b5a9189 | 193 | void thread_LedRun(void const *argument)//蓝灯闪烁线程 |
MrAI | 16:17d0db6c449d | 194 | { |
MrAI | 16:17d0db6c449d | 195 | while(1) { |
MrAI | 16:17d0db6c449d | 196 | while(isRunning) { |
MrAI | 16:17d0db6c449d | 197 | myled3 = !myled3; |
MrAI | 16:17d0db6c449d | 198 | Thread::wait(200); |
MrAI | 16:17d0db6c449d | 199 | } |
MrAI | 16:17d0db6c449d | 200 | myled3 = 1; |
MrAI | 16:17d0db6c449d | 201 | } |
MrAI | 16:17d0db6c449d | 202 | } |
MrAI | 16:17d0db6c449d | 203 | |
MrAI | 17:82d09b5a9189 | 204 | void reset_LedRun()//暂停闪烁 |
MrAI | 16:17d0db6c449d | 205 | { |
MrAI | 16:17d0db6c449d | 206 | isRunning = false; |
MrAI | 16:17d0db6c449d | 207 | wait(0.1); |
MrAI | 16:17d0db6c449d | 208 | } |
MrAI | 16:17d0db6c449d | 209 | |
MrAI | 16:17d0db6c449d | 210 | long sd_account() |
MrAI | 12:1b24ea479a59 | 211 | { |
MrAI | 15:7b56d49392be | 212 | setLedOff(); |
MrAI | 16:17d0db6c449d | 213 | isRunning = true; |
MrAI | 16:17d0db6c449d | 214 | string strWallet = "6f4WTd7MVPm9fGkzvwLAAnSjk5jeu9fWo3"; |
MrAI | 12:1b24ea479a59 | 215 | Account act; |
MrAI | 15:7b56d49392be | 216 | MbedJSONValue objJson; |
MrAI | 15:7b56d49392be | 217 | string strRet = act.getBalance(objJson,strWallet); |
MrAI | 15:7b56d49392be | 218 | if (strRet.empty()) |
MrAI | 12:1b24ea479a59 | 219 | { |
MrAI | 16:17d0db6c449d | 220 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 221 | setLedStatusErr(myled1); |
MrAI | 12:1b24ea479a59 | 222 | return -1; |
MrAI | 12:1b24ea479a59 | 223 | } |
MrAI | 16:17d0db6c449d | 224 | long sda = 0; |
MrAI | 15:7b56d49392be | 225 | bool bSuccess = act.getRequestRet(objJson); |
MrAI | 15:7b56d49392be | 226 | if (bSuccess) |
MrAI | 12:1b24ea479a59 | 227 | { |
MrAI | 16:17d0db6c449d | 228 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 229 | setLedStatus(myled2); |
MrAI | 15:7b56d49392be | 230 | int iLedger = act.getLedger(objJson); |
MrAI | 15:7b56d49392be | 231 | bool bSuccess = act.getRequestRet(objJson); |
MrAI | 15:7b56d49392be | 232 | int iCurrenciesNum = act.getBalanceSize(objJson, "balances"); |
MrAI | 15:7b56d49392be | 233 | for (int i = 0; i < iCurrenciesNum; i++) |
MrAI | 15:7b56d49392be | 234 | { |
MrAI | 15:7b56d49392be | 235 | string value = act.getBalanceArray(objJson, "balances", i, "value"); |
MrAI | 15:7b56d49392be | 236 | string currency = act.getBalanceArray(objJson, "balances", i, "currency"); |
MrAI | 15:7b56d49392be | 237 | string counterparty = act.getBalanceArray(objJson, "balances", i, "counterparty"); |
MrAI | 15:7b56d49392be | 238 | cout << "The" << i << "record:" << endl << "value:" << value << endl << "currency:" << currency << endl |
MrAI | 15:7b56d49392be | 239 | << "counterparty:" << counterparty << endl; |
MrAI | 16:17d0db6c449d | 240 | if("SDA" == currency) str2long(sda,value); |
MrAI | 15:7b56d49392be | 241 | } |
MrAI | 12:1b24ea479a59 | 242 | } |
MrAI | 15:7b56d49392be | 243 | else |
MrAI | 16:17d0db6c449d | 244 | { |
MrAI | 16:17d0db6c449d | 245 | reset_LedRun(); |
MrAI | 16:17d0db6c449d | 246 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 247 | } |
MrAI | 16:17d0db6c449d | 248 | return sda; |
MrAI | 12:1b24ea479a59 | 249 | } |
MrAI | 12:1b24ea479a59 | 250 | |
MrAI | 12:1b24ea479a59 | 251 | int sd_wallet() |
MrAI | 12:1b24ea479a59 | 252 | { |
MrAI | 15:7b56d49392be | 253 | //setLedVague(myled3); |
MrAI | 15:7b56d49392be | 254 | setLedOff(); |
MrAI | 16:17d0db6c449d | 255 | isRunning = true; |
MrAI | 15:7b56d49392be | 256 | MbedJSONValue mJson; |
MrAI | 12:1b24ea479a59 | 257 | Account act; |
MrAI | 15:7b56d49392be | 258 | string strRet = act.getWallet(mJson); |
MrAI | 15:7b56d49392be | 259 | if (strRet.empty()) |
MrAI | 12:1b24ea479a59 | 260 | { |
MrAI | 16:17d0db6c449d | 261 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 262 | setLedStatusErr(myled1); |
MrAI | 12:1b24ea479a59 | 263 | return -1; |
MrAI | 12:1b24ea479a59 | 264 | } |
MrAI | 15:7b56d49392be | 265 | bool bSuccess = act.getRequestRet(mJson); |
MrAI | 12:1b24ea479a59 | 266 | if (bSuccess) |
MrAI | 12:1b24ea479a59 | 267 | { |
MrAI | 16:17d0db6c449d | 268 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 269 | setLedStatus(myled2); |
MrAI | 15:7b56d49392be | 270 | string address1 = act.getKeyValue(mJson, "wallet", "address"); |
MrAI | 15:7b56d49392be | 271 | string secret1 = act.getKeyValue(mJson, "wallet", "secret"); |
MrAI | 12:1b24ea479a59 | 272 | cout << "address:" << address1 << endl << "secret:" << secret1 << endl; |
MrAI | 12:1b24ea479a59 | 273 | } |
MrAI | 15:7b56d49392be | 274 | else |
MrAI | 16:17d0db6c449d | 275 | { |
MrAI | 16:17d0db6c449d | 276 | reset_LedRun(); |
MrAI | 16:17d0db6c449d | 277 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 278 | } |
MrAI | 12:1b24ea479a59 | 279 | return 0; |
MrAI | 12:1b24ea479a59 | 280 | } |
MrAI | 12:1b24ea479a59 | 281 | |
MrAI | 16:17d0db6c449d | 282 | string sd_postpayment()//支付请求 |
MrAI | 12:1b24ea479a59 | 283 | { |
MrAI | 15:7b56d49392be | 284 | setLedOff(); |
MrAI | 16:17d0db6c449d | 285 | isRunning = true; |
MrAI | 12:1b24ea479a59 | 286 | string strJson = ""; |
MrAI | 12:1b24ea479a59 | 287 | Payment pay; |
MrAI | 12:1b24ea479a59 | 288 | MbedJSONValue mbJson; |
MrAI | 12:1b24ea479a59 | 289 | MbedJSONValue objJson; |
MrAI | 16:17d0db6c449d | 290 | string secret = "ss7YRUANnXH7aoiebqZCN8M9foeAV"; |
MrAI | 16:17d0db6c449d | 291 | string src_acc = "6h7oPUgcK38FjDftnKbkdFwXnPPP7CipTr"; |
MrAI | 16:17d0db6c449d | 292 | string dst_acc = "6f4WTd7MVPm9fGkzvwLAAnSjk5jeu9fWo3"; |
MrAI | 16:17d0db6c449d | 293 | string amount = "2"; |
MrAI | 12:1b24ea479a59 | 294 | string MemoType = "memos"; |
MrAI | 16:17d0db6c449d | 295 | string MemoData = "Transaction from ARM mbed OS"; |
MrAI | 16:17d0db6c449d | 296 | string strWallet = "6UjYKrZ5cPCiWTCgxJqNxn7g7vaHY3UULm"; |
MrAI | 12:1b24ea479a59 | 297 | string strUrl = "/v1/accounts/payments/"; |
MrAI | 12:1b24ea479a59 | 298 | pay.SetJsonBody(mbJson, secret, src_acc, dst_acc, amount, MemoType, MemoData); |
MrAI | 12:1b24ea479a59 | 299 | strJson = pay.PostPayment(mbJson, strUrl, strWallet,""); |
MrAI | 12:1b24ea479a59 | 300 | if (strJson.empty()) |
MrAI | 16:17d0db6c449d | 301 | { |
MrAI | 16:17d0db6c449d | 302 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 303 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 304 | return "error"; |
MrAI | 12:1b24ea479a59 | 305 | } |
MrAI | 12:1b24ea479a59 | 306 | string err = pay.getParseMbedJson(objJson, strJson.c_str()); |
MrAI | 12:1b24ea479a59 | 307 | bool bSuccess = pay.getRequestRet(objJson); |
MrAI | 12:1b24ea479a59 | 308 | if (bSuccess) |
MrAI | 12:1b24ea479a59 | 309 | { |
MrAI | 16:17d0db6c449d | 310 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 311 | setLedStatus(myled2); |
MrAI | 12:1b24ea479a59 | 312 | string hash = pay.getKeyValue(objJson, "hash"); |
MrAI | 12:1b24ea479a59 | 313 | string status_url = pay.getKeyValue(objJson, "status_url"); |
MrAI | 12:1b24ea479a59 | 314 | cout << "hash:" << hash << endl; |
MrAI | 12:1b24ea479a59 | 315 | cout << "status_url:" << status_url << endl; |
MrAI | 16:17d0db6c449d | 316 | return hash; |
MrAI | 12:1b24ea479a59 | 317 | } |
MrAI | 15:7b56d49392be | 318 | else |
MrAI | 16:17d0db6c449d | 319 | { |
MrAI | 16:17d0db6c449d | 320 | reset_LedRun(); |
MrAI | 16:17d0db6c449d | 321 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 322 | } |
MrAI | 16:17d0db6c449d | 323 | return "error"; |
MrAI | 12:1b24ea479a59 | 324 | } |
MrAI | 12:1b24ea479a59 | 325 | |
MrAI | 16:17d0db6c449d | 326 | string sd_getpaymentinfo(string hash) |
MrAI | 12:1b24ea479a59 | 327 | { |
MrAI | 15:7b56d49392be | 328 | setLedOff(); |
MrAI | 16:17d0db6c449d | 329 | isRunning = true; |
MrAI | 12:1b24ea479a59 | 330 | Payment pay; |
MrAI | 12:1b24ea479a59 | 331 | MbedJSONValue objJson; |
MrAI | 12:1b24ea479a59 | 332 | string strJson = ""; |
MrAI | 12:1b24ea479a59 | 333 | string strWallet = "69Hu8QsnEZUP4f3AVYSW7rkpLVm6DAEq9y"; |
MrAI | 12:1b24ea479a59 | 334 | string strUrl = "/v1/accounts/payments/"; |
MrAI | 16:17d0db6c449d | 335 | //string strHash = "EF252979355F2666486F69E9C96D137265214DE65B14E1136ECCDCE84F09AD11"; |
MrAI | 16:17d0db6c449d | 336 | string strHash = hash; |
MrAI | 12:1b24ea479a59 | 337 | strJson = pay.GetPaymentInfo(strUrl, strWallet, strHash); |
MrAI | 12:1b24ea479a59 | 338 | if (strJson.empty()) |
MrAI | 12:1b24ea479a59 | 339 | { |
MrAI | 16:17d0db6c449d | 340 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 341 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 342 | return "error"; |
MrAI | 12:1b24ea479a59 | 343 | } |
MrAI | 12:1b24ea479a59 | 344 | string err = pay.getParseMbedJson(objJson, strJson.c_str()); |
MrAI | 12:1b24ea479a59 | 345 | bool bSuccess = pay.getRequestRet(objJson); |
MrAI | 12:1b24ea479a59 | 346 | if (bSuccess) |
MrAI | 12:1b24ea479a59 | 347 | { |
MrAI | 16:17d0db6c449d | 348 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 349 | setLedStatus(myled2); |
MrAI | 12:1b24ea479a59 | 350 | string hash = pay.getKeyValue(objJson, "hash"); |
MrAI | 12:1b24ea479a59 | 351 | string ledger = pay.getKeyValue(objJson, "ledger"); |
MrAI | 12:1b24ea479a59 | 352 | string state = pay.getKeyValue(objJson, "state"); |
MrAI | 12:1b24ea479a59 | 353 | string source_account = pay.getKeyValue(objJson, "source_account"); |
MrAI | 12:1b24ea479a59 | 354 | string dst_account = pay.getKeyValue(objJson, "destination_account"); |
MrAI | 12:1b24ea479a59 | 355 | string amount_cur = pay.getKeyValue(objJson, "amount", "currency"); |
MrAI | 12:1b24ea479a59 | 356 | string value = pay.getKeyValue(objJson, "amount", "value"); |
MrAI | 12:1b24ea479a59 | 357 | string amount_issuer = pay.getKeyValue(objJson, "amount", "issuer"); |
MrAI | 12:1b24ea479a59 | 358 | string currency = pay.getKeyValue(objJson, "currency"); |
MrAI | 12:1b24ea479a59 | 359 | string issuer = pay.getKeyValue(objJson, "issuer"); |
MrAI | 12:1b24ea479a59 | 360 | string direction = pay.getKeyValue(objJson, "direction"); |
MrAI | 12:1b24ea479a59 | 361 | string timestamp = pay.getKeyValue(objJson, "timestamp"); |
MrAI | 12:1b24ea479a59 | 362 | string fee = pay.getKeyValue(objJson, "fee"); |
MrAI | 13:e77c7ae3a285 | 363 | cout << "hash:" << hash <<endl<<"ledger:" << ledger <<endl<< " state:" << state |
MrAI | 13:e77c7ae3a285 | 364 | <<endl<< " source_account:" << source_account <<endl<< " dst_account:" << dst_account |
MrAI | 13:e77c7ae3a285 | 365 | <<endl<< " amount_cur:" << amount_cur <<endl<< " value:" << value <<endl<< " amount_issuer:" << amount_issuer |
MrAI | 13:e77c7ae3a285 | 366 | <<endl<< " currency:" << currency <<endl<< " issuer" << issuer <<endl<< " direction" << direction |
MrAI | 13:e77c7ae3a285 | 367 | <<endl<< " timestamp:" << timestamp <<endl<< " fee" << fee <<endl; |
MrAI | 12:1b24ea479a59 | 368 | int iCurrenciesNum = pay.getBalanceSize(objJson, "memos"); |
MrAI | 12:1b24ea479a59 | 369 | for (int i = 0; i < iCurrenciesNum; i++) |
MrAI | 12:1b24ea479a59 | 370 | { |
MrAI | 12:1b24ea479a59 | 371 | string memo_type = pay.getBalanceArray(objJson, "memos", i, "memo_type"); |
MrAI | 12:1b24ea479a59 | 372 | string memo_data = pay.getBalanceArray(objJson, "memos", i, "memo_data"); |
MrAI | 12:1b24ea479a59 | 373 | cout << i << ":" << memo_type << "--" << memo_data << endl; |
MrAI | 12:1b24ea479a59 | 374 | } |
MrAI | 16:17d0db6c449d | 375 | return hash; |
MrAI | 12:1b24ea479a59 | 376 | } |
MrAI | 15:7b56d49392be | 377 | else |
MrAI | 16:17d0db6c449d | 378 | { |
MrAI | 16:17d0db6c449d | 379 | reset_LedRun(); |
MrAI | 16:17d0db6c449d | 380 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 381 | } |
MrAI | 16:17d0db6c449d | 382 | return "error"; |
MrAI | 12:1b24ea479a59 | 383 | } |
MrAI | 12:1b24ea479a59 | 384 | |
MrAI | 16:17d0db6c449d | 385 | int sd_gettransactions(string tx_hash) |
MrAI | 12:1b24ea479a59 | 386 | { |
MrAI | 15:7b56d49392be | 387 | setLedOff(); |
MrAI | 16:17d0db6c449d | 388 | isRunning = true; |
MrAI | 12:1b24ea479a59 | 389 | Payment pay; |
MrAI | 12:1b24ea479a59 | 390 | MbedJSONValue objJson; |
MrAI | 12:1b24ea479a59 | 391 | string strJson = ""; |
MrAI | 16:17d0db6c449d | 392 | //string strHash = "EF252979355F2666486F69E9C96D137265214DE65B14E1136ECCDCE84F09AD11"; |
MrAI | 16:17d0db6c449d | 393 | string strHash = tx_hash; |
MrAI | 12:1b24ea479a59 | 394 | string strUrl = "/v1/transactions/"; |
MrAI | 12:1b24ea479a59 | 395 | strJson = pay.GetPaymentInfo(strUrl,"", strHash); |
MrAI | 12:1b24ea479a59 | 396 | if (strJson.empty()) |
MrAI | 12:1b24ea479a59 | 397 | { |
MrAI | 16:17d0db6c449d | 398 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 399 | setLedStatusErr(myled1); |
MrAI | 12:1b24ea479a59 | 400 | return -1; |
MrAI | 12:1b24ea479a59 | 401 | } |
MrAI | 12:1b24ea479a59 | 402 | string err = pay.getParseMbedJson(objJson, strJson.c_str()); |
MrAI | 12:1b24ea479a59 | 403 | bool bSuccess = pay.getRequestRet(objJson); |
MrAI | 12:1b24ea479a59 | 404 | if (bSuccess) |
MrAI | 12:1b24ea479a59 | 405 | { |
MrAI | 16:17d0db6c449d | 406 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 407 | setLedStatus(myled2); |
MrAI | 12:1b24ea479a59 | 408 | string TransactionType = pay.getKeyValue(objJson, "transaction", "TransactionType"); |
MrAI | 12:1b24ea479a59 | 409 | int Flags = pay.getKeyValueInt(objJson, "transaction", "Flags"); |
MrAI | 12:1b24ea479a59 | 410 | int Sequence = pay.getKeyValueInt(objJson, "transaction", "Sequence"); |
MrAI | 12:1b24ea479a59 | 411 | int LastLedgerSequence = pay.getKeyValueInt(objJson, "transaction", "LastLedgerSequence"); |
MrAI | 12:1b24ea479a59 | 412 | string Amount = pay.getKeyValue(objJson, "transaction", "Amount"); |
MrAI | 12:1b24ea479a59 | 413 | string Fee = pay.getKeyValue(objJson, "transaction", "Fee"); |
MrAI | 12:1b24ea479a59 | 414 | string SigningPubKey = pay.getKeyValue(objJson, "transaction", "SigningPubKey"); |
MrAI | 12:1b24ea479a59 | 415 | string TxnSignature = pay.getKeyValue(objJson, "transaction", "TxnSignature"); |
MrAI | 12:1b24ea479a59 | 416 | string Account = pay.getKeyValue(objJson, "transaction", "Account"); |
MrAI | 12:1b24ea479a59 | 417 | string Destination = pay.getKeyValue(objJson, "transaction", "Destination"); |
MrAI | 12:1b24ea479a59 | 418 | int iCurrenciesNum = pay.getBalanceSize(objJson,"transaction","Memos"); |
MrAI | 15:7b56d49392be | 419 | for (int i = 0; i < iCurrenciesNum; i++) |
MrAI | 15:7b56d49392be | 420 | { |
MrAI | 15:7b56d49392be | 421 | string MemoType = pay.getBalanceArray(objJson, "transaction", "Memos", "Memo", i,"MemoType"); |
MrAI | 15:7b56d49392be | 422 | string MemoData = pay.getBalanceArray(objJson, "transaction", "Memos", "Memo", i, "MemoData"); |
MrAI | 15:7b56d49392be | 423 | string parsed_memo_type = pay.getBalanceArray(objJson, "transaction", "Memos", "Memo", i, "parsed_memo_type"); |
MrAI | 15:7b56d49392be | 424 | cout << i << ":" << MemoType << "--" << MemoData << "--" << parsed_memo_type << endl; |
MrAI | 15:7b56d49392be | 425 | } |
MrAI | 12:1b24ea479a59 | 426 | int date = pay.getKeyValueInt(objJson, "transaction", "date"); |
MrAI | 12:1b24ea479a59 | 427 | string hash = pay.getKeyValue(objJson, "transaction", "hash"); |
MrAI | 12:1b24ea479a59 | 428 | int inLedger = pay.getKeyValueInt(objJson, "transaction", "inLedger"); |
MrAI | 12:1b24ea479a59 | 429 | int ledger_index = pay.getKeyValueInt(objJson, "transaction", "ledger_index"); |
MrAI | 12:1b24ea479a59 | 430 | bool validated = pay.getKeyValueBool(objJson, "transaction", "validated"); |
MrAI | 15:7b56d49392be | 431 | |
MrAI | 12:1b24ea479a59 | 432 | } |
MrAI | 15:7b56d49392be | 433 | else |
MrAI | 16:17d0db6c449d | 434 | { |
MrAI | 16:17d0db6c449d | 435 | reset_LedRun(); |
MrAI | 16:17d0db6c449d | 436 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 437 | } |
MrAI | 12:1b24ea479a59 | 438 | return 0; |
MrAI | 12:1b24ea479a59 | 439 | } |
MrAI | 12:1b24ea479a59 | 440 | |
MrAI | 12:1b24ea479a59 | 441 | int sd_getpaymenthistory() |
MrAI | 12:1b24ea479a59 | 442 | { |
MrAI | 15:7b56d49392be | 443 | setLedOff(); |
MrAI | 16:17d0db6c449d | 444 | isRunning = true; |
MrAI | 12:1b24ea479a59 | 445 | Payment pay; |
MrAI | 12:1b24ea479a59 | 446 | MbedJSONValue objJson; |
MrAI | 12:1b24ea479a59 | 447 | MbedJSONValue mbJson; |
MrAI | 12:1b24ea479a59 | 448 | string strJson = ""; |
MrAI | 12:1b24ea479a59 | 449 | string strUrl = "/v1/accounts/payments/"; |
MrAI | 12:1b24ea479a59 | 450 | string strWallet = "6ByxwCh2Lqwwr3pk6mh4GBb4bsqFz2zAKY"; |
MrAI | 12:1b24ea479a59 | 451 | string src_acc = "6ByxwCh2Lqwwr3pk6mh4GBb4bsqFz2zAKY"; |
MrAI | 12:1b24ea479a59 | 452 | string dst_acc = "69Hu8QsnEZUP4f3AVYSW7rkpLVm6DAEq9y"; |
MrAI | 12:1b24ea479a59 | 453 | string direction = "incoming"; |
MrAI | 12:1b24ea479a59 | 454 | int start_ledger = 1; |
MrAI | 12:1b24ea479a59 | 455 | int end_ledger = 10000; |
MrAI | 12:1b24ea479a59 | 456 | int per_page = 10; |
MrAI | 12:1b24ea479a59 | 457 | int page = 1; |
MrAI | 12:1b24ea479a59 | 458 | pay.SetJsonBody(mbJson, src_acc, dst_acc, direction, start_ledger, end_ledger, per_page, page); |
MrAI | 12:1b24ea479a59 | 459 | strJson = pay.PostPayment(mbJson, strUrl, strWallet, ""); |
MrAI | 12:1b24ea479a59 | 460 | if (strJson.empty()) |
MrAI | 12:1b24ea479a59 | 461 | { |
MrAI | 16:17d0db6c449d | 462 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 463 | setLedStatusErr(myled1); |
MrAI | 12:1b24ea479a59 | 464 | return -1; |
MrAI | 12:1b24ea479a59 | 465 | } |
MrAI | 12:1b24ea479a59 | 466 | string err = pay.getParseMbedJson(objJson, strJson.c_str()); |
MrAI | 12:1b24ea479a59 | 467 | bool bSuccess = pay.getRequestRet(objJson); |
MrAI | 12:1b24ea479a59 | 468 | if (bSuccess) |
MrAI | 12:1b24ea479a59 | 469 | { |
MrAI | 16:17d0db6c449d | 470 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 471 | setLedStatus(myled2); |
MrAI | 12:1b24ea479a59 | 472 | int iCurrenciesNum = pay.getBalanceSize(objJson,"payments"); |
MrAI | 12:1b24ea479a59 | 473 | for (int i = 0; i < iCurrenciesNum; i++) |
MrAI | 12:1b24ea479a59 | 474 | { |
MrAI | 12:1b24ea479a59 | 475 | string hash = pay.getBalanceArray(objJson, "payments", i, "hash"); |
MrAI | 12:1b24ea479a59 | 476 | string ledger = pay.getBalanceArray(objJson, "payments", i, "ledger"); |
MrAI | 12:1b24ea479a59 | 477 | string source_account = pay.getBalanceArray(objJson, "payments", i, "source_account"); |
MrAI | 12:1b24ea479a59 | 478 | string destination_account = pay.getBalanceArray(objJson, "payments", i, "destination_account"); |
MrAI | 15:7b56d49392be | 479 | string currency = pay.getBalanceArrayEx(objJson, "payments", "amount", i,"currency"); |
MrAI | 15:7b56d49392be | 480 | string value = pay.getBalanceArrayEx(objJson, "payments", "amount", i, "value"); |
MrAI | 15:7b56d49392be | 481 | string issuer = pay.getBalanceArrayEx(objJson, "payments", "amount", i, "issuer"); |
MrAI | 12:1b24ea479a59 | 482 | string direction = pay.getBalanceArray(objJson, "payments", i, "direction"); |
MrAI | 12:1b24ea479a59 | 483 | string timestamp = pay.getBalanceArray(objJson, "payments", i, "timestamp"); |
MrAI | 12:1b24ea479a59 | 484 | string fee = pay.getBalanceArray(objJson, "payments", i, "fee"); |
MrAI | 15:7b56d49392be | 485 | int iCurrenciesNum = pay.getBalanceSizeEx(objJson, "payments", "Memos",i); |
MrAI | 12:1b24ea479a59 | 486 | for (int j = 0; j < iCurrenciesNum; j++) |
MrAI | 12:1b24ea479a59 | 487 | { |
MrAI | 15:7b56d49392be | 488 | string memo_type = pay.getBalanceArray_five(objJson, "payments", j,"memos", i, "memo_type"); |
MrAI | 15:7b56d49392be | 489 | string memo_data = pay.getBalanceArray_five(objJson, "payments",j, "memos", i, "memo_data"); |
MrAI | 12:1b24ea479a59 | 490 | cout << i << ":" << memo_type << "--" << memo_data << endl; |
MrAI | 12:1b24ea479a59 | 491 | } |
MrAI | 12:1b24ea479a59 | 492 | } |
MrAI | 12:1b24ea479a59 | 493 | } |
MrAI | 15:7b56d49392be | 494 | else |
MrAI | 16:17d0db6c449d | 495 | { |
MrAI | 16:17d0db6c449d | 496 | reset_LedRun(); |
MrAI | 16:17d0db6c449d | 497 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 498 | } |
MrAI | 12:1b24ea479a59 | 499 | return 0; |
MrAI | 12:1b24ea479a59 | 500 | } |
MrAI | 12:1b24ea479a59 | 501 | |
MrAI | 12:1b24ea479a59 | 502 | int sd_getdefaultfee() |
MrAI | 12:1b24ea479a59 | 503 | { |
MrAI | 15:7b56d49392be | 504 | setLedOff(); |
MrAI | 16:17d0db6c449d | 505 | isRunning = true; |
MrAI | 12:1b24ea479a59 | 506 | ServerInfo serInfo; |
MrAI | 12:1b24ea479a59 | 507 | MbedJSONValue objJson; |
MrAI | 12:1b24ea479a59 | 508 | string strJson = ""; |
MrAI | 12:1b24ea479a59 | 509 | string strUrl = "/v1/transaction-fee"; |
MrAI | 12:1b24ea479a59 | 510 | strJson = serInfo.GetPaymentInfo(strUrl, "", ""); |
MrAI | 12:1b24ea479a59 | 511 | if (strJson.empty()) |
MrAI | 12:1b24ea479a59 | 512 | { |
MrAI | 16:17d0db6c449d | 513 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 514 | setLedStatusErr(myled1); |
MrAI | 12:1b24ea479a59 | 515 | return -1; |
MrAI | 12:1b24ea479a59 | 516 | } |
MrAI | 12:1b24ea479a59 | 517 | string err = serInfo.getParseMbedJson(objJson, strJson.c_str()); |
MrAI | 12:1b24ea479a59 | 518 | bool bSuccess = serInfo.getRequestRet(objJson); |
MrAI | 12:1b24ea479a59 | 519 | if (bSuccess) |
MrAI | 12:1b24ea479a59 | 520 | { |
MrAI | 16:17d0db6c449d | 521 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 522 | setLedStatus(myled2); |
MrAI | 12:1b24ea479a59 | 523 | string fee = serInfo.getKeyValue(objJson, "fee"); |
MrAI | 12:1b24ea479a59 | 524 | cout << "fee:" << fee << endl; |
MrAI | 12:1b24ea479a59 | 525 | } |
MrAI | 15:7b56d49392be | 526 | else |
MrAI | 16:17d0db6c449d | 527 | { |
MrAI | 16:17d0db6c449d | 528 | reset_LedRun(); |
MrAI | 16:17d0db6c449d | 529 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 530 | } |
MrAI | 12:1b24ea479a59 | 531 | return 0; |
MrAI | 12:1b24ea479a59 | 532 | } |
MrAI | 12:1b24ea479a59 | 533 | |
MrAI | 12:1b24ea479a59 | 534 | int sd_getserverinfo() |
MrAI | 12:1b24ea479a59 | 535 | { |
MrAI | 15:7b56d49392be | 536 | setLedOff(); |
MrAI | 16:17d0db6c449d | 537 | isRunning = true; |
MrAI | 12:1b24ea479a59 | 538 | ServerInfo serInfo; |
MrAI | 12:1b24ea479a59 | 539 | MbedJSONValue objJson; |
MrAI | 12:1b24ea479a59 | 540 | string strJson = ""; |
MrAI | 12:1b24ea479a59 | 541 | string strUrl = "/v1/server"; |
MrAI | 12:1b24ea479a59 | 542 | strJson = serInfo.GetPaymentInfo(strUrl, "", ""); |
MrAI | 12:1b24ea479a59 | 543 | if (strJson.empty()) |
MrAI | 12:1b24ea479a59 | 544 | { |
MrAI | 16:17d0db6c449d | 545 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 546 | setLedStatusErr(myled1); |
MrAI | 12:1b24ea479a59 | 547 | return -1; |
MrAI | 12:1b24ea479a59 | 548 | } |
MrAI | 12:1b24ea479a59 | 549 | string err = serInfo.getParseMbedJson(objJson, strJson.c_str()); |
MrAI | 12:1b24ea479a59 | 550 | bool bSuccess = serInfo.getRequestRet(objJson); |
MrAI | 12:1b24ea479a59 | 551 | if (bSuccess) |
MrAI | 12:1b24ea479a59 | 552 | { |
MrAI | 16:17d0db6c449d | 553 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 554 | setLedStatus(myled2); |
MrAI | 12:1b24ea479a59 | 555 | string complete_ledgers = serInfo.getKeyValue(objJson, "sdchaind_server_status", "complete_ledgers"); |
MrAI | 12:1b24ea479a59 | 556 | string server_state = serInfo.getKeyValue(objJson, "sdchaind_server_status", "server_state"); |
MrAI | 12:1b24ea479a59 | 557 | int reserve_base_sda = serInfo.getKeyValueInt(objJson, "sdchaind_server_status", "reserve_base_sda"); |
MrAI | 13:e77c7ae3a285 | 558 | cout << "complete_ledgers:" << complete_ledgers <<endl<< "server_state:" << server_state<<endl << "reserve_base_sda:" << reserve_base_sda << endl; |
MrAI | 12:1b24ea479a59 | 559 | } |
MrAI | 15:7b56d49392be | 560 | else |
MrAI | 16:17d0db6c449d | 561 | { |
MrAI | 16:17d0db6c449d | 562 | reset_LedRun(); |
MrAI | 16:17d0db6c449d | 563 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 564 | } |
MrAI | 12:1b24ea479a59 | 565 | return 0; |
MrAI | 12:1b24ea479a59 | 566 | } |
MrAI | 12:1b24ea479a59 | 567 | |
MrAI | 12:1b24ea479a59 | 568 | int sd_getserverconnected() |
MrAI | 12:1b24ea479a59 | 569 | { |
MrAI | 15:7b56d49392be | 570 | setLedOff(); |
MrAI | 16:17d0db6c449d | 571 | isRunning = true; |
MrAI | 12:1b24ea479a59 | 572 | ServerInfo serInfo; |
MrAI | 12:1b24ea479a59 | 573 | MbedJSONValue objJson; |
MrAI | 12:1b24ea479a59 | 574 | string strJson = ""; |
MrAI | 12:1b24ea479a59 | 575 | string strUrl = "/v1/server/connected"; |
MrAI | 12:1b24ea479a59 | 576 | strJson = serInfo.GetPaymentInfo(strUrl, "", ""); |
MrAI | 12:1b24ea479a59 | 577 | if (strJson.empty()) |
MrAI | 12:1b24ea479a59 | 578 | { |
MrAI | 16:17d0db6c449d | 579 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 580 | setLedStatusErr(myled1); |
MrAI | 12:1b24ea479a59 | 581 | return -1; |
MrAI | 12:1b24ea479a59 | 582 | } |
MrAI | 12:1b24ea479a59 | 583 | string err = serInfo.getParseMbedJson(objJson, strJson.c_str()); |
MrAI | 12:1b24ea479a59 | 584 | bool bSuccess = serInfo.getRequestRet(objJson); |
MrAI | 12:1b24ea479a59 | 585 | if (bSuccess) |
MrAI | 12:1b24ea479a59 | 586 | { |
MrAI | 16:17d0db6c449d | 587 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 588 | setLedStatus(myled2); |
MrAI | 12:1b24ea479a59 | 589 | bool connected = serInfo.getKeyValueBool(objJson, "connected"); |
MrAI | 13:e77c7ae3a285 | 590 | if(connected) |
MrAI | 13:e77c7ae3a285 | 591 | {cout<<"server is running"<<endl;} |
MrAI | 13:e77c7ae3a285 | 592 | else |
MrAI | 13:e77c7ae3a285 | 593 | {cout<<"server stopped"<<endl;} |
MrAI | 12:1b24ea479a59 | 594 | } |
MrAI | 15:7b56d49392be | 595 | else |
MrAI | 16:17d0db6c449d | 596 | { |
MrAI | 16:17d0db6c449d | 597 | reset_LedRun(); |
MrAI | 16:17d0db6c449d | 598 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 599 | } |
MrAI | 12:1b24ea479a59 | 600 | return 0; |
MrAI | 12:1b24ea479a59 | 601 | } |
MrAI | 12:1b24ea479a59 | 602 | |
MrAI | 12:1b24ea479a59 | 603 | int sd_queryorderlist() |
MrAI | 12:1b24ea479a59 | 604 | { |
MrAI | 15:7b56d49392be | 605 | setLedOff(); |
MrAI | 16:17d0db6c449d | 606 | isRunning = true; |
MrAI | 12:1b24ea479a59 | 607 | Order orderInfo; |
MrAI | 12:1b24ea479a59 | 608 | MbedJSONValue objJson; |
MrAI | 12:1b24ea479a59 | 609 | string strJson = ""; |
MrAI | 12:1b24ea479a59 | 610 | string strUrl = "/v1/accounts/orders/"; |
MrAI | 12:1b24ea479a59 | 611 | string strWallet = "6ByxwCh2Lqwwr3pk6mh4GBb4bsqFz2zAKY"; |
MrAI | 12:1b24ea479a59 | 612 | strJson = orderInfo.GetPaymentInfo(strUrl, strWallet, ""); |
MrAI | 12:1b24ea479a59 | 613 | if (strJson.empty()) |
MrAI | 12:1b24ea479a59 | 614 | { |
MrAI | 16:17d0db6c449d | 615 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 616 | setLedStatusErr(myled1); |
MrAI | 12:1b24ea479a59 | 617 | return -1; |
MrAI | 12:1b24ea479a59 | 618 | } |
MrAI | 12:1b24ea479a59 | 619 | string err = orderInfo.getParseMbedJson(objJson, strJson.c_str()); |
MrAI | 12:1b24ea479a59 | 620 | bool bSuccess = orderInfo.getRequestRet(objJson); |
MrAI | 12:1b24ea479a59 | 621 | if (bSuccess) |
MrAI | 12:1b24ea479a59 | 622 | { |
MrAI | 16:17d0db6c449d | 623 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 624 | setLedStatus(myled2); |
MrAI | 12:1b24ea479a59 | 625 | int ledger = objJson["ledger"].get<int>(); |
MrAI | 12:1b24ea479a59 | 626 | bool validated = orderInfo.getKeyValueBool(objJson, "validated"); |
MrAI | 12:1b24ea479a59 | 627 | int iCurrenciesNum = orderInfo.getBalanceSize(objJson, "orders"); |
MrAI | 12:1b24ea479a59 | 628 | for (int i = 0; i < iCurrenciesNum; i++) |
MrAI | 12:1b24ea479a59 | 629 | { |
MrAI | 12:1b24ea479a59 | 630 | string type = orderInfo.getBalanceArray(objJson, "orders", i, "type"); |
MrAI | 12:1b24ea479a59 | 631 | string currency_gets = orderInfo.getBalanceArray(objJson, "orders","taker_gets",i,"currency"); |
MrAI | 12:1b24ea479a59 | 632 | string value_gets = orderInfo.getBalanceArray(objJson, "orders", "taker_gets", i, "value"); |
MrAI | 12:1b24ea479a59 | 633 | string counterparty_gets = orderInfo.getBalanceArray(objJson, "orders", "taker_gets", i, "counterparty"); |
MrAI | 12:1b24ea479a59 | 634 | string currency_pays = orderInfo.getBalanceArray(objJson, "orders", "taker_pays", i, "currency"); |
MrAI | 12:1b24ea479a59 | 635 | string value_pays = orderInfo.getBalanceArray(objJson, "orders", "taker_pays", i, "value"); |
MrAI | 12:1b24ea479a59 | 636 | string counterparty_pays = orderInfo.getBalanceArray(objJson, "orders", "taker_pays", i, "counterparty"); |
MrAI | 13:e77c7ae3a285 | 637 | cout << "type:" << type <<endl<< "currency_gets:" << currency_gets <<endl<< "value_gets:" << value_gets<<endl |
MrAI | 13:e77c7ae3a285 | 638 | << "counterparty_gets:" << counterparty_gets <<endl<< "currency_pays:" << currency_pays<<endl |
MrAI | 13:e77c7ae3a285 | 639 | << "value_pays:" << value_pays <<endl<< "counterparty_pays:" << counterparty_pays << endl; |
MrAI | 12:1b24ea479a59 | 640 | } |
MrAI | 13:e77c7ae3a285 | 641 | cout << "ledger:" << ledger <<endl<< "validated:" << validated << endl; |
MrAI | 12:1b24ea479a59 | 642 | } |
MrAI | 15:7b56d49392be | 643 | else |
MrAI | 16:17d0db6c449d | 644 | { |
MrAI | 16:17d0db6c449d | 645 | reset_LedRun(); |
MrAI | 16:17d0db6c449d | 646 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 647 | } |
MrAI | 12:1b24ea479a59 | 648 | return 0; |
MrAI | 12:1b24ea479a59 | 649 | } |
MrAI | 12:1b24ea479a59 | 650 | |
MrAI | 12:1b24ea479a59 | 651 | int sd_commitorder() |
MrAI | 12:1b24ea479a59 | 652 | { |
MrAI | 15:7b56d49392be | 653 | setLedOff(); |
MrAI | 16:17d0db6c449d | 654 | isRunning = true; |
MrAI | 12:1b24ea479a59 | 655 | Order orderCommit; |
MrAI | 12:1b24ea479a59 | 656 | MbedJSONValue objJson; |
MrAI | 12:1b24ea479a59 | 657 | MbedJSONValue mbJson; |
MrAI | 12:1b24ea479a59 | 658 | string strJson = ""; |
MrAI | 12:1b24ea479a59 | 659 | string strUrl = "/v1/accounts/orders/"; |
MrAI | 12:1b24ea479a59 | 660 | string strWallet = "6ByxwCh2Lqwwr3pk6mh4GBb4bsqFz2zAKY"; |
MrAI | 12:1b24ea479a59 | 661 | string secret = "sh7dqVn8mhg6BqGfAQyaYVUwK2zkR"; |
MrAI | 12:1b24ea479a59 | 662 | orderCommit.SetJsonBody(mbJson, secret, "buy", "SDA", "", "4", "CNY", "6UPd52jHtu1d88nc3S3WeroACFQpKfybhU", "22"); |
MrAI | 12:1b24ea479a59 | 663 | strJson = orderCommit.PostPayment(mbJson, strUrl, strWallet, ""); |
MrAI | 12:1b24ea479a59 | 664 | if (strJson.empty()) |
MrAI | 12:1b24ea479a59 | 665 | { |
MrAI | 16:17d0db6c449d | 666 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 667 | setLedStatusErr(myled1); |
MrAI | 12:1b24ea479a59 | 668 | return -1; |
MrAI | 12:1b24ea479a59 | 669 | } |
MrAI | 12:1b24ea479a59 | 670 | string err = orderCommit.getParseMbedJson(objJson, strJson.c_str()); |
MrAI | 12:1b24ea479a59 | 671 | bool bSuccess = orderCommit.getRequestRet(objJson); |
MrAI | 12:1b24ea479a59 | 672 | if (bSuccess) |
MrAI | 12:1b24ea479a59 | 673 | { |
MrAI | 16:17d0db6c449d | 674 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 675 | setLedStatus(myled2); |
MrAI | 12:1b24ea479a59 | 676 | string account = orderCommit.getKeyValue(objJson, "order", "account"); |
MrAI | 12:1b24ea479a59 | 677 | string currency_g = orderCommit.getKeyValue(objJson, "taker_gets", "currency"); |
MrAI | 12:1b24ea479a59 | 678 | string value_g = orderCommit.getKeyValue(objJson, "taker_gets", "value"); |
MrAI | 12:1b24ea479a59 | 679 | string counterparty_g = orderCommit.getKeyValue(objJson, "taker_gets", "counterparty"); |
MrAI | 12:1b24ea479a59 | 680 | string currency_p = orderCommit.getKeyValue(objJson, "taker_pays", "currency"); |
MrAI | 12:1b24ea479a59 | 681 | string value_p = orderCommit.getKeyValue(objJson, "taker_pays", "value"); |
MrAI | 12:1b24ea479a59 | 682 | string counterparty_p = orderCommit.getKeyValue(objJson, "taker_pays", "counterparty"); |
MrAI | 12:1b24ea479a59 | 683 | string fee = orderCommit.getKeyValue(objJson, "order", "fee"); |
MrAI | 12:1b24ea479a59 | 684 | string type = orderCommit.getKeyValue(objJson, "order", "type"); |
MrAI | 12:1b24ea479a59 | 685 | int sequence = orderCommit.getKeyValueInt(objJson, "order","sequence"); |
MrAI | 12:1b24ea479a59 | 686 | string hash = orderCommit.getKeyValue(objJson, "hash"); |
MrAI | 12:1b24ea479a59 | 687 | int ledger = orderCommit.getLedger(objJson); |
MrAI | 12:1b24ea479a59 | 688 | string state = orderCommit.getKeyValue(objJson, "state"); |
MrAI | 13:e77c7ae3a285 | 689 | cout<<"account:"<<account<<endl<<"fee:"<<fee<<endl<<"hash:"<<hash<<endl<<"state:"<<state<<endl; |
MrAI | 12:1b24ea479a59 | 690 | } |
MrAI | 15:7b56d49392be | 691 | else |
MrAI | 16:17d0db6c449d | 692 | { |
MrAI | 16:17d0db6c449d | 693 | reset_LedRun(); |
MrAI | 16:17d0db6c449d | 694 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 695 | } |
MrAI | 12:1b24ea479a59 | 696 | return 0; |
MrAI | 12:1b24ea479a59 | 697 | } |
MrAI | 12:1b24ea479a59 | 698 | |
MrAI | 12:1b24ea479a59 | 699 | int sd_deleteorder() |
MrAI | 12:1b24ea479a59 | 700 | { |
MrAI | 15:7b56d49392be | 701 | setLedOff(); |
MrAI | 16:17d0db6c449d | 702 | isRunning = true; |
MrAI | 12:1b24ea479a59 | 703 | Order orderCommit; |
MrAI | 12:1b24ea479a59 | 704 | MbedJSONValue objJson; |
MrAI | 12:1b24ea479a59 | 705 | MbedJSONValue mbJson; |
MrAI | 12:1b24ea479a59 | 706 | MbedJSONValue val; |
MrAI | 12:1b24ea479a59 | 707 | string strJson = ""; |
MrAI | 12:1b24ea479a59 | 708 | string strUrl = "/v1/accounts/orders/"; |
MrAI | 12:1b24ea479a59 | 709 | string strWallet = "6ByxwCh2Lqwwr3pk6mh4GBb4bsqFz2zAKY"; |
MrAI | 12:1b24ea479a59 | 710 | string strNum = "1234"; |
MrAI | 12:1b24ea479a59 | 711 | val["secret"] = "sh7dqVn8mhg6BqGfAQyaYVUwK2zkR"; |
MrAI | 12:1b24ea479a59 | 712 | strJson = orderCommit.PostOrder(val, strUrl, strWallet, strNum); |
MrAI | 12:1b24ea479a59 | 713 | if (strJson.empty()) |
MrAI | 12:1b24ea479a59 | 714 | { |
MrAI | 16:17d0db6c449d | 715 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 716 | setLedStatusErr(myled1); |
MrAI | 12:1b24ea479a59 | 717 | return -1; |
MrAI | 12:1b24ea479a59 | 718 | } |
MrAI | 12:1b24ea479a59 | 719 | string err = orderCommit.getParseMbedJson(objJson, strJson.c_str()); |
MrAI | 15:7b56d49392be | 720 | if (!err.empty()) |
MrAI | 15:7b56d49392be | 721 | { |
MrAI | 16:17d0db6c449d | 722 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 723 | cout<<"getParseMbedJson error"<<endl; |
MrAI | 15:7b56d49392be | 724 | setLedStatusErr(myled1); |
MrAI | 15:7b56d49392be | 725 | return -1; |
MrAI | 15:7b56d49392be | 726 | } |
MrAI | 12:1b24ea479a59 | 727 | bool bSuccess = orderCommit.getRequestRet(objJson); |
MrAI | 12:1b24ea479a59 | 728 | if (bSuccess) |
MrAI | 12:1b24ea479a59 | 729 | { |
MrAI | 16:17d0db6c449d | 730 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 731 | setLedStatus(myled2); |
MrAI | 12:1b24ea479a59 | 732 | string account = orderCommit.getKeyValue(objJson, "order", "account"); |
MrAI | 12:1b24ea479a59 | 733 | string fee = orderCommit.getKeyValue(objJson, "order", "fee"); |
MrAI | 12:1b24ea479a59 | 734 | string offer_sequence = orderCommit.getKeyValue(objJson, "order", "offer_sequence"); |
MrAI | 12:1b24ea479a59 | 735 | string sequence = orderCommit.getKeyValue(objJson, "order", "sequence"); |
MrAI | 12:1b24ea479a59 | 736 | string hash = orderCommit.getKeyValue(objJson, "hash"); |
MrAI | 12:1b24ea479a59 | 737 | string ledger = orderCommit.getKeyValue(objJson, "ledger"); |
MrAI | 12:1b24ea479a59 | 738 | string state = orderCommit.getKeyValue(objJson, "state"); |
MrAI | 13:e77c7ae3a285 | 739 | cout << "account:" << account <<endl<< "fee:" << fee <<endl<< "offer_sequence:" << offer_sequence<<endl |
MrAI | 13:e77c7ae3a285 | 740 | << "sequence:" << sequence <<endl<< "hash:" << hash <<endl<<"ledger:" << ledger <<endl<< "state:" << state << endl; |
MrAI | 12:1b24ea479a59 | 741 | } |
MrAI | 15:7b56d49392be | 742 | else |
MrAI | 16:17d0db6c449d | 743 | { |
MrAI | 16:17d0db6c449d | 744 | reset_LedRun(); |
MrAI | 16:17d0db6c449d | 745 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 746 | } |
MrAI | 12:1b24ea479a59 | 747 | return 0; |
MrAI | 12:1b24ea479a59 | 748 | } |
MrAI | 12:1b24ea479a59 | 749 | |
MrAI | 12:1b24ea479a59 | 750 | int sd_queryorderdetailed() |
MrAI | 12:1b24ea479a59 | 751 | { |
MrAI | 15:7b56d49392be | 752 | setLedOff(); |
MrAI | 16:17d0db6c449d | 753 | isRunning = true; |
MrAI | 12:1b24ea479a59 | 754 | cout << "call sd_queryorderdetailed begin" << endl; |
MrAI | 12:1b24ea479a59 | 755 | Order orderInfo; |
MrAI | 12:1b24ea479a59 | 756 | MbedJSONValue objJson; |
MrAI | 12:1b24ea479a59 | 757 | string strJson = ""; |
MrAI | 12:1b24ea479a59 | 758 | string strUrl = " /v1/accounts/orders/"; |
MrAI | 12:1b24ea479a59 | 759 | string strWallet = "6ByxwCh2Lqwwr3pk6mh4GBb4bsqFz2zAKY"; |
MrAI | 12:1b24ea479a59 | 760 | string hash = "EF252979355F2666486F69E9C96D137265214DE65B14E1136ECCDCE84F09AD11"; |
MrAI | 12:1b24ea479a59 | 761 | strJson = orderInfo.GetPaymentInfo(strUrl, strWallet,hash); |
MrAI | 12:1b24ea479a59 | 762 | if (strJson.empty()) |
MrAI | 12:1b24ea479a59 | 763 | { |
MrAI | 16:17d0db6c449d | 764 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 765 | setLedStatusErr(myled1); |
MrAI | 12:1b24ea479a59 | 766 | cout << "call sd_queryorderdetailed exception quit" << endl; |
MrAI | 12:1b24ea479a59 | 767 | return -1; |
MrAI | 12:1b24ea479a59 | 768 | } |
MrAI | 12:1b24ea479a59 | 769 | string err = orderInfo.getParseMbedJson(objJson, strJson.c_str()); |
MrAI | 12:1b24ea479a59 | 770 | bool bSuccess = orderInfo.getRequestRet(objJson); |
MrAI | 12:1b24ea479a59 | 771 | if (bSuccess) |
MrAI | 12:1b24ea479a59 | 772 | { |
MrAI | 16:17d0db6c449d | 773 | reset_LedRun(); |
MrAI | 15:7b56d49392be | 774 | setLedStatus(myled2); |
MrAI | 12:1b24ea479a59 | 775 | string hash = orderInfo.getKeyValue(objJson, "hash"); |
MrAI | 12:1b24ea479a59 | 776 | int ledger = objJson["ledger"].get<int>(); |
MrAI | 12:1b24ea479a59 | 777 | int iBalanceNum = orderInfo.getBalanceSize(objJson, "balance_changes"); |
MrAI | 12:1b24ea479a59 | 778 | for (int i = 0; i < iBalanceNum; i++) |
MrAI | 12:1b24ea479a59 | 779 | { |
MrAI | 12:1b24ea479a59 | 780 | string counterparty = orderInfo.getBalanceArray(objJson, "balance_changes", i, "counterparty"); |
MrAI | 13:e77c7ae3a285 | 781 | cout<<"counterparty:"<<counterparty<<endl; |
MrAI | 12:1b24ea479a59 | 782 | } |
MrAI | 12:1b24ea479a59 | 783 | int iOrderChangesNum = orderInfo.getBalanceSize(objJson, "order_changes"); |
MrAI | 12:1b24ea479a59 | 784 | for (int j = 0; j < iOrderChangesNum; j++) |
MrAI | 12:1b24ea479a59 | 785 | { |
MrAI | 12:1b24ea479a59 | 786 | string currency_gets = orderInfo.getBalanceArray(objJson, "order_changes", "taker_gets", j, "currency"); |
MrAI | 13:e77c7ae3a285 | 787 | cout<<"currency_gets:"<<currency_gets<<endl; |
MrAI | 12:1b24ea479a59 | 788 | } |
MrAI | 13:e77c7ae3a285 | 789 | cout<<"hash:"<<hash<<endl; |
MrAI | 12:1b24ea479a59 | 790 | |
MrAI | 12:1b24ea479a59 | 791 | } |
MrAI | 15:7b56d49392be | 792 | else |
MrAI | 16:17d0db6c449d | 793 | { |
MrAI | 16:17d0db6c449d | 794 | reset_LedRun(); |
MrAI | 16:17d0db6c449d | 795 | setLedStatusErr(myled1); |
MrAI | 16:17d0db6c449d | 796 | } |
MrAI | 12:1b24ea479a59 | 797 | cout << "call sd_queryorderdetailed end" << endl; |
MrAI | 12:1b24ea479a59 | 798 | return 0; |
MrAI | 12:1b24ea479a59 | 799 | } |
MrAI | 15:7b56d49392be | 800 | |
MrAI | 15:7b56d49392be | 801 | |
webmaster | 8:f2a567ee3a46 | 802 | int main(void) |
webmaster | 8:f2a567ee3a46 | 803 | { |
webmaster | 8:f2a567ee3a46 | 804 | printf("main start\n"); |
MrAI | 12:1b24ea479a59 | 805 | // test_uuid(); |
MrAI | 16:17d0db6c449d | 806 | Thread thread1(thread_LedRun); |
webmaster | 9:d7468574ef8f | 807 | |
webmaster | 8:f2a567ee3a46 | 808 | socket_init(); |
MrAI | 13:e77c7ae3a285 | 809 | cout<<"**************************GET NEW WALLET****************************"<<endl; |
MrAI | 12:1b24ea479a59 | 810 | sd_wallet(); |
MrAI | 16:17d0db6c449d | 811 | wait(3); |
MrAI | 13:e77c7ae3a285 | 812 | cout<<"*************************POST PAYMENT REQUEST********************"<<endl; |
MrAI | 16:17d0db6c449d | 813 | string strHash = sd_postpayment(); |
MrAI | 16:17d0db6c449d | 814 | wait(3); |
MrAI | 16:17d0db6c449d | 815 | cout<<"**************************GET ACCOUNT BALANCE************************"<<endl; |
MrAI | 16:17d0db6c449d | 816 | long balance = sd_account(); |
MrAI | 16:17d0db6c449d | 817 | wait(3); |
MrAI | 16:17d0db6c449d | 818 | setLedOff(); |
MrAI | 16:17d0db6c449d | 819 | wait(2); |
MrAI | 16:17d0db6c449d | 820 | if(balance > 400) |
MrAI | 16:17d0db6c449d | 821 | { |
MrAI | 16:17d0db6c449d | 822 | printf("balance more than 400\n"); |
MrAI | 16:17d0db6c449d | 823 | setLedStatus(myled2); |
MrAI | 16:17d0db6c449d | 824 | wait(8); |
MrAI | 16:17d0db6c449d | 825 | } |
MrAI | 13:e77c7ae3a285 | 826 | cout<<"*************************GET PAYMENT INFO****************"<<endl; |
MrAI | 16:17d0db6c449d | 827 | sd_getpaymentinfo(strHash); |
MrAI | 16:17d0db6c449d | 828 | wait(3); |
MrAI | 13:e77c7ae3a285 | 829 | cout<<"*************************GET TRANSACTIONS INFO***********"<<endl; |
MrAI | 16:17d0db6c449d | 830 | sd_gettransactions(strHash); |
MrAI | 16:17d0db6c449d | 831 | wait(3); |
MrAI | 13:e77c7ae3a285 | 832 | cout<<"*************************GET PAYMENT HISTORY*****************"<<endl; |
MrAI | 13:e77c7ae3a285 | 833 | sd_getpaymenthistory(); |
MrAI | 16:17d0db6c449d | 834 | wait(3); |
MrAI | 13:e77c7ae3a285 | 835 | cout<<"*************************GET DEFAULT FEE**********************"<<endl; |
MrAI | 13:e77c7ae3a285 | 836 | sd_getdefaultfee(); |
MrAI | 16:17d0db6c449d | 837 | wait(3); |
MrAI | 13:e77c7ae3a285 | 838 | cout<<"*************************GET SERVER INFO******************"<<endl; |
MrAI | 13:e77c7ae3a285 | 839 | sd_getserverinfo(); |
MrAI | 16:17d0db6c449d | 840 | wait(3); |
MrAI | 13:e77c7ae3a285 | 841 | cout<<"*************************GET SERVER CONNECTED******************"<<endl; |
MrAI | 13:e77c7ae3a285 | 842 | sd_getserverconnected(); |
MrAI | 16:17d0db6c449d | 843 | wait(3); |
MrAI | 13:e77c7ae3a285 | 844 | cout<<"*************************GET ORDER LIST********************"<<endl; |
MrAI | 13:e77c7ae3a285 | 845 | sd_queryorderlist(); |
MrAI | 16:17d0db6c449d | 846 | wait(3); |
MrAI | 13:e77c7ae3a285 | 847 | cout<<"*************************POST ORDER INFO********************"<<endl; |
MrAI | 13:e77c7ae3a285 | 848 | sd_commitorder(); |
MrAI | 16:17d0db6c449d | 849 | wait(3); |
MrAI | 13:e77c7ae3a285 | 850 | cout<<"*************************DELETE ORDER INFO********************"<<endl; |
MrAI | 13:e77c7ae3a285 | 851 | sd_deleteorder(); |
MrAI | 16:17d0db6c449d | 852 | wait(3); |
MrAI | 13:e77c7ae3a285 | 853 | cout<<"*************************GET ORDER DETAILED*******************"<<endl; |
MrAI | 13:e77c7ae3a285 | 854 | sd_queryorderdetailed(); |
MrAI | 12:1b24ea479a59 | 855 | |
webmaster | 10:aabd720e632c | 856 | //char isContinue = 'y'; |
webmaster | 10:aabd720e632c | 857 | // do |
webmaster | 10:aabd720e632c | 858 | //{ |
MrAI | 13:e77c7ae3a285 | 859 | //tring type = "spend_account"; |
webmaster | 10:aabd720e632c | 860 | //string type = "issue"; |
webmaster | 10:aabd720e632c | 861 | //test_transaction(type); |
MrAI | 13:e77c7ae3a285 | 862 | //est_transaction(); |
MrAI | 13:e77c7ae3a285 | 863 | //rintf("=============5========\n"); |
webmaster | 10:aabd720e632c | 864 | // }while(1); |
webmaster | 10:aabd720e632c | 865 | //}while (isContinue = getch() != 'q'); |
webmaster | 8:f2a567ee3a46 | 866 | |
webmaster | 10:aabd720e632c | 867 | |
webmaster | 10:aabd720e632c | 868 | //test_socket_client(); |
webmaster | 8:f2a567ee3a46 | 869 | |
webmaster | 8:f2a567ee3a46 | 870 | socket_fini(); |
MrAI | 15:7b56d49392be | 871 | setLedOff(); |
webmaster | 8:f2a567ee3a46 | 872 | printf("main end\n"); |
webmaster | 8:f2a567ee3a46 | 873 | return 0; |
webmaster | 8:f2a567ee3a46 | 874 | } |
webmaster | 8:f2a567ee3a46 | 875 | |
webmaster | 8:f2a567ee3a46 | 876 | int socket_init() |
webmaster | 8:f2a567ee3a46 | 877 | { |
webmaster | 8:f2a567ee3a46 | 878 | int ret = 0; |
webmaster | 8:f2a567ee3a46 | 879 | // EthernetInterface eth; |
webmaster | 8:f2a567ee3a46 | 880 | printf("Initializing Ethernet\n"); |
webmaster | 8:f2a567ee3a46 | 881 | ret = eth.init(); //Use DHCP |
webmaster | 8:f2a567ee3a46 | 882 | //eth.init("192.168.31.186", "255.255.255.0", "192.168.31.1"); //Use static ip |
webmaster | 8:f2a567ee3a46 | 883 | printf("Connecting\n"); |
webmaster | 8:f2a567ee3a46 | 884 | ret = eth.connect(); |
webmaster | 8:f2a567ee3a46 | 885 | printf("IP Address is %s\n", eth.getIPAddress()); |
webmaster | 8:f2a567ee3a46 | 886 | |
webmaster | 8:f2a567ee3a46 | 887 | return ret; |
webmaster | 8:f2a567ee3a46 | 888 | } |
webmaster | 8:f2a567ee3a46 | 889 | |
webmaster | 8:f2a567ee3a46 | 890 | int socket_fini() |
webmaster | 8:f2a567ee3a46 | 891 | { |
webmaster | 8:f2a567ee3a46 | 892 | return eth.disconnect(); |
webmaster | 8:f2a567ee3a46 | 893 | } |
webmaster | 8:f2a567ee3a46 | 894 | |
webmaster | 8:f2a567ee3a46 | 895 | int test_socket_client(void) |
webmaster | 8:f2a567ee3a46 | 896 | { |
webmaster | 8:f2a567ee3a46 | 897 | TCPSocketConnection socket; |
webmaster | 8:f2a567ee3a46 | 898 | while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0) { |
webmaster | 8:f2a567ee3a46 | 899 | printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); |
webmaster | 8:f2a567ee3a46 | 900 | wait(1); |
webmaster | 8:f2a567ee3a46 | 901 | } |
webmaster | 8:f2a567ee3a46 | 902 | printf("Connected to Server at %s\n",ECHO_SERVER_ADDRESS); |
webmaster | 8:f2a567ee3a46 | 903 | |
webmaster | 8:f2a567ee3a46 | 904 | // Send message to server |
webmaster | 8:f2a567ee3a46 | 905 | char hello[] = "Hello World"; |
webmaster | 8:f2a567ee3a46 | 906 | printf("Sending message to Server : '%s' \n",hello); |
webmaster | 8:f2a567ee3a46 | 907 | socket.send_all(hello, sizeof(hello) - 1); |
webmaster | 8:f2a567ee3a46 | 908 | |
webmaster | 8:f2a567ee3a46 | 909 | // Receive message from server |
webmaster | 8:f2a567ee3a46 | 910 | char buf[256]; |
webmaster | 8:f2a567ee3a46 | 911 | int n = socket.receive(buf, 256); |
webmaster | 8:f2a567ee3a46 | 912 | buf[n] = '\0'; |
webmaster | 8:f2a567ee3a46 | 913 | printf("Received message from server: '%s'\n", buf); |
webmaster | 8:f2a567ee3a46 | 914 | |
webmaster | 8:f2a567ee3a46 | 915 | // Clean up |
webmaster | 8:f2a567ee3a46 | 916 | socket.close(); |
webmaster | 8:f2a567ee3a46 | 917 | |
webmaster | 8:f2a567ee3a46 | 918 | return 0; |
webmaster | 8:f2a567ee3a46 | 919 | } |
webmaster | 8:f2a567ee3a46 | 920 | |
MrAI | 11:6d9cefb14158 | 921 | /* |
gsteiert | 0:28bc7ce77e20 | 922 | void get_file(char* uri) |
gsteiert | 0:28bc7ce77e20 | 923 | { |
gsteiert | 3:4f71a37a1ed2 | 924 | uart.printf("get_file %s\n", uri); |
gsteiert | 0:28bc7ce77e20 | 925 | char *lstchr = strrchr(uri, NULL) -1; |
gsteiert | 0:28bc7ce77e20 | 926 | if ('/' == *lstchr) { |
gsteiert | 3:4f71a37a1ed2 | 927 | uart.printf("Open directory /sd%s\n", uri); |
gsteiert | 0:28bc7ce77e20 | 928 | *lstchr = 0; |
gsteiert | 3:4f71a37a1ed2 | 929 | sprintf(fileName, "/sd%s", uri); |
gsteiert | 3:4f71a37a1ed2 | 930 | DIR *d = opendir(fileName); |
gsteiert | 0:28bc7ce77e20 | 931 | if (d != NULL) { |
gsteiert | 0:28bc7ce77e20 | 932 | sprintf(httpHeader,"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n"); |
gsteiert | 0:28bc7ce77e20 | 933 | client.send(httpHeader,strlen(httpHeader)); |
gsteiert | 3:4f71a37a1ed2 | 934 | sprintf(httpHeader,"<html><head><title>Directory Listing</title></head><body><h1>%s Directory Listing</h1><ul>", uri); |
gsteiert | 0:28bc7ce77e20 | 935 | client.send(httpHeader,strlen(httpHeader)); |
gsteiert | 0:28bc7ce77e20 | 936 | struct dirent *p; |
gsteiert | 0:28bc7ce77e20 | 937 | while((p = readdir(d)) != NULL) { |
gsteiert | 3:4f71a37a1ed2 | 938 | sprintf(dirName, "%s/%s", fileName, p->d_name); |
gsteiert | 3:4f71a37a1ed2 | 939 | uart.printf("%s\n", dirName); |
gsteiert | 3:4f71a37a1ed2 | 940 | DIR *subDir = opendir(dirName); |
gsteiert | 3:4f71a37a1ed2 | 941 | if (subDir != NULL) { |
gsteiert | 3:4f71a37a1ed2 | 942 | sprintf(httpHeader,"<li><a href=\"./%s/\">%s/</a></li>", p->d_name, p->d_name); |
gsteiert | 3:4f71a37a1ed2 | 943 | } else { |
gsteiert | 3:4f71a37a1ed2 | 944 | sprintf(httpHeader,"<li><a href=\"./%s\">%s</a></li>", p->d_name, p->d_name); |
gsteiert | 3:4f71a37a1ed2 | 945 | } |
gsteiert | 0:28bc7ce77e20 | 946 | client.send(httpHeader,strlen(httpHeader)); |
gsteiert | 0:28bc7ce77e20 | 947 | } |
gsteiert | 0:28bc7ce77e20 | 948 | } |
gsteiert | 0:28bc7ce77e20 | 949 | closedir(d); |
gsteiert | 3:4f71a37a1ed2 | 950 | uart.printf("Directory closed\n"); |
gsteiert | 0:28bc7ce77e20 | 951 | sprintf(httpHeader,"</ul></body></html>"); |
gsteiert | 0:28bc7ce77e20 | 952 | client.send(httpHeader,strlen(httpHeader)); |
gsteiert | 0:28bc7ce77e20 | 953 | } else { |
gsteiert | 3:4f71a37a1ed2 | 954 | sprintf(fileName, "/sd%s", uri); |
gsteiert | 3:4f71a37a1ed2 | 955 | fp = fopen(fileName, "r"); |
gsteiert | 0:28bc7ce77e20 | 956 | if (fp == NULL) { |
gsteiert | 7:04744a9ce2b9 | 957 | uart.printf("File not found\n"); |
gsteiert | 0:28bc7ce77e20 | 958 | sprintf(httpHeader,"HTTP/1.1 404 Not Found \r\nContent-Type: text\r\nConnection: Close\r\n\r\n"); |
gsteiert | 0:28bc7ce77e20 | 959 | client.send(httpHeader,strlen(httpHeader)); |
gsteiert | 0:28bc7ce77e20 | 960 | client.send(uri,strlen(uri)); |
gsteiert | 0:28bc7ce77e20 | 961 | } else { |
gsteiert | 7:04744a9ce2b9 | 962 | uart.printf("Sending: header"); |
gsteiert | 0:28bc7ce77e20 | 963 | sprintf(httpHeader,"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: Close\r\n\r\n"); |
gsteiert | 0:28bc7ce77e20 | 964 | client.send(httpHeader,strlen(httpHeader)); |
gsteiert | 7:04744a9ce2b9 | 965 | uart.printf(" file"); |
gsteiert | 0:28bc7ce77e20 | 966 | while ((rdCnt = fread(buffer, sizeof( char ), 1024, fp)) == 1024) { |
gsteiert | 0:28bc7ce77e20 | 967 | client.send(buffer, rdCnt); |
gsteiert | 7:04744a9ce2b9 | 968 | uart.printf("."); |
gsteiert | 0:28bc7ce77e20 | 969 | } |
gsteiert | 0:28bc7ce77e20 | 970 | client.send(buffer, rdCnt); |
gsteiert | 0:28bc7ce77e20 | 971 | fclose(fp); |
gsteiert | 7:04744a9ce2b9 | 972 | uart.printf("done\n"); |
gsteiert | 0:28bc7ce77e20 | 973 | } |
gsteiert | 0:28bc7ce77e20 | 974 | } |
gsteiert | 0:28bc7ce77e20 | 975 | } |
gsteiert | 0:28bc7ce77e20 | 976 | |
webmaster | 8:f2a567ee3a46 | 977 | int main_1 (void) |
gsteiert | 0:28bc7ce77e20 | 978 | { |
gsteiert | 3:4f71a37a1ed2 | 979 | // Serial Interface eth; |
gsteiert | 3:4f71a37a1ed2 | 980 | uart.baud(115200); |
gsteiert | 5:27b09a0f3fb6 | 981 | uart.printf("Initializing\n"); |
gsteiert | 3:4f71a37a1ed2 | 982 | |
gsteiert | 3:4f71a37a1ed2 | 983 | // Check File System |
gsteiert | 5:27b09a0f3fb6 | 984 | uart.printf("Checking File System\n"); |
gsteiert | 3:4f71a37a1ed2 | 985 | DIR *d = opendir("/sd/"); |
gsteiert | 3:4f71a37a1ed2 | 986 | if (d != NULL) { |
gsteiert | 3:4f71a37a1ed2 | 987 | uart.printf("SD Card Present\n"); |
gsteiert | 3:4f71a37a1ed2 | 988 | } else { |
gsteiert | 3:4f71a37a1ed2 | 989 | uart.printf("SD Card Root Directory Not Found\n"); |
gsteiert | 3:4f71a37a1ed2 | 990 | } |
gsteiert | 3:4f71a37a1ed2 | 991 | |
gsteiert | 0:28bc7ce77e20 | 992 | // EthernetInterface eth; |
gsteiert | 5:27b09a0f3fb6 | 993 | uart.printf("Initializing Ethernet\n"); |
webmaster | 8:f2a567ee3a46 | 994 | //eth.init(); //Use DHCP |
webmaster | 8:f2a567ee3a46 | 995 | eth.init("192.168.31.186", "255.255.255.0", "192.168.31.1"); //Use |
gsteiert | 5:27b09a0f3fb6 | 996 | uart.printf("Connecting\n"); |
gsteiert | 0:28bc7ce77e20 | 997 | eth.connect(); |
gsteiert | 3:4f71a37a1ed2 | 998 | uart.printf("IP Address is %s\n", eth.getIPAddress()); |
webmaster | 8:f2a567ee3a46 | 999 | |
webmaster | 8:f2a567ee3a46 | 1000 | //test socket client |
webmaster | 8:f2a567ee3a46 | 1001 | //my_client.connect("192.168.31.185",10003); |
webmaster | 8:f2a567ee3a46 | 1002 | //my_client.send_all("hello world",11); |
webmaster | 8:f2a567ee3a46 | 1003 | |
webmaster | 8:f2a567ee3a46 | 1004 | TCPSocketConnection socket; |
webmaster | 8:f2a567ee3a46 | 1005 | while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0) { |
webmaster | 8:f2a567ee3a46 | 1006 | uart.printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); |
webmaster | 8:f2a567ee3a46 | 1007 | wait(1); |
webmaster | 8:f2a567ee3a46 | 1008 | } |
webmaster | 8:f2a567ee3a46 | 1009 | uart.printf("Connected to Server at %s\n",ECHO_SERVER_ADDRESS); |
webmaster | 8:f2a567ee3a46 | 1010 | |
webmaster | 8:f2a567ee3a46 | 1011 | // Send message to server |
webmaster | 8:f2a567ee3a46 | 1012 | char hello[] = "Hello World"; |
webmaster | 8:f2a567ee3a46 | 1013 | uart.printf("Sending message to Server : '%s' \n",hello); |
webmaster | 8:f2a567ee3a46 | 1014 | socket.send_all(hello, sizeof(hello) - 1); |
webmaster | 8:f2a567ee3a46 | 1015 | |
webmaster | 8:f2a567ee3a46 | 1016 | // Receive message from server |
webmaster | 8:f2a567ee3a46 | 1017 | char buf[256]; |
webmaster | 8:f2a567ee3a46 | 1018 | int n = socket.receive(buf, 256); |
webmaster | 8:f2a567ee3a46 | 1019 | buf[n] = '\0'; |
webmaster | 8:f2a567ee3a46 | 1020 | uart.printf("Received message from server: '%s'\n", buf); |
webmaster | 8:f2a567ee3a46 | 1021 | |
webmaster | 8:f2a567ee3a46 | 1022 | // Clean up |
webmaster | 8:f2a567ee3a46 | 1023 | socket.close(); |
webmaster | 8:f2a567ee3a46 | 1024 | //////////////////////////////////////////////////////////////////////////// |
gsteiert | 0:28bc7ce77e20 | 1025 | |
gsteiert | 0:28bc7ce77e20 | 1026 | // TCPSocketServer server; |
gsteiert | 0:28bc7ce77e20 | 1027 | server.bind(HTTPD_SERVER_PORT); |
gsteiert | 0:28bc7ce77e20 | 1028 | server.listen(); |
gsteiert | 5:27b09a0f3fb6 | 1029 | uart.printf("Server Listening\n"); |
gsteiert | 0:28bc7ce77e20 | 1030 | |
gsteiert | 0:28bc7ce77e20 | 1031 | while (true) { |
gsteiert | 3:4f71a37a1ed2 | 1032 | uart.printf("\nWait for new connection...\r\n"); |
gsteiert | 0:28bc7ce77e20 | 1033 | server.accept(client); |
gsteiert | 0:28bc7ce77e20 | 1034 | client.set_blocking(false, 1500); // Timeout after (1.5)s |
webmaster | 8:f2a567ee3a46 | 1035 | |
webmaster | 8:f2a567ee3a46 | 1036 | my_client.send_all("hello world",11); |
gsteiert | 0:28bc7ce77e20 | 1037 | |
gsteiert | 3:4f71a37a1ed2 | 1038 | uart.printf("Connection from: %s\r\n", client.get_address()); |
gsteiert | 0:28bc7ce77e20 | 1039 | while (true) { |
gsteiert | 0:28bc7ce77e20 | 1040 | int n = client.receive(buffer, sizeof(buffer)); |
gsteiert | 0:28bc7ce77e20 | 1041 | if (n <= 0) break; |
gsteiert | 3:4f71a37a1ed2 | 1042 | uart.printf("Recieved Data: %d\r\n\r\n%.*s\r\n",n,n,buffer); |
gsteiert | 0:28bc7ce77e20 | 1043 | if (n >= 1024) { |
gsteiert | 0:28bc7ce77e20 | 1044 | sprintf(httpHeader,"HTTP/1.1 413 Request Entity Too Large \r\nContent-Type: text\r\nConnection: Close\r\n\r\n"); |
gsteiert | 0:28bc7ce77e20 | 1045 | client.send(httpHeader,strlen(httpHeader)); |
gsteiert | 0:28bc7ce77e20 | 1046 | client.send(buffer,n); |
gsteiert | 0:28bc7ce77e20 | 1047 | break; |
gsteiert | 0:28bc7ce77e20 | 1048 | } else { |
gsteiert | 0:28bc7ce77e20 | 1049 | buffer[n]=0; |
gsteiert | 0:28bc7ce77e20 | 1050 | } |
gsteiert | 0:28bc7ce77e20 | 1051 | if (!strncmp(buffer, "GET ", 4)) { |
gsteiert | 0:28bc7ce77e20 | 1052 | uristr = buffer + 4; |
gsteiert | 0:28bc7ce77e20 | 1053 | eou = strstr(uristr, " "); |
gsteiert | 0:28bc7ce77e20 | 1054 | if (eou == NULL) { |
gsteiert | 0:28bc7ce77e20 | 1055 | sprintf(httpHeader,"HTTP/1.1 400 Bad Request \r\nContent-Type: text\r\nConnection: Close\r\n\r\n"); |
gsteiert | 0:28bc7ce77e20 | 1056 | client.send(httpHeader,strlen(httpHeader)); |
gsteiert | 0:28bc7ce77e20 | 1057 | client.send(buffer,n); |
gsteiert | 0:28bc7ce77e20 | 1058 | } else { |
gsteiert | 0:28bc7ce77e20 | 1059 | *eou = 0; |
gsteiert | 3:4f71a37a1ed2 | 1060 | get_file(uristr); |
gsteiert | 0:28bc7ce77e20 | 1061 | } |
gsteiert | 0:28bc7ce77e20 | 1062 | } |
gsteiert | 0:28bc7ce77e20 | 1063 | } |
gsteiert | 0:28bc7ce77e20 | 1064 | |
gsteiert | 0:28bc7ce77e20 | 1065 | client.close(); |
gsteiert | 0:28bc7ce77e20 | 1066 | } |
gsteiert | 0:28bc7ce77e20 | 1067 | } |
MrAI | 11:6d9cefb14158 | 1068 | */ |
webmaster | 8:f2a567ee3a46 | 1069 | |
webmaster | 8:f2a567ee3a46 | 1070 | int main_2() { |
webmaster | 8:f2a567ee3a46 | 1071 | // Serial Interface eth; |
webmaster | 8:f2a567ee3a46 | 1072 | uart.baud(115200); |
webmaster | 8:f2a567ee3a46 | 1073 | uart.printf("Initializing\n"); |
webmaster | 8:f2a567ee3a46 | 1074 | |
webmaster | 8:f2a567ee3a46 | 1075 | EthernetInterface eth; |
webmaster | 8:f2a567ee3a46 | 1076 | eth.init(); //Use DHCP |
webmaster | 8:f2a567ee3a46 | 1077 | eth.connect(); |
webmaster | 8:f2a567ee3a46 | 1078 | printf("\nClient IP Address is %s\n", eth.getIPAddress()); |
webmaster | 8:f2a567ee3a46 | 1079 | |
webmaster | 8:f2a567ee3a46 | 1080 | // Connect to Server |
webmaster | 8:f2a567ee3a46 | 1081 | TCPSocketConnection socket; |
webmaster | 8:f2a567ee3a46 | 1082 | while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0) { |
webmaster | 8:f2a567ee3a46 | 1083 | printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); |
webmaster | 8:f2a567ee3a46 | 1084 | wait(1); |
webmaster | 8:f2a567ee3a46 | 1085 | } |
webmaster | 8:f2a567ee3a46 | 1086 | printf("Connected to Server at %s\n",ECHO_SERVER_ADDRESS); |
webmaster | 8:f2a567ee3a46 | 1087 | |
webmaster | 8:f2a567ee3a46 | 1088 | // Send message to server |
webmaster | 8:f2a567ee3a46 | 1089 | char hello[] = "Hello World"; |
webmaster | 8:f2a567ee3a46 | 1090 | printf("Sending message to Server : '%s' \n",hello); |
webmaster | 8:f2a567ee3a46 | 1091 | socket.send_all(hello, sizeof(hello) - 1); |
webmaster | 8:f2a567ee3a46 | 1092 | |
webmaster | 8:f2a567ee3a46 | 1093 | // Receive message from server |
webmaster | 8:f2a567ee3a46 | 1094 | char buf[256]; |
webmaster | 8:f2a567ee3a46 | 1095 | int n = socket.receive(buf, 256); |
webmaster | 8:f2a567ee3a46 | 1096 | buf[n] = '\0'; |
webmaster | 8:f2a567ee3a46 | 1097 | printf("Received message from server: '%s'\n", buf); |
webmaster | 8:f2a567ee3a46 | 1098 | |
webmaster | 8:f2a567ee3a46 | 1099 | // Clean up |
webmaster | 8:f2a567ee3a46 | 1100 | socket.close(); |
webmaster | 8:f2a567ee3a46 | 1101 | eth.disconnect(); |
webmaster | 8:f2a567ee3a46 | 1102 | |
webmaster | 8:f2a567ee3a46 | 1103 | while(true) {} |
webmaster | 8:f2a567ee3a46 | 1104 | } |