Карту пополняет

This commit is contained in:
Dmitriy 2025-05-13 01:14:50 +03:00
parent 46286e26bc
commit ae0a42bc74
6 changed files with 2126 additions and 2101 deletions

View File

@ -780,36 +780,42 @@ void AppVladEventProcess(CPU_INT32U event)
// Select one of the cards
if (picc_read_card_serial()) {
if(read_mifare_card() != NULL) {
if(is_empty_mifare_card()) {
init_mifare_card_data();
if(!write_mifare_card())
if(app_state.user_menu != USER_MENU_INSERT_BONUS_CARD) {
if(read_mifare_card() != NULL) {
if(is_empty_mifare_card()) {
init_mifare_card_data();
if(!write_mifare_card())
{
app_state.user_menu = USER_MENU_IDLE;
stop_card_working();
break;
}
}
if(app_state.user_menu == USER_MENU_IDLE)
{
app_state.user_menu = USER_MENU_IDLE;
break;
}
}
if(app_state.user_menu == USER_MENU_IDLE)
{
// ïðîâåðèì - íå íàäî ëè áîíóñû î÷èñòèòü
if(need_clear_bonus()) {
// íóæíî - çàïèøåì ýòî
write_mifare_card();
}
// ïðîâåðèì - íå íàäî ëè áîíóñû î÷èñòèòü
if(need_clear_bonus()) {
// íóæíî - çàïèøåì ýòî
write_mifare_card();
}
// íóæíî ïîêàçàòü áàëàíñ
app_state.last_card_manipulation_time = OSTimeGet();
// íóæíî ïîêàçàòü áàëàíñ
app_state.last_card_manipulation_time = OSTimeGet();
app_state.user_menu = USER_MENU_BALANCE_CARD;
PrintBalanceMenu();
RefreshMenu();
PlayMusicFile(41);
app_state.user_menu = USER_MENU_BALANCE_CARD;
PrintBalanceMenu();
RefreshMenu();
PlayMusicFile(41);
}
stop_card_working();
} else {
app_state.user_menu = USER_MENU_IDLE;
break;
}
} else {
app_state.user_menu = USER_MENU_IDLE;
break;
}
if(app_state.user_menu == USER_MENU_INSERT_BONUS_CARD) {
@ -839,6 +845,8 @@ void AppVladEventProcess(CPU_INT32U event)
RefreshMenu();
PlayMusicFile(52);
}
stop_card_working();
}
} else {
app_state.user_menu = USER_MENU_IDLE;
@ -1004,6 +1012,12 @@ void AppVladEventProcess(CPU_INT32U event)
{
PrintInsertBankCardMenu();
RefreshMenu();
// temporally
SetAcceptedMoney(app_state.abonementtopay);
SaveEventRecord(app_state.current_abonement, JOURNAL_EVENT_CARD_ACCEPTED, app_state.abonementtopay);
app_state.user_menu = USER_MENU_INSERT_BONUS_CARD;
PostUserEvent(EVENT_FINISH_PAYMENT_ABONEMENT);
}
}
else if (app_state.user_menu == USER_MENU_SHOW_THANKS)
@ -1159,6 +1173,13 @@ void AppVladEventProcess(CPU_INT32U event)
RefreshMenu();
PlayMusicFile(2);
}
else if(app_state.user_menu == USER_MENU_FINISH_PAY_BONUS_CARD)
{
app_state.user_menu = USER_MENU_IDLE;
PrintHelloMenu();
RefreshMenu();
StopMusic();
}
else if(app_state.user_menu == USER_MENU_BALANCE_CARD)
{
// ïðåäëîæèì ïîïîëíèòü êàðòó
@ -1177,7 +1198,7 @@ void AppVladEventProcess(CPU_INT32U event)
RefreshMenu();
PlayMusicFile(43);
}
else if(app_state.user_menu == USER_MENU_START_INSERT_CARD_MONEY)
else if(app_state.user_menu == USER_MENU_ALL_PRICE)
{
app_state.user_menu = USER_MENU_SILVER_BONUS + app_state.current_abonement;
@ -1614,7 +1635,7 @@ void AppVladEventProcess(CPU_INT32U event)
{
if (AppCanStart())
{
app_state.current_abonement = (app_state.current_abonement + 1) & 0x02;
app_state.current_abonement = (app_state.current_abonement + 1) & 0x03;
PrintMenuAllPrice(app_state.blink_ctr >= 500);
RefreshMenu();
}
@ -1674,7 +1695,7 @@ void AppVladEventProcess(CPU_INT32U event)
{
if (AppCanStart())
{
app_state.current_abonement = (app_state.current_abonement + 1) & 0x02;
app_state.current_abonement = (app_state.current_abonement + 1) & 0x03;
PrintMenuAllPrice(app_state.blink_ctr >= 500);
RefreshMenu();
}
@ -1974,6 +1995,7 @@ void AppVladEventProcess(CPU_INT32U event)
|| app_state.user_menu == USER_MENU_PLATINUM_BONUS
|| app_state.user_menu == USER_MENU_BRILLANCE_BONUS
|| app_state.user_menu == USER_MENU_ERROR_BANK_CARD
|| app_state.user_menu == USER_MENU_FINISH_PAY_BONUS_CARD
)
{
app_state.user_menu = USER_MENU_IDLE;
@ -2369,7 +2391,7 @@ void PrintMenuAllPrice(CPU_INT08U blink)
void PrintSilverMenu(void)
{
char str[32];
char str1[16];
char str1[20];
uint32_t pay_silver = 0, bonus_silver = 0, best_before = 0;
GetData(&AbonementMoneyDesc, &pay_silver, 0, DATA_FLAG_DIRECT_INDEX);
@ -2394,7 +2416,7 @@ void PrintSilverMenu(void)
void PrintGoldMenu(void)
{
char str[32];
char str1[16];
char str1[20];
uint32_t pay_gold = 0, bonus_gold = 0, best_before = 0;
GetData(&AbonementMoneyDesc, &pay_gold, 1, DATA_FLAG_DIRECT_INDEX);
@ -2419,7 +2441,7 @@ void PrintGoldMenu(void)
void PrintPlatMenu(void)
{
char str[32];
char str1[16];
char str1[20];
uint32_t pay_plat = 0, bonus_plat = 0, best_before = 0;
GetData(&AbonementMoneyDesc, &pay_plat, 2, DATA_FLAG_DIRECT_INDEX);
@ -2444,7 +2466,7 @@ void PrintPlatMenu(void)
void PrintDiamondMenu(void)
{
char str[32];
char str1[16];
char str1[20];
uint32_t pay_diamond = 0, bonus_diamond = 0, best_before = 0;
GetData(&AbonementMoneyDesc, &pay_diamond, 3, DATA_FLAG_DIRECT_INDEX);

View File

@ -65,7 +65,6 @@ bool try_key_a(MIFARE_Key *key)
result = true;
}
//stop_card_working();
return result;
}
@ -92,7 +91,6 @@ bool try_key_b(MIFARE_Key *key)
result = true;
}
//stop_card_working();
return result;
}
@ -160,19 +158,16 @@ bool write_mifare_card()
0,
255, 255, 255, 255, 255, 255}; // Keep default key B
for (uint8_t i = 0; i < MF_KEY_SIZE; i++){
trailerBuffer[i] = knownKeys[1][i];
trailerBuffer[i + 10] = knownKeys[1][i];
}
MIFARE_SetAccessBits(&trailerBuffer[6], 4, 4, 4, 1);
MIFARE_Key key;
for (uint8_t k = 0; k < NR_KNOWN_KEYS; k++) {
for (uint8_t i = 0; i < MF_KEY_SIZE; i++) {
key.keyByte[i] = knownKeys[k][i];
trailerBuffer[i] = knownKeys[k][i];
trailerBuffer[i + 10] = knownKeys[k][i];
}
if (try_key_a(&key)) {
if (try_key_b(&key)) {
break;
}
@ -187,6 +182,8 @@ bool write_mifare_card()
return false;
}
MIFARE_SetAccessBits(&trailerBuffer[6], 4, 4, 4, 1);
for(uint8_t i = 0; i < sizeof(mifare_card_data); i += 16)
{
status = pcd_authenticate(PICC_CMD_MF_AUTH_KEY_B, block, &key, get_uid());
@ -203,20 +200,18 @@ bool write_mifare_card()
if(block%4 == 3) {
// write security
/*status = pcd_authenticate(PICC_CMD_MF_AUTH_KEY_A, block, &key, get_uid());
status = pcd_authenticate(PICC_CMD_MF_AUTH_KEY_B, block, &key, get_uid());
if (status != STATUS_OK) {
return false;
}
status = mifare_write(block, &trailerBuffer[0], 16);
if (status != STATUS_OK) {
return false;
}*/
}
block++;
}
}
//stop_card_working();
return true;
}
@ -240,7 +235,7 @@ mifaredata_t* init_mifare_card_data()
bool is_empty_mifare_card()
{
return mifare_card_data.init != 0xDEADBEE0;
return mifare_card_data.init != 0xDEADBEEF;
}
bool need_clear_bonus()

File diff suppressed because one or more lines are too long

View File

@ -46,11 +46,11 @@
<MultiCoreRunAll>1</MultiCoreRunAll>
</Simulator>
<PlDriver>
<FirstRun>0</FirstRun>
<MemConfigValue>C:\Program Files\IAR Systems\Embedded Workbench 9.0\arm\CONFIG\debugger\NXP\LPC2368.ddf</MemConfigValue>
<FirstRun>0</FirstRun>
</PlDriver>
<DebugChecksum>
<Checksum>1544313793</Checksum>
<Checksum>959379000</Checksum>
</DebugChecksum>
<Exceptions>
<StopOnUncaught>_ 0</StopOnUncaught>
@ -82,19 +82,36 @@
<array_types>
<Fmt0>uint32_t[10] 4 0</Fmt0>
</array_types>
<watch_formats>
<Fmt0>{W}1:app_state.user_menu 3 0</Fmt0>
</watch_formats>
<Trace2>
<Enabled>0</Enabled>
<ShowSource>0</ShowSource>
</Trace2>
<TermIOLog>
<LoggingEnabled>_ 0</LoggingEnabled>
<LogFile>_ ""</LogFile>
</TermIOLog>
<DisassembleMode>
<mode>0</mode>
</DisassembleMode>
<Breakpoints2>
<Bp0>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\drivers\mfrc522\rfid-spi.c}.321.7" 0 0 1 "" 0 "" 0</Bp0>
<Bp1>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\drivers\mfrc522\rfid-spi.c}.190.3" 0 0 1 "" 0 "" 0</Bp1>
<Bp2>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\drivers\mfrc522\mfrc522data.c}.185.5" 0 0 1 "" 0 "" 0</Bp2>
<Bp3>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\drivers\mfrc522\mfrc522data.c}.209.15" 0 0 1 "" 0 "" 0</Bp3>
<Bp4>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\drivers\mfrc522\mfrc522data.c}.215.5" 0 0 1 "" 0 "" 0</Bp4>
<Bp5>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\app\app_vlad.c}.823.50" 0 0 1 "" 0 "" 0</Bp5>
<Bp6>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\app\app_vlad.c}.783.25" 0 0 1 "" 0 "" 0</Bp6>
<Bp7>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\app\app_vlad.c}.1111.39" 0 0 1 "" 0 "" 0</Bp7>
<Count>8</Count>
</Breakpoints2>
<LogFile>
<LoggingEnabled>_ 0</LoggingEnabled>
<LogFile>_ ""</LogFile>
<Category>_ 0</Category>
</LogFile>
<Aliases>
<Count>0</Count>
<SuppressDialog>0</SuppressDialog>
</Aliases>
<DriverProfiling>
<Enabled>0</Enabled>
<Mode>1</Mode>
@ -107,20 +124,8 @@
<CallStackStripe>
<ShowTiming>1</ShowTiming>
</CallStackStripe>
<DisassembleMode>
<mode>0</mode>
</DisassembleMode>
<Breakpoints2>
<Bp0>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\drivers\mfrc522\rfid-spi.c}.321.7" 0 0 1 "" 0 "" 0</Bp0>
<Bp1>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\drivers\mfrc522\rfid-spi.c}.190.3" 0 0 1 "" 0 "" 0</Bp1>
<Bp2>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\app\app_vlad.c}.753.36" 0 0 1 "" 0 "" 0</Bp2>
<Bp3>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\app\app_vlad.c}.752.32" 0 0 1 "" 0 "" 0</Bp3>
<Bp4>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\drivers\mfrc522\mfrc522data.c}.113.9" 0 0 1 "" 0 "" 0</Bp4>
<Bp5>_ 1 "EMUL_CODE" "{$PROJ_DIR$\PROJECT\drivers\mfrc522\mfrc522data.c}.214.13" 0 0 1 "" 0 "" 0</Bp5>
<Count>6</Count>
</Breakpoints2>
<Aliases>
<Count>0</Count>
<SuppressDialog>0</SuppressDialog>
</Aliases>
<TermIOLog>
<LoggingEnabled>_ 0</LoggingEnabled>
<LogFile>_ ""</LogFile>
</TermIOLog>
</settings>

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff