USSD response is numeric - sms

AT+CUSD=1,"service_code",15
+CUSD: 0,"0056006F0074007200650020006300720065006400690074002000730074006F0072006D002D0063007200650064006900740020006500730074002000310036003500310032002E00300030002000440069006E00610072002E",72
How to get readable response? thanks.
this is AT&V:
&C: 1; &D: 2; &E: 0; &F: 0; &S: 0; &W: 0; E: 0; L: 0; M: 0; Q: 0; V: 1;X: 1; Z: 0; \Q: 3; \S: 0; \V: 0; S0: 0; S2: 43; S3: 13; S4: 10; S5: 8;S6: 2; S7: 60; S8: 2; S9: 6; S10: 14; S11: 95; S30: 0; S103: 1; S104: 1;+FCLASS: 0; +ICF: 3,3; +IFC: 2,2; +IPR: 115200; +DR: 0; +DS: 0,0,2048,6;+WS46: 12; +CBST: 0,0,1;+CRLP: (61,61,48,6,0),(61,61,48,6,1),(240,240,52,6,2);+CV120: 1,1,1,0,0,0; +CHSN: 0,0,0,0; +CSSN: 0,0; +CREG: 0; +CGREG: 0;+CFUN:; +CSCS: "IRA"; +CSTA: 129; +CR: 0; +CRC: 0; +CMEE: 2; +CGDCONT: (1,"IP","internet","0.0.0.0",0,0); +CGDSCONT: ; +CGTFT: ; +CGEQREQ: ; +CGEQMIN: ; +CGQREQ: ; +CGQMIN: ;+CGEREP: 0,0; +CGDATA: "PPP"; +CGCLASS: "A"; +CGSMS: 1; +CSMS: 0;+CMGF: 1; +CSAS: 0; +CRES: 0; +CSCA: "+21350001701",145; +CSMP: ,,0,0;+CSDH: 0; +CSCB: 0,"",""; +FDD: 0; +FAR: 0; +FCL: 0; +FIT: 0,0; +ES: ,,;+ESA: 0,,,,0,0,255,; +CMOD: 0; +CVHU: 1; +CPIN: ÿÿÿÿÿÿÿÿ,ÿÿÿÿÿÿÿÿ;+CMEC: 0,0,0; +CKPD: 1,1; +CIND: 0,2,1,0,0,0,0,0; +CMER: 0,0,0,0,0;+CGATT: 0; +CGACT: 0; +CPBS: "SM"; +CPMS: "ME","ME","ME";+CNMI: 3,1,0,2,0; +CMMS: 0; +FTS: 0; +FRS: 0; +FTH: 3; +FRH: 3; +FTM: 96;+FRM: 96; +CCUG: 0,0,0; +COPS: 1,0,""; +CUSD: 1; +CAOC: 1; +CCWA: 1;+CCLK: ""; +CLVL: 2; +CMUT: 0; +CPOL: 0,2,"",0,0,0; +CPLS: 0; +CTZR: 0;+CTZU: 0; +CLIP: 1; +COLP: 0; +CDIP: 0; +CLIR: 0; +ZSNT: 0,0,0;+ZDLFREQ: 0,0; +ZOPRT: 0; +CMVL: 0

Basic answer is just interpret each 2 byte as string representation of hex number. Each 2 number is UCS-2 symbol.
So your string is
Votre credit storm-credit est 16512.00 Dinar.
Long answer is you need read 3GPP TS 23.038 V13.0.0 (2015-12) and interpet 72 value to figure out how to decode this string.
In your case is group=0100 coding=UCS2 compressed=false.
Also I think +CMGF has no affect to +CUSD. It more for sms related command. You can try set at+cscs="IRA" to seitch your charset but I do not think it helps with UCS2 and this is not standart way.
3GPP TS 27.007 V13.4.0 (2016-03)
if dcs indicates that 16-bit data coding scheme (UCS2) is used:
MT/TA splits the 16 bits into two 8-bit octets. Each of those octets
are converted as per the 8-bit data coding scheme, with the most
significant octet first (e.g. decimal value 4906 is presented to TE as
four characters 132A (IRA 49, 51, 50 and 65))
Byt my WaveCom SIM300 send UCS2 directly if set IRA and hex string if set HEX.

