|
|
View previous topic :: View next topic |
Author |
Message |
densimitre
Joined: 21 Dec 2004 Posts: 45
|
How 2 make a TP-UD field encoder for PDU-SMS mode |
Posted: Wed Apr 20, 2005 11:53 pm |
|
|
Hi
I need my PIC send SMS in PDU mode.....but i want that PIC generate the User Data field of PDU frame..not using predefined PDU message...
because I have something like this:
Code: | int ad=getadc()
float val=5*ad/255;
sprintf(buffer,"The Value is=%2.3f",val); |
The idea is store the string "The Value.." in buffer string, then encode to TP-UD this buffer, then strcat()ing the others PDU field strings to send entire SMS mesage..
Thank you very much
Last edited by densimitre on Mon May 02, 2005 11:33 pm; edited 1 time in total |
|
|
densimitre
Joined: 21 Dec 2004 Posts: 45
|
|
|
densimitre
Joined: 21 Dec 2004 Posts: 45
|
|
Posted: Mon May 02, 2005 11:12 pm |
|
|
Hi,
I have this code, but ist not work:
Code: | #include <16f84.h>
#use delay(clock=4000000)
#use RS232(BAUD=9600, BITS=8, PARITY=N, XMIT=PIN_B4, RCV=PIN_B5)
//#device icd=true
//#include <stdio.h>
//#include <string.h>
//#include <stdlibm.h> // Libreria que incluye la funcion malloc()
#include "pduconv.c" // Funciones y tablas para la conversion de ASCII a PDU
//#include "pduconv.h" // Fichero con definicion de las funciones
int main()
{
char buffer[]="Esta es una Prueba"
int pdulen, i;
unsigned char *pdu;
pdulen=ascii_to_pdu(buffer,&pdu);
for (i=0; i<pdulen;i++)
{
printf("%02hX",pdu[i]);
}
free(pdu);
} |
pduconv.c
Code: | /***************************************************************************
*
* Functions for converting between an ISO-8859-1 ASCII string and a
* PDU-coded string as described in ETSI GSM 03.38 and ETSI GSM 03.40.
*
* This code is released to the public domain in 2003 by Mats Engstrom,
* Nerdlabs Consulting. ( matseng at nerdlabs dot org )
*
**************************************************************************/
#include <string.h>
//#include <stdlib.h> Ma be this .h ist not have in CCS
#include <STDLIBM.H>
#include "pduconv.h"
#define VERSION 0.1
/* Define Non-Printable Characters as a question mark */
#define NPC7 63
#define NPC8 '?'
/****************************************************************************
This lookup table converts from ISO-8859-1 8-bit ASCII to the
7 bit "default alphabet" as defined in ETSI GSM 03.38
ISO-characters that don't have any correspondning character in the
7-bit alphabet is replaced with the NPC7-character. If there's
a close match between the ISO-char and a 7-bit character (for example
the letter i with a circumflex and the plain i-character) a substitution
is done. These "close-matches" are marked in the lookup table by
having its value negated.
There are some character (for example the curly brace "}") that must
be converted into a 2 byte 7-bit sequence. These characters are
marked in the table by having 256 added to its value.
****************************************************************************/
int lookup_ascii8to7[]={
NPC7, /* 0 null [NUL] */
NPC7, /* 1 start of heading [SOH] */
NPC7, /* 2 start of text [STX] */
NPC7, /* 3 end of text [ETX] */
NPC7, /* 4 end of transmission [EOT] */
NPC7, /* 5 enquiry [ENQ] */
NPC7, /* 6 acknowledge [ACK] */
NPC7, /* 7 bell [BEL] */
NPC7, /* 8 backspace [BS] */
NPC7, /* 9 horizontal tab [HT] */
10, /* 10 line feed [LF] */
NPC7, /* 11 vertical tab [VT] */
10+256, /* 12 form feed [FF] */
13, /* 13 carriage return [CR] */
NPC7, /* 14 shift out [SO] */
NPC7, /* 15 shift in [SI] */
NPC7, /* 16 data link escape [DLE] */
NPC7, /* 17 device control 1 [DC1] */
NPC7, /* 18 device control 2 [DC2] */
NPC7, /* 19 device control 3 [DC3] */
NPC7, /* 20 device control 4 [DC4] */
NPC7, /* 21 negative acknowledge [NAK] */
NPC7, /* 22 synchronous idle [SYN] */
NPC7, /* 23 end of trans. block [ETB] */
NPC7, /* 24 cancel [CAN] */
NPC7, /* 25 end of medium [EM] */
NPC7, /* 26 substitute [SUB] */
NPC7, /* 27 escape [ESC] */
NPC7, /* 28 file separator [FS] */
NPC7, /* 29 group separator [GS] */
NPC7, /* 30 record separator [RS] */
NPC7, /* 31 unit separator [US] */
32, /* 32 space */
33, /* 33 ! exclamation mark */
34, /* 34 " double quotation mark */
35, /* 35 # number sign */
2, /* 36 $ dollar sign */
37, /* 37 % percent sign */
38, /* 38 & ampersand */
39, /* 39 ' apostrophe */
40, /* 40 ( left parenthesis */
41, /* 41 ) right parenthesis */
42, /* 42 * asterisk */
43, /* 43 + plus sign */
44, /* 44 , comma */
45, /* 45 - hyphen */
46, /* 46 . period */
47, /* 47 / slash, */
48, /* 48 0 digit 0 */
49, /* 49 1 digit 1 */
50, /* 50 2 digit 2 */
51, /* 51 3 digit 3 */
52, /* 52 4 digit 4 */
53, /* 53 5 digit 5 */
54, /* 54 6 digit 6 */
55, /* 55 7 digit 7 */
56, /* 56 8 digit 8 */
57, /* 57 9 digit 9 */
58, /* 58 : colon */
59, /* 59 ; semicolon */
60, /* 60 < less-than sign */
61, /* 61 = equal sign */
62, /* 62 > greater-than sign */
63, /* 63 ? question mark */
0, /* 64 @ commercial at sign */
65, /* 65 A uppercase A */
66, /* 66 B uppercase B */
67, /* 67 C uppercase C */
68, /* 68 D uppercase D */
69, /* 69 E uppercase E */
70, /* 70 F uppercase F */
71, /* 71 G uppercase G */
72, /* 72 H uppercase H */
73, /* 73 I uppercase I */
74, /* 74 J uppercase J */
75, /* 75 K uppercase K */
76, /* 76 L uppercase L */
77, /* 77 M uppercase M */
78, /* 78 N uppercase N */
79, /* 79 O uppercase O */
80, /* 80 P uppercase P */
81, /* 81 Q uppercase Q */
82, /* 82 R uppercase R */
83, /* 83 S uppercase S */
84, /* 84 T uppercase T */
85, /* 85 U uppercase U */
86, /* 86 V uppercase V */
87, /* 87 W uppercase W */
88, /* 88 X uppercase X */
89, /* 89 Y uppercase Y */
90, /* 90 Z uppercase Z */
60+256, /* 91 [ left square bracket */
47+256, /* 92 \ backslash */
62+256, /* 93 ] right square bracket */
20+256, /* 94 ^ circumflex accent */
17, /* 95 _ underscore */
-39, /* 96 ` back apostrophe */
97, /* 97 a lowercase a */
98, /* 98 b lowercase b */
99, /* 99 c lowercase c */
100, /* 100 d lowercase d */
101, /* 101 e lowercase e */
102, /* 102 f lowercase f */
103, /* 103 g lowercase g */
104, /* 104 h lowercase h */
105, /* 105 i lowercase i */
106, /* 106 j lowercase j */
107, /* 107 k lowercase k */
108, /* 108 l lowercase l */
109, /* 109 m lowercase m */
110, /* 110 n lowercase n */
111, /* 111 o lowercase o */
112, /* 112 p lowercase p */
113, /* 113 q lowercase q */
114, /* 114 r lowercase r */
115, /* 115 s lowercase s */
116, /* 116 t lowercase t */
117, /* 117 u lowercase u */
118, /* 118 v lowercase v */
119, /* 119 w lowercase w */
120, /* 120 x lowercase x */
121, /* 121 y lowercase y */
122, /* 122 z lowercase z */
40+256, /* 123 { left brace */
64+256, /* 124 | vertical bar */
41+256, /* 125 } right brace */
61+256, /* 126 ~ tilde accent */
NPC7, /* 127 delete [DEL] */
NPC7, /* 128 */
NPC7, /* 129 */
-39, /* 130 low left rising single quote */
-102, /* 131 lowercase italic f */
-34, /* 132 low left rising double quote */
NPC7, /* 133 low horizontal ellipsis */
NPC7, /* 134 dagger mark */
NPC7, /* 135 double dagger mark */
NPC7, /* 136 letter modifying circumflex */
NPC7, /* 137 per thousand (mille) sign */
-83, /* 138 uppercase S caron or hacek */
-39, /* 139 left single angle quote mark */
-214, /* 140 uppercase OE ligature */
NPC7, /* 141 */
NPC7, /* 142 */
NPC7, /* 143 */
NPC7, /* 144 */
-39, /* 145 left single quotation mark */
-39, /* 146 right single quote mark */
-34, /* 147 left double quotation mark */
-34, /* 148 right double quote mark */
-42, /* 149 round filled bullet */
-45, /* 150 en dash */
-45, /* 151 em dash */
-39, /* 152 small spacing tilde accent */
NPC7, /* 153 trademark sign */
-115, /* 154 lowercase s caron or hacek */
-39, /* 155 right single angle quote mark */
-111, /* 156 lowercase oe ligature */
NPC7, /* 157 */
NPC7, /* 158 */
-89, /* 159 uppercase Y dieresis or umlaut */
-32, /* 160 non-breaking space */
64, /* 161 ¡ inverted exclamation mark */
-99, /* 162 ¢ cent sign */
1, /* 163 £ pound sterling sign */
36, /* 164 ¤ general currency sign */
3, /* 165 ¥ yen sign */
-33, /* 166 ¦ broken vertical bar */
95, /* 167 § section sign */
-34, /* 168 ¨ spacing dieresis or umlaut */
NPC7, /* 169 © copyright sign */
NPC7, /* 170 ª feminine ordinal indicator */
-60, /* 171 « left (double) angle quote */
NPC7, /* 172 ¬ logical not sign */
-45, /* 173 soft hyphen */
NPC7, /* 174 ® registered trademark sign */
NPC7, /* 175 ¯ spacing macron (long) accent */
NPC7, /* 176 ° degree sign */
NPC7, /* 177 ± plus-or-minus sign */
-50, /* 178 ² superscript 2 */
-51, /* 179 ³ superscript 3 */
-39, /* 180 ´ spacing acute accent */
-117, /* 181 µ micro sign */
NPC7, /* 182 ¶ paragraph sign, pilcrow sign */
NPC7, /* 183 · middle dot, centered dot */
NPC7, /* 184 ¸ spacing cedilla */
-49, /* 185 ¹ superscript 1 */
NPC7, /* 186 º masculine ordinal indicator */
-62, /* 187 » right (double) angle quote (guillemet) */
NPC7, /* 188 ¼ fraction 1/4 */
NPC7, /* 189 ½ fraction 1/2 */
NPC7, /* 190 ¾ fraction 3/4 */
96, /* 191 ¿ inverted question mark */
-65, /* 192 À uppercase A grave */
-65, /* 193 Á uppercase A acute */
-65, /* 194 Â uppercase A circumflex */
-65, /* 195 Ã uppercase A tilde */
91, /* 196 Ä uppercase A dieresis or umlaut */
14, /* 197 Å uppercase A ring */
28, /* 198 Æ uppercase AE ligature */
9, /* 199 Ç uppercase C cedilla */
-31, /* 200 È uppercase E grave */
31, /* 201 É uppercase E acute */
-31, /* 202 Ê uppercase E circumflex */
-31, /* 203 Ë uppercase E dieresis or umlaut */
-73, /* 204 Ì uppercase I grave */
-73, /* 205 Í uppercase I acute */
-73, /* 206 Î uppercase I circumflex */
-73, /* 207 Ï uppercase I dieresis or umlaut */
-68, /* 208 Ð uppercase ETH */
93, /* 209 Ñ uppercase N tilde */
-79, /* 210 Ò uppercase O grave */
-79, /* 211 Ó uppercase O acute */
-79, /* 212 Ô uppercase O circumflex */
-79, /* 213 Õ uppercase O tilde */
92, /* 214 Ö uppercase O dieresis or umlaut */
-42, /* 215 × multiplication sign */
11, /* 216 Ø uppercase O slash */
-85, /* 217 Ù uppercase U grave */
-85, /* 218 Ú uppercase U acute */
-85, /* 219 Û uppercase U circumflex */
94, /* 220 Ü uppercase U dieresis or umlaut */
-89, /* 221 Ý uppercase Y acute */
NPC7, /* 222 Þ uppercase THORN */
30, /* 223 ß lowercase sharp s, sz ligature */
127, /* 224 à lowercase a grave */
-97, /* 225 á lowercase a acute */
-97, /* 226 â lowercase a circumflex */
-97, /* 227 ã lowercase a tilde */
123, /* 228 ä lowercase a dieresis or umlaut */
15, /* 229 å lowercase a ring */
29, /* 230 æ lowercase ae ligature */
-9, /* 231 ç lowercase c cedilla */
4, /* 232 è lowercase e grave */
5, /* 233 é lowercase e acute */
-101, /* 234 ê lowercase e circumflex */
-101, /* 235 ë lowercase e dieresis or umlaut */
7, /* 236 ì lowercase i grave */
7, /* 237 í lowercase i acute */
-105, /* 238 î lowercase i circumflex */
-105, /* 239 ï lowercase i dieresis or umlaut */
NPC7, /* 240 ð lowercase eth */
125, /* 241 ñ lowercase n tilde */
8, /* 242 ò lowercase o grave */
-111, /* 243 ó lowercase o acute */
-111, /* 244 ô lowercase o circumflex */
-111, /* 245 õ lowercase o tilde */
124, /* 246 ö lowercase o dieresis or umlaut */
-47, /* 247 ÷ division sign */
12, /* 248 ø lowercase o slash */
6, /* 249 ù lowercase u grave */
-117, /* 250 ú lowercase u acute */
-117, /* 251 û lowercase u circumflex */
126, /* 252 ü lowercase u dieresis or umlaut */
-121, /* 253 ý lowercase y acute */
NPC7, /* 254 þ lowercase thorn */
-121 /* 255 ÿ lowercase y dieresis or umlaut */
};
/*
* Use a lookup table to convert from an ISO-8859-1 string to
* the 7-bit default alphabet used by SMS.
*
* *ascii The string to convert
*
* **a7bit A pointer to the array that the result is stored in,
* the space is malloced by this function
*
* Returns the length of the a7bit-array
*
* Note: The a7bit-array must be free()'ed by te caller
*/
static int convert_ascii_to_7bit(char *ascii, char **a7bit) {
int r;
int w;
r=0;
w=0;
/* Allocate sufficient memory for the result string */
*a7bit=malloc(strlen(ascii)*2+1);
while (ascii[r]!=0) {
if ((lookup_ascii8to7[(unsigned char)ascii[r]])<256) {
(*a7bit)[w++]=abs(lookup_ascii8to7[(unsigned char)ascii[r++]]);
} else {
(*a7bit)[w++]=27;
(*a7bit)[w++]=lookup_ascii8to7[(unsigned char)ascii[r++]]-256;
}
}
/* Realloc the result array to the correct size */
*a7bit=realloc(*a7bit,w);
return w;
}
/*
* Convert an ISO-8859-1 ASCII string to an array of PDU-coded bytes
*
* *ascii The ISO-cleartext to convert
*
* **pdu Pointer to an array where the pdu-bytes will be stored in, this
* function allocates the neccesary memory for the array
*
* Returns the number of bytes stored in the pdu-array
*
* Note: Don't forget to free() the pdu-array when you're finished with it.
*
*/
int ascii_to_pdu(char *ascii, unsigned char **pdu) {
int r;
int w;
char *ascii7bit;
int len7bit;
/* Start by converting the ISO-string to a 7bit-string */
len7bit=convert_ascii_to_7bit(ascii,&ascii7bit);
*pdu=malloc(len7bit);
/* Now, we can create a PDU string by packing the 7bit-string */
r=0;
w=0;
while (r<len7bit) {
(*pdu)[w]=((ascii7bit[r]>>(w%7))&0x7F) | ((ascii7bit[r+1]<<(7-(w%7)))&0xFF);
if ((w%7)==6) r++;
r++;
w++;
}
free(ascii7bit);
return w;
}
|
and pduconv.h:
Code: | #ifndef _PDU_H_
#define _PDU_H_
int ascii_to_pdu(char *ascii, unsigned char **pdu);
#endif |
I had try to compile, but it have many error..
It seems than this code is not for CCS, especially in pduconv.c please help me...
Thnak you very much
Last edited by densimitre on Mon May 02, 2005 11:21 pm; edited 1 time in total |
|
|
densimitre
Joined: 21 Dec 2004 Posts: 45
|
|
Posted: Mon May 02, 2005 11:14 pm |
|
|
Its possible make a pointer to a pointer??? |
|
|
Richter
Joined: 18 Mar 2005 Posts: 8
|
|
Posted: Tue May 03, 2005 5:22 am |
|
|
A GOOOD QUESTION!
I m sorry to get offtopic but it s very important this question:
can I create a double pointer?
like this
char** a;
?? I have tried it too, but only an error occurred! _________________ Why I get all these strange problems ? |
|
|
Ttelmah Guest
|
|
Posted: Tue May 03, 2005 7:49 am |
|
|
Use:
char *a[];
instead.
Remember in C, there is a cross equivalence between arrays and pointers. The declaration makes 'a', an array of pointers to characters. You can access an element of the array, using 'a' as a pointer, and *(a+5), will be the item in the sixth array entry, which will itself be a pointer to a character.
Best Wishes |
|
|
densimitre
Joined: 21 Dec 2004 Posts: 45
|
|
Posted: Tue May 03, 2005 2:32 pm |
|
|
Ttelmah wrote: | Use:
char *a[];
instead.
Remember in C, there is a cross equivalence between arrays and pointers. The declaration makes 'a', an array of pointers to characters. You can access an element of the array, using 'a' as a pointer, and *(a+5), will be the item in the sixth array entry, which will itself be a pointer to a character.
Best Wishes |
WOW...thank you very much..
In this moment, i had finished to make the changes of the code....and pic c compile it...but ist very expensive in RAM/ROM use...perhaps I would have to use a 18F series PIC.....
Code: |
ROM used: 3198 (21%)
3198 (21%) including unused fragments
2 Average locations per line
11 Average locations per statement
RAM used: 158 (21%) at main() level
211 (28%) worst case
Lines Stmts % Files
----- ----- --- -----
20 5 2 C:\SMS\main.c
267 0 0 C:\PICC\devices\18f242.h
259 26 9 C:\SMS\pduconv.c
417 126 40 C:\PICC\drivers\string.h
28 0 0 C:\PICC\drivers\stddef.h
28 0 0 C:\PICC\drivers\ctype.h
225 111 25 C:\PICC\drivers\stdlibm.h
70 16 3 C:\PICC\drivers\memmgmt.c
----- -----
2628 568 Total
Page ROM % RAM Functions:
---- --- --- --- ----------
0 56 1 5 strlen
0 54 1 8 create_node
0 20 0 6 update_node
0 130 2 8 insert_node_after
0 114 2 8 remove_node
0 68 1 2 @PRINTF_X_9600_31766_31767
0 278 4 11 traverse
0 316 5 15 malloc
0 110 2 8 free
0 860 13 21 realloc
0 252 4 14 convert_ascii_to_7bit
0 252 4 18 ascii_to_pdu
0 40 1 3 @DIV88
0 644 10 26 main
Segment Used Free
--------- ---- ----
00000-00002 4 0
00004-03CBE 3194 12354
|
How can i make a less expensive code to use a 16F877 or 16F648? (8K and 4 K).
I post my new code...
MAIN.c
Code: | #include <18f242.h>
#device icd=true
#use delay(clock=4000000)
#use RS232(BAUD=9600, BITS=8, PARITY=N, XMIT=PIN_C6, RCV=PIN_C7)
#include "pduconv.c"
int main()
{
int i;
int pdulen;
unsigned char *pdu;
char buffer[]="This is a First Test";
pdulen=ascii_to_pdu(buffer,&pdu);
for (i=0; i<pdulen;i++)
{
printf("%02X",pdu[i]);
}
free(pdu); |
pducov.c
Code: | #include <string.h>
#include <stdlibm.h> // Contains malloc() function for CCS
//#include <stdio.h>
#define VERSION 0.1
/* Define Non-Printable Characters as a question mark */
#define NPC7 63
#define NPC8 '?'
// Reduced LU table for save ROM usage
int lookup_ascii8to7[]={
NPC7, /* 0 null [NUL] */
NPC7, /* 1 start of heading [SOH] */
NPC7, /* 2 start of text [STX] */
NPC7, /* 3 end of text [ETX] */
NPC7, /* 4 end of transmission [EOT] */
NPC7, /* 5 enquiry [ENQ] */
NPC7, /* 6 acknowledge [ACK] */
NPC7, /* 7 bell [BEL] */
NPC7, /* 8 backspace [BS] */
NPC7, /* 9 horizontal tab [HT] */
10, /* 10 line feed [LF] */
NPC7, /* 11 vertical tab [VT] */
10+256, /* 12 form feed [FF] */
13, /* 13 carriage return [CR] */
NPC7, /* 14 shift out [SO] */
NPC7, /* 15 shift in [SI] */
NPC7, /* 16 data link escape [DLE] */
NPC7, /* 17 device control 1 [DC1] */
NPC7, /* 18 device control 2 [DC2] */
NPC7, /* 19 device control 3 [DC3] */
NPC7, /* 20 device control 4 [DC4] */
NPC7, /* 21 negative acknowledge [NAK] */
NPC7, /* 22 synchronous idle [SYN] */
NPC7, /* 23 end of trans. block [ETB] */
NPC7, /* 24 cancel [CAN] */
NPC7, /* 25 end of medium [EM] */
NPC7, /* 26 substitute [SUB] */
NPC7, /* 27 escape [ESC] */
NPC7, /* 28 file separator [FS] */
NPC7, /* 29 group separator [GS] */
NPC7, /* 30 record separator [RS] */
NPC7, /* 31 unit separator [US] */
32, /* 32 space */
33, /* 33 ! exclamation mark */
34, /* 34 " double quotation mark */
35, /* 35 # number sign */
2, /* 36 $ dollar sign */
37, /* 37 % percent sign */
38, /* 38 & ampersand */
39, /* 39 ' apostrophe */
40, /* 40 ( left parenthesis */
41, /* 41 ) right parenthesis */
42, /* 42 * asterisk */
43, /* 43 + plus sign */
44, /* 44 , comma */
45, /* 45 - hyphen */
46, /* 46 . period */
47, /* 47 / slash, */
48, /* 48 0 digit 0 */
49, /* 49 1 digit 1 */
50, /* 50 2 digit 2 */
51, /* 51 3 digit 3 */
52, /* 52 4 digit 4 */
53, /* 53 5 digit 5 */
54, /* 54 6 digit 6 */
55, /* 55 7 digit 7 */
56, /* 56 8 digit 8 */
57, /* 57 9 digit 9 */
58, /* 58 : colon */
59, /* 59 ; semicolon */
60, /* 60 < less-than sign */
61, /* 61 = equal sign */
62, /* 62 > greater-than sign */
63, /* 63 ? question mark */
0, /* 64 @ commercial at sign */
65, /* 65 A uppercase A */
66, /* 66 B uppercase B */
67, /* 67 C uppercase C */
68, /* 68 D uppercase D */
69, /* 69 E uppercase E */
70, /* 70 F uppercase F */
71, /* 71 G uppercase G */
72, /* 72 H uppercase H */
73, /* 73 I uppercase I */
74, /* 74 J uppercase J */
75, /* 75 K uppercase K */
76, /* 76 L uppercase L */
77, /* 77 M uppercase M */
78, /* 78 N uppercase N */
79, /* 79 O uppercase O */
80, /* 80 P uppercase P */
81, /* 81 Q uppercase Q */
82, /* 82 R uppercase R */
83, /* 83 S uppercase S */
84, /* 84 T uppercase T */
85, /* 85 U uppercase U */
86, /* 86 V uppercase V */
87, /* 87 W uppercase W */
88, /* 88 X uppercase X */
89, /* 89 Y uppercase Y */
90, /* 90 Z uppercase Z */
60+256, /* 91 [ left square bracket */
47+256, /* 92 \ backslash */
62+256, /* 93 ] right square bracket */
20+256, /* 94 ^ circumflex accent */
17, /* 95 _ underscore */
-39, /* 96 ` back apostrophe */
97, /* 97 a lowercase a */
98, /* 98 b lowercase b */
99, /* 99 c lowercase c */
100, /* 100 d lowercase d */
101, /* 101 e lowercase e */
102, /* 102 f lowercase f */
103, /* 103 g lowercase g */
104, /* 104 h lowercase h */
105, /* 105 i lowercase i */
106, /* 106 j lowercase j */
107, /* 107 k lowercase k */
108, /* 108 l lowercase l */
109, /* 109 m lowercase m */
110, /* 110 n lowercase n */
111, /* 111 o lowercase o */
112, /* 112 p lowercase p */
113, /* 113 q lowercase q */
114, /* 114 r lowercase r */
115, /* 115 s lowercase s */
116, /* 116 t lowercase t */
117, /* 117 u lowercase u */
118, /* 118 v lowercase v */
119, /* 119 w lowercase w */
120, /* 120 x lowercase x */
121, /* 121 y lowercase y */
122, /* 122 z lowercase z */
};
static int convert_ascii_to_7bit(char *ascii, char *a7bit[]) {
int r;
int w;
r=0;
w=0;
/* Allocate sufficient memory for the result string */
*a7bit=malloc(strlen(ascii)*2+1);
while (ascii[r]!=0) {
if ((lookup_ascii8to7[(unsigned char)ascii[r]])<256) {
*a7bit[w++]=abs(lookup_ascii8to7[(unsigned char)ascii[r++]]);
} else {
*a7bit[w++]=27;
*a7bit[w++]=lookup_ascii8to7[(unsigned char)ascii[r++]]-256;
}
}
/* Realloc the result array to the correct size */
*a7bit=realloc(*a7bit,w);
return w;
}
/*
* Convert an ISO-8859-1 ASCII string to an array of PDU-coded bytes
*
* *ascii The ISO-cleartext to convert
*
* **pdu Pointer to an array where the pdu-bytes will be stored in, this
* function allocates the neccesary memory for the array
* Use +pdu[] for CCS
*
* Returns the number of bytes stored in the pdu-array
*
* Note: Don't forget to free() the pdu-array when you're finished with it.
*
*/
int ascii_to_pdu(char *ascii, unsigned char *pdu[]) {
int r;
int w;
char *ascii7bit;
int len7bit;
/* Start by converting the ISO-string to a 7bit-string */
len7bit=convert_ascii_to_7bit(ascii,&ascii7bit);
*pdu=malloc(len7bit);
/* Now, we can create a PDU string by packing the 7bit-string */
r=0;
w=0;
while (r<len7bit) {
*pdu[w]=((ascii7bit[r]>>(w%7))&0x7F) | ((ascii7bit[r+1]<<(7-(w%7)))&0xFF);
if ((w%7)==6) r++;
r++;
w++;
}
free(ascii7bit);
return w;
}
|
I wait for your cooperation
Thank you |
|
|
densimitre
Joined: 21 Dec 2004 Posts: 45
|
|
Posted: Tue May 03, 2005 2:33 pm |
|
|
I only have a 16F877 and 16F648.... |
|
|
densimitre
Joined: 21 Dec 2004 Posts: 45
|
|
Posted: Thu May 05, 2005 11:05 pm |
|
|
Hello again
Im having troubles cimpiling this part of main.c
Code: | for (i=0; i<pdulen;i++) {
printf("%02hhx ",pdu[i]);
} |
It says: Print Format (%) invalid...
Above code is for ANSI C...and I dont know how to translate into CCS C..
help me please..
Bye |
|
|
densimitre
Joined: 21 Dec 2004 Posts: 45
|
|
Posted: Sat Jun 25, 2005 10:38 pm |
|
|
Hi
Im having troubles witth the code....is not working very well...in fact, it does´nt converting into correct format...
Can you give some idea about this...
Thank you |
|
|
softjad
Joined: 21 Sep 2006 Posts: 3
|
|
Posted: Sun Dec 16, 2007 1:36 pm |
|
|
Someone has an example to work?
Thanks |
|
|
|
|
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
|