bladox.com Forum Index bladox.com
Turbo SIM Toolkit Adapter Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Do I have to reflash tsim?

 
Post new topic   Reply to topic    bladox.com Forum Index -> Development
View previous topic :: View next topic  
Author Message
obass
Guest





PostPosted: Mon Dec 11, 2006 11:25 am    Post subject: Do I have to reflash tsim? Reply with quote

Hi,
First of all bladox is a great company providing great sim based solutions.
I've been watching this board and need to salute y'all for the great job y'all is doing.

However I bought a new tsim and wrote an app for it. The app size read 17535.

I loaded the app via infrared on Nokia6600 using turbo-cable-utils-0.7.0 on WinXp. The app didn't appear after this even though "Ok.No Error" message was displayed and the phone indicated receiving data.

I tried switching off and then switching on the phone. But on switching ON I discover that the pone doesn't start up fully until I remove tsim. I tried putting it into sonyErricsson k310i but the same thing happens and this time the message "Sim problem" appears. Since it means I can't access tsim any longer it also implies I can't reset it equally. I don't have turbo programmer or any other turbo for that matter so don't know how am going to solve this. Or is turbo dead?

Could anybody here tell me what to do?

obass

-SELF CONFIDENCE IS THE GENESIS OF PRIDE[/quote]


Last edited by obass on Wed Dec 13, 2006 10:57 am; edited 1 time in total
Back to top
mike
Guest





PostPosted: Mon Dec 11, 2006 11:46 am    Post subject: Reply with quote

I also have a similar problem, meaning
I upload the helloworld.trb with turbo-app and
OK. no error
is returned, however I cannot find the application neither in the turbo menu either with the application loader.

However, i do restart my phone without any problem....
Back to top
mike
Guest





PostPosted: Mon Dec 11, 2006 3:44 pm    Post subject: Reply with quote

finally, I did not target the right COM....

so now is everything ok!
Back to top
pz
Guest





PostPosted: Mon Dec 11, 2006 3:55 pm    Post subject: Re: Do I have to reflash tsim? Reply with quote

obass wrote:
Hi,
First of all bladox is a great company providing great sim based solutions.
I've been watching this board and need to salute y'all for the great job y'all is doing.

However I bought a new tsim and wrote an app for it. The app size read 17535.

I loaded the app via infrared on Nokia6600 using turbo-cable-utils-0.7.0 on WinXp. The app didn't appear after this even though "Ok.No Error" message was displayed and the phone indicated receiving data.

I tried switching off and then switching on the phone. But on switching ON I discover that the pone doesn't start up fully until I remove tsim. I tried putting it into sonyErricsson k310i but the same thing happens and this time the message "Sim problem" appears. Since it means I can't access tsim any longer it also implies I can't reset it equally. I don't have turbo programmer or any other turbo for that matter so don't know how am going to solve this. Or is turbo dead?

Could anybody here tell me what to do?

obass

-SELF CONFIDENCE IS THE GENESIS OF PRIDE
[/quote]

It seems something wrong - malfunction application - has been uploaded making this problem. But it's not lost! There is so called TPIN - exactly for such situation - to reset/remove all applications on turbo and make it like brand new. So unless you application was real killer you should be able to recover turbo. Activate PIN on your phone and when asked for PIN enter TPIN (printed on label in tsim package) - 8 digits. You will get "wrong pin" message (technical resons why we cannot say anything else) and then enter PIN of the SIM card used. Turbo applciations are initalized *after* user performs PIN, i.e. all bad can be removed by TPIN.

Try to practise uploading with e.g. helloworld.
Back to top
obass
Guest





PostPosted: Tue Dec 12, 2006 1:58 pm    Post subject: Reply with quote

Thanks. I tried TPIN and everything is back to normal. I'm so much relieved

However the application am trying to load didn't act that way until I added code for application persistent data. I don't know what went wrong with that perhaps it has to do with EEPROM. I tried using ordinary emallocs but still got the same error and sometimes the phone resets. Is there anything I need to know about EEPROM and application persistent data.

Thanks once again. You guys are great.
Back to top
pz
Guest





PostPosted: Tue Dec 12, 2006 7:20 pm    Post subject: Reply with quote

obass wrote:
Thanks. I tried TPIN and everything is back to normal. I'm so much relieved

However the application am trying to load didn't act that way until I added code for application persistent data. I don't know what went wrong with that perhaps it has to do with EEPROM. I tried using ordinary emallocs but still got the same error and sometimes the phone resets. Is there anything I need to know about EEPROM and application persistent data.


Can you post what you did? It hard to say, my guess some '&' in something like wb(&p->x,...) is missing, something pointer related. Then you can of course rewrite different part of eeprom and during application init anything can happen.

Quote:

Thanks once again. You guys are great.


Blushing Smile
Back to top
obass
Guest





PostPosted: Wed Dec 13, 2006 10:52 am    Post subject: Reply with quote

Thanx for the reply.

Here's the code its some mobile payment stuff:

#include<config.h>
#include<turbo/turbo.h>

#define MAX_SEND_ERR 10

#define MERCHANT 0
#define POWER_BILL 1
#define WATER_BILL 2
#define LOAD_PURSE 3
#define OFFLOAD_PURSE 4
#define SERVER 5

#define BANK 0
#define CREDIT 1

#define TRUE 1
#define FALSE 0

#define NO_ERR 0
#define MER_ERR 1
#define CUS_ERR 2
#define BANK_ERR 3
#define CREDIT_ERR 4

#define NEW 0

#define STAGE_1 1
#define STAGE_2 2
#define STAGE_3 3

void inform_on_text(void*);

typedef struct _App_p_Dat{
u16 m_purse_nL;
u16 m_purse_nH;
u8 m_purse_k;
u8 read_msg;
u8 pin[6];
u8 pass1[15];
u8 pass2[15];
u8 back_end[20];
u8 sms[165];
}App_Per_Dat;

App_Per_Dat* p = NULL;

u8* sms = NULL;
u8* pay_msg = NULL;
u8* amount = NULL;
u8* amount_k = NULL;
u8* m_purse_t = NULL;
u8* show_bal = NULL;
u32 m_purse_n = NULL;

u8 transID;
u8 transType;
u8 transStage;
u8* merchantNO = NULL;
u8* customerNO = NULL;
u8* prodID;
u8 acctType;
u8 confirm;
u8* acctBal = NULL;
u8 error_code;

u8 PROGMEM defpin[] = "1111";
u8 PROGMEM defp1[] = "password1";
u8 PROGMEM defp2[] = "password2";
u8 PROGMEM defSno[] = "+2348024359890";

u8 nul = '\0';
u8 sep = '#';
u8 nl = '\n';