Related

Unsigned char out of range

I am trying to figure out, how to use an unsigned char type of a variable inside a for loop, while not "breaking" out of range for unsigned char, which can vary form 0 to 255.
main(void) {
TRISC = 0;
LATC = 0;
unsigned char j;
for (j = 0; j <= 255 ; j++){
LATC = j;
__delay_ms(1000);
}
return;
}
This is code in C, where PIC is programmed. "TRISC = 0" means setting port C as an output and "LATC" is referring to port C itself. Basically I want to assign values from including 0 to 255 to this port. But if I try to compile this, the compiler (xc8) returns following two warnings:
I cannot quite understand what these two are saying, but I assume it has to do something with variable j exceeding the limit value of unsigned char, that is 255 (in last iteration j = 256, which is not allowed/defined).
However, this code gets compiled and works as meant. But I still want to write and understand a code that assigns port C the value of 255 without entering "prohibited" range of values.
*P.S. I would use any other variable type than unsigned char or char, however to ports in PICs only these two types can be applied directly (without conversion).
j <= 255 is always true if j is only 8 Bit wide.
This version should work:
main(void) {
TRISC = 0;
LATC = 0;
int j;
for (j = 0; j <= 255 ; j++){
LATC = (unsigned char)j;
__delay_ms(1000);
}
return;
}
First, in microcontroller firmware, you should not return from main(). Your main() should include some kind of endless loop.
j <= 255 is always true for a uint8_t variable. Because j can't be 256. Adding 1 to j when it's 255, makes it 0, not 256.
As others have suggested, using an 16-bit integer, signed or unsigned, is the easiest and the cleanest way. However, in performance sensitive loops you may prefer to stick with 8 bit loop counters as these are the fastest ones for a 8-bit PIC microcontroller.
This particular one-time loop can be written as:
uint8_t j = 0;
do {
LATC = j++;
__delay_ms(1000);
} while (j != 0);

Unable to execute interrupt function

