.amr
デスクトップから UART 経由で SIM900 GSM モジュールにファイルを送信しようとしています。
私はteunizのRS232ライブラリを使用しています。
AT コマンドを使用して初期化を行い、ファイルをバッファに読み込み、RS232_SendByte()
ライブラリ関数を使用してバイト単位で UART に書き込みますが、動作していないようです。
次の AT コマンドを送信します。
AT+CFSINIT
AT+CFSWFILE=\"audio.amr\",0,6694,13000 # After which I get the CONNECT message from the SIM900 module
# Here's where I send the file
AT+CFSGFIS=\"audio.amr\"
これが私のコードです:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "rs232.h"
char *readFile(char *filename, int *size) {
char *source = NULL;
FILE *fp = fopen(filename, "rb");
if (fp != NULL) {
/* Go to the end of the file. */
if (fseek(fp, 0L, SEEK_END) == 0) {
/* Get the size of the file. */
long bufsize = ftell(fp);
if (bufsize == -1) { return NULL; }
/* Allocate our buffer to that size. */
source = malloc(sizeof(char) * (bufsize + 1));
if(!source) return NULL;
/* Go back to the start of the file. */
if (fseek(fp, 0L, SEEK_SET) != 0) { return NULL; }
/* Read the entire file into memory. */
size_t newLen = fread(source, sizeof(char), bufsize, fp);
if ( ferror( fp ) != 0 ) {
fputs("Error reading file", stderr);
free(source);
return NULL;
} else {
source[newLen++] = 0; /* Just to be safe. */
}
*size = bufsize;
}
fclose(fp);
}
return source;
}
int main(int argc, char *argv[])
{
int ret = 0, cport_nr = 2, bdrate=38400;
char data[2000] = {0};
if(RS232_OpenComport(cport_nr, bdrate)) {
printf("Can not open comport\n");
ret = -1;
goto END;
}
int size;
unsigned char *filebuf = readFile("audio.amr", &size);
if (!filebuf) {
ret = -1;
goto END_1;
}
/* Initialization */
RS232_cputs(cport_nr, "AT");
RS232_cputs(cport_nr, "AT+CFSINIT");
sleep(1);
RS232_cputs(cport_nr, "AT+CFSWFILE=\"audio.amr\",0,6694,13000");
/* Wait for CONNECT */
sleep(2);
printf("Sending file of size: %d\n", size);
int i;
for (i = 0; i < size; ++i) {
putchar(filebuf[i]);
RS232_SendByte(cport_nr, filebuf[i]);
}
free(filebuf);
sleep(1);
/* Check if file transferred right */
RS232_cputs(cport_nr, "AT+CFSGFIS=\"audio.amr\"");
END_1:
RS232_CloseComport(cport_nr);
END:
return ret;
}
編集1
通常、AT コマンドを使用して SIM900 にファイルを送信する手順は、次のドキュメントに記載されています。
AT+CFSINIT
# フラッシュを初期化します。対応OKですAT+CFSWFILE=<filename>,<writeMode>,<fileSize>,<InputTime>
# これらのパラメーターでファイルを書き込みます。応答は次のとおりですCONNECT
。これがファイルの送信を開始するときです- ここにファイルを送ります。それが機能し、送信されたファイル サイズが
<filesize>
上記のコマンドで送信されたものと一致した場合、SIM900 は OK で応答する必要がありますが、そうではありません。:( AT+CFSGFIS=<filename>
# フラッシュ上のファイル サイズを示します。ファイルが正しくアップロードされなかったため、エラーが発生しました。
これにより、私のプログラムに何か問題があると信じるようになります。私はバイナリモードでファイルを読んでいます。AT+CFSWFILE=<filename>,<writeMode>,<fileSize>,<InputTime>
報告されたサイズは、コマンドで指定したものとまったく同じです。