NMT: Fix test of SMS code for different time zones

This commit is contained in:
Andreas Eversberg 2018-11-10 14:43:31 +01:00
parent 2cff22ef54
commit 73757ba083
4 changed files with 15 additions and 14 deletions

View File

@ -1272,7 +1272,7 @@ static void tx_mt_complete(nmt_t *nmt, frame_t *frame)
}
if (trans->dms_call) {
time_t ti = time(NULL);
sms_deliver(nmt, sms_ref, trans->caller_id, trans->caller_type, SMS_PLAN_ISDN_TEL, ti, trans->sms_string);
sms_deliver(nmt, sms_ref, trans->caller_id, trans->caller_type, SMS_PLAN_ISDN_TEL, ti, 1, trans->sms_string);
}
}
}

View File

@ -163,9 +163,9 @@ static int encode_address(uint8_t *data, const char *address, uint8_t type, uint
}
/* encode time stamp */
static int encode_time(uint8_t *data, time_t timestamp)
static int encode_time(uint8_t *data, time_t timestamp, int local)
{
struct tm *tm = localtime(&timestamp);
struct tm *tm = (local) ? localtime(&timestamp) : gmtime(&timestamp);
int length = 0;
uint8_t digit1, digit2;
int quarters, sign;
@ -227,7 +227,7 @@ static int encode_time(uint8_t *data, time_t timestamp)
data[length++] = (digit2 << 4) | digit1;
/* zone */
quarters = timezone / 900;
quarters = (local) ? (timezone / 900) : 0;
if (quarters < 0) {
quarters = -quarters;
sign = 1;
@ -244,7 +244,7 @@ static int encode_time(uint8_t *data, time_t timestamp)
static int encode_userdata(uint8_t *data, const char *message)
{
int length = 1;
char character;
uint8_t character;
int i, j, pos;
PDEBUG(DSMS, DEBUG_DEBUG, "Encode user data '%s'\n", message);
@ -286,7 +286,7 @@ static int encode_userdata(uint8_t *data, const char *message)
}
/* deliver SMS (SC->MS) */
int sms_deliver(nmt_t *nmt, uint8_t ref, const char *orig_address, uint8_t orig_type, uint8_t orig_plan, time_t timestamp, const char *message)
int sms_deliver(nmt_t *nmt, uint8_t ref, const char *orig_address, uint8_t orig_type, uint8_t orig_plan, time_t timestamp, int local, const char *message)
{
uint8_t data[256], *tpdu_length;
int length = 0;
@ -321,7 +321,7 @@ int sms_deliver(nmt_t *nmt, uint8_t ref, const char *orig_address, uint8_t orig_
length += encode_address(data + length, orig_address, orig_type, orig_plan); /* TP-OA */
data[length++] = 0; /* TP-PID */
data[length++] = 0; /* TP-DCS */
length += encode_time(data + length, timestamp);
length += encode_time(data + length, timestamp, local);
length += encode_userdata(data + length, message);
/* RP length */

View File

@ -28,7 +28,7 @@ int sms_init_sender(nmt_t *nmt);
void sms_cleanup_sender(nmt_t *nmt);
int sms_submit(nmt_t *nmt, uint8_t ref, const char *orig_address, uint8_t orig_type, uint8_t orig_plan, int msg_ref, const char *dest_address, uint8_t dest_type, uint8_t dest_plan, const char *message);
void sms_deliver_report(nmt_t *nmt, uint8_t ref, int error, uint8_t cause);
int sms_deliver(nmt_t *nmt, uint8_t ref, const char *orig_address, uint8_t type, uint8_t plan, time_t timestamp, const char *message);
int sms_deliver(nmt_t *nmt, uint8_t ref, const char *orig_address, uint8_t type, uint8_t plan, time_t timestamp, int local, const char *message);
void sms_release(nmt_t *nmt);
void sms_reset(nmt_t *nmt);

View File

@ -39,7 +39,7 @@ static const uint8_t test_mt_sms_data[] = {
0x0a, 0x91, 0x94, 0x84, 0x14, 0xa6, 0x86,
0x00,
0x00,
0x69, 0x21, 0x42, 0x31, 0x53, 0x4a, 0x48,
0x69, 0x21, 0x42, 0x21, 0x53, 0x4a, 0x00,
0x09, 0xcd, 0x77, 0xda, 0x0d, 0x6a, 0xbe, 0xd3, 0x6e,
};
@ -63,7 +63,7 @@ static uint8_t dms_buffer[256];
static int dms_buffer_count;
void dms_send(nmt_t *nmt, const uint8_t *data, int length, int eight_bits)
{
// int i;
int i;
/* skip deliver report */
if (length == 13)
@ -73,10 +73,11 @@ void dms_send(nmt_t *nmt, const uint8_t *data, int length, int eight_bits)
memcpy(dms_buffer, data, length);
assert(length == sizeof(test_mt_sms_data), "Expecting SMS binary data length to match");
for (i = 0; i < length; i++) {
if (data[i] != test_mt_sms_data[i])
printf("offset: %d got: 0x%02x expecting: 0x%02x\n", i, data[i], test_mt_sms_data[i]);
}
assert(!memcmp(data, test_mt_sms_data, length), "Expecting SMS binary data to match");
// for (i = 0; i < length; i++) {
// printf("(0x%02x)\n", data[i]);
// }
}
void sms_release(nmt_t *nmt)
@ -116,7 +117,7 @@ int main(void)
/* deliver */
printf("(delivering SMS)\n");
rc = sms_deliver(nmt, 1, test_mt_sms_tel, SMS_TYPE_INTERNATIONAL, SMS_PLAN_ISDN_TEL, test_mt_sms_time, test_mt_sms_text);
rc = sms_deliver(nmt, 1, test_mt_sms_tel, SMS_TYPE_INTERNATIONAL, SMS_PLAN_ISDN_TEL, test_mt_sms_time, 0, test_mt_sms_text);
assert(rc == 0, "Expecting sms_deliver() to return 0");
sms_cleanup_sender(nmt);