u8 PROGMEM t_Mpay_mime[] = "tMpay";
u8 PROGMEM error[] = "Error";
u8 PROGMEM enter_amount[] = "Enter Amount:";
u8 PROGMEM enter_pin[] = "Enter PIN:";
u8 PROGMEM enter_newpin[] = "Enter New PIN:";
u8 PROGMEM wrong_pin[] = "Wrong PIN";
u8 PROGMEM wrong_amount[] = "Amount should not exceed\n 999999.99";
u8 PROGMEM wrong_pass1[] = "Wrong Passcode1";
u8 PROGMEM enter_pass1[] = "Enter Passcode1:";
u8 PROGMEM enter_newpass1[] = "Enter New Passcode1:";
u8 PROGMEM enter_pass2[] = "Enter Passcode2:";
u8 PROGMEM enter_newpass2[] = "Enter New Passcode2:";
u8 PROGMEM wrong_pass2[] = "Wrong Passcode2";
u8 PROGMEM enter_prodID[] = "Enter Product ID:";
u8 PROGMEM wrong_parameter[] = "Wrong Parameter Entered";
u8 PROGMEM bal_2_low[] = "Your M-purse balance is too low for the transaction";
u8 PROGMEM purse_msg[] = "This bal. is with respect to the last transaction started";
u8 PROGMEM send_msg[] = "Sending request...";
u8 PROGMEM succ_send[] = "Request sent";
u8 PROGMEM send_req[] = "Send Request?";
u8 PROGMEM err_send_end[] = "Can't contact server. Quitting...";
u8 PROGMEM err_send[] = "Network failure!\n Try Again?";
u8 PROGMEM rcvd_new_msg[] = "New M-payment message received";
u8 PROGMEM t_pay_details[] = "Payment Details:";
u8 PROGMEM t_merchant[] = "Merchant: ";
u8 PROGMEM t_customer[] = "Customer: ";
u8 PROGMEM t_prodID[] = "Product ID: ";
u8 PROGMEM t_powerbill[] = "POWER BILL";
u8 PROGMEM t_waterbill[] = "WATER BILL";
u8 PROGMEM t_accttype[] = "Acct Type:";
u8 PROGMEM t_request[] = "A customer wishes to pay as above. Accept?";
u8 PROGMEM t_loadpurse[] = "LOAD PURSE";
u8 PROGMEM t_offloadpurse[] = "OFFLOAD PURSE";
u8 PROGMEM t_amount[] = "Amount: ";
u8 PROGMEM t_mpurse[] = "M-purse Bal: ";
u8 PROGMEM t_bank[] = "Bank Bal: ";
u8 PROGMEM t_credit[] = "Credit Bal: ";
u8 PROGMEM t_mer_accept[] = "The merchant has accepted your request.";
u8 PROGMEM t_mer_reject[] = "The merchant has rejected your request.";
u8 PROGMEM t_pay_again[] = "Would you like to pay?";
u8 PROGMEM t_success[] = "Your payment completed successfully";
u8 PROGMEM err_mer_send[] = "The Merchant could not be contacted";
u8 PROGMEM err_cus_send[] = "The Customer could not be contacted";
u8 PROGMEM err_bank_send[] = "The Bank could not be contacted";
u8 PROGMEM err_credit_send[] = "The Mobile Operator could not be contacted";
u8 PROGMEM about_message[] = "Universal M-payment System.";

lc_char PROGMEM about_Mpay[] = {
LC_UN ("About")
LC_END
};
lc_char PROGMEM Mpay[] = {
LC_UN("M-pay")
LC_END
};
lc_char PROGMEM portal_Mpay[] = {
LC_UN("Portal")
LC_END
};
lc_char PROGMEM login_Mpay[] = {
LC_UN ("Login")
LC_END
};
lc_char PROGMEM pay_Mpay[] = {
LC_UN ("Pay")
LC_END
};
lc_char PROGMEM bills_Mpay[] = {
LC_UN ("Bills")
LC_END
};
lc_char PROGMEM bal_Mpay[] = {
LC_UN ("Balance")
LC_END
};
lc_char PROGMEM security_Mpay[] = {
LC_UN ("Security")
LC_END
};
lc_char PROGMEM change_PIN[] = {
LC_UN ("Change PIN")
LC_END
};
lc_char PROGMEM change_pass1[] = {
LC_UN ("Change Pass 1")
LC_END
};
lc_char PROGMEM change_pass2[] = {
LC_UN ("Change Pass 2")
LC_END
};

lc_char PROGMEM power_Mpay[] = {
LC_UN ("Power Bills")
LC_END
};
lc_char PROGMEM water_Mpay[] = {
LC_UN ("Water Bills")
LC_END
};
lc_char PROGMEM load_Mpay[] = {
LC_UN ("Load Purse")
LC_END
};
lc_char PROGMEM offload_Mpay[] = {
LC_UN ("Offload Purse")
LC_END
};
lc_char PROGMEM bank_Mpay[] = {
LC_UN ("Bank")
LC_END
};
lc_char PROGMEM credit_Mpay[] = {
LC_UN ("Credit")
LC_END
};
lc_char PROGMEM mpurse_Mpay[] = {
LC_UN ("Mpurse")
LC_END
};


u8 enterAmount(){
u32 i;
u8* res;

ENTER_AMOUNT:
res = get_input(enter_amount, 1, 9, NULL, Q_GET_INPUT_DIGITS);
if(res == ENULL)
return APP_END;
if(res == NULL)
return APP_BACK;

res[res[0] + 1] = nul;

// check unwanted characters
i = 0;
while(i < (res[0] - 1)){
if(res[2+(i++)] == '+')
break;
}

if(i < (res[0] - 1)){
*res = display_text(wrong_parameter, NULL);
if(*res == APP_OK)
goto ENTER_AMOUNT;
else
return *res;
}

// change '*' or '#' to '.'
i = 0;
while(i < (res[0] - 1)){
if(res[2+i] == '*' || res[2+i] == '#')
res[2+(i++)] = '.';
}

memcpy(amount, res+2, res[0]);
// get the kobo
i = 0;
while(i < strlen(amount))
if(amount[i++] == '.')
break;

if(i >= strlen(amount)){// no kobo
*(amount_k++) = '0';
amount_k = '\0';
--amount_k;
}
else{
memcpy(amount_k, amount+i, strlen(amount+i)+1);
// make it only two digits
*(amount_k+3) = '\0';
}

// check if the amount exceeds the expected limit
if((u32)(atoi(amount) + 1) >= 1000000){
display_text_raw(wrong_amount, Q_DISPLAY_TEXT_USER_CLEAR);
return APP_BACK;
}

// check if m-purse balance is insufficient
if(m_purse_n < (u32)(atoi(amount) + 1)){
display_text_raw(bal_2_low, Q_DISPLAY_TEXT_USER_CLEAR);
return APP_BACK;
}
return APP_OK;
}



