How to extract program from ".ucf" configuration file generated by unico? - stm32
In my project i am using LSM6SOX sensor to generate the interrupt for every 10 degree incrementation on X axis.
I found this link...
https://github.com/STMicroelectronics/STMems_Standard_C_drivers/blob/master/lsm6dsox_STdC/examples/lsm6dsox_fsm_raw.c
it worked well! Similar way of "/Program: glance/"
static const uint8_t lsm6so_prg_glance[] = {
0xb2, 0x10, 0x24, 0x20, 0x17, 0x17, 0x66, 0x32,
0x66, 0x3c, 0x20, 0x20, 0x02, 0x02, 0x08, 0x08,
0x00, 0x04, 0x0c, 0x00, 0xc7, 0x66, 0x33, 0x73,
0x77, 0x64, 0x88, 0x75, 0x99, 0x66, 0x33, 0x53,
0x44, 0xf5, 0x22, 0x00,
};
I am try to generate .ucf.. using this link...
https://github.com/STMicroelectronics/STMems_Finite_State_Machine/tree/master/configuration_examples/example_0_fsm
`const ucf_line_t Free_fall[] = {
{.address = 0x10, .data = 0x00,},
{.address = 0x11, .data = 0x00,},
{.address = 0x01, .data = 0x80,},
{.address = 0x04, .data = 0x00,},
{.address = 0x05, .data = 0x00,},
{.address = 0x5F, .data = 0x4B,},
{.address = 0x46, .data = 0x01,},
{.address = 0x47, .data = 0x00,},
{.address = 0x0A, .data = 0x00,},
{.address = 0x0B, .data = 0x01,},
{.address = 0x0C, .data = 0x00,},
{.address = 0x0E, .data = 0x00,},
{.address = 0x0F, .data = 0x00,},
{.address = 0x10, .data = 0x00,},
{.address = 0x17, .data = 0x40,},
{.address = 0x02, .data = 0x11,},
{.address = 0x08, .data = 0x7A,},
{.address = 0x09, .data = 0x00,},
{.address = 0x09, .data = 0x00,},
{.address = 0x09, .data = 0x01,},
{.address = 0x09, .data = 0x01,},
{.address = 0x09, .data = 0x00,},
{.address = 0x09, .data = 0x04,},
{.address = 0x02, .data = 0x41,},
{.address = 0x08, .data = 0x00,},
{.address = 0x09, .data = 0x61,},
{.address = 0x09, .data = 0x10,},
{.address = 0x09, .data = 0x1A,},
{.address = 0x09, .data = 0x00,},
{.address = 0x09, .data = 0x0F,},
{.address = 0x09, .data = 0x00,},
{.address = 0x09, .data = 0xCD,},
{.address = 0x09, .data = 0x34,},
{.address = 0x09, .data = 0xAB,},
{.address = 0x09, .data = 0x00,},
{.address = 0x09, .data = 0x00,},
{.address = 0x09, .data = 0x00,},
{.address = 0x09, .data = 0x00,},
{.address = 0x09, .data = 0x01,},
{.address = 0x09, .data = 0x00,},
{.address = 0x09, .data = 0xF5,},
{.address = 0x09, .data = 0x77,},
{.address = 0x09, .data = 0x99,},
{.address = 0x09, .data = 0x12,},
{.address = 0x09, .data = 0x66,},
{.address = 0x09, .data = 0x53,},
{.address = 0x09, .data = 0xC7,},
{.address = 0x09, .data = 0x66,},
{.address = 0x09, .data = 0x99,},
{.address = 0x09, .data = 0x50,},
{.address = 0x09, .data = 0x00,},
{.address = 0x04, .data = 0x00,},
{.address = 0x05, .data = 0x01,},
{.address = 0x17, .data = 0x00,},
{.address = 0x01, .data = 0x00,},
{.address = 0x5E, .data = 0x02,},
{.address = 0x10, .data = 0x20,},
{.address = 0x11, .data = 0x60,}
};'`
I am able to generate above file which is different from above /* Program: glance / why it is different and How to generate same way (/ Program: glance */ ) and don't get any ideal to generate interrupt at every 10 degree..
I am using STEVAL-MKI197V1
Thanks
Deepak Aagri
Related
3des encryption kCCAlignmentError error
I am trying to encrypt an xml string.After the encryption is done then the decrypt the encrypted d I am getting the string as ALIGNMENT. I dont understand what is the reason (NSString*) doCipher:(NSString*)plainText:(CCOperation)encryptOrDecrypt { const void *vplainText; size_t plainTextBufferSize; if (encryptOrDecrypt == kCCDecrypt) { NSData *EncryptData = [NSData dataFromBase64String:plainText]; plainTextBufferSize = [EncryptData length]; vplainText = [EncryptData bytes]; } else { plainTextBufferSize = [plainText length]; vplainText = (const void *) [plainText UTF8String]; } CCCryptorStatus ccStatus; uint8_t *bufferPtr = NULL; size_t bufferPtrSize = 0; size_t movedBytes = 0; // uint8_t iv[kCCBlockSize3DES]; bufferPtrSize = (plainTextBufferSize + kCCBlockSize3DES) & ~(kCCBlockSize3DES - 1); bufferPtr = malloc( bufferPtrSize * sizeof(uint8_t)); memset((void *)bufferPtr, 0x0, bufferPtrSize); // memset((void *) iv, 0x0, (size_t) sizeof(iv)); NSString *key = #"123456789012345678901234"; NSString *initVec = #"init Vec"; const void *vkey = (const void *) [key UTF8String]; const void *vinitVec = (const void *) [initVec UTF8String]; ccStatus = CCCrypt(encryptOrDecrypt, kCCAlgorithm3DES, kCCOptionPKCS7Padding, vkey, //"123456789012345678901234", //key kCCKeySize3DES, vinitVec, //"init Vec", //iv, vplainText, //"Your Name", //plainText, plainTextBufferSize, (void *)bufferPtr, bufferPtrSize, &movedBytes); //if (ccStatus == kCCSuccess) NSLog(#"SUCCESS"); //else/ if (ccStatus == kCCParamError) return #"PARAM ERROR"; else if (ccStatus == kCCBufferTooSmall) return #"BUFFER TOO SMALL"; else if (ccStatus == kCCMemoryFailure) return #"MEMORY FAILURE"; else if (ccStatus == kCCAlignmentError) return #"ALIGNMENT"; else if (ccStatus == kCCDecodeError) return #"DECODE ERROR"; else if (ccStatus == kCCUnimplemented) return #"UNIMPLEMENTED"; NSString *result; if (encryptOrDecrypt == kCCDecrypt) { result = [ [NSString alloc] initWithData: [NSData dataWithBytes:(const void *)bufferPtr length:(NSUInteger)movedBytes] encoding:NSASCIIStringEncoding]; } else { NSData *myData = [NSData dataWithBytes:(const void *)bufferPtr length:(NSUInteger)movedBytes]; result = [myData base64EncodedString]; } return result; }
kCCAlignmentError means that the data you are passing is not correctly padded (specifically that the entire data length including padding is not a multiple of the block size). The most likely cause is that you are truncating your encrypted data somewhere, possibly outside of this routine. You should check your encrypted data at each step and make sure that it is always a multiple of the block size (8 bytes). You'll need to base64-decode before checking the length.
How to convert Hexadecimal NSData to Decimal array?
I have an array with hexadecimal value like below: const UInt8 request_MifareID[] = { 0x00, 0xCA, 0x01, 0x0A, 0x00 }; then i transfer it to NSData for communication: NSData *data = [[NSData alloc] initWithBytesNoCopy:(UInt8 *)request_MifareID length:5]; Sent "data" to server and get the server response: Printing description of resp: <ee97562d 02280400 00000000 21074400 9000> NSUInteger len = [resp length]; Printing description of len: (NSUInteger) len = 18 the "resp" is also a Hexadecimal format NSData now, i have to transfer the "resp" to Decimal array how should i do? ------------------------------------------------------Edit Ok, first i have to transfer the NSData which server response(it is not String, just numbers): ee97562d 02280400 00000000 21074400 9000 into what kind of object? Byte? when i use NSString * str = [[NSString alloc] initWithData: resp encoding:NSUTF8StringEncoding]; it returns nil
int number = 0xe; // or 0x3, 0x6, 0x8, 0x2 NSString * decimalString = [NSString stringWithFormat:#"%d", number]; NSString * hexString = [NSString stringWithFormat:#"%x", number];
**NSData *data = [NSData dataWithBytes:"FF3C" length:4]; NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; string = [#"0x" stringByAppendingString:string]; unsigned short value; sscanf([string UTF8String], "%hx", &value); NSLog(#"%d", value)**
DES Decryption objectiveC Similar to C# Decryption
In my project I got a DES Encrypted Key from Server I need to Decrypt it in my iOS Application. Here is the code used in server, public static string DecryptLicenseKey(string EncryptedLicense) { string str; byte[] rgbIV = new byte[] { 10, 20, 30, 40, 50, 60, 70, 80 }; byte[] buffer = new byte[EncryptedLicense.Length + 1]; try { //Decrypt the license //----------------------------------- byte[] bytes = Encoding.UTF8.GetBytes("!$#$%^%&"); DESCryptoServiceProvider provider = new DESCryptoServiceProvider(); buffer = Convert.FromBase64String(EncryptedLicense); MemoryStream stream2 = new MemoryStream(); CryptoStream stream = new CryptoStream(stream2, provider.CreateDecryptor(bytes, rgbIV), CryptoStreamMode.Write); stream.Write(buffer, 0, buffer.Length); stream.FlushFinalBlock(); str = Encoding.UTF8.GetString(stream2.ToArray()); //----------------------------------- } catch (Exception ex) { return null; } return str; } Here is the code I try, - (void)DESDecrypt { if (!self.key) { self.key = #"!$#$%^%&"; } const void *constkey = (const void *) [self.key UTF8String]; self.inputData = [Base64Converter decode:self.inputString]; const void *dataIn = (const void *) self.inputData; size_t dataInLength = [self.inputData length]; uint8_t *dataOut = NULL; size_t dataOutAvailable = 0; size_t dataOutMoved = 0; dataOutAvailable = (dataInLength + kCCBlockSizeDES) & ~(kCCBlockSizeDES - 1); dataOut = malloc( dataOutAvailable * sizeof(uint8_t)); memset((void *)dataOut, 0x0, dataOutAvailable); Byte iv [] = {10, 20, 30, 40, 50, 60, 70, 80}; // CCCryptorStatus CCCrypt( // CCOperation op, /* kCCEncrypt, etc. */ // CCAlgorithm alg, /* kCCAlgorithmAES128, etc. */ // CCOptions options, /* kCCOptionPKCS7Padding, etc. */ // const void *key, // size_t keyLength, // const void *iv, /* optional initialization vector */ // const void *dataIn, /* optional per op and alg */ // size_t dataInLength, // void *dataOut, /* data RETURNED here */ // size_t dataOutAvailable, // size_t *dataOutMoved) // __OSX_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_2_0); CCCryptorStatus ccStatus = CCCrypt(kCCDecrypt, kCCAlgorithmDES, kCCOptionECBMode, constkey, kCCKeySizeDES, iv, dataIn, dataInLength, (void *)dataOut, dataOutAvailable, &dataOutMoved); NSLog(#"CCStatus : %d",ccStatus); if (ccStatus == kCCSuccess) { self.outputData = [NSData dataWithBytes:(const void *)dataOut length:(NSUInteger)dataOutAvailable]; self.outputString = [[NSString alloc] initWithBytes:dataOut length:dataOutAvailable encoding:NSUTF8StringEncoding]; } } I got the CCStatus Success And data received is (self.outputData), self.outputString is empty. Where I got wrong, thanks in advance
SetProperty with AudioQueueStart how?
how can i set property of audioqueuestart ? i want to recording sound of device and someone tell me use 'kAudioSessionCategory_PlayAndRecord' UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord; AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory); but when apply my simple code, it doesn't work. how can i set property ? #include <AudioToolbox/AudioQueue.h> #include <AudioToolbox/AudioFile.h> #include <AudioToolbox/AudioConverter.h> #include <AudioToolbox/AudioToolbox.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/stat.h> #include <sys/select.h> #define AUDIO_BUFFERS 3 typedef struct AQCallbackStruct { AudioStreamBasicDescription mDataFormat; AudioQueueRef queue; AudioQueueBufferRef mBuffers[AUDIO_BUFFERS]; AudioFileID outputFile; unsigned long frameSize; long long recPtr; int run; } AQCallbackStruct; static void AQInputCallback( void *aqr, AudioQueueRef inQ, AudioQueueBufferRef inQB, const AudioTimeStamp *timestamp, unsigned long frameSize, const AudioStreamPacketDescription *mDataFormat) { AQCallbackStruct *aqc = (AQCallbackStruct *) aqr; /* Write data to file */ if (AudioFileWritePackets (aqc->outputFile, false, inQB->mAudioDataByteSize, mDataFormat, aqc->recPtr, &frameSize, inQB->mAudioData) == noErr) { aqc->recPtr += frameSize; } /* Don't re-queue the sound buffers if we're supposed to stop recording */ if (!aqc->run) return; AudioQueueEnqueueBuffer (aqc->queue, inQB, 0, NULL); } int main(int argc, char *argv[]) { AQCallbackStruct aqc; AudioFileTypeID fileFormat; CFURLRef filename; struct timeval tv; int i; if (argc < 3) { fprintf(stderr, "Syntax: %s [filename.aif] [seconds]", argv[0]); exit(EXIT_FAILURE); } //how ? //UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord; //AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory); aqc.mDataFormat.mFormatID = kAudioFormatLinearPCM;//kAudioFormatLinearPCM; aqc.mDataFormat.mSampleRate = 44100.0; aqc.mDataFormat.mChannelsPerFrame = 2; aqc.mDataFormat.mBitsPerChannel = 16; aqc.mDataFormat.mBytesPerPacket = aqc.mDataFormat.mBytesPerFrame = aqc.mDataFormat.mChannelsPerFrame * sizeof (short int); aqc.mDataFormat.mFramesPerPacket = 1; aqc.mDataFormat.mFormatFlags = kLinearPCMFormatFlagIsBigEndian | kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked; aqc.frameSize = 735; AudioQueueNewInput (&aqc.mDataFormat, AQInputCallback, &aqc, NULL, kCFRunLoopCommonModes, 0, &aqc.queue); /* Create output file */ fileFormat = kAudioFileAIFFType; filename = CFURLCreateFromFileSystemRepresentation (NULL, (const UInt8*)argv[1], strlen (argv[1]), false); AudioFileCreateWithURL ( filename, fileFormat, &aqc.mDataFormat, kAudioFileFlags_EraseFile, &aqc.outputFile ); /* Initialize the recording buffers */ for(i=0; i<AUDIO_BUFFERS; i++) { AudioQueueAllocateBuffer (aqc.queue, aqc.frameSize, &aqc.mBuffers[i]); AudioQueueEnqueueBuffer (aqc.queue, aqc.mBuffers[i], 0, NULL); //AudioQueueEnqueueBuffer (aqc.queue, aqc.mBuffers[i], 0x11, (const AudioStreamPacketDescription)"\x22"); } aqc.recPtr = 0; aqc.run = 1; AudioQueueStart (aqc.queue, NULL); /* Hang around for a while while the recording takes place */ tv.tv_sec = atof(argv[2]); tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); /* Shut down recording */ AudioQueueStop (aqc.queue, true); aqc.run = 0; AudioQueueDispose (aqc.queue, true); AudioFileClose (aqc.outputFile); exit(EXIT_SUCCESS); }
Create dummy audio file in iPhone
I woud like to programatically create and save to disk a dummy audio file to use in unit tests involving AVAudioPlayer. What's the simplest way to do this in iOS?
You can either record some random noise for some duration using AVAudioRecord. Alternatively, you can create one wave file from scratch using details given in following link : http://www.iphonedevsdk.com/forum/iphone-sdk-development/45613-creating-audio-programmatically.html Edit: link is dead. Try this https://web.archive.org/web/20120701191443/http://www.iphonedevsdk.com/forum/iphone-sdk-development/45613-creating-audio-programmatically.html NSString *path = [[NSBundle mainBundle] pathForResource:#"WavHeader" ofType:#"wav"]; NSMutableData *audioData = [[NSMutableData alloc] initWithContentsOfFile:path]; int samples = 22050; uint8_t dataToRecord[samples]; int x; for(x = 0; x < samples; x++) { // populate the "dataToRecord" array with audio data. // } [audioData appendBytes:(const void *)dataToRecord length:samples]; // Get path to documents folder and set a file name // [audioData writeToFile:pathToFile atomically:YES];
A colleague suggested an alternative solution: create the smallest audio file possible with Audacitiy, get its bytes, and copy them into the code. This is the result: const char bytes[] = {0x52, 0x49, 0x46, 0x46, 0x26, 0x0, 0x0, 0x0, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x0, 0x0, 0x0, 0x1, 0x0, 0x1, 0x0, 0x44, 0xac, 0x0, 0x0, 0x88, 0x58, 0x1, 0x0, 0x2, 0x0, 0x10, 0x0, 0x64, 0x61, 0x74, 0x61, 0x2, 0x0, 0x0, 0x0, 0xfc, 0xff}; NSData* data = [NSData dataWithBytes:bytes length:sizeof(bytes)]; NSString* filePath = [path_ stringByAppendingPathComponent:#"test.wav"]; [data writeToFile:filePath atomically:YES]; audioURL_ = [NSURL fileURLWithPath:filePath];