Using Mplab ide 5.10 and xc8 compiler for the pic18f4550 I am unable to get the code to get into the interrupt function the goal is to get J to count up in the background until something trigger it to output a value in the lcd. Currently only the lcd display the first message and using ICD 3 the value of J does not change and does not look like the program runs the interrupt function at all
#define _XTAL_FREQ 48000000
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include "lcd.h"
unsigned char j, output = 0, i, outchar;
char buffer[2] = " ";
char Message[ ] = "Hands Position ";
void interrupt timer0_isr();
void lcd_write_cmd(unsigned char cmd);
void lcd_write_data(unsigned char data);
void lcd_strobe(void); // Generate the E pulse
void lcd_init(void);
void interrupt timer0_ISR() // Timer0 Interrupt Service Routine (ISR)
{
if (INTCONbits.TMR0IF) // TMR0IF:- Timer0 Overflow Interrupt Flag Bit
{
TMR0H = 0x48; // Timer0 start value = 0x48E5 for 1 second
TMR0L = 0xE5;
PORTCbits.RC1 = !PORTCbits.RC1; /* external timing check - toggle every 1ms */
if (j <= 4) { //limit up to 7
j++; // Increase count by 1
PORTB = j; // Output to Demultiplexer
} else {
j = 0; // Reset count aftwr it hit 7
PORTB = j; // Output to Demultiplexer
}
INTCONbits.TMR0IF = 0; // Reset TMR0IF at interrupt end
}
}
void main(void) // Main Function
{
ADCON1 = 0x0F;
CMCON = 0x07;
RCONbits.IPEN = 1; // Bit7 Interrupt Priority Enable Bit
INTCONbits.GIEH = 1; // Bit7 Global Interrupt Enable bit
INTCONbits.GIEL = 0; /* turn on low & high interrupts */
T0CONbits.TMR0ON = 1; // Turn on timer
T0CON = 0b00000111; // bit7:0 Stop Timer0
// bit6:0 Timer0 as 16 bit timer
// bit5:0 Clock source is internal
// bit4:0 Increment on lo to hi transition on TOCKI pin
// bit3:0 Prescaler output is assigned to Timer0
// bit2-bit0:111 1:256 prescaler
INTCON2 = 0b10000100; // bit7 :PORTB Pull-Up Enable bit
// 1 All PORTB pull-ups are disabled
// bit2 :TMR0 Overflow Int Priority Bit
// 1 High Priority
TMR0H = 0x48; // Initialising TMR0H
TMR0L = 0xE5; // Initialising TMR0L for 1 second interrupt
INTCONbits.TMR0IE = 1; // bit5 TMR0 Overflow Int Enable bit
INTCONbits.TMR0IF = 0; // bit2 TMR0 Overflow Int Flag bit
// 0 TMR0 register did not overflow
TRISC = 0; /* all outputs */
TRISAbits.TRISA5 = 1; // RA5 is the check for signal from input Multiplexer.
TRISAbits.TRISA0 = 0; // RA0, RA1 & RA2 output to arduino
TRISAbits.TRISA1 = 0;
TRISAbits.TRISA2 = 0;
TRISD = 0x00; // PortD connects to Demultiplexer
TRISB = 0;
lcd_init(); // LCD init
lcd_write_cmd(0x80); // Cursor set at line 1 positon 1
for (i = 0; i < 16; i++) {
outchar = Message[i]; // Store Message in outchar
lcd_write_data(outchar); // Display Message
}
__delay_ms(100);
PORTD = 0x00; // Clear PortD
PORTB = 0;
j = 0; // Start count from 0
while (1) // Main Process
{
if (PORTAbits.RA5 == 1) { // If RA3 detect a signal
switch (j) { // Switch case to determine hand position & output to RA0, RA1 & RA2 to transmit to arduino
case(0):
output = 10;
PORTAbits.RA0 = 0;
PORTAbits.RA1 = 0;
PORTAbits.RA2 = 0;
break;
case(1):
output = 20;
PORTAbits.RA0 = 1;
PORTAbits.RA1 = 0;
PORTAbits.RA2 = 0;
break;
case(2):
output = 30;
PORTAbits.RA0 = 0;
PORTAbits.RA1 = 1;
PORTAbits.RA2 = 0;
break;
case(3):
output = 40;
PORTAbits.RA0 = 1;
PORTAbits.RA1 = 1;
PORTAbits.RA2 = 0;
break;
case(4):
output = 50;
PORTAbits.RA0 = 0;
PORTAbits.RA1 = 0;
PORTAbits.RA2 = 1;
break;
}
lcd_write_cmd(0xC0); // Cursor set at line 2 positon 1
sprintf(buffer, "%d", output); // Convert numbers to character
for (i = 0; i < 2; i++)
lcd_write_data(buffer[i]); // Display Hand Position
}
}
}

multi_array boost library error?

