e-MMC returns FR_OK at very first bring-up but mk_dir return FR_NO_FILESYSTEM - fatfs

I am using stm32H753xx and Cube FatFs library.
After our e-MMC has been soldered to our board, I want to bring-up.
My startup codes is here:
res = f_mount(&fat_fs, "0:", 0);
if (res != FR_OK) {
res = f_mkfs("", FM_ANY, 0, work, sizeof(work));
if (res != FR_OK) {
while(1) {
LOGGER_REPORT(FORMAT_REQUEST_FAILED);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
res = f_mount(&fat_fs, "0:", 0);
if (res != FR_OK) {
while(1) {
LOGGER_REPORT(FORMATTED_BUT_NOT_MOUNTED);
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
}
I generally expect an error at mounting phase if bringing-up of a memory device is very first time and this implies why I made my software branch to f_mkfs functions if f_mount fails. But f_mount is returning FR_OK and software is skipping here.
Afterwards, I am doing some api calls to detect latest directory in the root and to create new one by giving a name in way that would be latest+1. ( latest is like ./70/ new one ./71/ anyway)
There are some api calls here f_opendir, f_readdir, f_closedir respectively and all of them returns succesfully but,
whenever I want to create new dir by calling fs_mkdir, it returns FR_NO_FILESYTEM.
If I call f_mkfs after f_mount above, a FAT is creating and software works but I can not call f_mkfs ile that and could not figure it out where I have to put this code to make it run only once at very initial bring-up of e-MMC.

Related

How can I determine the debugged program/process in handlers of EnvDTE.Events.DebuggerEvents?

I am creating a Visual Studio Extension that performs some tasks when debugging of a specific application is stopped. This is my code for handling the debugger event:
...
DTE2 ide = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;
if (ide != null)
{
debuggerEvents = ide.Events.DebuggerEvents;
debuggerEvents.OnEnterDesignMode += DebuggerEvents_OnEnterDesignMode;
}
}
private static void DebuggerEvents_OnEnterDesignMode(dbgEventReason Reason)
{
ThreadHelper.ThrowIfNotOnUIThread();
DTE2 ide = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE2;
if (ide != null && ide.Debugger.CurrentProcess != null)
{
DebuggedProcName = ide.Debugger.CurrentProcess.Name;
}
if (Reason == dbgEventReason.dbgEventReasonStopDebugging &&
DebuggedProcName == "MyApp")
{
...
}
}
The problem is that ide.Debugger.CurrentProcess and .CurrentProgram is null in OnEnterDesignMode(). They are not null in OnEnterBreakMode() but that one might not be called. How can I determine the currently debugged program/process in a Visual Studio extension?
I wanted to perform a specific task if debugging of a certain project is stopped. Since using the event handler seems impossible I helped myself with a menu command that is executed when I press Ctrl + F5. After performing the task this command also kills the debugged process which effectively stops debugging. Rather rude, I guess, but I can live with this solution.

Flutter Blue Writing Automatically

I have used Flutter Blue for a college work, where I need to create an application to fetch and pass information to an equipment. The passing of this data must be automatic, as in any application (after all the end user should not look for the services and characteristics necessary to carry out the process). The problem is that I am not being able to perform the data passing soon after connecting with the device.
I'm using the App example I downloaded at https://github.com/pauldemarco/flutter_blue, so the basic idea is that as soon as I connect to my bluetooth device I send a message to a certain device. There is already an answered question that has the interest of setting notifications when connecting at Flutter Blue Setting Notifications
I followed the same example but instead of using _setNotification (c) I used the _writeCharacteristic (c), but it does not work.
_connect(BluetoothDevice d) async {
device = d;
// Connect to device
deviceConnection = _flutterBlue
.connect(device, timeout: const Duration(seconds: 4))
.listen(
null,
onDone: _disconnect,
);
// Update the connection state immediately
device.state.then((s) {
setState(() {
deviceState = s;
});
});
// Subscribe to connection changes
deviceStateSubscription = device.onStateChanged().listen((s) {
setState(() {
deviceState = s;
});
if (s == BluetoothDeviceState.connected) {
device.discoverServices().then((s) {
services = s;
for(BluetoothService service in services) {
for(BluetoothCharacteristic c in service.characteristics) {
if(c.uuid == new Guid("06d1e5e7-79ad-4a71-8faa-373789f7d93c")) {
_writeCharacteristic(c);
} else {
print("Nope");
}
}
}
setState(() {
services = s;
});
});
}
});
}
I have changed the original code so that it prints me the notifications as soon as I perform the writing method. The notifications should show me a standard message that is in the firmware of the device, but instead it is printing me the Local Name of the bluetooth chip, being that if I select the service and characteristic manually the return is the correct message.
You'd need to elaborate how you're executing writes on the descriptor - inside _writeCharacteristic(c).
BluetoothDescriptor.write() is a Future per docs, you should be able to catch any errors thrown during write.

How to recognize changes in log file

I'm trying to write a java program that reacts if a new entry occures in the file C:/xampp/apache/logs/access.log in order to recognize a new request to my Apache Server.
I used the following code:
public static void monitor() throws IOException {
WatchService watcher = FileSystems.getDefault().newWatchService();
File file = new File("C:/xampp/apache/logs/");
Path dir = file.toPath();
dir.register(watcher, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY, OVERFLOW);
for (;;) {
// wait for key to be signaled
WatchKey key;
try {
key = watcher.take();
} catch (InterruptedException x) {
return;
}
for (WatchEvent<?> event : key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
// get file name
#SuppressWarnings("unchecked")
WatchEvent<Path> ev = (WatchEvent<Path>) event;
Path fileName = ev.context();
System.out.println(kind.name() + ": " + fileName);
if (kind == OVERFLOW) {
continue;
} else if (kind == ENTRY_CREATE) {
System.out.println("entry created occured");
// process create event
} else if (kind == ENTRY_DELETE) {
// process delete event
} else if (kind == ENTRY_MODIFY && fileName.toString().equals("access.log")) {
System.out.println("entry modified occured");
// process modify event
}
}
// Reset the key -- this step is critical if you want to
// receive further watch events. If the key is no longer valid,
// the directory is inaccessible so exit the loop.
boolean valid = key.reset();
if (!valid) {
break;
}
}
}
But it does not recognize the change in access.log until I manually open the file. Is there something wrong with my code?
There are differents options.
There are two questions that can be kind of similiar, the only difference is that they want to check a whole direcotry instead of just a file, but you could adapt the code to detect if the modified file is the one that you want.
Watching a Directory for Changes in Java
Java detect changes in filesystem
For a specific solution I've found
http://www.rgagnon.com/javadetails/java-0490.html
This code launches a thread that checks the lastModified value of the file, if it's different from the previous one, it means that the file has been modified. I don't know if it's very efficient, check them out.

libspotify does not connect

I'm trying to get familiar with libspotify and I must say the documentation on libspotify is seriously lacking. I've hacked together a small app from the examples but I can't get it to work.
I'm building a C Console Application in Visual Studio 2012. The appkey is correct.
sp_session_config config;
sp_error error;
sp_session *session;
char *blob = NULL;
memset(&config, 0, sizeof(config));
config.api_version = SPOTIFY_API_VERSION;
config.cache_location = "tmp";
config.settings_location = "tmp";
config.application_key = g_appkey;
config.application_key_size = g_appkey_size;
config.user_agent = "SpotiTest";
error = sp_session_create(&config, &session);
if (SP_ERROR_OK != error) {
fprintf(stderr, "failed to create session: %s\n",
sp_error_message(error));
return;
}
error = sp_session_login(session, "USERNAME", "PASSWORD", 1, blob);
if (SP_ERROR_OK != error) {
fprintf(stderr, "failed to log in to Spotify: %s\n",
sp_error_message(error));
sp_session_release(session);
exit(4);
}
sp_connectionstate cs = sp_session_connectionstate (session);
No matter what the username and password (false or correct) sp_session_login always returns SP_ERROR_OK. When I check the connection state with sp_session_connectionstate it always returns SP_CONNECTION_STATE_LOGGED_OUT.
I'm not seeing what I'm doing wrong here and also can't seem to find any relevant answers through the regular channels.
The API is asynchronous. sp_session_login returns immediately, and the login process continues in the background. Look at the examples that come with the API. You need some kind of event loop to call sp_session_process_events, or libspotify won't get any work done, and you probably want to wait until you receive the logged_in callback.

Reading / writing file on local machine

I pretty much copied this code right out of the MDN File I/O page.. except I added an if statement to check if the file exists already and if it does, read it instead.
Components.utils.import("resource://gre/modules/NetUtil.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");
var file = Components.classes["#mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("Desk", Components.interfaces.nsIFile);
file.append("test.txt");
if (!file.exists()) {
this.user_id = Math.floor(Math.random()*10001) +'-'+ Math.floor(Math.random()*10001) +'-'+ Math.floor(Math.random()*10001) +'-'+ Math.floor(Math.random()*10001);
var ostream = FileUtils.openSafeFileOutputStream(file)
var converter = Components.classes["#mozilla.org/intl/scriptableunicodeconverter"].
createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
var istream = converter.convertToInputStream(this.user_id);
// The last argument (the callback) is optional.
NetUtil.asyncCopy(istream, ostream, function(status) {
if (!Components.isSuccessCode(status)) {
alert('Error '+ status);
return;
}
alert('File created');
});
} else
{
NetUtil.asyncFetch(file, function(inputStream, status) {
if (!Components.isSuccessCode(status)) {
alert('error '+ status);
return;
}
// The file data is contained within inputStream.
// You can read it into a string with
this.user_id = NetUtil.readInputStreamToString(inputStream, inputStream.available());
});
alert('File exists already, do not create');
}
alert(this.user_id);
It creates the file just fine, I can open it and read it. If the file already exists however, it does not populate this.user_id.. just equals null. So my issue is specifically with reading the file.
File reading in your code works asynchronously - meaning that your code completes (including the alert() call which will show that this.user_id is null), then at some point the callback from NetUtil.asyncFetch() gets called with the data. Until that happens this.user_id won't be set of course. If you move alert(this.user_id) into the callback function it should show the correct value.
Note that it is highly recommended to keep file I/O operations asynchronous because they might take significant time depending on the current state of the file system. But you have to structure your code in such a way that it doesn't assume that file operations happen immediately.

Resources