u8 sendSms(){

u8 i = 0;
u8* ms;
u8* alpha;
u8* res;
u8 nr_send_err = 0;

SEND_SMS:
alpha = malloc(strlen(send_msg)+1);
memcpy(alpha, send_msg, strlen(send_msg)+1);
ms = str2msisdn(p->back_end, MSISDN_ADN, MEM_R);
res = send_sms(sms, strlen(sms), ms, MSISDN_ADN, 0xF6, 0x00, alpha, NULL);
free(alpha);
free(ms);

i = get_tag (res, T_RESULT);
if(i != 0){
i += 2;
if(res[i] == 0x00){// send is successful
display_text_raw(succ_send, Q_DISPLAY_TEXT_USER_CLEAR);
return APP_OK;
}
else if(nr_send_err >= MAX_SEND_ERR){// too many unsuccessful sends
display_text_raw(err_send_end, Q_DISPLAY_TEXT_USER_CLEAR);
return APP_END;
}
else{// unsuccessful send
nr_send_err++;
*res = display_text(err_send, NULL);
if(*res == APP_OK)
goto SEND_SMS;
else
return *res;
}
}
else{
display_text_raw(error, Q_DISPLAY_TEXT_USER_CLEAR);
return APP_END;
}

}


u8 about(SCtx* ctx, u8 action){
if (action == APP_ENTER)
{
display_text_raw(about_message, Q_DISPLAY_TEXT_USER_CLEAR);
return APP_BACK;
}

}


u8 login(SCtx* ctx, u8 action){

if (action == APP_ENTER)
{
u8* s;
u8* res;

// GET PIN
res = get_input(enter_pin, 4, 4, NULL, Q_GET_INPUT_DIGITS | Q_GET_INPUT_NO_ECHO);
if (res == NULL)
return APP_BACK;
if (res == ENULL)
return APP_END;

res[res[0] + 1] = nul;
if (memcmp(p->pin, res+2, 4)){// compare PIN.
*res = display_text(wrong_pin, NULL);
if (*res == APP_OK)
*res = APP_BACK;
return *res;
}

if(!(rb(&p->read_msg))){// if a message is expected to be read;
// get passcode 1
res = get_input(enter_pass1, 6, 12, NULL, Q_GET_INPUT_ALPHABET);
if (res == NULL)
return APP_BACK;
if (res == ENULL)
return APP_END;

res[res[0] + 1] = nul;

if (memcmp(p->pass1, res+2, strlen(p->pass1)) != 0){

*res = display_text(wrong_pass1, NULL);
if (*res == APP_OK)
*res = APP_BACK;
return *res;

}
return APP_OK;
}

else{
// get passcode 2
res = get_input(enter_pass2, 6, 12, NULL, Q_GET_INPUT_ALPHABET);
if (res == NULL)
return APP_BACK;
if (res == ENULL)
return APP_END;

res[res[0] + 1] = nul;

if (memcmp(p->pass2, res+2, strlen(p->pass2)) != 0){

*res = display_text(wrong_pass2, NULL);
if (*res == APP_OK)
*res = APP_BACK;
return *res;

}

return handle_request();

}


}
}

u8 confirmSend(){

u8* res;

switch(transType){

case MERCHANT:
{
res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
res = sprints(res, t_merchant);
res = sprints(res, merchantNO);
res = sprintc(res, nl);
res = sprints(res, t_prodID);
res = sprints(res, prodID);
res = sprintc(res, nl);
res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);
res = sprintc(res, nl);
res = sprints(res, send_req);
res = sprintc(res, nul);
*res = yesno(pay_msg, 0, 0);
return *res;
}

case POWER_BILL:
{
res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
res = sprints(res, t_merchant);
res = sprints(res, t_powerbill);
res = sprintc(res, nl);
res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);
res = sprintc(res, nl);
res = sprints(res, send_req);
res = sprintc(res, nul);
*res = yesno(pay_msg, 0, 0);
return *res;
}
case WATER_BILL:
{
res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
res = sprints(res, t_merchant);
res = sprints(res, t_waterbill);
res = sprintc(res, nl);
res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);
res = sprintc(res, nl);
res = sprints(res, send_req);
res = sprintc(res, nul);
*res = yesno(pay_msg, 0, 0);
return *res;
}
case LOAD_PURSE:
{
res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
res = sprints(res, t_merchant);
res = sprints(res, t_loadpurse);
res = sprintc(res, nl);
res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);
res = sprintc(res, nl);
res = sprints(res, send_req);
res = sprintc(res, nul);
*res = yesno(pay_msg, 0, 0);
return *res;
}
case OFFLOAD_PURSE:
{
res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
res = sprints(res, t_merchant);
res = sprints(res, t_offloadpurse);
res = sprintc(res, nl);
res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);
res = sprintc(res, nl);
res = sprints(res, send_req);
res = sprintc(res, nul);
*res = yesno(pay_msg, 0, 0);
return *res;
}

default:
return APP_END;
}

}



u8 pay (SCtx* ctx, u8 action){

if (action == APP_ENTER)
{
u8 i;
u8* mnum;
u8* res;
u8 rs;
u8 kobo;
u32 temp;


// GET MERCHANT PHONE NUMBER//

MERCHANT_NUMBER:
res = msisdn(NULL);
if (res == NULL)
return APP_BACK;
if (res == ENULL)
return APP_END;
res = msisdn2str(res, MSISDN_ADN, MEM_R);

// check length
if (strlen(res) < 7){
rs = display_text(wrong_parameter, NULL);
if(rs == APP_OK){
free(res);
goto MERCHANT_NUMBER;
}
else{
free(res);
return rs;
}
}

memcpy(merchantNO, res, strlen(res)+1);
free(res);

// GET PRODUCT ID //
res = get_input(enter_prodID, 1, 12, NULL, Q_GET_INPUT_ALPHABET);
res[res[0] + 1] = nul;
memcpy(prodID, res+2, strlen(res+2) + 1);

// GET AMOUNT TO PAY //
*res = enterAmount();
if(*res != APP_OK)
return *res;

// FORMAT SMS FOR SEND
res = sms;
// set transaction id to NEW
transID = NEW;
res = sprinti(res, transID);
res = sprintc(res, sep);
// set transaction type to MERCHANT
transType = MERCHANT;
res = sprinti(res, transType);
res = sprintc(res, sep);
// set transaction stage to STAGE_1
transStage = STAGE_1;
res = sprinti(res, transStage);
res = sprintc(res, sep);
// attach other info
res = sprints(res, merchantNO);
res = sprintc(res, sep);
res = sprints(res, prodID);
res = sprintc(res, sep);
res = sprints(res, amount);
res = sprintc(res, nul);

//confirm send
*res = confirmSend();
if(*res == APP_NO)
*res = APP_BACK;
if(*res != APP_YES)
return *res;

// SEND SMS
*res = sendSms();
// take money from m-purse
if (*res == APP_OK){

kobo = rb(&p->m_purse_k);
if(kobo < (u8)(atoi(amount_k))){
--m_purse_n ;
kobo += 100;
}
kobo -= (u8)(atoi(amount_k));
m_purse_n -= (u32)(atoi(amount));
temp = m_purse_n;
// get lower word
temp &= 0x0000FFFF;
ww(&p->m_purse_nL, temp);
temp = m_purse_n;
// get higher word
temp >>= 16;
ww(&p->m_purse_nH, temp);
// get kobo
wb(&p->m_purse_k, kobo);
*res = APP_BACK;
}

return *res;


}

}


