Commit bedf4827 authored by Your Name's avatar Your Name

release for sent uart success, not done with angle,vedio and media

parent 226d9d1e
......@@ -31,6 +31,9 @@ int count = 1;
int fileusb;
int fileuart;
int t = 0;
int spi_fd;
......@@ -55,7 +58,7 @@ int xfm_Init()
}
printf("/dev/ttyUSB0 Open success\r\n");
if ((fileuart = serialOpen("/dev/ttyAMA0", 9600)) < 0) //changed from 115200 to 9600
if ((fileuart = serialOpen("/dev/ttyAMA0", 9600)) < 0)
{
printf("/dev/ttyAMA0 Open Faild\r\n");
return 0;
......@@ -69,7 +72,7 @@ int xfm_Init()
void protocalAck(int fileusb)
{
printf("protocalAck..\n");
printf("protocalAck..\n");
char retExmaple[12] = {0};
strcpy(retExmaple, ret);
retExmaple[3] = 0x04;
......@@ -114,9 +117,8 @@ uint16_t getAngle(char *rece)
angle = result;
return angle;
}
// crc
uint16_t CrcValueCalc(const uint8_t *cpucData, uint16_t usLength)
uint16_t CrcValueCalc(uint8_t *cpucData, uint16_t usLength) //changed
{
uint16_t crcValue = 0xffff;
int i;
......@@ -137,8 +139,10 @@ uint16_t CrcValueCalc(const uint8_t *cpucData, uint16_t usLength)
}
return crcValue;
}
extern int get_audio_device_id();
void sendMessageHead(int mode, char* message)
void sendMessageHead(int mode, char* message) //changed
{
*(message) = 0x40;
*(message + 1) = 0x38; // head
......@@ -153,78 +157,162 @@ void sendMessageHead(int mode, char* message)
*(message + 2) = 0x0b; //length
*(message + 3) = 0x06; //instru
*(message + 4) = 0x00; //reg0
*(message + 5) = 0x02; //reg1 write angle
*(message + 6) = 0x00; //ack
*(message + 5) = 0x02; //reg1 write
*(message + 6) = 0x00;
*(message + 7) = 0x00;
*(message + 8) = 0x00;
}
}
void sentMessageAngle(int fileuart, uint16_t angle) //changed
{
char messageAngle[13];
char messageAngle[11];
sendMessageHead(1, messageAngle);
messageAngle[7] = 0x00;
messageAngle[8] = 0x00;
messageAngle[9] = (angle >> 8) & 0xff;
messageAngle[10] = angle & 0xff;
uint16_t crc;
crc = CrcValueCalc(messageAngle, 11);
messageAngle[11] = crc & 0xff;
messageAngle[12] = (crc >> 8) & 0xff;
messageAngle[11] = crc & 0xff;
write(fileuart, messageAngle, 11);
write(fileuart, messageAngle, 13);
}
extern int get_audio_device_id();
void releaseAckeachwakenwords(char* totalbuf) //used for test
char* readMessageAngle(int fileuart)
{
char* p = totalbuf;
while (*p != 'k' || *(p+1) != 'e')
char* result = malloc(sizeof(char));
return result;
}
char* readMessageStatus(int fileuart)
{
char message[9];
sendMessageHead(0, message);
message[5] = 0x01;
uint16_t crc;
crc = CrcValueCalc(message, 7);
message[7] = (crc >> 8) & 0xff;
message[8] = crc & 0xff;
int t = 0;
while (!t)
{
p++;
}
p += 12;
if (g_callback != NULL){
char buf[256] = {0};
snprintf(buf, 256, "cvlc --play-and-exit --aout alsa --alsa-audio-device hw:%d,0 /usr/local/bin/Videos/aaaa.mp3 &", get_audio_device_id());
//system("mpg321 /usr/local/bin/Videos/aaaa.mp3 &");
//system("cvlc --play-and-exit --aout alsa --alsa-audio-device hw:2,0 /usr/local/bin/Videos/aaaa.mp3 &");
system(buf);
write(fileuart, message, 9);
int recbyte = serialDataAvail(fileuart);
while (1);
}
uint16_t angle;
angle = getAngle(totalbuf);
sentMessageAngle(fileuart, angle);
switch(*p)
char* result = malloc(sizeof(char));
return result;
}
int judgeData()
{
return 1;
}
void waitforReady(int fileuart)
{
int t = 0;
while (!t)
{
case 'x':
g_callback(g_callback_ctx, 2);
break;
case 'z':
g_callback(g_callback_ctx, 4);
break;
case 'y':
g_callback(g_callback_ctx, 3);
int recbytenum = serialDataAvail(fileuart);
if (recbytenum > 1)
{
char buf[24] = {0};
int temp = 0;
while (recbytenum--) //recbyte
{
buf[temp++] = serialGetchar(fileuart);
}
if (!judgeData) //judge data if not right
{
usleep(500);
readMessageStatus(fileuart);
continue;
}
// check receive data .....
serialFlush(fileuart); //make status ready for next place
break;
default:
}
}
}
void waitforReady_test(int fileuart) //test_version
{
while (1)
{
int recbytenum = serialDataAvail(fileuart);
if (recbytenum > 1)
{
char buf[24] = {0};
int temp = 0;
while (recbytenum--)
{
buf[temp++] = serialGetchar(fileuart);
}
for (int i = 0; i < temp; i++)
{
printf("%x", buf[i]);
if ( (i%2) == 0)
printf(" ");
}
printf("\n");
serialFlush(fileuart);
break;
}
}
usleep(100);
}
void sentUart(char *buf, int fileuart)
void sentUart(char *buf, int fileuart, int fileusb) //changed
{
if (count == 9)
{
strcat(totalbuf, buf);
uint16_t angle;
angle = getAngle(totalbuf);
printf("angle = %x\n", angle);
sentMessageAngle(fileuart, angle);
//sentMessageAngle(fileuart, angle);
// 0x40 0x38 0x0b 0x06 0x00 0x02 0x01 00 -- -- -- 1d 08 0
// 04 b0 1e 7c 120
// char message1[13] = {0x40, 0x38, 0x0b, 0x06, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x08};
// char message2[13] = {0x40, 0x38, 0x0b, 0x06, 0x00, 0x02, 0x01, 0x00, 0x00, 0x04, 0xb0, 0x1e, 0x7c};
// if (t == 0){
// write(fileuart, message1, 13);
// t = 1;
// }
// else{
// write(fileuart, message2, 13);
// t = 0;
// }
count = 1;
memset(totalbuf, 0, 1024);
protocalAck(fileusb);
if (g_callback != NULL){
char buf[256] = {0};
snprintf(buf, 256, "cvlc --play-and-exit --aout alsa --alsa-audio-device hw:%d,0 /usr/local/bin/Videos/aaaa.mp3 &", get_audio_device_id());
//system("mpg321 /usr/local/bin/Videos/aaaa.mp3 &");
//system("cvlc --play-and-exit --aout alsa --alsa-audio-device hw:2,0 /usr/local/bin/Videos/aaaa.mp3 &");
system(buf);
g_callback(g_callback_ctx, 2);
}
//waitforReady_test(fileuart);
releaseAckeachwakenwords(totalbuf);
}
else
{
......@@ -234,7 +322,7 @@ void sentUart(char *buf, int fileuart)
}
void circleReading()
void circleReading() //changed
{
printf("cicleReading..\n");
serialFlush(fileusb);
......@@ -257,16 +345,14 @@ void circleReading()
}
else
{
sentUart(buf, fileuart); printf(" %d\n", __LINE__);
serialFlush(fileusb);
sentUart(buf, fileuart, fileusb); printf(" %d\n", __LINE__);
serialFlush(fileusb); //guarantee buf wont affect next input
}
}
}
return;
}
//localdimming
void LocalDimming_Init()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment