Commit 4c35b5cf authored by 张泽仁's avatar 张泽仁

still featuring, not done

parent 76e8723c
{
"files.associations": {
"egl_ctx.h": "c"
}
},
"C_Cpp.errorSquiggles": "disabled"
}
\ No newline at end of file
......@@ -118,7 +118,7 @@ uint16_t getAngle(char *rece)
}
// crc
uint16_t CrcValueCalc(const uint8_t *cpucData, uint16_t usLength)
uint16_t CrcValueCalc(uint8_t *cpucData, uint16_t usLength)
{
uint16_t crcValue = 0xffff;
int i;
......@@ -142,7 +142,137 @@ uint16_t CrcValueCalc(const uint8_t *cpucData, uint16_t usLength)
extern int get_audio_device_id();
void sentUart(char *buf, int fileuart)
void sendMessageHead(int mode, char* message)
{
*(message) = 0x40;
*(message + 1) = 0x38; // head
if (mode == 0) // read
{
*(message + 2) = 0x07; //length
*(message + 3) = 0x03; //instru
*(message + 4) = 0x00; //reg0
*(message + 6) = 0x01; //ack
}
else{ // write
*(message + 2) = 0x09; //length
*(message + 3) = 0x06; //instru
*(message + 4) = 0x00; //reg0
*(message + 5) = 0x02; //reg1 write angle
*(message + 8) = 0x00; //ack
}
}
void sentMessageAngle(int fileuart, uint16_t angle) //changed
{
char messageAngle[11];
sendMessageHead(1, messageAngle);
messageAngle[6] = (angle >> 8) & 0xff;
messageAngle[7] = angle & 0xff;
uint16_t crc;
crc = CrcValueCalc(messageAngle, 9);
messageAngle[9] = (crc >> 8) & 0xff;
messageAngle[10] = crc & 0xff;
write(fileuart, messageAngle, 11);
}
char* readMessageAngle(int fileuart)
{
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)
{
write(fileuart, message, 9);
int recbyte = serialDataAvail(fileuart);
while (1);
}
char* result = malloc(sizeof(char));
return result;
}
int judgeData()
{
return 1;
}
void waitforReady(int fileuart)
{
int t = 0;
while (!t)
{
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;
}
}
}
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;
}
}
}
void sentUart(char *buf, int fileuart, int fileusb) //changed
{
if (count == 9)
{
......@@ -150,21 +280,15 @@ void sentUart(char *buf, int fileuart)
uint16_t angle;
angle = getAngle(totalbuf);
printf("angle = %x\n", angle);
char angleret[2];
angleret[1] = angle & 0xff;
angleret[0] = (angle >> 8) & 0xff;
write(fileuart, angleret, 2);
sentMessageAngle(fileuart, angle);
count = 1;
memset(totalbuf, 0, 1024);
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);
}
protocalAck(fileusb);
waitforReady_test(fileuart);
}
else
{
......@@ -174,7 +298,7 @@ void sentUart(char *buf, int fileuart)
}
void circleReading()
void circleReading() //changed
{
printf("cicleReading..\n");
serialFlush(fileusb);
......@@ -197,14 +321,14 @@ void circleReading()
}
else
{
sentUart(buf, fileuart); printf(" %d\n", __LINE__);
sentUart(buf, fileuart, fileusb); printf(" %d\n", __LINE__);
serialFlush(fileusb); //guarantee buf wont affect next input
}
}
}
return;
}
//localdimming
void LocalDimming_Init()
{
......@@ -407,3 +531,36 @@ void eachPicWrite(int num, int pic)
}
}
// void sentUart(char *buf, int fileuart)
// {
// if (count == 9)
// {
// strcat(totalbuf, buf);
// uint16_t angle;
// angle = getAngle(totalbuf);
// printf("angle = %x\n", angle);
// char angleret[2];
// angleret[1] = angle & 0xff;
// angleret[0] = (angle >> 8) & 0xff;
// write(fileuart, angleret, 2);
// count = 1;
// memset(totalbuf, 0, 1024);
// 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);
// }
// }
// else
// {
// count++;
// strcat(totalbuf, buf);
// }
// }
\ No newline at end of file
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