u8 powerBill(SCtx* ctx, u8 action){

if (action == APP_ENTER){
u8* res;
u8 kobo;
u32 temp;

// GET AMOUNT
*res = enterAmount();
if (*res != APP_OK)
return *res;

// FORMAT SMS FOR SEND

res = sms;
// set transaction id to NEW
transID = NEW;
res = sprinti(res, transID);
res = sprintc(res, sep);
// set transaction type to POWER_BILL
transType = POWER_BILL;
res = sprinti(res, transType);
res = sprintc(res, sep);
// attach other info
res = sprints(res, amount);
res = sprintc(res, nul);

// confirm send
*res = confirmSend();
if(*res == APP_NO)
*res = APP_BACK;
if(*res != APP_YES)
return *res;


// SEND SMS
*res = sendSms();
// take money from m-purse
if (*res == APP_OK){

kobo = rb(&p->m_purse_k);
if(kobo < (u8)(atoi(amount_k))){
--m_purse_n ;
kobo += 100;
}
kobo -= (u8)(atoi(amount_k));
m_purse_n -= (u32)(atoi(amount));
temp = m_purse_n;
// get lower word
temp &= 0x0000FFFF;
ww(&p->m_purse_nL, temp);
temp = m_purse_n;
// get higher word
temp >>= 16;
ww(&p->m_purse_nH, temp);
// get kobo
wb(&p->m_purse_k, kobo);
*res = APP_BACK;
}
return *res;


}

}


u8 waterBill(SCtx* ctx, u8 action){

if(action == APP_ENTER){
u8* res;
u8 kobo;
u32 temp;

// GET AMOUNT
*res = enterAmount();
if (*res != APP_OK)
return *res;

// FORMAT SMS FOR SEND

res = sms;
// set transaction id to NEW
transID = NEW;
res = sprinti(res, transID);
res = sprintc(res, sep);
// set transaction type to water bill
transType = WATER_BILL;
res = sprinti(res, transType);
res = sprintc(res, sep);
// attach other info
res = sprints(res, amount);
res = sprintc(res, nul);

// confirm send
*res = confirmSend();
if(*res == APP_NO)
*res = APP_BACK;
if(*res != APP_YES)
return *res;

// SEND SMS
*res = sendSms();
// take money from m-purse
if (*res == APP_OK){

kobo = rb(&p->m_purse_k);
if(kobo < (u8)(atoi(amount_k))){
--m_purse_n ;
kobo += 100;
}
kobo -= (u8)(atoi(amount_k));
m_purse_n -= (u32)(atoi(amount));
temp = m_purse_n;
// get lower word
temp &= 0x0000FFFF;
ww(&p->m_purse_nL, temp);
temp = m_purse_n;
// get higher word
temp >>= 16;
ww(&p->m_purse_nH, temp);
// get kobo
wb(&p->m_purse_k, kobo);
*res = APP_BACK;
}

return *res;

}

}


u8 showBal(SCtx* ctx, u8 action){

if (action == APP_ENTER){
u8* res;

res = m_purse_t;
res = sprinti(res, m_purse_n);
res = sprintc(res, '.');
if(rb(&p->m_purse_k) < 10)// add leading zero
res = sprintc(res, '0');
res = sprinti(res, rb(&p->m_purse_k));
res = sprintc(res, nul);

res = show_bal;
res = sprints(res, m_purse_t);
res = sprintc(res, nl);
res = sprints(res, purse_msg);
res = sprintc(res, nul);

*res = display_text(show_bal, NULL);
if(*res == APP_OK)
return APP_BACK;
return *res;
}

}


u8 load(SCtx* ctx, u8 action){

if (action == APP_ENTER){
u8* res;
// GET AMOUNT
*res = enterAmount();
if (*res != APP_OK)
return *res;

// SET TRANSACTION TYPE
transType = LOAD_PURSE;

return APP_OK;

}

}

u8 offload(SCtx* ctx, u8 action){

if (action == APP_ENTER) {
u8* res;
// GET AMOUNT
*res = enterAmount();
if (*res != APP_OK)
return *res;

// SET TRANSACTION TYPE
transType = OFFLOAD_PURSE;

return APP_OK;

}

}


u8 bank(SCtx* ctx, u8 action){

if (action == APP_ENTER){
u8* res;
u8 kobo;
u32 temp;

// SET ACCOUNT TYPE
acctType = BANK;

// FORMAT SMS FOR SEND

res = sms;
// set transaction id to NEW
transID = NEW;
res = sprinti(res, transID);
res = sprintc(res, sep);
// attach other info
res = sprinti(res, transType);
res = sprintc(res, sep);
res = sprinti(res, acctType);
res = sprintc(res, sep);
res = sprints(res, amount);
res = sprintc(res, nul);

// confirm send
*res = confirmSend();
if(*res == APP_NO)
*res = APP_BACK;
if(*res != APP_YES)
return *res;


// SEND SMS
*res = sendSms();
// take money from m-purse
if (*res == APP_OK){

kobo = rb(&p->m_purse_k);
if(kobo < (u8)(atoi(amount_k))){
--m_purse_n ;
kobo += 100;
}
kobo -= (u8)(atoi(amount_k));
m_purse_n -= (u32)(atoi(amount));
temp = m_purse_n;
// get lower word
temp &= 0x0000FFFF;
ww(&p->m_purse_nL, temp);
temp = m_purse_n;
// get higher word
temp >>= 16;
ww(&p->m_purse_nH, temp);
// get kobo
wb(&p->m_purse_k, kobo);
*res = APP_BACK;
}

return *res;
}
}


u8 credit(SCtx* ctx, u8 action){

if (action == APP_ENTER){
u8* res;
u8 kobo;
u32 temp;

// SET ACCOUNT TYPE
acctType = CREDIT;
// FORMAT SMS FOR SEND

res = sms;
// set transaction id to NEW
transID = NEW;
res = sprinti(res, transID);
res = sprintc(res, sep);
// attach other info
res = sprinti(res, transType);
res = sprintc(res, sep);
res = sprinti(res, acctType);
res = sprintc(res, sep);
res = sprints(res, amount);
res = sprintc(res, nul);

// confirm send
*res = confirmSend();
if(*res == APP_NO)
*res = APP_BACK;
if(*res != APP_YES)
return *res;

// SEND SMS
*res = sendSms();
// take money from m-purse
if (*res == APP_OK){

kobo = rb(&p->m_purse_k);
if(kobo < (u8)(atoi(amount_k))){
--m_purse_n ;
kobo += 100;
}
kobo -= (u8)(atoi(amount_k));
m_purse_n -= (u32)(atoi(amount));
temp = m_purse_n;
// get lower word
temp &= 0x0000FFFF;
ww(&p->m_purse_nL, temp);
temp = m_purse_n;
// get higher word
temp >>= 16;
ww(&p->m_purse_nH, temp);
// get kobo
wb(&p->m_purse_k, kobo);
*res = APP_BACK;
}

return *res;
}

}

