Moved the exit until after the Ack or Error has returned for AtomicReadFile and AtomicWriteFile demo client applications. Thank you, Sergei!

This commit is contained in:
skarg
2011-07-20 15:47:13 +00:00
parent acbfe10349
commit 52e0d00f4f
2 changed files with 39 additions and 25 deletions
+18 -11
View File
@@ -272,10 +272,9 @@ int main(
npdu_handler(&src, &Rx_Buf[0], pdu_len); npdu_handler(&src, &Rx_Buf[0], pdu_len);
} }
/* at least one second has passed */ /* at least one second has passed */
if (current_seconds != last_seconds) if (current_seconds != last_seconds) {
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000)); tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
if (End_Of_File_Detected || Error_Detected) }
break;
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = found =
address_bind_request(Target_Device_Object_Instance, &max_apdu, address_bind_request(Target_Device_Object_Instance, &max_apdu,
@@ -285,24 +284,30 @@ int main(
and remove the overhead of the APDU (about 16 octets max). and remove the overhead of the APDU (about 16 octets max).
note: we could fail if there is a bottle neck (router) note: we could fail if there is a bottle neck (router)
and smaller MPDU in betweeen. */ and smaller MPDU in betweeen. */
if (max_apdu < MAX_APDU) if (max_apdu < MAX_APDU) {
my_max_apdu = max_apdu; my_max_apdu = max_apdu;
else } else {
my_max_apdu = MAX_APDU; my_max_apdu = MAX_APDU;
}
/* Typical sizes are 50, 128, 206, 480, 1024, and 1476 octets */ /* Typical sizes are 50, 128, 206, 480, 1024, and 1476 octets */
if (my_max_apdu <= 50) if (my_max_apdu <= 50) {
requestedOctetCount = my_max_apdu - 20; requestedOctetCount = my_max_apdu - 20;
else if (my_max_apdu <= 480) } else if (my_max_apdu <= 480) {
requestedOctetCount = my_max_apdu - 32; requestedOctetCount = my_max_apdu - 32;
else if (my_max_apdu <= 1476) } else if (my_max_apdu <= 1476) {
requestedOctetCount = my_max_apdu - 64; requestedOctetCount = my_max_apdu - 64;
else } else {
requestedOctetCount = my_max_apdu / 2; requestedOctetCount = my_max_apdu / 2;
}
/* has the previous invoke id expired or returned? /* has the previous invoke id expired or returned?
note: invoke ID = 0 is invalid, so it will be idle */ note: invoke ID = 0 is invalid, so it will be idle */
if ((invoke_id == 0) || tsm_invoke_id_free(invoke_id)) { if ((invoke_id == 0) || tsm_invoke_id_free(invoke_id)) {
if (invoke_id != 0) if (End_Of_File_Detected || Error_Detected) {
break;
}
if (invoke_id != 0) {
fileStartPosition += requestedOctetCount; fileStartPosition += requestedOctetCount;
}
/* we'll read the file in chunks /* we'll read the file in chunks
less than max_apdu to keep unsegmented */ less than max_apdu to keep unsegmented */
invoke_id = invoke_id =
@@ -330,7 +335,9 @@ int main(
last_seconds = current_seconds; last_seconds = current_seconds;
} }
if (Error_Detected) if (Error_Detected) {
return 1; return 1;
}
return 0; return 0;
} }
+21 -14
View File
@@ -229,11 +229,8 @@ int main(
npdu_handler(&src, &Rx_Buf[0], pdu_len); npdu_handler(&src, &Rx_Buf[0], pdu_len);
} }
/* at least one second has passed */ /* at least one second has passed */
if (current_seconds != last_seconds) if (current_seconds != last_seconds) {
tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000)); tsm_timer_milliseconds(((current_seconds - last_seconds) * 1000));
if (End_Of_File_Detected || Error_Detected) {
printf("\r\n");
break;
} }
/* wait until the device is bound, or timeout and quit */ /* wait until the device is bound, or timeout and quit */
found = found =
@@ -247,25 +244,32 @@ int main(
and remove the overhead of the APDU (varies depending on size). and remove the overhead of the APDU (varies depending on size).
note: we could fail if there is a bottle neck (router) note: we could fail if there is a bottle neck (router)
and smaller MPDU in betweeen. */ and smaller MPDU in betweeen. */
if (max_apdu < MAX_APDU) if (max_apdu < MAX_APDU) {
my_max_apdu = max_apdu; my_max_apdu = max_apdu;
else } else {
my_max_apdu = MAX_APDU; my_max_apdu = MAX_APDU;
}
/* Typical sizes are 50, 128, 206, 480, 1024, and 1476 octets */ /* Typical sizes are 50, 128, 206, 480, 1024, and 1476 octets */
if (my_max_apdu <= 50) if (my_max_apdu <= 50) {
requestedOctetCount = my_max_apdu - 19; requestedOctetCount = my_max_apdu - 19;
else if (my_max_apdu <= 480) } else if (my_max_apdu <= 480) {
requestedOctetCount = my_max_apdu - 32; requestedOctetCount = my_max_apdu - 32;
else if (my_max_apdu <= 1476) } else if (my_max_apdu <= 1476) {
requestedOctetCount = my_max_apdu - 64; requestedOctetCount = my_max_apdu - 64;
else } else {
requestedOctetCount = my_max_apdu / 2; requestedOctetCount = my_max_apdu / 2;
}
} }
/* has the previous invoke id expired or returned? /* has the previous invoke id expired or returned?
note: invoke ID = 0 is invalid, so it will be idle */ note: invoke ID = 0 is invalid, so it will be idle */
if ((invoke_id == 0) || tsm_invoke_id_free(invoke_id)) { if ((invoke_id == 0) || tsm_invoke_id_free(invoke_id)) {
if (invoke_id != 0) if (End_Of_File_Detected || Error_Detected) {
printf("\r\n");
break;
}
if (invoke_id != 0) {
fileStartPosition += requestedOctetCount; fileStartPosition += requestedOctetCount;
}
/* we'll read the file in chunks /* we'll read the file in chunks
less than max_apdu to keep unsegmented */ less than max_apdu to keep unsegmented */
pFile = fopen(Local_File_Name, "rb"); pFile = fopen(Local_File_Name, "rb");
@@ -274,12 +278,14 @@ int main(
len = len =
fread(octetstring_value(&fileData), 1, fread(octetstring_value(&fileData), 1,
requestedOctetCount, pFile); requestedOctetCount, pFile);
if (len < requestedOctetCount) if (len < requestedOctetCount) {
End_Of_File_Detected = true; End_Of_File_Detected = true;
}
octetstring_truncate(&fileData, len); octetstring_truncate(&fileData, len);
fclose(pFile); fclose(pFile);
} else } else {
End_Of_File_Detected = true; End_Of_File_Detected = true;
}
printf("\rSending %d bytes", (fileStartPosition + len)); printf("\rSending %d bytes", (fileStartPosition + len));
invoke_id = invoke_id =
Send_Atomic_Write_File_Stream Send_Atomic_Write_File_Stream
@@ -306,7 +312,8 @@ int main(
last_seconds = current_seconds; last_seconds = current_seconds;
} }
if (Error_Detected) if (Error_Detected) {
return 1; return 1;
}
return 0; return 0;
} }