I got this error in C++. I am trying to implement Strassen matrix multiplication with multi_array. I assign one array to another which they same dimension.
Like that A11[i][j][k] = A[i][j][k]. I think reason is that kind of lines.
Assertion failed: (size_type(idx - index_bases[0]) < extents[0]),
function access, file
/usr/local/Cellar/boost/1.65.1/include/boost/multi_array/base.hpp,
line 136. Abort trap: 6
Do you know the reason? What does this error mean?
typedef boost::multi_array<int_type, 3> array_type;
array_type::extent_gen extents;
array_type A(boost::extents[size][size][noc]);
array_type B(boost::extents[size][size][noc]);
array_type C(boost::extents[size][size][noc]);
std::fill( A.origin(), A.origin() + A.num_elements(), 0 );
std::fill( B.origin(), B.origin() + B.num_elements(), 0 );
std::fill( C.origin(), C.origin() + C.num_elements(), 0 );
array_type Strr(int size,int noc,array_type A,array_type B, array_type C) {
if(size == 2) { //2-order
C=Matrix_Multiply(size,noc, A, B, C);
} else {
//
for(int i=0; i<size/2; i++) {
for(int j=0; j<size/2; j++) {
for(int k=0; k<noc; j++) {
A11[i][j][k] = A[i][j][k] ;
A12[i][j][k] = A[i][j+size/2][k] ;
}
}
}
My code is like that: I do not know what the problem is.
Error:Assertion failed: (size_type(idx - index_bases[0]) < extents[0]), function access, file /usr/local/Cellar/boost/1.65.1/include/boost/multi_array/base.hpp, line 136.
In the inner most loop you have:
for (int k = 0; k < noc; j++) {
You must have meant ++k instead of ++j:
for (int k = 0; k < noc; ++k) {
I'd simplify main too:
int dim[] = {size,size,noc};
array_type A(dim), B(dim), C(dim);
Value-initialization is done by default.
The idea of multi_array is that the arrays self-describe, instead of you passing separate parameters (size and noc e.g.):
array_type Strr(array_type A, array_type B) {
static_assert(array_type::dimensionality == 3, "static invariant");
size_t size = A.shape()[0];
size_t noc = A.shape()[2];
assert(A.shape()[0] == A.shape()[1]);
assert(std::equal_range(A.shape(), A.shape()+3, B.shape()));
assert(std::equal_range(A.shape(), A.shape()+3, C.shape()));

Error while freeing an array within a data structure

Status bit_flags_set_flag(BIT_FLAGS hBit_flags, int flag_position) {
Bit_Flags* temp = (Bit_Flags*)hBit_flags;
int* nums;
int i;
int old_size;
if (temp->size < flag_position) {
nums = malloc(sizeof(int)*flag_position+1);
if (nums == NULL) {
return FAILURE;
}
for (i = 0; i < temp->size; i++) {
nums[i] = temp->data[i];
}
free(temp->data);
temp->data = nums;
old_size = temp->size;
temp->size = flag_position + 1;
for (i = old_size; i < temp->size; i++) {
temp->data[i] = 0;
}
}
temp->data[flag_position / 32] |= 1 << flag_position % 32;
return SUCCESS;
}
according to the debugger the error is from the free(temp->data) part. however. I only run into the error the second time I go through the function. any ideas what is happening here.
am getting a heap corruption error on visual studio.
I am writing on some assumptions like you are assuming int size is 32 bits and you are trying to set the bit at flag_position in the bitset and you are using 1 int for 1 bit for setting and unsetting bits
Few comments now
temp->data[flag_position / 32] |= 1 << flag_position % 32; now this doesn't make any sense, this line role is to set bit at flag_position, this should be temp->data[flag_position] = 1; instead because if you see your code your are using ints for each bit.
Also this line temp->size = flag_position + 1; is also incorrect , this should be temp->size = flag_position;

bootloader avr atmega128RFA1

I am also working on the bootloader.
I had the problem in the following:
Once the cmd 'B' is received, later, 'F' is received, then I would start to call block load.
static void start_block_flash_load(uint16_t size, uint32_t *addr) {
uint16_t data_word;
uint8_t sreg = SREG;
uint16_t temp;
int i;
uint8_t my_size;
fprintf(lcdout, "B");
cli();
// Disable interrupts
(*addr) <<= 1;
if (size <= SPM_PAGESIZE) {
boot_page_erase(*addr);
boot_spm_busy_wait();
fprintf(lcdout, "%"PRIu16, size);
uint16_t i;
//store all values. PROBLEM here!!!
my_size = 208;
uint8_t buf[SPM_PAGESIZE] = { 0 };
for (i = 0; i < my_size; i++) {
//for (i=0; i<size; i++){
buf[i] = uart_getc();
// lcd_clear();
// lcd_setCursor(0, 2);
// fprintf(lcdout, "%3d", i);
// _delay_ms(500);
}
for (i = 0; i < my_size; i += 2) { //if size is odd, then use do-while
uint16_t w = buf[i];
w += buf[i + 1] << 8; //first one is low byte, second is high???
boot_page_fill((*addr)+i, w);
}
boot_page_write(*addr);
boot_spm_busy_wait();
(*addr) >>= 1;
uart_putc('\r');
} else
uart_putc('?');
boot_rww_enable ();
SREG = sreg;
}
I can see on the lcd that the size of the block is 256. However, when entering the loop to collect data, it will get stuck.
I tested with my_size and I found that only if my_size=208 the program will run further.
The strange thing is that if I put some statements inside the loop, e.g.
lcd_clear();
lcd_setCursor(0, 2);
then 'i' which I printed out on lcd will not go up to 140 something. I put different statements, the 'i' will give different value. That is very strange, since the uart_getc() will not lose data.
What I expect is that the loop will go up to 256. I cannot figure out what happened there.
Please help if you have any idea.
Thanks

Resources