u8 changePIN(SCtx* ctx, u8 action){

if (action == APP_ENTER){

u8* res;

// enter previous PIN
res = get_input(enter_pin, 4, 4, NULL, Q_GET_INPUT_DIGITS | Q_GET_INPUT_NO_ECHO);
if (res == NULL)
return APP_BACK;
if (res == ENULL)
return APP_END;

res[res[0] + 1] = nul;
if (memcmp(p->pin, res+2, 4)){// compare PIN
*res = display_text(wrong_pin, NULL);
if (*res == APP_OK)
*res = APP_BACK;
return *res;
}

// enter new PIN
res = get_input(enter_newpin, 4, 4, NULL, Q_GET_INPUT_DIGITS | Q_GET_INPUT_NO_ECHO);
if (res == NULL)
return APP_BACK;
if (res == ENULL)
return APP_END;

res[res[0] + 1] = nul;
memcpy(p->pin, res+2, strlen(res+2));
wb(&p->pin[strlen(res+2)], nul);

return APP_BACK;
}

}

u8 changePass1(SCtx* ctx, u8 action){
if (action == APP_ENTER){

u8* res;
u8 i;
// enter previous pass1
res = get_input(enter_pass1, 6, 12, NULL, Q_GET_INPUT_ALPHABET);
if (res == NULL)
return APP_BACK;
if (res == ENULL)
return APP_END;

res[res[0] + 1] = nul;

if (memcmp(p->pass1, res+2, strlen(p->pass1)) != 0){

*res = display_text(wrong_pass1, NULL);
if (*res == APP_OK)
return *res = APP_BACK;
return *res;
}
// enter new pass1

res = get_input(enter_newpass1, 6, 12, NULL, Q_GET_INPUT_ALPHABET);
if (res == NULL)
return APP_BACK;
if (res == ENULL)
return APP_END;

res[res[0] + 1] = nul;
memcpy(p->pass1, res+2, strlen(res+2));
wb(&p->pass1[strlen(res+2)], nul);
return APP_BACK;
}

}

u8 changePass2(SCtx* ctx, u8 action){
if (action == APP_ENTER){

u8* res;
u8 i;
// enter previous pass2
res = get_input(enter_pass2, 6, 12, NULL, Q_GET_INPUT_ALPHABET);
if (res == NULL)
return APP_BACK;
if (res == ENULL)
return APP_END;

res[res[0] + 1] = nul;

if (memcmp(p->pass2, res+2, strlen(p->pass2)) != 0){

*res = display_text(wrong_pass2, NULL);
if (*res == APP_OK)
*res = APP_BACK;
return *res;
}
// enter new pass2

res = get_input(enter_newpass2, 6, 12, NULL, Q_GET_INPUT_ALPHABET);
if (res == NULL)
return APP_BACK;
if (res == ENULL)
return APP_END;

res[res[0] + 1] = nul;
memcpy(p->pass2, res+2, strlen(res+2));
wb(&p->pass2[strlen(res+2)], nul);
return APP_BACK;
}

}


void pay_reports(u8* s){


u8 i;
u8* t = skip_head(s);

memcpy(sms, t, strlen(t)+1);
memcpy(p->sms, sms, strlen(sms)+1);
parse();
wb(&p->read_msg, TRUE);

}

void parse(){

u8 i, j = 0;
u8* res = malloc(20);
u8 kobo;
void* data = NULL;
u32 temp;

// GET ERROR CODE

while(sms[i] != '#' && i < strlen(sms))
*(res++) = sms[i++];
*res = nul;
j = i - j;
res -= j;
error_code = (u8)atoi(res);


// GET TRANSACTION ID

j = ++i;
while(sms[i] != '#' && i < strlen(sms))
*(res++) = sms[i++];
*res = nul;
j = i - j;
res -= j;
transID = (u8)atoi(res);

// GET TRANSACTION TYPE

j = ++i;
while(sms[i] != '#' && i < strlen(sms))
*(res++) = sms[i++];
*res = nul;
j = i - j;
res -= j;
transType = (u8)atoi(res);

// GET OTHER PARAMETERS BASED ON THE TYPE

if(transType == MERCHANT){

// get stage
j = ++i;
while(sms[i] != '#' && i < strlen(sms))
*(res++) = sms[i++];
*res = nul;
j = i - j;
res -= j;
transStage = (u8)atoi(res);

if(transStage == STAGE_1){// get customer number
j = ++i;
while(sms[i] != '#' && i < strlen(sms))
*(res++) = sms[i++];
*res = nul;
j = i - j;
res -= j;
memcpy(customerNO, res, strlen(res)+1);
}

else{// get merchant number
j = ++i;
while(sms[i] != '#' && i < strlen(sms))
*(res++) = sms[i++];
*res = nul;
j = i - j;
res -= j;
memcpy(merchantNO, res, strlen(res)+1);
}
// get product id
j = ++i;
while(sms[i] != '#' && i < strlen(sms))
*(res++) = sms[i++];
*res = nul;
j = i - j;
res -= j;
memcpy(prodID, res, strlen(res)+1);
// get confirmation
if(transStage == STAGE_2){
j = ++i;
while(sms[i] != '#' && i < strlen(sms))
*(res++) = sms[i++];
*res = nul;
j = i - j;
res -= j;
confirm = (u8)atoi(res);
}

}

if (transType == LOAD_PURSE || transType == OFFLOAD_PURSE){
// get account type
j = ++i;
while(sms[i] != '#' && i < strlen(sms))
*(res++) = sms[i++];
*res = nul;
j = i - j;
res -= j;
acctType = (u8)atoi(res);
// get account balance
j = ++i;
while(sms[i] != '#' && i < strlen(sms))
*(res++) = sms[i++];
*res = nul;
j = i - j;
res -= j;
memcpy(acctBal, res, strlen(res)+1);
}

if (transType == SERVER){
// get new address
j = ++i;
while(sms[i] != '#' && i < strlen(sms))
*(res++) = sms[i++];
*res = nul;
j = i - j;
res -= j;
memcpy(p->back_end, res, strlen(res)+1);
wb(&p->read_msg, FALSE);
return;
}

// get amount paid
j = ++i;
while(sms[i] != '#' && i < strlen(sms))
*(res++) = sms[i++];
*res = nul;
j = i - j;
res -= j;
memcpy(amount, res, strlen(res)+1);

// get m-purse balance
j = ++i;
while(sms[i] != '#' && i < strlen(sms))
*(res++) = sms[i++];
*res = nul;
j = i - j;
res -= j;
memcpy(m_purse_t, res, strlen(res)+1);

i = 0;
while(i < strlen(m_purse_t))
if(m_purse_t[i++] == '.')
break;

if(i >= strlen(m_purse_t)){
kobo = 0;
}
else
kobo = (u8)atoi(m_purse_t+i);
m_purse_n = (u32)atoi(m_purse_t);

temp = m_purse_n;
temp &= 0x0000FFFF;
ww(&p->m_purse_nL, temp);
temp = m_purse_n;
// get higher word
temp >>= 16;
ww(&p->m_purse_nH, temp);
// get kobo
wb(&p->m_purse_k, kobo);

free(sms);
stk_thread(inform_on_text, data);

}

void inform_on_text(void* data){

u8* alpha = malloc(strlen(rcvd_new_msg));
memcpy(alpha, rcvd_new_msg, strlen(rcvd_new_msg)+1);
play_tone(alpha, TONE_RINGING, DURATION_SEC, 30);
free(alpha);

}

u8 handle_request(){


u8* res;
u8* rs;
// handle errors here
switch(error_code){

case MER_ERR:
{
res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
res = sprints(res, t_merchant);
res = sprints(res, merchantNO);
res = sprintc(res, nl);
res = sprints(res, t_prodID );
res = sprints(res, prodID);
res = sprintc(res, nl);
res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);
res = sprints(res, err_mer_send);
res = sprintc(res, nul);

display_text_raw(pay_msg, Q_DISPLAY_TEXT_USER_CLEAR);
wb(&p->read_msg, FALSE);
return APP_BACK;

}

case CUS_ERR:
{

res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
res = sprints(res, t_customer);
res = sprints(res, customerNO);
res = sprintc(res, nl);
res = sprints(res, t_prodID );
res = sprints(res, prodID);
res = sprintc(res, nl);
res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);
res = sprints(res, err_cus_send);
res = sprintc(res, nul);

display_text_raw(pay_msg, Q_DISPLAY_TEXT_USER_CLEAR);
wb(&p->read_msg, FALSE);
return APP_BACK;

}

case BANK_ERR:
{
res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
if (transType == LOAD_PURSE){
res = sprints(res, t_merchant);
res = sprints(res, t_loadpurse);
res = sprintc(res, nl);
}
else if(transType == OFFLOAD_PURSE){
res = sprints(res, t_merchant);
res = sprints(res, t_offloadpurse);
res = sprintc(res, nl);
}
else if(transType == POWER_BILL){
res = sprints(res, t_merchant);
res = sprints(res, t_powerbill);
res = sprintc(res, nl);
}
else if(transType == WATER_BILL){
res = sprints(res, t_merchant);
res = sprints(res, t_waterbill);
res = sprintc(res, nl);
}

res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);
res = sprints(res, t_accttype);
res = sprints(res, t_bank);
res = sprintc(res, nl);
res = sprints(res, err_bank_send);
res = sprintc(res, nul);

display_text_raw(pay_msg, Q_DISPLAY_TEXT_USER_CLEAR);
wb(&p->read_msg, FALSE);
return APP_BACK;

}

case CREDIT_ERR:
{
res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
if (transType == LOAD_PURSE){
res = sprints(res, t_merchant);
res = sprints(res, t_loadpurse);
res = sprintc(res, nl);
}
else if(transType == OFFLOAD_PURSE){
res = sprints(res, t_merchant);
res = sprints(res, t_offloadpurse);
res = sprintc(res, nl);
}
res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);
res = sprints(res, t_accttype);
res = sprints(res, t_credit);
res = sprintc(res, nl);
res = sprints(res, err_credit_send);
res = sprintc(res, nul);

display_text_raw(pay_msg, Q_DISPLAY_TEXT_USER_CLEAR);
wb(&p->read_msg, FALSE);
return APP_BACK;
}

default:
break;

}
// compose message to display

switch(transType){

case MERCHANT:
{

res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
if(transStage == STAGE_1){
res = sprints(res, t_customer);
res = sprints(res, customerNO);
res = sprintc(res, nl);
}
else{
res = sprints(res, t_merchant);
res = sprints(res, merchantNO);
res = sprintc(res, nl);
}
res = sprints(res, t_prodID);
res = sprints(res, prodID);
res = sprintc(res, nl);
res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);

if(transStage == STAGE_1){// customer request
res = sprints(res, t_request);
res = sprintc(res, nul);
*res = yesno(pay_msg, 0, 0);// get merchant's response
if (*res == APP_YES || *res == APP_NO){
// FORMAT SMS FOR SEND
res = sms;
res = sprinti(res, transID);
res = sprintc(res, sep);
res = sprinti(res, transType);
res = sprintc(res, sep);
// set transaction stage to STAGE_2
transStage = STAGE_2;
res = sprinti(res, transStage);
res = sprintc(res, sep);
// attach other info
res = sprints(res, customerNO);
res = sprintc(res, sep);
res = sprints(res, prodID);

if (*res == APP_NO)
confirm = 0;
else
confirm = 1;

res = sprinti(res, confirm);
res = sprintc(res, sep);
res = sprints(res, amount);
res = sprintc(res, nul);


// SEND SMS
*res = sendSms();
if ( *res == APP_OK){
wb(&p->read_msg, FALSE);
}

}
return *res;
}

else if (transStage == STAGE_2){// get confirmation and send
if (confirm){// the merchant has accepted it
res = sprints(res, t_mer_accept);
res = sprintc(res, nl);
res = sprints(res, t_pay_again);
res = sprintc(res, nul);

*res = yesno(pay_msg, 0, 0);// get customers response
if (*res == APP_YES || *res == APP_NO){
// FORMAT SMS FOR SEND
res = sms;
res = sprinti(res, transID);
res = sprintc(res, sep);
res = sprinti(res, transType);
res = sprintc(res, sep);
// set transaction stage to STAGE_3
transStage = STAGE_3;
res = sprinti(res, transStage);
res = sprintc(res, sep);
// attach other info
res = sprints(res, merchantNO);
res = sprintc(res, sep);
res = sprints(res, prodID);

if (*res == APP_NO)
confirm = 0;

res = sprinti(res, confirm);
res = sprintc(res, sep);
res = sprints(res, amount);
res = sprintc(res, nul);


// SEND SMS
*res = sendSms();
if ( *res == APP_OK){
wb(&p->read_msg, FALSE);
}

}
return *res;
}

if(!confirm){// if the merchant rejected it
res = sprints(res, t_mer_reject);
res = sprintc(res, nul);
display_text_raw(pay_msg, Q_DISPLAY_TEXT_USER_CLEAR);
wb(&p->read_msg, FALSE);

return APP_BACK;
}
}

else if(transStage == STAGE_3){// payment report from server
res = sprints(res, t_mpurse);
res = sprints(res, m_purse_t);
res = sprintc(res, nl);
res = sprints(res, t_success);
res = sprintc(res, nul);
*res = display_text(pay_msg, NULL);
wb(&p->read_msg, FALSE);

if(*res == APP_OK)
*res = APP_BACK;

return *res;
}

}

case POWER_BILL:
{
res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
res = sprints(res, t_merchant);
res = sprints(res, t_powerbill);
res = sprintc(res, nl);
res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);
res = sprints(res, t_mpurse);
res = sprints(res, m_purse_t);
res = sprintc(res, nl);
res = sprints(res, t_success);
res = sprintc(res, nul);
*res = display_text(pay_msg, NULL);

wb(&p->read_msg, FALSE);

if(*res == APP_OK)
*res = APP_BACK;

return *res;
}

case WATER_BILL:
{
res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
res = sprints(res, t_merchant);
res = sprints(res, t_waterbill);
res = sprintc(res, nl);
res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);
res = sprints(res, t_mpurse);
res = sprints(res, m_purse_t);
res = sprintc(res, nl);
res = sprints(res, t_success);
res = sprintc(res, nul);
*res = display_text(pay_msg, NULL);
wb(&p->read_msg, FALSE);

if(*res == APP_OK)
*res = APP_BACK;

return *res;

}

case LOAD_PURSE:
{
res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
res = sprints(res, t_merchant);
res = sprints(res, t_loadpurse);
res = sprintc(res, nl);
res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);
res = sprints(res, t_mpurse);
res = sprints(res, m_purse_t);
res = sprintc(res, nl);
if (acctType == BANK){
res = sprints(res, t_bank);
res = sprints(res, acctBal);
res = sprintc(res, nl);
}

else if (acctType == CREDIT){
res = sprints(res, t_credit);
res = sprints(res, acctBal);
res = sprintc(res, nl);
}
res = sprints(res, t_success);
res = sprintc(res, nul);
*res = display_text(pay_msg, NULL);
wb(&p->read_msg, FALSE);

if(*res == APP_OK)
*res = APP_BACK;

return *res;
}

case OFFLOAD_PURSE:
{
res = pay_msg;
res = sprints(res, t_pay_details);
res = sprintc(res, nl);
res = sprints(res, t_merchant);
res = sprintc(res, nl);
res = sprints(res, t_offloadpurse);
res = sprintc(res, nl);
res = sprints(res, t_amount);
res = sprints(res, amount);
res = sprintc(res, nl);
res = sprints(res, t_mpurse);
res = sprints(res, m_purse_t);
res = sprintc(res, nl);
if (acctType == BANK){
res = sprints(res, t_bank);
res = sprints(res, acctBal);
res = sprintc(res, nl);
}

else if (acctType == CREDIT){
res = sprints(res, t_credit);
res = sprints(res, acctBal);
res = sprintc(res, nl);
}
res = sprints(res, t_success);
res = sprintc(res, nul);
*res = display_text(pay_msg, NULL);
wb(&p->read_msg, FALSE);

if(*res == APP_OK)
*res = APP_BACK;

return *res;
}

default:
return APP_END;

}
}

SNodeP n = {Mpay, NULL};
SNodeP n_1 = {about_Mpay, about};
SNodeP n_02 = {login_Mpay, login};
SNodeP n_2 = {portal_Mpay, NULL};
SNodeP n_2_1 = {pay_Mpay, pay};
SNodeP n_2_2 = {bills_Mpay, NULL};
SNodeP n_2_3 = {mpurse_Mpay, NULL};
SNodeP n_2_4 = {security_Mpay, NULL};
SNodeP n_2_2_1 = {power_Mpay, powerBill};
SNodeP n_2_2_2 = {water_Mpay, waterBill};
SNodeP n_2_3_1 = {bal_Mpay, showBal};
SNodeP n_2_3_2 = {load_Mpay, load};
SNodeP n_2_3_3 = {offload_Mpay, offload};
SNodeP n_2_4_1 = {change_PIN, changePIN};
SNodeP n_2_4_2 = {change_pass1, changePass1};
SNodeP n_2_4_3 = {change_pass2, changePass2};
SNodeP n_2_3_2_1 = {bank_Mpay, bank};
SNodeP n_2_3_2_2 = {credit_Mpay, credit};

SEdgeP Mpay_edges[] = {

{&n, &n_1},
{&n, &n_02},
{&n_02, &n_2},
{&n_2, &n_2_1},
{&n_2, &n_2_2},
{&n_2, &n_2_3},
{&n_2, &n_2_4},
{&n_2_2, &n_2_2_1},
{&n_2_2, &n_2_2_2},
{&n_2_3, &n_2_3_1},
{&n_2_3, &n_2_3_2},
{&n_2_3, &n_2_3_3},
{&n_2_4, &n_2_4_1},
{&n_2_4, &n_2_4_2},
{&n_2_4, &n_2_4_3},
{&n_2_3_2, &n_2_3_2_1},
{&n_2_3_2, &n_2_3_2_2},
{&n_2_3_3, &n_2_3_2_1},
{&n_2_3_3, &n_2_3_2_2},
NULL

};


void action_menu (void *data)
{
SCtx *c = spider_init ();

if (c == NULL)
return;

c->n = &n;
c->eP = &Mpay_edges;

spider (c);
}


void turbo_handler (u8 action, void* data)
{
switch (action)
{

case ACTION_APP_REGISTER:
reg_sms_tag(locale(Mpay), t_Mpay_mime, SMS_TYPE_MSG);
{
u8 i;
App_Per_Dat* pt = emalloc(sizeof(App_Per_Dat));

memcpy(pt->pin, defpin, strlen(defpin)+1);
memcpy(pt->pass1, defp1, strlen(defp1)+1);
memcpy(pt->pass2, defp2, strlen(defp2)+1);
memcpy(pt->back_end, defSno, strlen(defSno)+1);
wb(&pt->read_msg, FALSE);
ww(&pt->m_purse_nL, 1000);
ww(&pt->m_purse_nH, 0);
wb(&pt->m_purse_k, 0);

reg_app_data(pt);
}
break;

case ACTION_SMS_MSG:
stk_thread(pay_reports, data);
break;

case ACTION_INSERT_MENU:
insert_menu (locale(Mpay));
break;

case ACTION_MENU_SELECTION:
stk_thread (action_menu, data);
break;
case ACTION_APP_INIT:
{
u8 i;
p = app_data();

m_purse_n = rw(&p->m_purse_nH);
m_purse_n <<= 16;
m_purse_n |= rw(&p->m_purse_nL);

if(pay_msg)
free(pay_msg);
if(sms)
free(sms);
if(amount)
free(amount);
if(amount_k)
free(amount_k);
if(m_purse_t)
free(m_purse_t);
if(show_bal)
free(show_bal);
if(acctBal)
free(acctBal);
if(merchantNO)
free(merchantNO);
if(customerNO)
free(customerNO);
if(prodID)
free(prodID);


sms = (u8*)malloc(165);
pay_msg = (u8*)malloc(250);
amount = (u8*)malloc(15);
amount_k = (u8*)malloc(5);
m_purse_t = (u8*)malloc(15);
show_bal = (u8*)malloc(75);
acctBal = (u8*)malloc(15);
merchantNO = (u8*)malloc(20);
customerNO = (u8*)malloc(20);
prodID = (u8*)malloc(15);

if(rb(&p->read_msg) == TRUE){
memcpy(sms, p->sms, strlen(p->sms)+1);
parse();
}
}
break;
case ACTION_APP_UNREGISTER:
{
App_Per_Dat* p = app_data();

efree(p);
}
break;
default:
break;
}
}

