Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXOS8700CQ MODSERIAL mbed
Fork of Avnet_ATT_Cellular_IOT by
Diff: main.cpp
- Revision:
- 1:af7a42f7d465
- Parent:
- 0:9d5134074d84
- Child:
- 2:0e2ef866af95
--- a/main.cpp Fri Jul 08 23:52:38 2016 +0000
+++ b/main.cpp Sat Jul 09 00:45:53 2016 +0000
@@ -63,10 +63,12 @@
//
int DecodeASCIIstr(string& ins, string& outs) {
int val, n = 0;
- char ts[2];
+ char ts[] = {0,0,0};
while(n<ins.length()) {
- val = atoi((const char*)ins[n])*16+atoi((const char*)ins[n+1]);
+ ts[0] = ins[n];
+ ts[1] = ins[n+1];
+ sscanf(ts,"%X",&val);
sprintf(ts,"%c",val);
outs.append(ts);
n += 2;
@@ -85,19 +87,19 @@
// will only accept up to 1500 characters, and the converted srings will be 2x the
// input string since the hex representation of 1 character is a two digit hex value.
//
-int CreateASCIIstr(string& in, string& out) {
+int CreateASCIIstr(string& ins, string& outs) {
int i = 0;
char ts[3];
-
- if( in.length() > 749 )
+
+ if( ins.length() > 749 )
return 0;
- while(in[i] != 0x00) {
- sprintf(ts,"%02X", in[i]);
- out.append(ts);
+ while(ins[i] != 0x00) {
+ sprintf(ts,"%02X", ins[i]);
+ outs.append(ts);
i++;
}
- return out.length();
+ return outs.length();
}
@@ -220,7 +222,7 @@
void hts221_init(void);
- pc.printf(BLU "Hello World from AT&T Shape!\r\n");
+ pc.printf(BLU "Hello World from AT&T Shape!\r\n\n\r");
pc.printf(GRN "Initialize the HTS221\n\r");
i = hts221.begin();
@@ -231,6 +233,15 @@
printf("Temp is: %0.2f F \n\r",CTOF(hts221.readTemperature()));
printf("Humid is: %02d %%\n\r",hts221.readHumidity());
+
+ string newstr, outstr, instr = "0123456789aAbBcCdDeEfFxXyYzZ";
+ pc.printf("\n\rTest ASCII String creation: \n\r");
+ i = CreateASCIIstr(instr,outstr);
+ pc.printf(">Initially the string is '%s' (%d long)\n\r>after encode it is '%s' (%d characters long).\n\r",
+ instr.c_str(),instr.length(),outstr.c_str(),i);
+ i = DecodeASCIIstr(outstr, newstr);
+ pc.printf(">after decoding the encoded string, it is '%s' (%d long)\n\r\n\r",newstr.c_str(),i);
+
// Initialize the modem
printf(GRN "Modem initializing... will take up to 60 seconds" DEF "\r\n");