and this is what I did to "config.h"

#ifndef _CONFIG_TURBO_
#define _CONFIG_TURBO_

#define CONFIG_LANG_UN

#endif



I hope you can find what's wrong especially in the App_Per_Dat struct. I'm really confused on how to reference an array stored in eeprom.

Also I borrowed a friend's fone to do the transfer. I was supposed to return it on the day before yesterday but I didn't because I want to be sure I've done this well b4 I return it cos he swore he'll neva lend me his fone again. So if am not asking too much could you please reply say by 4:00pm GMT.

Too much talk I guess. Let me leave it to u the guru. pls help in the shortest possible time.

obass

-BIG means Bladox Is Great.
Back to top
pz
Guest





PostPosted: Wed Dec 13, 2006 6:09 pm    Post subject: Reply with quote

I went thru only the APP_REGISTER and APP_INIT, see comments below.

obass wrote:
Thanx for the reply.

Here's the code its some mobile payment stuff:



typedef struct _App_p_Dat{
u16 m_purse_nL;
u16 m_purse_nH;
u8 m_purse_k;
u8 read_msg;
u8 pin[6];
u8 pass1[15];
u8 pass2[15];
u8 back_end[20];
u8 sms[165];
}App_Per_Dat;


lc_char PROGMEM about_Mpay[] = {
LC_UN ("About")
LC_END
};

Surprising to see anybody used LC_UN, I wonder how this one works in practise, it should - somehow - but please can you go rather with LC_EN? This is definitely better handled in kernel, also many strings in kernel are not LC_UN, etc. Please use LC_EN just to be on safe side. But probably not the real issue.

void turbo_handler (u8 action, void* data)
{
switch (action)
{

case ACTION_APP_REGISTER:
reg_sms_tag(locale(Mpay), t_Mpay_mime, SMS_TYPE_MSG);
{
u8 i;
App_Per_Dat* pt = emalloc(sizeof(App_Per_Dat));

memcpy(pt->pin, defpin, strlen(defpin)+1);
memcpy(pt->pass1, defp1, strlen(defp1)+1);
memcpy(pt->pass2, defp2, strlen(defp2)+1);
memcpy(pt->back_end, defSno, strlen(defSno)+1);

What does compiler warn about this?
Mmmm, can you try memcpy(&pt->x[0]...)?

wb(&pt->read_msg, FALSE);
ww(&pt->m_purse_nL, 1000);
ww(&pt->m_purse_nH, 0);
wb(&pt->m_purse_k, 0);

reg_app_data(pt);
}
break;


case ACTION_APP_INIT:
{
u8 i;
p = app_data();

m_purse_n = rw(&p->m_purse_nH);
m_purse_n <<= 16;
m_purse_n |= rw(&p->m_purse_nL);

if(pay_msg)
free(pay_msg);
if(sms)
free(sms);
if(amount)
free(amount);
if(amount_k)
free(amount_k);
if(m_purse_t)
free(m_purse_t);
if(show_bal)
free(show_bal);
if(acctBal)
free(acctBal);
if(merchantNO)
free(merchantNO);
if(customerNO)
free(customerNO);
if(prodID)
free(prodID);

You can avoid all this if(...) free() - APP_INIT is done only once, it also quite possible that your variables/pointers are *not* set to be NULL - there are some limitations when/how/if globals are initated in this embedded environment. Definitely better not to read/use varilables before setting them here - this is why it is calle APP_INIT action.

sms = (u8*)malloc(165);
pay_msg = (u8*)malloc(250);
amount = (u8*)malloc(15);
amount_k = (u8*)malloc(5);
m_purse_t = (u8*)malloc(15);
show_bal = (u8*)malloc(75);
acctBal = (u8*)malloc(15);
merchantNO = (u8*)malloc(20);
customerNO = (u8*)malloc(20);
prodID = (u8*)malloc(15);

if(rb(&p->read_msg) == TRUE){
memcpy(sms, p->sms, strlen(p->sms)+1);

As above, can you try &p->sms[0]?

parse();
}
}
break;

}
}

and this is what I did to "config.h"

#ifndef _CONFIG_TURBO_
#define _CONFIG_TURBO_

#define CONFIG_LANG_UN

#endif



I hope you can find what's wrong especially in the App_Per_Dat struct. I'm really confused on how to reference an array stored in eeprom.


Yeah, it can be tricky, do you have a programmer? You could see what the values really are, print pointers, etc. Helps a lot.

Quote:

Also I borrowed a friend's fone to do the transfer. I was supposed to return it on the day before yesterday but I didn't because I want to be sure I've done this well b4 I return it cos he swore he'll neva lend me his fone again. So if am not asking too much could you please reply say by 4:00pm GMT.


Really sorry, haven't seen your post earlier, everybody has been busy over here.


Quote:

Too much talk I guess. Let me leave it to u the guru. pls help in the shortest possible time.


Well, sometimes guru are also lost and confused, I don't have possibility to try/test it, my suggestions. And no books around to check standard. But I think it will be one or combination of the above.

Quote:

obass

-BIG means Bladox Is Great.


Smile
Back to top
obass
Guest





PostPosted: Thu Dec 14, 2006 10:50 am    Post subject: Reply with quote

Thanks a great deal. Am going to try them out.
Could you check out enterAmount() and sendSms() I think there's something wrong there with the gotos or APP_BACK returned. Also check the comparisons involving u32 data type in enterAmount(). I had problems using them initially. Sorry I forgot to add this in the last post.

Thanks.

-BIG (guess u know what that means to me by now).

obass
Back to top
obass
Guest





PostPosted: Thu Dec 14, 2006 10:50 am    Post subject: Reply with quote

Thanks a great deal. Am going to try them out.

Could you check out enterAmount() and sendSms() I think there's something wrong there with the gotos or APP_BACK returned. Also check the comparisons involving u32 data type in enterAmount(). I had problems using them initially. Sorry I forgot to add this in the last post.

Thanks.

-BIG (guess u know what that means to me by now).

obass
Back to top
pz
Guest





PostPosted: Mon Dec 18, 2006 5:34 pm    Post subject: Reply with quote

Did it help? So we can move to enterAmount() and sendSms()... Don't like to fixing more bugs at once.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    bladox.com Forum Index -> Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group